apply requested changes

* `FMT_USE_NONTYPE_TEMPLATE_PARAMETERS` define added
* `std::size_t` changed to `size_t`
This commit is contained in:
Alexey Ochapov 2020-12-02 21:11:53 +03:00
parent 506230ba5d
commit 8c8b1cc74f
No known key found for this signature in database
GPG Key ID: 9DC52E8F031B8DA8
2 changed files with 12 additions and 9 deletions

View File

@ -13,6 +13,12 @@
#include "format.h" #include "format.h"
#if !defined(FMT_USE_NONTYPE_TEMPLATE_PARAMETERS) && \
defined(__cpp_nontype_template_parameter_class) && \
(!FMT_GCC_VERSION || FMT_GCC_VERSION >= 903)
# define FMT_USE_NONTYPE_TEMPLATE_PARAMETERS
#endif
FMT_BEGIN_NAMESPACE FMT_BEGIN_NAMESPACE
namespace detail { namespace detail {
@ -37,9 +43,8 @@ struct is_compiled_string : std::is_base_of<compiled_string, S> {};
*/ */
#define FMT_COMPILE(s) FMT_STRING_IMPL(s, fmt::detail::compiled_string) #define FMT_COMPILE(s) FMT_STRING_IMPL(s, fmt::detail::compiled_string)
#if defined(__cpp_nontype_template_parameter_class) && \ #ifdef FMT_USE_NONTYPE_TEMPLATE_PARAMETERS
(!FMT_GCC_VERSION || FMT_GCC_VERSION >= 903) template <typename Char, size_t N> struct fixed_string {
template <typename Char, std::size_t N> struct fixed_string {
constexpr fixed_string(const Char (&str)[N + 1]) { constexpr fixed_string(const Char (&str)[N + 1]) {
copy_str<Char, const Char*, Char*>(static_cast<const Char*>(str), str + N, copy_str<Char, const Char*, Char*>(static_cast<const Char*>(str), str + N,
data); data);
@ -47,10 +52,10 @@ template <typename Char, std::size_t N> struct fixed_string {
Char data[N]{}; Char data[N]{};
}; };
template <typename Char, std::size_t N> template <typename Char, size_t N>
fixed_string(const Char (&str)[N]) -> fixed_string<Char, N - 1>; fixed_string(const Char (&str)[N]) -> fixed_string<Char, N - 1>;
template <typename Char, std::size_t N, fixed_string<Char, N> Str> template <typename Char, size_t N, fixed_string<Char, N> Str>
struct udl_compiled_string : compiled_string { struct udl_compiled_string : compiled_string {
using char_type = Char; using char_type = Char;
constexpr operator basic_string_view<char_type>() const { constexpr operator basic_string_view<char_type>() const {
@ -720,8 +725,7 @@ size_t formatted_size(const CompiledFormat& cf, const Args&... args) {
return format_to(detail::counting_iterator(), cf, args...).count(); return format_to(detail::counting_iterator(), cf, args...).count();
} }
#if defined(__cpp_nontype_template_parameter_class) && \ #ifdef FMT_USE_NONTYPE_TEMPLATE_PARAMETERS
(!FMT_GCC_VERSION || FMT_GCC_VERSION >= 903)
inline namespace literals { inline namespace literals {
template <detail::fixed_string Str> template <detail::fixed_string Str>
constexpr detail::udl_compiled_string<remove_cvref_t<decltype(Str.data[0])>, constexpr detail::udl_compiled_string<remove_cvref_t<decltype(Str.data[0])>,

View File

@ -179,8 +179,7 @@ TEST(CompileTest, Empty) {
} }
#endif #endif
#if defined(__cpp_nontype_template_parameter_class) && \ #ifdef FMT_USE_NONTYPE_TEMPLATE_PARAMETERS
(!FMT_GCC_VERSION || FMT_GCC_VERSION >= 903)
TEST(CompileTest, CompileFormatStringLiteral) { TEST(CompileTest, CompileFormatStringLiteral) {
using namespace fmt::literals; using namespace fmt::literals;
EXPECT_EQ("42", fmt::format("{}"_cf, 42)); EXPECT_EQ("42", fmt::format("{}"_cf, 42));