Commit 8ca6e76d authored by Victor Zverovich's avatar Victor Zverovich

Detect user-defined literal templates

parent a7e98616
...@@ -79,6 +79,10 @@ ...@@ -79,6 +79,10 @@
# endif # endif
#endif #endif
#ifdef __clang__
# define FMT_CLANG_VERSION (__clang_major__ * 100 + __clang_minor__)
#endif
#if defined(__INTEL_COMPILER) #if defined(__INTEL_COMPILER)
# define FMT_ICC_VERSION __INTEL_COMPILER # define FMT_ICC_VERSION __INTEL_COMPILER
#elif defined(__ICL) #elif defined(__ICL)
...@@ -88,6 +92,7 @@ ...@@ -88,6 +92,7 @@
#if defined(__clang__) && !defined(FMT_ICC_VERSION) #if defined(__clang__) && !defined(FMT_ICC_VERSION)
# pragma clang diagnostic push # pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wdocumentation-unknown-command" # pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
# pragma clang diagnostic ignored "-Wgnu-string-literal-operator-template"
# pragma clang diagnostic ignored "-Wpadded" # pragma clang diagnostic ignored "-Wpadded"
#endif #endif
...@@ -185,6 +190,13 @@ ...@@ -185,6 +190,13 @@
# endif # endif
#endif #endif
#if FMT_USE_USER_DEFINED_LITERALS && \
(FMT_GCC_VERSION >= 600 || FMT_CLANG_VERSION >= 304)
# define FMT_UDL_TEMPLATE 1
#else
# define FMT_UDL_TEMPLATE 0
#endif
#ifndef FMT_ASSERT #ifndef FMT_ASSERT
# define FMT_ASSERT(condition, message) assert((condition) && message) # define FMT_ASSERT(condition, message) assert((condition) && message)
#endif #endif
...@@ -3839,10 +3851,27 @@ operator"" _a(const char *s, std::size_t) { return {s}; } ...@@ -3839,10 +3851,27 @@ operator"" _a(const char *s, std::size_t) { return {s}; }
inline internal::UdlArg<wchar_t> inline internal::UdlArg<wchar_t>
operator"" _a(const wchar_t *s, std::size_t) { return {s}; } operator"" _a(const wchar_t *s, std::size_t) { return {s}; }
# if FMT_UDL_TEMPLATE
template <typename Char, Char... CHARS>
struct udl_formatter {
template <typename... Args>
std::string operator()(const Args &... args) const {
const Char s[] = {CHARS...};
// TODO
return s;
}
};
template <typename Char, Char... CHARS>
constexpr auto operator""_format() {
return udl_formatter<Char, CHARS...>();
}
# endif
} // inline namespace literals } // inline namespace literals
} // namespace fmt } // namespace fmt
#endif // FMT_USE_USER_DEFINED_LITERALS #endif // FMT_USE_USER_DEFINED_LITERALS
#ifdef FMT_HEADER_ONLY #ifdef FMT_HEADER_ONLY
# define FMT_FUNC inline # define FMT_FUNC inline
# include "format.cc" # include "format.cc"
......
...@@ -1812,3 +1812,9 @@ TEST(FormatTest, ConstexprParseFormatString) { ...@@ -1812,3 +1812,9 @@ TEST(FormatTest, ConstexprParseFormatString) {
static_assert(parse_string("{foo}"), ""); static_assert(parse_string("{foo}"), "");
static_assert(parse_string("{:}"), ""); static_assert(parse_string("{:}"), "");
} }
#if FMT_UDL_TEMPLATE
TEST(FormatTest, UdlTemplate) {
EXPECT_EQ("foo", "foo"_format());
}
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment