Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:48

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef _LIBCPP___FORMAT_CONCEPTS_H
0011 #define _LIBCPP___FORMAT_CONCEPTS_H
0012 
0013 #include <__concepts/same_as.h>
0014 #include <__concepts/semiregular.h>
0015 #include <__config>
0016 #include <__format/format_parse_context.h>
0017 #include <__fwd/format.h>
0018 #include <__fwd/tuple.h>
0019 #include <__tuple/tuple_size.h>
0020 #include <__type_traits/is_specialization.h>
0021 #include <__type_traits/remove_const.h>
0022 #include <__type_traits/remove_reference.h>
0023 #include <__utility/pair.h>
0024 
0025 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0026 #  pragma GCC system_header
0027 #endif
0028 
0029 _LIBCPP_BEGIN_NAMESPACE_STD
0030 
0031 #if _LIBCPP_STD_VER >= 20
0032 
0033 /// The character type specializations of \ref formatter.
0034 template <class _CharT>
0035 concept __fmt_char_type =
0036     same_as<_CharT, char>
0037 #  if _LIBCPP_HAS_WIDE_CHARACTERS
0038     || same_as<_CharT, wchar_t>
0039 #  endif
0040     ;
0041 
0042 // The output iterator isn't specified. A formatter should accept any
0043 // output_iterator. This iterator is a minimal iterator to test the concept.
0044 // (Note testing for (w)format_context would be a valid choice, but requires
0045 // selecting the proper one depending on the type of _CharT.)
0046 template <class _CharT>
0047 using __fmt_iter_for _LIBCPP_NODEBUG = _CharT*;
0048 
0049 template <class _Tp, class _Context, class _Formatter = typename _Context::template formatter_type<remove_const_t<_Tp>>>
0050 concept __formattable_with =
0051     semiregular<_Formatter> &&
0052     requires(_Formatter& __f,
0053              const _Formatter& __cf,
0054              _Tp&& __t,
0055              _Context __fc,
0056              basic_format_parse_context<typename _Context::char_type> __pc) {
0057       { __f.parse(__pc) } -> same_as<typename decltype(__pc)::iterator>;
0058       { __cf.format(__t, __fc) } -> same_as<typename _Context::iterator>;
0059     };
0060 
0061 template <class _Tp, class _CharT>
0062 concept __formattable =
0063     __formattable_with<remove_reference_t<_Tp>, basic_format_context<__fmt_iter_for<_CharT>, _CharT>>;
0064 
0065 #  if _LIBCPP_STD_VER >= 23
0066 template <class _Tp, class _CharT>
0067 concept formattable = __formattable<_Tp, _CharT>;
0068 
0069 // [tuple.like] defines a tuple-like exposition only concept. This concept is
0070 // not related to that. Therefore it uses a different name for the concept.
0071 //
0072 // TODO FMT Add a test to validate we fail when using that concept after P2165
0073 // has been implemented.
0074 template <class _Tp>
0075 concept __fmt_pair_like =
0076     __is_specialization_v<_Tp, pair> || (__is_specialization_v<_Tp, tuple> && tuple_size_v<_Tp> == 2);
0077 
0078 #  endif // _LIBCPP_STD_VER >= 23
0079 #endif   // _LIBCPP_STD_VER >= 20
0080 
0081 _LIBCPP_END_NAMESPACE_STD
0082 
0083 #endif // _LIBCPP___FORMAT_CONCEPTS_H