1 // -*- C++ -*- 2 //===----------------------------------------------------------------------===// 3 // 4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 // See https://llvm.org/LICENSE.txt for license information. 6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef _LIBCPP___FORMAT_CONCEPTS_H 11 #define _LIBCPP___FORMAT_CONCEPTS_H 12 13 #include <__concepts/same_as.h> 14 #include <__concepts/semiregular.h> 15 #include <__config> 16 #include <__format/format_fwd.h> 17 #include <__format/format_parse_context.h> 18 #include <__type_traits/is_specialization.h> 19 #include <__utility/pair.h> 20 #include <tuple> 21 22 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 23 # pragma GCC system_header 24 #endif 25 26 _LIBCPP_BEGIN_NAMESPACE_STD 27 28 #if _LIBCPP_STD_VER >= 20 29 30 /// The character type specializations of \ref formatter. 31 template <class _CharT> 32 concept __fmt_char_type = 33 same_as<_CharT, char> 34 # ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 35 || same_as<_CharT, wchar_t> 36 # endif 37 ; 38 39 // The output iterator isn't specified. A formatter should accept any 40 // output_iterator. This iterator is a minimal iterator to test the concept. 41 // (Note testing for (w)format_context would be a valid choice, but requires 42 // selecting the proper one depending on the type of _CharT.) 43 template <class _CharT> 44 using __fmt_iter_for = _CharT*; 45 46 template <class _Tp, class _CharT> 47 concept __formattable = 48 (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)49 requires(formatter<remove_cvref_t<_Tp>, _CharT> __f, 50 const formatter<remove_cvref_t<_Tp>, _CharT> __cf, 51 _Tp __t, 52 basic_format_context<__fmt_iter_for<_CharT>, _CharT> __fc, 53 basic_format_parse_context<_CharT> __pc) { 54 { __f.parse(__pc) } -> same_as<typename basic_format_parse_context<_CharT>::iterator>; 55 { __cf.format(__t, __fc) } -> same_as<__fmt_iter_for<_CharT>>; 56 }; 57 58 # if _LIBCPP_STD_VER >= 23 59 template <class _Tp, class _CharT> 60 concept formattable = __formattable<_Tp, _CharT>; 61 62 // [tuple.like] defines a tuple-like exposition only concept. This concept is 63 // not related to that. Therefore it uses a different name for the concept. 64 // 65 // TODO FMT Add a test to validate we fail when using that concept after P2165 66 // has been implemented. 67 template <class _Tp> 68 concept __fmt_pair_like = 69 __is_specialization_v<_Tp, pair> || (__is_specialization_v<_Tp, tuple> && tuple_size_v<_Tp> == 2); 70 71 # endif //_LIBCPP_STD_VER >= 23 72 #endif //_LIBCPP_STD_VER >= 20 73 74 _LIBCPP_END_NAMESPACE_STD 75 76 #endif // _LIBCPP___FORMAT_CONCEPTS_H 77