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> 19 20 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 21 # pragma GCC system_header 22 #endif 23 24 _LIBCPP_BEGIN_NAMESPACE_STD 25 26 #if _LIBCPP_STD_VER > 17 27 28 // The output iterator isn't specified. A formatter should accept any 29 // output_iterator. This iterator is a minimal iterator to test the concept. 30 // (Note testing for (w)format_context would be a valid choice, but requires 31 // selecting the proper one depending on the type of _CharT.) 32 template <class _CharT> 33 using __fmt_iter_for = _CharT*; 34 35 // The concept is based on P2286R6 36 // It lacks the const of __cf as required by, the not yet accepted, LWG-3636. 37 // The current formatters can't be easily adapted, but that is WIP. 38 // TODO FMT properly implement this concepts once accepted. 39 template <class _Tp, class _CharT> 40 concept __formattable = (semiregular<formatter<remove_cvref_t<_Tp>, _CharT>>) && 41 requires(formatter<remove_cvref_t<_Tp>, _CharT> __f, 42 formatter<remove_cvref_t<_Tp>, _CharT> __cf, _Tp __t, 43 basic_format_context<__fmt_iter_for<_CharT>, _CharT> __fc, 44 basic_format_parse_context<_CharT> __pc) { 45 { __f.parse(__pc) } -> same_as<typename basic_format_parse_context<_CharT>::iterator>; 46 { __cf.format(__t, __fc) } -> same_as<__fmt_iter_for<_CharT>>; 47 }; 48 49 #endif //_LIBCPP_STD_VER > 17 50 51 _LIBCPP_END_NAMESPACE_STD 52 53 #endif // _LIBCPP___FORMAT_CONCEPTS_H 54