Skip to content

Commit 0e36aa1

Browse files
[ADT, Support] Use std::bool_constant (NFC) (#158503)
This patch replaces, std::integral_constant<bool, ...> with std::bool_constant for brevity. Note that std::bool_constant was introduced as part of C++17. There are cases where we could strip away std::bool_constant altogether: std::bool_constant<std::is_same<T, U>> but I'm not doing that in this patch to avoid doing multiple things in one patch.
1 parent 885546c commit 0e36aa1

File tree

7 files changed

+47
-57
lines changed

7 files changed

+47
-57
lines changed

llvm/include/llvm/ADT/Hashing.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -333,20 +333,21 @@ inline uint64_t get_execution_seed() {
333333
// for equality. For all the platforms we care about, this holds for integers
334334
// and pointers, but there are platforms where it doesn't and we would like to
335335
// support user-defined types which happen to satisfy this property.
336-
template <typename T> struct is_hashable_data
337-
: std::integral_constant<bool, ((is_integral_or_enum<T>::value ||
338-
std::is_pointer<T>::value) &&
339-
64 % sizeof(T) == 0)> {};
336+
template <typename T>
337+
struct is_hashable_data : std::bool_constant<((is_integral_or_enum<T>::value ||
338+
std::is_pointer<T>::value) &&
339+
64 % sizeof(T) == 0)> {};
340340

341341
// Special case std::pair to detect when both types are viable and when there
342342
// is no alignment-derived padding in the pair. This is a bit of a lie because
343343
// std::pair isn't truly POD, but it's close enough in all reasonable
344344
// implementations for our use case of hashing the underlying data.
345-
template <typename T, typename U> struct is_hashable_data<std::pair<T, U> >
346-
: std::integral_constant<bool, (is_hashable_data<T>::value &&
347-
is_hashable_data<U>::value &&
348-
(sizeof(T) + sizeof(U)) ==
349-
sizeof(std::pair<T, U>))> {};
345+
template <typename T, typename U>
346+
struct is_hashable_data<std::pair<T, U>>
347+
: std::bool_constant<(is_hashable_data<T>::value &&
348+
is_hashable_data<U>::value &&
349+
(sizeof(T) + sizeof(U)) == sizeof(std::pair<T, U>))> {
350+
};
350351

351352
/// Helper to get the hashable data representation for a type.
352353
template <typename T> auto get_hashable_data(const T &value) {

llvm/include/llvm/ADT/ilist_node_options.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ template <class... Options> struct extract_sentinel_tracking;
8282
template <bool EnableSentinelTracking, class... Options>
8383
struct extract_sentinel_tracking<
8484
ilist_sentinel_tracking<EnableSentinelTracking>, Options...>
85-
: std::integral_constant<bool, EnableSentinelTracking>, is_explicit {};
85+
: std::bool_constant<EnableSentinelTracking>, is_explicit {};
8686
template <class Option1, class... Options>
8787
struct extract_sentinel_tracking<Option1, Options...>
8888
: extract_sentinel_tracking<Options...> {};
@@ -119,7 +119,7 @@ template <class Tag> struct is_valid_option<ilist_tag<Tag>> : std::true_type {};
119119
template <class... Options> struct extract_iterator_bits;
120120
template <bool IteratorBits, class... Options>
121121
struct extract_iterator_bits<ilist_iterator_bits<IteratorBits>, Options...>
122-
: std::integral_constant<bool, IteratorBits> {};
122+
: std::bool_constant<IteratorBits> {};
123123
template <class Option1, class... Options>
124124
struct extract_iterator_bits<Option1, Options...>
125125
: extract_iterator_bits<Options...> {};
@@ -149,8 +149,8 @@ template <class... Options> struct check_options;
149149
template <> struct check_options<> : std::true_type {};
150150
template <class Option1, class... Options>
151151
struct check_options<Option1, Options...>
152-
: std::integral_constant<bool, is_valid_option<Option1>::value &&
153-
check_options<Options...>::value> {};
152+
: std::bool_constant<is_valid_option<Option1>::value &&
153+
check_options<Options...>::value> {};
154154

155155
/// Traits for options for \a ilist_node.
156156
///

llvm/include/llvm/Support/CFGDiff.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,17 @@ namespace llvm {
3434

3535
namespace detail {
3636
template <typename Range>
37-
auto reverse_if_helper(Range &&R, std::integral_constant<bool, false>) {
37+
auto reverse_if_helper(Range &&R, std::bool_constant<false>) {
3838
return std::forward<Range>(R);
3939
}
4040

4141
template <typename Range>
42-
auto reverse_if_helper(Range &&R, std::integral_constant<bool, true>) {
42+
auto reverse_if_helper(Range &&R, std::bool_constant<true>) {
4343
return llvm::reverse(std::forward<Range>(R));
4444
}
4545

4646
template <bool B, typename Range> auto reverse_if(Range &&R) {
47-
return reverse_if_helper(std::forward<Range>(R),
48-
std::integral_constant<bool, B>{});
47+
return reverse_if_helper(std::forward<Range>(R), std::bool_constant<B>{});
4948
}
5049
} // namespace detail
5150

llvm/include/llvm/Support/FormatProviders.h

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,35 +29,31 @@ namespace support {
2929
namespace detail {
3030
template <typename T>
3131
struct use_integral_formatter
32-
: public std::integral_constant<
33-
bool, is_one_of<T, uint8_t, int16_t, uint16_t, int32_t, uint32_t,
34-
int64_t, uint64_t, int, unsigned, long, unsigned long,
35-
long long, unsigned long long>::value> {};
32+
: public std::bool_constant<
33+
is_one_of<T, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t,
34+
uint64_t, int, unsigned, long, unsigned long, long long,
35+
unsigned long long>::value> {};
3636

3737
template <typename T>
38-
struct use_char_formatter
39-
: public std::integral_constant<bool, std::is_same_v<T, char>> {};
38+
struct use_char_formatter : public std::bool_constant<std::is_same_v<T, char>> {
39+
};
4040

4141
template <typename T>
4242
struct is_cstring
43-
: public std::integral_constant<bool,
44-
is_one_of<T, char *, const char *>::value> {
45-
};
43+
: public std::bool_constant<is_one_of<T, char *, const char *>::value> {};
4644

4745
template <typename T>
4846
struct use_string_formatter
49-
: public std::integral_constant<bool,
50-
std::is_convertible_v<T, llvm::StringRef>> {
51-
};
47+
: public std::bool_constant<std::is_convertible_v<T, llvm::StringRef>> {};
5248

5349
template <typename T>
5450
struct use_pointer_formatter
55-
: public std::integral_constant<bool, std::is_pointer_v<T> &&
56-
!is_cstring<T>::value> {};
51+
: public std::bool_constant<std::is_pointer_v<T> && !is_cstring<T>::value> {
52+
};
5753

5854
template <typename T>
5955
struct use_double_formatter
60-
: public std::integral_constant<bool, std::is_floating_point_v<T>> {};
56+
: public std::bool_constant<std::is_floating_point_v<T>> {};
6157

6258
class HelperFunctions {
6359
protected:
@@ -330,8 +326,7 @@ using IterValue = typename std::iterator_traits<IterT>::value_type;
330326

331327
template <typename IterT>
332328
struct range_item_has_provider
333-
: public std::integral_constant<
334-
bool,
329+
: public std::bool_constant<
335330
!support::detail::uses_missing_provider<IterValue<IterT>>::value> {};
336331
} // namespace detail
337332
} // namespace support

llvm/include/llvm/Support/FormatVariadicDetails.h

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,37 +96,34 @@ template <class T> class has_StreamOperator {
9696
// based format() invocation.
9797
template <typename T>
9898
struct uses_format_member
99-
: public std::integral_constant<
100-
bool, std::is_base_of_v<format_adapter, std::remove_reference_t<T>>> {
101-
};
99+
: public std::bool_constant<
100+
std::is_base_of_v<format_adapter, std::remove_reference_t<T>>> {};
102101

103102
// Simple template that decides whether a type T should use the format_provider
104103
// based format() invocation. The member function takes priority, so this test
105104
// will only be true if there is not ALSO a format member.
106105
template <typename T>
107106
struct uses_format_provider
108-
: public std::integral_constant<
109-
bool, !uses_format_member<T>::value && has_FormatProvider<T>::value> {
110-
};
107+
: public std::bool_constant<!uses_format_member<T>::value &&
108+
has_FormatProvider<T>::value> {};
111109

112110
// Simple template that decides whether a type T should use the operator<<
113111
// based format() invocation. This takes last priority.
114112
template <typename T>
115113
struct uses_stream_operator
116-
: public std::integral_constant<bool, !uses_format_member<T>::value &&
117-
!uses_format_provider<T>::value &&
118-
has_StreamOperator<T>::value> {};
114+
: public std::bool_constant<!uses_format_member<T>::value &&
115+
!uses_format_provider<T>::value &&
116+
has_StreamOperator<T>::value> {};
119117

120118
// Simple template that decides whether a type T has neither a member-function
121119
// nor format_provider based implementation that it can use. Mostly used so
122120
// that the compiler spits out a nice diagnostic when a type with no format
123121
// implementation can be located.
124122
template <typename T>
125123
struct uses_missing_provider
126-
: public std::integral_constant<bool, !uses_format_member<T>::value &&
127-
!uses_format_provider<T>::value &&
128-
!uses_stream_operator<T>::value> {
129-
};
124+
: public std::bool_constant<!uses_format_member<T>::value &&
125+
!uses_format_provider<T>::value &&
126+
!uses_stream_operator<T>::value> {};
130127

131128
template <typename T>
132129
std::enable_if_t<uses_format_member<T>::value, T>

llvm/include/llvm/Support/HashBuilder.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ namespace hashbuilder_detail {
3232
/// Trait to indicate whether a type's bits can be hashed directly (after
3333
/// endianness correction).
3434
template <typename U>
35-
struct IsHashableData
36-
: std::integral_constant<bool, is_integral_or_enum<U>::value> {};
35+
struct IsHashableData : std::bool_constant<is_integral_or_enum<U>::value> {};
3736

3837
} // namespace hashbuilder_detail
3938

llvm/include/llvm/Support/YAMLTraits.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,7 @@ template <class T> struct has_FlowTraits<T, true> {
459459
// Test if SequenceTraits<T> is defined on type T
460460
template <typename T>
461461
struct has_SequenceTraits
462-
: public std::integral_constant<bool, has_SequenceMethodTraits<T>::value> {
463-
};
462+
: public std::bool_constant<has_SequenceMethodTraits<T>::value> {};
464463

465464
// Test if DocumentListTraits<T> is defined on type T
466465
template <class T> struct has_DocumentListTraits {
@@ -683,15 +682,15 @@ struct missingTraits
683682

684683
template <typename T, typename Context>
685684
struct validatedMappingTraits
686-
: public std::integral_constant<
687-
bool, has_MappingTraits<T, Context>::value &&
688-
has_MappingValidateTraits<T, Context>::value> {};
685+
: public std::bool_constant<has_MappingTraits<T, Context>::value &&
686+
has_MappingValidateTraits<T, Context>::value> {
687+
};
689688

690689
template <typename T, typename Context>
691690
struct unvalidatedMappingTraits
692-
: public std::integral_constant<
693-
bool, has_MappingTraits<T, Context>::value &&
694-
!has_MappingValidateTraits<T, Context>::value> {};
691+
: public std::bool_constant<has_MappingTraits<T, Context>::value &&
692+
!has_MappingValidateTraits<T, Context>::value> {
693+
};
695694

696695
// Base class for Input and Output.
697696
class LLVM_ABI IO {

0 commit comments

Comments
 (0)