72 lines · c
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-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCPP___FORMAT_RANGE_FORMAT_H11#define _LIBCPP___FORMAT_RANGE_FORMAT_H12 13#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)14# pragma GCC system_header15#endif16 17#include <__concepts/same_as.h>18#include <__config>19#include <__format/fmt_pair_like.h>20#include <__ranges/concepts.h>21#include <__type_traits/remove_cvref.h>22 23_LIBCPP_BEGIN_NAMESPACE_STD24 25#if _LIBCPP_STD_VER >= 2326 27_LIBCPP_DIAGNOSTIC_PUSH28_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wshadow")29_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wshadow")30// This shadows map, set, and string.31enum class range_format { disabled, map, set, sequence, string, debug_string };32_LIBCPP_DIAGNOSTIC_POP33 34template <class _Rp>35constexpr range_format format_kind = [] {36 // [format.range.fmtkind]/137 // A program that instantiates the primary template of format_kind is ill-formed.38 static_assert(sizeof(_Rp) != sizeof(_Rp), "create a template specialization of format_kind for your type");39 return range_format::disabled;40}();41 42template <ranges::input_range _Rp>43 requires same_as<_Rp, remove_cvref_t<_Rp>>44inline constexpr range_format format_kind<_Rp> = [] {45 // [format.range.fmtkind]/246 47 // 2.1 If same_as<remove_cvref_t<ranges::range_reference_t<R>>, R> is true,48 // Otherwise format_kind<R> is range_format::disabled.49 if constexpr (same_as<remove_cvref_t<ranges::range_reference_t<_Rp>>, _Rp>)50 return range_format::disabled;51 // 2.2 Otherwise, if the qualified-id R::key_type is valid and denotes a type:52 else if constexpr (requires { typename _Rp::key_type; }) {53 // 2.2.1 If the qualified-id R::mapped_type is valid and denotes a type ...54 if constexpr (requires { typename _Rp::mapped_type; } &&55 // 2.2.1 ... If either U is a specialization of pair or U is a specialization56 // of tuple and tuple_size_v<U> == 257 __fmt_pair_like<remove_cvref_t<ranges::range_reference_t<_Rp>>>)58 return range_format::map;59 else60 // 2.2.2 Otherwise format_kind<R> is range_format::set.61 return range_format::set;62 } else63 // 2.3 Otherwise, format_kind<R> is range_format::sequence.64 return range_format::sequence;65}();66 67#endif // _LIBCPP_STD_VER >= 2368 69_LIBCPP_END_NAMESPACE_STD70 71#endif72