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_RANGE_FORMAT_H
11#define _LIBCPP___FORMAT_RANGE_FORMAT_H
12
13#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
14# pragma GCC system_header
15#endif
16
17#include <__concepts/same_as.h>
18#include <__config>
19#include <__format/fmt_pair_like.h>
20#include <__fwd/format.h>
21#include <__ranges/concepts.h>
22#include <__type_traits/remove_cvref.h>
23
24_LIBCPP_BEGIN_NAMESPACE_STD
25
26#if _LIBCPP_STD_VER >= 23
27
28template <ranges::input_range _Rp>
29 requires same_as<_Rp, remove_cvref_t<_Rp>>
30inline constexpr range_format format_kind<_Rp> = [] {
31 // [format.range.fmtkind]/2
32
33 // 2.1 If same_as<remove_cvref_t<ranges::range_reference_t<R>>, R> is true,
34 // Otherwise format_kind<R> is range_format::disabled.
35 if constexpr (same_as<remove_cvref_t<ranges::range_reference_t<_Rp>>, _Rp>)
36 return range_format::disabled;
37 // 2.2 Otherwise, if the qualified-id R::key_type is valid and denotes a type:
38 else if constexpr (requires { typename _Rp::key_type; }) {
39 // 2.2.1 If the qualified-id R::mapped_type is valid and denotes a type ...
40 if constexpr (requires { typename _Rp::mapped_type; } &&
41 // 2.2.1 ... If either U is a specialization of pair or U is a specialization
42 // of tuple and tuple_size_v<U> == 2
43 __fmt_pair_like<remove_cvref_t<ranges::range_reference_t<_Rp>>>)
44 return range_format::map;
45 else
46 // 2.2.2 Otherwise format_kind<R> is range_format::set.
47 return range_format::set;
48 } else
49 // 2.3 Otherwise, format_kind<R> is range_format::sequence.
50 return range_format::sequence;
51}();
52
53#endif // _LIBCPP_STD_VER >= 23
54
55_LIBCPP_END_NAMESPACE_STD
56
57#endif
58