aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Müller <jonathanmueller.dev@gmail.com>2016-11-05 20:59:05 +0100
committerJonathan Müller <jonathanmueller.dev@gmail.com>2016-11-05 21:03:40 +0100
commit6c0125785bc39a57a424164dd07393d733c3982c (patch)
treeccc493e079dbf244ba569c3bf7a7a0f0eda1a500
parent49ccb2e4497ce3d2acae9c0cca81756aa341627d (diff)
downloadfmtlib-6c0125785bc39a57a424164dd07393d733c3982c.tar.gz
Add extern templates for format_float
Fixes #413.
-rw-r--r--fmt/format.h41
1 files changed, 34 insertions, 7 deletions
diff --git a/fmt/format.h b/fmt/format.h
index 87e449ed..c84e3a0d 100644
--- a/fmt/format.h
+++ b/fmt/format.h
@@ -255,6 +255,21 @@ typedef __int64 intmax_t;
(!defined(FMT_ICC_VERSION) || FMT_ICC_VERSION >= 1500)
#endif
+#ifndef FMT_USE_EXTERN_TEMPLATES
+// Clang doesn't have a feature check for extern templates so we check
+// for variadic templates which were introduced in the same version.
+// For GCC according to cppreference.com they were introduced in 3.3.
+# define FMT_USE_EXTERN_TEMPLATES \
+ ((__clang__ && FMT_USE_VARIADIC_TEMPLATES) || \
+ FMT_GCC_VERSION >= 303)
+#endif
+
+#ifdef FMT_HEADER_ONLY
+// If header only do not use extern templates.
+# undef FMT_USE_EXTERN_TEMPLATES
+# define FMT_USE_EXTERN_TEMPLATES 0
+#endif
+
#ifndef FMT_ASSERT
# define FMT_ASSERT(condition, message) assert((condition) && message)
#endif
@@ -812,6 +827,15 @@ class CharTraits<char> : public BasicCharTraits<char> {
const char *format, unsigned width, int precision, T value);
};
+#if FMT_USE_EXTERN_TEMPLATES
+extern template int CharTraits<char>::format_float<double>
+ (char *buffer, std::size_t size,
+ const char* format, unsigned width, int precision, double value);
+extern template int CharTraits<char>::format_float<long double
+ (char *buffer, std::size_t size,
+ const char* format, unsigned width, int precision, long double value);
+#endif
+
template <>
class CharTraits<wchar_t> : public BasicCharTraits<wchar_t> {
public:
@@ -823,6 +847,15 @@ class CharTraits<wchar_t> : public BasicCharTraits<wchar_t> {
const wchar_t *format, unsigned width, int precision, T value);
};
+#if FMT_USE_EXTERN_TEMPLATES
+extern template int CharTraits<wchar_t>::format_float<double>
+ (wchar_t *buffer, std::size_t size,
+ const wchar_t* format, unsigned width, int precision, double value);
+extern template int CharTraits<wchar_t>::format_float<long double>
+ (wchar_t *buffer, std::size_t size,
+ const wchar_t* format, unsigned width, int precision, long double value);
+#endif
+
// Checks if a number is negative - used to avoid warnings.
template <bool IsSigned>
struct SignChecker {
@@ -869,13 +902,7 @@ struct FMT_API BasicData {
static const char DIGITS[];
};
-#ifndef FMT_USE_EXTERN_TEMPLATES
-// Clang doesn't have a feature check for extern templates so we check
-// for variadic templates which were introduced in the same version.
-# define FMT_USE_EXTERN_TEMPLATES (__clang__ && FMT_USE_VARIADIC_TEMPLATES)
-#endif
-
-#if FMT_USE_EXTERN_TEMPLATES && !defined(FMT_HEADER_ONLY)
+#if FMT_USE_EXTERN_TEMPLATES
extern template struct BasicData<void>;
#endif