Skip to content

Commit f1924d3

Browse files
committed
Cleanup macros
1 parent 5217495 commit f1924d3

File tree

1 file changed

+55
-79
lines changed

1 file changed

+55
-79
lines changed

include/fmt/base.h

+55-79
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,19 @@
131131
# define FMT_CONSTEXPR20
132132
#endif
133133

134+
#if defined(FMT_USE_NONTYPE_TEMPLATE_ARGS)
135+
// Use the provided definition.
136+
#elif defined(__NVCOMPILER)
137+
# define FMT_USE_NONTYPE_TEMPLATE_ARGS 0
138+
#elif FMT_GCC_VERSION >= 903 && FMT_CPLUSPLUS >= 201709L
139+
# define FMT_USE_NONTYPE_TEMPLATE_ARGS 0
140+
#elif defined(__cpp_nontype_template_args) && \
141+
__cpp_nontype_template_args >= 201911L
142+
# define FMT_USE_NONTYPE_TEMPLATE_ARGS 1
143+
#else
144+
# define FMT_USE_NONTYPE_TEMPLATE_ARGS 0
145+
#endif
146+
134147
// Check if exceptions are disabled.
135148
#ifdef FMT_EXCEPTIONS
136149
// Use the provided definition.
@@ -197,6 +210,13 @@
197210
# endif
198211
#endif
199212

213+
// GCC < 5 requires this-> in decltype.
214+
#if FMT_GCC_VERSION && FMT_GCC_VERSION < 500
215+
# define FMT_DECLTYPE_THIS this->
216+
#else
217+
# define FMT_DECLTYPE_THIS
218+
#endif
219+
200220
#if FMT_MSC_VERSION
201221
# define FMT_MSC_WARNING(...) __pragma(warning(__VA_ARGS__))
202222
# define FMT_UNCHECKED_ITERATOR(It) \
@@ -238,30 +258,9 @@
238258
# define FMT_UNICODE !FMT_MSC_VERSION
239259
#endif
240260

241-
#ifndef FMT_USE_NONTYPE_TEMPLATE_ARGS
242-
# if defined(__cpp_nontype_template_args) && \
243-
((FMT_GCC_VERSION >= 903 && FMT_CPLUSPLUS >= 201709L) || \
244-
__cpp_nontype_template_args >= 201911L) && \
245-
!defined(__NVCOMPILER) && !defined(__LCC__)
246-
# define FMT_USE_NONTYPE_TEMPLATE_ARGS 1
247-
# else
248-
# define FMT_USE_NONTYPE_TEMPLATE_ARGS 0
249-
# endif
250-
#endif
251-
252-
// GCC < 5 requires this-> in decltype.
253-
#ifndef FMT_DECLTYPE_THIS
254-
# if FMT_GCC_VERSION && FMT_GCC_VERSION < 500
255-
# define FMT_DECLTYPE_THIS this->
256-
# else
257-
# define FMT_DECLTYPE_THIS
258-
# endif
259-
#endif
260-
261261
// Enable minimal optimizations for more compact code in debug mode.
262262
FMT_GCC_PRAGMA("GCC push_options")
263-
#if !defined(__OPTIMIZE__) && !defined(__NVCOMPILER) && !defined(__LCC__) && \
264-
!defined(__CUDACC__)
263+
#if !defined(__OPTIMIZE__) && !defined(__CUDACC__)
265264
FMT_GCC_PRAGMA("GCC optimize(\"Og\")")
266265
#endif
267266

@@ -777,10 +776,8 @@ class compile_parse_context : public basic_format_parse_context<Char> {
777776

778777
FMT_CONSTEXPR void check_dynamic_spec(int arg_id) {
779778
detail::ignore_unused(arg_id);
780-
#if !defined(__LCC__)
781779
if (arg_id < num_args_ && types_ && !is_integral_type(types_[arg_id]))
782780
throw_format_error("width/precision is not integer");
783-
#endif
784781
}
785782
};
786783

@@ -1315,42 +1312,33 @@ template <typename T>
13151312
struct has_format_as
13161313
: bool_constant<!std::is_same<format_as_t<T>, void>::value> {};
13171314

