Path: blob/main/contrib/llvm-project/libcxx/include/__format/concepts.h
35259 views
// -*- C++ -*-1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//89#ifndef _LIBCPP___FORMAT_CONCEPTS_H10#define _LIBCPP___FORMAT_CONCEPTS_H1112#include <__concepts/same_as.h>13#include <__concepts/semiregular.h>14#include <__config>15#include <__format/format_parse_context.h>16#include <__fwd/format.h>17#include <__fwd/tuple.h>18#include <__tuple/tuple_size.h>19#include <__type_traits/is_specialization.h>20#include <__type_traits/remove_const.h>21#include <__type_traits/remove_reference.h>22#include <__utility/pair.h>2324#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)25# pragma GCC system_header26#endif2728_LIBCPP_BEGIN_NAMESPACE_STD2930#if _LIBCPP_STD_VER >= 203132/// The character type specializations of \ref formatter.33template <class _CharT>34concept __fmt_char_type =35same_as<_CharT, char>36# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS37|| same_as<_CharT, wchar_t>38# endif39;4041// The output iterator isn't specified. A formatter should accept any42// output_iterator. This iterator is a minimal iterator to test the concept.43// (Note testing for (w)format_context would be a valid choice, but requires44// selecting the proper one depending on the type of _CharT.)45template <class _CharT>46using __fmt_iter_for = _CharT*;4748template <class _Tp, class _Context, class _Formatter = typename _Context::template formatter_type<remove_const_t<_Tp>>>49concept __formattable_with =50semiregular<_Formatter> &&51requires(_Formatter& __f,52const _Formatter& __cf,53_Tp&& __t,54_Context __fc,55basic_format_parse_context<typename _Context::char_type> __pc) {56{ __f.parse(__pc) } -> same_as<typename decltype(__pc)::iterator>;57{ __cf.format(__t, __fc) } -> same_as<typename _Context::iterator>;58};5960template <class _Tp, class _CharT>61concept __formattable =62__formattable_with<remove_reference_t<_Tp>, basic_format_context<__fmt_iter_for<_CharT>, _CharT>>;6364# if _LIBCPP_STD_VER >= 2365template <class _Tp, class _CharT>66concept formattable = __formattable<_Tp, _CharT>;6768// [tuple.like] defines a tuple-like exposition only concept. This concept is69// not related to that. Therefore it uses a different name for the concept.70//71// TODO FMT Add a test to validate we fail when using that concept after P216572// has been implemented.73template <class _Tp>74concept __fmt_pair_like =75__is_specialization_v<_Tp, pair> || (__is_specialization_v<_Tp, tuple> && tuple_size_v<_Tp> == 2);7677# endif //_LIBCPP_STD_VER >= 2378#endif //_LIBCPP_STD_VER >= 207980_LIBCPP_END_NAMESPACE_STD8182#endif // _LIBCPP___FORMAT_CONCEPTS_H838485