181ad6265SDimitry Andric // -*- C++ -*- 281ad6265SDimitry Andric //===----------------------------------------------------------------------===// 381ad6265SDimitry Andric // 481ad6265SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 581ad6265SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 681ad6265SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 781ad6265SDimitry Andric // 881ad6265SDimitry Andric //===----------------------------------------------------------------------===// 981ad6265SDimitry Andric 1081ad6265SDimitry Andric #ifndef _LIBCPP___FORMAT_CONCEPTS_H 1181ad6265SDimitry Andric #define _LIBCPP___FORMAT_CONCEPTS_H 1281ad6265SDimitry Andric 1381ad6265SDimitry Andric #include <__concepts/same_as.h> 1481ad6265SDimitry Andric #include <__concepts/semiregular.h> 1581ad6265SDimitry Andric #include <__config> 1681ad6265SDimitry Andric #include <__format/format_fwd.h> 1781ad6265SDimitry Andric #include <__format/format_parse_context.h> 18*bdd1243dSDimitry Andric #include <__type_traits/is_specialization.h> 19*bdd1243dSDimitry Andric #include <__utility/pair.h> 20*bdd1243dSDimitry Andric #include <tuple> 2181ad6265SDimitry Andric #include <type_traits> 2281ad6265SDimitry Andric 2381ad6265SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 2481ad6265SDimitry Andric # pragma GCC system_header 2581ad6265SDimitry Andric #endif 2681ad6265SDimitry Andric 2781ad6265SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD 2881ad6265SDimitry Andric 2981ad6265SDimitry Andric #if _LIBCPP_STD_VER > 17 3081ad6265SDimitry Andric 31*bdd1243dSDimitry Andric /// The character type specializations of \ref formatter. 32*bdd1243dSDimitry Andric template <class _CharT> 33*bdd1243dSDimitry Andric concept __fmt_char_type = 34*bdd1243dSDimitry Andric same_as<_CharT, char> 35*bdd1243dSDimitry Andric # ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 36*bdd1243dSDimitry Andric || same_as<_CharT, wchar_t> 37*bdd1243dSDimitry Andric # endif 38*bdd1243dSDimitry Andric ; 39*bdd1243dSDimitry Andric 4081ad6265SDimitry Andric // The output iterator isn't specified. A formatter should accept any 4181ad6265SDimitry Andric // output_iterator. This iterator is a minimal iterator to test the concept. 4281ad6265SDimitry Andric // (Note testing for (w)format_context would be a valid choice, but requires 4381ad6265SDimitry Andric // selecting the proper one depending on the type of _CharT.) 4481ad6265SDimitry Andric template <class _CharT> 4581ad6265SDimitry Andric using __fmt_iter_for = _CharT*; 4681ad6265SDimitry Andric 4781ad6265SDimitry Andric template <class _Tp, class _CharT> 48*bdd1243dSDimitry Andric concept __formattable = 49*bdd1243dSDimitry Andric (semiregular<formatter<remove_cvref_t<_Tp>, _CharT>>) && 5081ad6265SDimitry Andric requires(formatter<remove_cvref_t<_Tp>, _CharT> __f, 51*bdd1243dSDimitry Andric const formatter<remove_cvref_t<_Tp>, _CharT> __cf, 52*bdd1243dSDimitry Andric _Tp __t, 5381ad6265SDimitry Andric basic_format_context<__fmt_iter_for<_CharT>, _CharT> __fc, 5481ad6265SDimitry Andric basic_format_parse_context<_CharT> __pc) { 5581ad6265SDimitry Andric { __f.parse(__pc) } -> same_as<typename basic_format_parse_context<_CharT>::iterator>; 5681ad6265SDimitry Andric { __cf.format(__t, __fc) } -> same_as<__fmt_iter_for<_CharT>>; 5781ad6265SDimitry Andric }; 5881ad6265SDimitry Andric 59*bdd1243dSDimitry Andric # if _LIBCPP_STD_VER > 20 60*bdd1243dSDimitry Andric template <class _Tp, class _CharT> 61*bdd1243dSDimitry Andric concept formattable = __formattable<_Tp, _CharT>; 62*bdd1243dSDimitry Andric 63*bdd1243dSDimitry Andric // [tuple.like] defines a tuple-like exposition only concept. This concept is 64*bdd1243dSDimitry Andric // not related to that. Therefore it uses a different name for the concept. 65*bdd1243dSDimitry Andric // 66*bdd1243dSDimitry Andric // TODO FMT Add a test to validate we fail when using that concept after P2165 67*bdd1243dSDimitry Andric // has been implemented. 68*bdd1243dSDimitry Andric template <class _Tp> 69*bdd1243dSDimitry Andric concept __fmt_pair_like = __is_specialization_v<_Tp, pair> || 70*bdd1243dSDimitry Andric // Use a requires since tuple_size_v may fail to instantiate, 71*bdd1243dSDimitry Andric (__is_specialization_v<_Tp, tuple> && requires { tuple_size_v<_Tp> == 2; }); 72*bdd1243dSDimitry Andric 73*bdd1243dSDimitry Andric # endif //_LIBCPP_STD_VER > 20 7481ad6265SDimitry Andric #endif //_LIBCPP_STD_VER > 17 7581ad6265SDimitry Andric 7681ad6265SDimitry Andric _LIBCPP_END_NAMESPACE_STD 7781ad6265SDimitry Andric 7881ad6265SDimitry Andric #endif // _LIBCPP___FORMAT_CONCEPTS_H 79