xref: /freebsd-src/contrib/llvm-project/libcxx/include/__format/concepts.h (revision 81ad626541db97eb356e2c1d4a20eb2a26a766ab)
1*81ad6265SDimitry Andric // -*- C++ -*-
2*81ad6265SDimitry Andric //===----------------------------------------------------------------------===//
3*81ad6265SDimitry Andric //
4*81ad6265SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5*81ad6265SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
6*81ad6265SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7*81ad6265SDimitry Andric //
8*81ad6265SDimitry Andric //===----------------------------------------------------------------------===//
9*81ad6265SDimitry Andric 
10*81ad6265SDimitry Andric #ifndef _LIBCPP___FORMAT_CONCEPTS_H
11*81ad6265SDimitry Andric #define _LIBCPP___FORMAT_CONCEPTS_H
12*81ad6265SDimitry Andric 
13*81ad6265SDimitry Andric #include <__concepts/same_as.h>
14*81ad6265SDimitry Andric #include <__concepts/semiregular.h>
15*81ad6265SDimitry Andric #include <__config>
16*81ad6265SDimitry Andric #include <__format/format_fwd.h>
17*81ad6265SDimitry Andric #include <__format/format_parse_context.h>
18*81ad6265SDimitry Andric #include <type_traits>
19*81ad6265SDimitry Andric 
20*81ad6265SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21*81ad6265SDimitry Andric #  pragma GCC system_header
22*81ad6265SDimitry Andric #endif
23*81ad6265SDimitry Andric 
24*81ad6265SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD
25*81ad6265SDimitry Andric 
26*81ad6265SDimitry Andric #if _LIBCPP_STD_VER > 17
27*81ad6265SDimitry Andric 
28*81ad6265SDimitry Andric // The output iterator isn't specified. A formatter should accept any
29*81ad6265SDimitry Andric // output_iterator. This iterator is a minimal iterator to test the concept.
30*81ad6265SDimitry Andric // (Note testing for (w)format_context would be a valid choice, but requires
31*81ad6265SDimitry Andric // selecting the proper one depending on the type of _CharT.)
32*81ad6265SDimitry Andric template <class _CharT>
33*81ad6265SDimitry Andric using __fmt_iter_for = _CharT*;
34*81ad6265SDimitry Andric 
35*81ad6265SDimitry Andric // The concept is based on P2286R6
36*81ad6265SDimitry Andric // It lacks the const of __cf as required by, the not yet accepted, LWG-3636.
37*81ad6265SDimitry Andric // The current formatters can't be easily adapted, but that is WIP.
38*81ad6265SDimitry Andric // TODO FMT properly implement this concepts once accepted.
39*81ad6265SDimitry Andric template <class _Tp, class _CharT>
40*81ad6265SDimitry Andric concept __formattable = (semiregular<formatter<remove_cvref_t<_Tp>, _CharT>>) &&
41*81ad6265SDimitry Andric                         requires(formatter<remove_cvref_t<_Tp>, _CharT> __f,
42*81ad6265SDimitry Andric                                  formatter<remove_cvref_t<_Tp>, _CharT> __cf, _Tp __t,
43*81ad6265SDimitry Andric                                  basic_format_context<__fmt_iter_for<_CharT>, _CharT> __fc,
44*81ad6265SDimitry Andric                                  basic_format_parse_context<_CharT> __pc) {
45*81ad6265SDimitry Andric                           { __f.parse(__pc) } -> same_as<typename basic_format_parse_context<_CharT>::iterator>;
46*81ad6265SDimitry Andric                           { __cf.format(__t, __fc) } -> same_as<__fmt_iter_for<_CharT>>;
47*81ad6265SDimitry Andric                         };
48*81ad6265SDimitry Andric 
49*81ad6265SDimitry Andric #endif //_LIBCPP_STD_VER > 17
50*81ad6265SDimitry Andric 
51*81ad6265SDimitry Andric _LIBCPP_END_NAMESPACE_STD
52*81ad6265SDimitry Andric 
53*81ad6265SDimitry Andric #endif // _LIBCPP___FORMAT_CONCEPTS_H
54