FMT_CONSTEXPR_LIB

This commit is contained in:
Shawn Zhong 2023-04-29 05:28:01 -05:00
parent eaf8c1b772
commit 11c3634d6f
2 changed files with 12 additions and 5 deletions

View File

@ -112,6 +112,13 @@
# define FMT_CONSTEXPR20 # define FMT_CONSTEXPR20
#endif #endif
#if defined(__cpp_lib_constexpr_string) && __cpp_lib_constexpr_string >= 201907L && \
defined(__cpp_lib_constexpr_iterator) && __cpp_lib_constexpr_iterator >= 201811L
# define FMT_CONSTEXPR_LIB constexpr
#else
# define FMT_CONSTEXPR_LIB
#endif
// Check if constexpr std::char_traits<>::{compare,length} are supported. // Check if constexpr std::char_traits<>::{compare,length} are supported.
#if defined(__GLIBCXX__) #if defined(__GLIBCXX__)
# if FMT_CPLUSPLUS >= 201703L && defined(_GLIBCXX_RELEASE) && \ # if FMT_CPLUSPLUS >= 201703L && defined(_GLIBCXX_RELEASE) && \
@ -1494,8 +1501,8 @@ class appender : public std::back_insert_iterator<detail::buffer<char>> {
appender(base it) noexcept : base(it) {} appender(base it) noexcept : base(it) {}
FMT_UNCHECKED_ITERATOR(appender); FMT_UNCHECKED_ITERATOR(appender);
FMT_CONSTEXPR20 auto operator++() noexcept -> appender& { return *this; } FMT_CONSTEXPR_LIB auto operator++() noexcept -> appender& { return *this; }
FMT_CONSTEXPR20 auto operator++(int) noexcept -> appender { return *this; } FMT_CONSTEXPR_LIB auto operator++(int) noexcept -> appender { return *this; }
}; };
// A formatting argument. It is a trivially copyable/constructible type to // A formatting argument. It is a trivially copyable/constructible type to
@ -1605,7 +1612,7 @@ FMT_CONSTEXPR FMT_INLINE auto visit_format_arg(
namespace detail { namespace detail {
template <typename Char, typename InputIt> template <typename Char, typename InputIt>
FMT_CONSTEXPR20 auto copy_str(InputIt begin, InputIt end, appender out) FMT_CONSTEXPR_LIB auto copy_str(InputIt begin, InputIt end, appender out)
-> appender { -> appender {
get_container(out).append(begin, end); get_container(out).append(begin, end);
return out; return out;

View File

@ -4465,7 +4465,7 @@ auto join(Range&& range, string_view sep)
\endrst \endrst
*/ */
template <typename T, FMT_ENABLE_IF(!std::is_integral<T>::value)> template <typename T, FMT_ENABLE_IF(!std::is_integral<T>::value)>
FMT_NODISCARD FMT_CONSTEXPR20 inline auto to_string(const T& value) FMT_NODISCARD FMT_CONSTEXPR_LIB inline auto to_string(const T& value)
-> std::string { -> std::string {
auto buffer = memory_buffer(); auto buffer = memory_buffer();
detail::write<char>(appender(buffer), value); detail::write<char>(appender(buffer), value);
@ -4473,7 +4473,7 @@ FMT_NODISCARD FMT_CONSTEXPR20 inline auto to_string(const T& value)
} }
template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value)> template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value)>
FMT_NODISCARD FMT_CONSTEXPR20 inline auto to_string(T value) -> std::string { FMT_NODISCARD FMT_CONSTEXPR_LIB inline auto to_string(T value) -> std::string {
// The buffer should be large enough to store the number including the sign // The buffer should be large enough to store the number including the sign
// or "false" for bool. // or "false" for bool.
constexpr int max_size = detail::digits10<T>() + 2; constexpr int max_size = detail::digits10<T>() + 2;