use is_constant_evaluated() to initialize class value` with string
This commit is contained in:
parent
6742642dcd
commit
de42f13712
@ -283,6 +283,14 @@ struct monostate {};
|
|||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
|
constexpr bool is_constant_evaluated() FMT_DETECTED_NOEXCEPT {
|
||||||
|
#ifdef __cpp_lib_is_constant_evaluated
|
||||||
|
return std::is_constant_evaluated();
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// A helper function to suppress "conditional expression is constant" warnings.
|
// A helper function to suppress "conditional expression is constant" warnings.
|
||||||
template <typename T> constexpr T const_check(T value) { return value; }
|
template <typename T> constexpr T const_check(T value) { return value; }
|
||||||
|
|
||||||
@ -1082,7 +1090,12 @@ template <typename Context> class value {
|
|||||||
FMT_INLINE value(long double val) : long_double_value(val) {}
|
FMT_INLINE value(long double val) : long_double_value(val) {}
|
||||||
constexpr FMT_INLINE value(bool val) : bool_value(val) {}
|
constexpr FMT_INLINE value(bool val) : bool_value(val) {}
|
||||||
constexpr FMT_INLINE value(char_type val) : char_value(val) {}
|
constexpr FMT_INLINE value(char_type val) : char_value(val) {}
|
||||||
FMT_CONSTEXPR value(const char_type* val) : string() { string.data = val; }
|
FMT_CONSTEXPR value(const char_type* val) {
|
||||||
|
string.data = val;
|
||||||
|
if (is_constant_evaluated()) {
|
||||||
|
string.size = {};
|
||||||
|
}
|
||||||
|
}
|
||||||
FMT_CONSTEXPR value(basic_string_view<char_type> val) {
|
FMT_CONSTEXPR value(basic_string_view<char_type> val) {
|
||||||
string.data = val.data();
|
string.data = val.data();
|
||||||
string.size = val.size();
|
string.size = val.size();
|
||||||
|
|||||||
@ -288,14 +288,6 @@ namespace detail {
|
|||||||
# define FMT_CONSTEXPR20 inline
|
# define FMT_CONSTEXPR20 inline
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
constexpr bool is_constant_evaluated() FMT_DETECTED_NOEXCEPT {
|
|
||||||
#ifdef __cpp_lib_is_constant_evaluated
|
|
||||||
return std::is_constant_evaluated();
|
|
||||||
#else
|
|
||||||
return false;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// An equivalent of `*reinterpret_cast<Dest*>(&source)` that doesn't have
|
// An equivalent of `*reinterpret_cast<Dest*>(&source)` that doesn't have
|
||||||
// undefined behavior (e.g. due to type aliasing).
|
// undefined behavior (e.g. due to type aliasing).
|
||||||
// Example: uint64_t d = bit_cast<uint64_t>(2.718);
|
// Example: uint64_t d = bit_cast<uint64_t>(2.718);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user