Improvements detection of features, part 15, added FASTFLOAT_NO_UNIQUE_ADDRESS and improves more.

This commit is contained in:
HedgehogInTheCPP 2026-08-25 22:54:57 +03:00
parent 9b65f41bbf
commit 870fc1a720
3 changed files with 59 additions and 33 deletions

View File

@ -473,19 +473,19 @@ enum class parse_error : uint_fast8_t {
};
template <typename UC> struct parsed_number_string_t {
am_mant_t mantissa;
am_pow_t exponent;
UC const *lastmatch;
FASTFLOAT_NO_UNIQUE_ADDRESS am_mant_t mantissa;
FASTFLOAT_NO_UNIQUE_ADDRESS am_pow_t exponent;
FASTFLOAT_NO_UNIQUE_ADDRESS UC const *lastmatch;
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
bool negative;
FASTFLOAT_NO_UNIQUE_ADDRESS bool negative;
#endif
bool invalid;
bool too_many_digits;
parse_error error;
FASTFLOAT_NO_UNIQUE_ADDRESS bool invalid;
FASTFLOAT_NO_UNIQUE_ADDRESS bool too_many_digits;
FASTFLOAT_NO_UNIQUE_ADDRESS parse_error error;
// contains the range of the significant digits
span<UC const> integer; // non-nullable
span<UC const> fraction; // nullable
FASTFLOAT_NO_UNIQUE_ADDRESS span<UC const> integer; // non-nullable
FASTFLOAT_NO_UNIQUE_ADDRESS span<UC const> fraction; // nullable
};
using byte_span = span<char const>;
@ -774,9 +774,8 @@ parse_int_string(UC const *p, UC const *pend, T &value,
FASTFLOAT_ASSUME(p < pend); // so dereference without checks
from_chars_result_t<UC> answer;
auto const *const first = p;
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
auto const *const first = p;
// Read sign
auto const negative = (*p == UC('-'));
#ifdef FASTFLOAT_VISUAL_STUDIO

View File

@ -1,16 +1,42 @@
#ifndef FASTFLOAT_CONSTEXPR_FEATURE_DETECT_H
#define FASTFLOAT_CONSTEXPR_FEATURE_DETECT_H
#ifdef __has_include
#if __has_include(<version>)
#include <version>
#ifdef _MSVC_LANG
#define FASTFLOAT_CPLUSPLUS _MSVC_LANG
#else
#define FASTFLOAT_CPLUSPLUS __cplusplus
#endif
// Detect __has_*.
#ifdef __has_feature
#define FASTFLOAT_HAS_FEATURE(x) __has_feature(x)
#else
#define FASTFLOAT_HAS_FEATURE(x) 0
#endif
#ifdef __has_include
#define FASTFLOAT_HAS_INCLUDE(x) __has_include(x)
#else
#define FASTFLOAT_HAS_INCLUDE(x) 0
#endif
#ifdef __has_builtin
#define FASTFLOAT_HAS_BUILTIN(x) __has_builtin(x)
#else
#define FASTFLOAT_HAS_BUILTIN(x) 0
#endif
#ifdef __has_cpp_attribute
#define FASTFLOAT_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
#else
#define FASTFLOAT_HAS_CPP_ATTRIBUTE(x) 0
#endif
#if FASTFLOAT_HAS_INCLUDE(<version>)
#include <version>
#endif
// C++14 constexpr
#if defined(__cpp_constexpr) && __cpp_constexpr >= 201304L
#define FASTFLOAT_CONSTEXPR14 constexpr
#elif __cplusplus >= 201402L
#elif FASTFLOAT_CPLUSPLUS >= 201402L
#define FASTFLOAT_CONSTEXPR14 constexpr
#elif defined(_MSC_VER) && _MSC_VER >= 1910 && _MSVC_LANG >= 201402L
#define FASTFLOAT_CONSTEXPR14 constexpr
@ -21,10 +47,7 @@
// C++14 variable templates
#if defined(__cpp_variable_templates) && __cpp_variable_templates >= 201304L
#define FASTFLOAT_HAS_VARIABLE_TEMPLATES 1
#elif __cplusplus >= 201402L
#define FASTFLOAT_HAS_VARIABLE_TEMPLATES 1
#elif defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 190023918L && \
defined(_MSC_VER) && _MSVC_LANG >= 201402L
#elif FASTFLOAT_CPLUSPLUS >= 201402L
#define FASTFLOAT_HAS_VARIABLE_TEMPLATES 1
#else
#define FASTFLOAT_HAS_VARIABLE_TEMPLATES 0
@ -35,9 +58,7 @@
#define FASTFLOAT_CONSTEXPR17 constexpr
#elif defined(__cpp_constexpr) && __cpp_constexpr >= 201603L
#define FASTFLOAT_CONSTEXPR17 constexpr
#elif __cplusplus >= 201703L
#define FASTFLOAT_CONSTEXPR17 constexpr
#elif defined(_MSC_VER) && _MSC_VER >= 1911 && _MSVC_LANG >= 201703L
#elif FASTFLOAT_CPLUSPLUS >= 201703L
#define FASTFLOAT_CONSTEXPR17 constexpr
#else
#define FASTFLOAT_CONSTEXPR17
@ -55,7 +76,7 @@
#endif
// Before C++17 constexpr variables may need an out-of-class definition.
#if __cplusplus >= 201703L || (defined(_MSC_VER) && _MSVC_LANG >= 201703L)
#if FASTFLOAT_CPLUSPLUS >= 201703L
#define FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE 0
#else
#define FASTFLOAT_DETAIL_MUST_DEFINE_CONSTEXPR_VARIABLE 1
@ -92,17 +113,23 @@
#define FASTFLOAT_HAS_BYTESWAP 0
#endif
#if defined(__has_builtin)
#define FASTFLOAT_HAS_BUILTIN(x) __has_builtin(x)
#else
#define FASTFLOAT_HAS_BUILTIN(x) false
#endif
#if defined(__cpp_attrubute_assume)
// For support attribute [[assume]] is declared in P1774
#ifdef FASTFLOAT_ASSUME
// Use the provided definition.
#elif FASTFLOAT_HAS_CPP_ATTRIBUTE(assume)
#define FASTFLOAT_ASSUME(expr) [[assume(expr)]]
#else
#define FASTFLOAT_ASSUME(expr)
#endif
#ifdef FASTFLOAT_NO_UNIQUE_ADDRESS
// Use the provided definition.
#elif FASTFLOAT_CPLUSPLUS < 202002L
// Not supported.
#elif FASTFLOAT_HAS_CPP_ATTRIBUTE(no_unique_address)
#define FASTFLOAT_NO_UNIQUE_ADDRESS [[no_unique_address]]
// VS2019 v16.10 and later except clang-cl (https://reviews.llvm.org/D110485).
#elif defined(_MSC_VER) && _MSC_VER >= 1929 && !defined(__clang__)
#define FASTFLOAT_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
#endif
#endif // FASTFLOAT_CONSTEXPR_FEATURE_DETECT_H

View File

@ -687,8 +687,8 @@ full_multiplication(uint64_t a, uint64_t b) noexcept {
/* alignas(16) - better data cache usage without align */
struct adjusted_mantissa {
am_mant_t mantissa;
am_pow_t power2;
FASTFLOAT_NO_UNIQUE_ADDRESS am_mant_t mantissa;
FASTFLOAT_NO_UNIQUE_ADDRESS am_pow_t power2;
constexpr adjusted_mantissa() noexcept : mantissa(0), power2(0) {}