From bce5b364d39add56025713a01a5af9f331d3ce0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Mon, 3 Feb 2020 20:48:44 +0100 Subject: [PATCH] Unconditionally provide StringMakers --- docs/configuration.md | 1 - docs/release-notes.md | 3 ++- src/catch2/catch_tostring.cpp | 11 ----------- src/catch2/catch_tostring.h | 19 +++++++++---------- .../UsageTests/ToStringChrono.tests.cpp | 1 - 5 files changed, 11 insertions(+), 24 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 4b7af698..8dc80e95 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -206,7 +206,6 @@ By default, Catch does not stringify some types from the standard library. This CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER // Provide StringMaker specialization for std::pair CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER // Provide StringMaker specialization for std::tuple - CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER // Provide StringMaker specialization for std::chrono::duration, std::chrono::timepoint CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER // Provide StringMaker specialization for std::variant, std::monostate (on C++17) CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER // Provide StringMaker specialization for std::optional (on C++17) CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS // Defines all of the above diff --git a/docs/release-notes.md b/docs/release-notes.md index baf34a2d..7a5b5fce 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -59,7 +59,8 @@ ### Other changes * `CATCH_CONFIG_DISABLE_MATCHERS` no longer exists. * If you do not want to use Matchers in a TU, do not include their header. - +* `CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER` no longer exists. + * `StringMaker` specializations for are always provided ## 2.10.2 diff --git a/src/catch2/catch_tostring.cpp b/src/catch2/catch_tostring.cpp index 913cd22b..0e3abbde 100644 --- a/src/catch2/catch_tostring.cpp +++ b/src/catch2/catch_tostring.cpp @@ -12,10 +12,6 @@ # pragma clang diagnostic ignored "-Wglobal-constructors" #endif -// Enable specific decls locally -#if !defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER) -#define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER -#endif #include #include @@ -250,13 +246,6 @@ std::string StringMaker::convert(double value) { return fpToString(value, precision); } -std::string ratio_string::symbol() { return "a"; } -std::string ratio_string::symbol() { return "f"; } -std::string ratio_string::symbol() { return "p"; } -std::string ratio_string::symbol() { return "n"; } -std::string ratio_string::symbol() { return "u"; } -std::string ratio_string::symbol() { return "m"; } - } // end namespace Catch #if defined(__clang__) diff --git a/src/catch2/catch_tostring.h b/src/catch2/catch_tostring.h index 57d43a6d..b5339688 100644 --- a/src/catch2/catch_tostring.h +++ b/src/catch2/catch_tostring.h @@ -351,13 +351,12 @@ namespace Catch { ////////////////////////////////////////////////////// // Separate std-lib types stringification, so it can be selectively enabled -// This means that we do not bring in +// This means that we do not bring in their headers #if defined(CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS) # define CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER # define CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER # define CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER -# define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER # define CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER #endif @@ -532,7 +531,6 @@ namespace Catch { } // namespace Catch // Separate std::chrono::duration specialization -#if defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER) #include #include #include @@ -552,29 +550,31 @@ std::string ratio_string::symbol() { << Ratio::den << ']'; return rss.str(); } + + template <> struct ratio_string { - static std::string symbol(); + static std::string symbol() { return "a"; } }; template <> struct ratio_string { - static std::string symbol(); + static std::string symbol() { return "f"; } }; template <> struct ratio_string { - static std::string symbol(); + static std::string symbol() { return "p"; } }; template <> struct ratio_string { - static std::string symbol(); + static std::string symbol() { return "n"; } }; template <> struct ratio_string { - static std::string symbol(); + static std::string symbol() { return "u"; } }; template <> struct ratio_string { - static std::string symbol(); + static std::string symbol() { return "m"; } }; //////////// @@ -647,7 +647,6 @@ struct ratio_string { } }; } -#endif // CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER #include diff --git a/tests/SelfTest/UsageTests/ToStringChrono.tests.cpp b/tests/SelfTest/UsageTests/ToStringChrono.tests.cpp index a2be85a3..27a3dc3d 100644 --- a/tests/SelfTest/UsageTests/ToStringChrono.tests.cpp +++ b/tests/SelfTest/UsageTests/ToStringChrono.tests.cpp @@ -1,4 +1,3 @@ -#define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER #include #include