Skip to content

Commit a749e68

Browse files
[libc++][format][NFC] Granularize __fmt_pair_like (#150583)
`<optional>` needs `format_kind` and `range_format` since C++26, but it shouldn't drag in too many other stuffs necessary for `<__format/concepts.h>`.
1 parent 9f00ab4 commit a749e68

File tree

7 files changed

+47
-15
lines changed

7 files changed

+47
-15
lines changed

libcxx/include/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ set(files
381381
__format/enable_insertable.h
382382
__format/escaped_output_table.h
383383
__format/extended_grapheme_cluster_table.h
384+
__format/fmt_pair_like.h
384385
__format/format_arg.h
385386
__format/format_arg_store.h
386387
__format/format_args.h

libcxx/include/__format/concepts.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,8 @@
1515
#include <__config>
1616
#include <__format/format_parse_context.h>
1717
#include <__fwd/format.h>
18-
#include <__fwd/tuple.h>
19-
#include <__tuple/tuple_size.h>
20-
#include <__type_traits/is_specialization.h>
2118
#include <__type_traits/remove_const.h>
2219
#include <__type_traits/remove_reference.h>
23-
#include <__utility/pair.h>
2420

2521
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2622
# pragma GCC system_header
@@ -65,16 +61,6 @@ concept __formattable =
6561
# if _LIBCPP_STD_VER >= 23
6662
template <class _Tp, class _CharT>
6763
concept formattable = __formattable<_Tp, _CharT>;
68-
69-
// [tuple.like] defines a tuple-like exposition only concept. This concept is
70-
// not related to that. Therefore it uses a different name for the concept.
71-
//
72-
// TODO FMT Add a test to validate we fail when using that concept after P2165
73-
// has been implemented.
74-
template <class _Tp>
75-
concept __fmt_pair_like =
76-
__is_specialization_v<_Tp, pair> || (__is_specialization_v<_Tp, tuple> && tuple_size_v<_Tp> == 2);
77-
7864
# endif // _LIBCPP_STD_VER >= 23
7965
#endif // _LIBCPP_STD_VER >= 20
8066

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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_FMT_PAIR_LIKE_H
11+
#define _LIBCPP___FORMAT_FMT_PAIR_LIKE_H
12+
13+
#include <__config>
14+
#include <__fwd/pair.h>
15+
#include <__fwd/tuple.h>
16+
#include <__tuple/tuple_size.h>
17+
#include <__type_traits/is_specialization.h>
18+
19+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20+
# pragma GCC system_header
21+
#endif
22+
23+
_LIBCPP_BEGIN_NAMESPACE_STD
24+
25+
#if _LIBCPP_STD_VER >= 23
26+
27+
// [tuple.like] defines a tuple-like exposition only concept. This concept is not related to that. Therefore it uses a
28+
// different name for the concept.
29+
//
30+
// TODO FMT Add a test to validate we fail when using that concept after P2165 has been implemented.
31+
32+
// [format.range.fmtkind]/2.2.1 and [tab:formatter.range.type]:
33+
// "U is either a specialization of pair or a specialization of tuple such that tuple_size_v<U> is 2."
34+
template <class _Tp>
35+
concept __fmt_pair_like =
36+
__is_specialization_v<_Tp, pair> || (__is_specialization_v<_Tp, tuple> && tuple_size_v<_Tp> == 2);
37+
38+
#endif // _LIBCPP_STD_VER >= 23
39+
40+
_LIBCPP_END_NAMESPACE_STD
41+
42+
#endif // _LIBCPP___FORMAT_FMT_PAIR_LIKE_H

libcxx/include/__format/range_default_formatter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <__chrono/statically_widen.h>
1919
#include <__config>
2020
#include <__format/concepts.h>
21+
#include <__format/fmt_pair_like.h>
2122
#include <__format/formatter.h>
2223
#include <__format/range_format.h>
2324
#include <__format/range_formatter.h>

libcxx/include/__format/range_format.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#include <__concepts/same_as.h>
1818
#include <__config>
19-
#include <__format/concepts.h>
19+
#include <__format/fmt_pair_like.h>
2020
#include <__ranges/concepts.h>
2121
#include <__type_traits/remove_cvref.h>
2222

libcxx/include/__format/range_formatter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <__config>
2121
#include <__format/buffer.h>
2222
#include <__format/concepts.h>
23+
#include <__format/fmt_pair_like.h>
2324
#include <__format/format_context.h>
2425
#include <__format/format_error.h>
2526
#include <__format/formatter.h>

libcxx/include/module.modulemap.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,7 @@ module std [system] {
13381338
module enable_insertable { header "__format/enable_insertable.h" }
13391339
module escaped_output_table { header "__format/escaped_output_table.h" }
13401340
module extended_grapheme_cluster_table { header "__format/extended_grapheme_cluster_table.h" }
1341+
module fmt_pair_like { header "__format/fmt_pair_like.h" }
13411342
module format_arg { header "__format/format_arg.h" }
13421343
module format_arg_store { header "__format/format_arg_store.h" }
13431344
module format_args { header "__format/format_args.h" }

0 commit comments

Comments
 (0)