aboutsummaryrefslogtreecommitdiff
path: root/libcxx/include/__format/concepts.h
diff options
context:
space:
mode:
Diffstat (limited to 'libcxx/include/__format/concepts.h')
-rw-r--r--libcxx/include/__format/concepts.h49
1 files changed, 37 insertions, 12 deletions
diff --git a/libcxx/include/__format/concepts.h b/libcxx/include/__format/concepts.h
index 8df6493b0aed..fe4a7b9625ce 100644
--- a/libcxx/include/__format/concepts.h
+++ b/libcxx/include/__format/concepts.h
@@ -15,6 +15,9 @@
#include <__config>
#include <__format/format_fwd.h>
#include <__format/format_parse_context.h>
+#include <__type_traits/is_specialization.h>
+#include <__utility/pair.h>
+#include <tuple>
#include <type_traits>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -25,6 +28,15 @@ _LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER > 17
+/// The character type specializations of \ref formatter.
+template <class _CharT>
+concept __fmt_char_type =
+ same_as<_CharT, char>
+# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+ || same_as<_CharT, wchar_t>
+# endif
+ ;
+
// The output iterator isn't specified. A formatter should accept any
// output_iterator. This iterator is a minimal iterator to test the concept.
// (Note testing for (w)format_context would be a valid choice, but requires
@@ -32,20 +44,33 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _CharT>
using __fmt_iter_for = _CharT*;
-// The concept is based on P2286R6
-// It lacks the const of __cf as required by, the not yet accepted, LWG-3636.
-// The current formatters can't be easily adapted, but that is WIP.
-// TODO FMT properly implement this concepts once accepted.
template <class _Tp, class _CharT>
-concept __formattable = (semiregular<formatter<remove_cvref_t<_Tp>, _CharT>>) &&
- requires(formatter<remove_cvref_t<_Tp>, _CharT> __f,
- formatter<remove_cvref_t<_Tp>, _CharT> __cf, _Tp __t,
- basic_format_context<__fmt_iter_for<_CharT>, _CharT> __fc,
- basic_format_parse_context<_CharT> __pc) {
- { __f.parse(__pc) } -> same_as<typename basic_format_parse_context<_CharT>::iterator>;
- { __cf.format(__t, __fc) } -> same_as<__fmt_iter_for<_CharT>>;
- };
+concept __formattable =
+ (semiregular<formatter<remove_cvref_t<_Tp>, _CharT>>) &&
+ requires(formatter<remove_cvref_t<_Tp>, _CharT> __f,
+ const formatter<remove_cvref_t<_Tp>, _CharT> __cf,
+ _Tp __t,
+ basic_format_context<__fmt_iter_for<_CharT>, _CharT> __fc,
+ basic_format_parse_context<_CharT> __pc) {
+ { __f.parse(__pc) } -> same_as<typename basic_format_parse_context<_CharT>::iterator>;
+ { __cf.format(__t, __fc) } -> same_as<__fmt_iter_for<_CharT>>;
+ };
+
+# if _LIBCPP_STD_VER > 20
+template <class _Tp, class _CharT>
+concept formattable = __formattable<_Tp, _CharT>;
+
+// [tuple.like] defines a tuple-like exposition only concept. This concept is
+// not related to that. Therefore it uses a different name for the concept.
+//
+// TODO FMT Add a test to validate we fail when using that concept after P2165
+// has been implemented.
+template <class _Tp>
+concept __fmt_pair_like = __is_specialization_v<_Tp, pair> ||
+ // Use a requires since tuple_size_v may fail to instantiate,
+ (__is_specialization_v<_Tp, tuple> && requires { tuple_size_v<_Tp> == 2; });
+# endif //_LIBCPP_STD_VER > 20
#endif //_LIBCPP_STD_VER > 17
_LIBCPP_END_NAMESPACE_STD