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> 18bdd1243dSDimitry Andric #include <__type_traits/is_specialization.h> 19bdd1243dSDimitry Andric #include <__utility/pair.h> 20bdd1243dSDimitry 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 31bdd1243dSDimitry Andric /// The character type specializations of \ref formatter. 32bdd1243dSDimitry Andric template <class _CharT> 33bdd1243dSDimitry Andric concept __fmt_char_type = 34bdd1243dSDimitry Andric same_as<_CharT, char> 35bdd1243dSDimitry Andric # ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 36bdd1243dSDimitry Andric || same_as<_CharT, wchar_t> 37bdd1243dSDimitry Andric # endif 38bdd1243dSDimitry Andric ; 39bdd1243dSDimitry 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> 48bdd1243dSDimitry Andric concept __formattable = 49bdd1243dSDimitry Andric (semiregular<formatter<remove_cvref_t<_Tp>, _CharT>>) && 5081ad6265SDimitry Andric requires(formatter<remove_cvref_t<_Tp>, _CharT> __f, 51bdd1243dSDimitry Andric const formatter<remove_cvref_t<_Tp>, _CharT> __cf, 52bdd1243dSDimitry 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 59bdd1243dSDimitry Andric # if _LIBCPP_STD_VER > 20 60bdd1243dSDimitry Andric template <class _Tp, class _CharT> 61bdd1243dSDimitry Andric concept formattable = __formattable<_Tp, _CharT>; 62bdd1243dSDimitry Andric 63bdd1243dSDimitry Andric // [tuple.like] defines a tuple-like exposition only concept. This concept is 64bdd1243dSDimitry Andric // not related to that. Therefore it uses a different name for the concept. 65bdd1243dSDimitry Andric // 66bdd1243dSDimitry Andric // TODO FMT Add a test to validate we fail when using that concept after P2165 67bdd1243dSDimitry Andric // has been implemented. 68bdd1243dSDimitry Andric template <class _Tp> 69*1ac55f4cSDimitry Andric concept __fmt_pair_like = 70*1ac55f4cSDimitry Andric __is_specialization_v<_Tp, pair> || (__is_specialization_v<_Tp, tuple> && tuple_size_v<_Tp> == 2); 71bdd1243dSDimitry Andric 72bdd1243dSDimitry Andric # endif //_LIBCPP_STD_VER > 20 7381ad6265SDimitry Andric #endif //_LIBCPP_STD_VER > 17 7481ad6265SDimitry Andric 7581ad6265SDimitry Andric _LIBCPP_END_NAMESPACE_STD 7681ad6265SDimitry Andric 7781ad6265SDimitry Andric #endif // _LIBCPP___FORMAT_CONCEPTS_H 78