1315+
#define FMT_MAP_API FMT_CONSTEXPR FMT_INLINE
1316+
13181317
// Maps formatting arguments to core types.
13191318
// arg_mapper reports errors by returning unformattable instead of using
13201319
// static_assert because it's used in the is_formattable trait.
13211320
template <typename Context> struct arg_mapper {
13221321
using char_type = typename Context::char_type;
13231322

1324-
FMT_CONSTEXPR FMT_INLINE auto map(signed char val) -> int { return val; }
1325-
FMT_CONSTEXPR FMT_INLINE auto map(unsigned char val) -> unsigned {
1323+
FMT_MAP_API auto map(signed char val) -> int { return val; }
1324+
FMT_MAP_API auto map(unsigned char val) -> unsigned { return val; }
1325+
FMT_MAP_API auto map(short val) -> int { return val; }
1326+
FMT_MAP_API auto map(unsigned short val) -> unsigned { return val; }
1327+
FMT_MAP_API auto map(int val) -> int { return val; }
1328+
FMT_MAP_API auto map(unsigned val) -> unsigned { return val; }
1329+
FMT_MAP_API auto map(long val) -> long_type { return val; }
1330+
FMT_MAP_API auto map(unsigned long val) -> ulong_type { return val; }
1331+
FMT_MAP_API auto map(long long val) -> long long { return val; }
1332+
FMT_MAP_API auto map(unsigned long long val) -> unsigned long long {
13261333
return val;
13271334
}
1328-
FMT_CONSTEXPR FMT_INLINE auto map(short val) -> int { return val; }
1329-
FMT_CONSTEXPR FMT_INLINE auto map(unsigned short val) -> unsigned {
1330-
return val;
1331-
}
1332-
FMT_CONSTEXPR FMT_INLINE auto map(int val) -> int { return val; }
1333-
FMT_CONSTEXPR FMT_INLINE auto map(unsigned val) -> unsigned { return val; }
1334-
FMT_CONSTEXPR FMT_INLINE auto map(long val) -> long_type { return val; }
1335-
FMT_CONSTEXPR FMT_INLINE auto map(unsigned long val) -> ulong_type {
1336-
return val;
1337-
}
1338-
FMT_CONSTEXPR FMT_INLINE auto map(long long val) -> long long { return val; }
1339-
FMT_CONSTEXPR FMT_INLINE auto map(unsigned long long val)
1340-
-> unsigned long long {
1341-
return val;
1342-
}
1343-
FMT_CONSTEXPR FMT_INLINE auto map(int128_opt val) -> int128_opt {
1344-
return val;
1345-
}
1346-
FMT_CONSTEXPR FMT_INLINE auto map(uint128_opt val) -> uint128_opt {
1347-
return val;
1348-
}
1349-
FMT_CONSTEXPR FMT_INLINE auto map(bool val) -> bool { return val; }
1335+
FMT_MAP_API auto map(int128_opt val) -> int128_opt { return val; }
1336+
FMT_MAP_API auto map(uint128_opt val) -> uint128_opt { return val; }
1337+
FMT_MAP_API auto map(bool val) -> bool { return val; }
13501338

13511339
template <typename T, FMT_ENABLE_IF(std::is_same<T, char>::value ||
13521340
std::is_same<T, char_type>::value)>
1353-
FMT_CONSTEXPR FMT_INLINE auto map(T val) -> char_type {
1341+
FMT_MAP_API auto map(T val) -> char_type {
13541342
return val;
13551343
}
13561344
template <typename T, enable_if_t<(std::is_same<T, wchar_t>::value ||
@@ -1361,42 +1349,32 @@ template <typename Context> struct arg_mapper {
13611349
std::is_same<T, char32_t>::value) &&
13621350
!std::is_same<T, char_type>::value,
13631351
int> = 0>
1364-
FMT_CONSTEXPR FMT_INLINE auto map(T) -> unformattable_char {
1352+
FMT_MAP_API auto map(T) -> unformattable_char {
13651353
return {};
13661354
}
13671355

1368-
FMT_CONSTEXPR FMT_INLINE auto map(float val) -> float { return val; }
1369-
FMT_CONSTEXPR FMT_INLINE auto map(double val) -> double { return val; }
1370-
FMT_CONSTEXPR FMT_INLINE auto map(long double val) -> long double {
1371-
return val;
1372-
}
1356+
FMT_MAP_API auto map(float val) -> float { return val; }
1357+
FMT_MAP_API auto map(double val) -> double { return val; }
1358+
FMT_MAP_API auto map(long double val) -> long double { return val; }
13731359

1374-
FMT_CONSTEXPR FMT_INLINE auto map(char_type* val) -> const char_type* {
1375-
return val;
1376-
}
1377-
FMT_CONSTEXPR FMT_INLINE auto map(const char_type* val) -> const char_type* {
1378-
return val;
1379-
}
1360+
FMT_MAP_API auto map(char_type* val) -> const char_type* { return val; }
1361+
FMT_MAP_API auto map(const char_type* val) -> const char_type* { return val; }
13801362
template <typename T, typename Char = char_t<T>,
13811363
FMT_ENABLE_IF(std::is_same<Char, char_type>::value &&
13821364
!std::is_pointer<T>::value)>
1383-
FMT_CONSTEXPR FMT_INLINE auto map(const T& val) -> basic_string_view<Char> {
1365+
FMT_MAP_API auto map(const T& val) -> basic_string_view<Char> {
13841366
return to_string_view(val);
13851367
}
13861368
template <typename T, typename Char = char_t<T>,
13871369
FMT_ENABLE_IF(!std::is_same<Char, char_type>::value &&
13881370
!std::is_pointer<T>::value)>
1389-
FMT_CONSTEXPR FMT_INLINE auto map(const T&) -> unformattable_char {
1371+
FMT_MAP_API auto map(const T&) -> unformattable_char {
13901372
return {};
13911373
}
13921374

1393-
FMT_CONSTEXPR FMT_INLINE auto map(void* val) -> const void* { return val; }
1394-
FMT_CONSTEXPR FMT_INLINE auto map(const void* val) -> const void* {
1395-
return val;
1396-
}
1397-
FMT_CONSTEXPR FMT_INLINE auto map(std::nullptr_t val) -> const void* {
1398-
return val;
1399-
}
1375+
FMT_MAP_API auto map(void* val) -> const void* { return val; }
1376+
FMT_MAP_API auto map(const void* val) -> const void* { return val; }
1377+
FMT_MAP_API auto map(std::nullptr_t val) -> const void* { return val; }
14001378

14011379
// Use SFINAE instead of a const T* parameter to avoid a conflict with the
14021380
// array overload.
@@ -1413,15 +1391,14 @@ template <typename Context> struct arg_mapper {
14131391

14141392
template <typename T, std::size_t N,
14151393
FMT_ENABLE_IF(!std::is_same<T, wchar_t>::value)>
1416-
FMT_CONSTEXPR FMT_INLINE auto map(const T (&values)[N]) -> const T (&)[N] {
1394+
FMT_MAP_API auto map(const T (&values)[N]) -> const T (&)[N] {
14171395
return values;
14181396
}
14191397

14201398
// Only map owning types because mapping views can be unsafe.
14211399
template <typename T, typename U = format_as_t<T>,
14221400
FMT_ENABLE_IF(std::is_arithmetic<U>::value)>
1423-
FMT_CONSTEXPR FMT_INLINE auto map(const T& val)
1424-
-> decltype(FMT_DECLTYPE_THIS map(U())) {
1401+
FMT_MAP_API auto map(const T& val) -> decltype(FMT_DECLTYPE_THIS map(U())) {
14251402
return map(format_as(val));
14261403
}
14271404

@@ -1431,11 +1408,11 @@ template <typename Context> struct arg_mapper {
14311408
!std::is_const<T>::value)> {};
14321409

14331410
template <typename T, FMT_ENABLE_IF(formattable<T>::value)>
1434-
FMT_CONSTEXPR FMT_INLINE auto do_map(T& val) -> T& {
1411+
FMT_MAP_API auto do_map(T& val) -> T& {
14351412
return val;
14361413
}
14371414
template <typename T, FMT_ENABLE_IF(!formattable<T>::value)>
1438-
FMT_CONSTEXPR FMT_INLINE auto do_map(T&) -> unformattable {
1415+
FMT_MAP_API auto do_map(T&) -> unformattable {
14391416
return {};
14401417
}
14411418

@@ -1445,13 +1422,12 @@ template <typename Context> struct arg_mapper {
14451422
!has_to_string_view<U>::value && !is_char<U>::value &&
14461423
!is_named_arg<U>::value &&
14471424
!std::is_arithmetic<format_as_t<U>>::value)>
1448-
FMT_CONSTEXPR FMT_INLINE auto map(T& val)
1449-
-> decltype(FMT_DECLTYPE_THIS do_map(val)) {
1425+
FMT_MAP_API auto map(T& val) -> decltype(FMT_DECLTYPE_THIS do_map(val)) {
14501426
return do_map(val);
14511427
}
14521428

14531429
template <typename T, FMT_ENABLE_IF(is_named_arg<T>::value)>
1454-
FMT_CONSTEXPR FMT_INLINE auto map(const T& named_arg)
1430+
FMT_MAP_API auto map(const T& named_arg)
14551431
-> decltype(FMT_DECLTYPE_THIS map(named_arg.value)) {
14561432
return map(named_arg.value);
14571433
}
@@ -1584,7 +1560,7 @@ struct format_arg_store {
15841560
named_arg_info<typename Context::char_type> named_args[NUM_NAMED_ARGS];
15851561

15861562
template <typename... T>
1587-
FMT_CONSTEXPR FMT_INLINE format_arg_store(T&... values)
1563+
FMT_MAP_API format_arg_store(T&... values)
15881564
: args{{named_args, NUM_NAMED_ARGS},
15891565
make_arg<NUM_ARGS <= max_packed_args, Context>(values)...} {
15901566
using dummy = int[];

0 commit comments

Comments
 (0)