Skip to content

Commit 0dc891b

Browse files
Werner HenzeWerner Henze
authored andcommitted
Better use of std::enable_if
Replace the occurances of `class = std::enable_if_t<Cond>` and `typename = std::enable_if_t<Cond>` that have been identified in the previous commit with `std::enable_if_t<Cond, bool> = true`. This commit is inspired by #1174, which changed one occurance in the owner header. This commit is aimed to fix all remaining occurances.
1 parent 5a1fb8e commit 0dc891b

File tree

5 files changed

+28
-28
lines changed

5 files changed

+28
-28
lines changed

docs/headers.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,16 @@ See [SL.str.5: Use `std::byte` to refer to byte values that do not necessarily r
9191
### Non-member functions
9292
9393
```cpp
94-
template <class IntegerType, class = std::enable_if_t<std::is_integral<IntegerType>::value>>
94+
template <class IntegerType, std::enable_if_t<std::is_integral<IntegerType>::value, bool> = true>
9595
constexpr byte& operator<<=(byte& b, IntegerType shift) noexcept;
9696
97-
template <class IntegerType, class = std::enable_if_t<std::is_integral<IntegerType>::value>>
97+
template <class IntegerType, std::enable_if_t<std::is_integral<IntegerType>::value, bool> = true>
9898
constexpr byte operator<<(byte b, IntegerType shift) noexcept;
9999
100-
template <class IntegerType, class = std::enable_if_t<std::is_integral<IntegerType>::value>>
100+
template <class IntegerType, std::enable_if_t<std::is_integral<IntegerType>::value, bool> = true>
101101
constexpr byte& operator>>=(byte& b, IntegerType shift) noexcept;
102102
103-
template <class IntegerType, class = std::enable_if_t<std::is_integral<IntegerType>::value>>
103+
template <class IntegerType, std::enable_if_t<std::is_integral<IntegerType>::value, bool> = true>
104104
constexpr byte operator>>(byte b, IntegerType shift) noexcept;
105105
```
106106

@@ -134,7 +134,7 @@ constexpr byte operator~(byte b) noexcept;
134134
Bitwise negation of a `byte`. Flips all bits. Zeroes become ones, ones become zeroes.
135135

136136
```cpp
137-
template <class IntegerType, class = std::enable_if_t<std::is_integral<IntegerType>::value>>
137+
template <class IntegerType, std::enable_if_t<std::is_integral<IntegerType>::value, bool> = true>
138138
constexpr IntegerType to_integer(byte b) noexcept;
139139
```
140140
@@ -310,7 +310,7 @@ auto make_not_null(T&& t) noexcept;
310310
Creates a `gsl::not_null` object, deducing the target type from the type of the argument.
311311

312312
```cpp
313-
template <typename T, typename = std::enable_if_t<std::is_move_assignable<T>::value && std::is_move_constructible<T>::value>>
313+
template <typename T, std::enable_if_t<std::is_move_assignable<T>::value && std::is_move_constructible<T>::value, bool> = true>
314314
void swap(not_null<T>& a, not_null<T>& b);
315315
```
316316

include/gsl/byte

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,25 +91,25 @@ enum class byte_may_alias byte : unsigned char
9191
{
9292
};
9393

94-
template <class IntegerType, class = std::enable_if_t<std::is_integral<IntegerType>::value>>
94+
template <class IntegerType, std::enable_if_t<std::is_integral<IntegerType>::value, bool> = true>
9595
constexpr byte& operator<<=(byte& b, IntegerType shift) noexcept
9696
{
9797
return b = byte(static_cast<unsigned char>(b) << shift);
9898
}
9999

100-
template <class IntegerType, class = std::enable_if_t<std::is_integral<IntegerType>::value>>
100+
template <class IntegerType, std::enable_if_t<std::is_integral<IntegerType>::value, bool> = true>
101101
constexpr byte operator<<(byte b, IntegerType shift) noexcept
102102
{
103103
return byte(static_cast<unsigned char>(b) << shift);
104104
}
105105

106-
template <class IntegerType, class = std::enable_if_t<std::is_integral<IntegerType>::value>>
106+
template <class IntegerType, std::enable_if_t<std::is_integral<IntegerType>::value, bool> = true>
107107
constexpr byte& operator>>=(byte& b, IntegerType shift) noexcept
108108
{
109109
return b = byte(static_cast<unsigned char>(b) >> shift);
110110
}
111111

112-
template <class IntegerType, class = std::enable_if_t<std::is_integral<IntegerType>::value>>
112+
template <class IntegerType, std::enable_if_t<std::is_integral<IntegerType>::value, bool> = true>
113113
constexpr byte operator>>(byte b, IntegerType shift) noexcept
114114
{
115115
return byte(static_cast<unsigned char>(b) >> shift);
@@ -147,7 +147,7 @@ constexpr byte operator^(byte l, byte r) noexcept
147147

148148
constexpr byte operator~(byte b) noexcept { return byte(~static_cast<unsigned char>(b)); }
149149

150-
template <class IntegerType, class = std::enable_if_t<std::is_integral<IntegerType>::value>>
150+
template <class IntegerType, std::enable_if_t<std::is_integral<IntegerType>::value, bool> = true>
151151
constexpr IntegerType to_integer(byte b) noexcept
152152
{
153153
return static_cast<IntegerType>(b);

include/gsl/pointers

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ private:
145145
T ptr_;
146146
};
147147

148-
template <typename T, typename = std::enable_if_t<std::is_move_assignable<T>::value && std::is_move_constructible<T>::value>>
148+
template <typename T, std::enable_if_t<std::is_move_assignable<T>::value && std::is_move_constructible<T>::value, bool> = true>
149149
void swap(not_null<T>& a, not_null<T>& b)
150150
{
151151
a.swap(b);

tests/byte_tests.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,36 +136,36 @@ template <typename U, typename = void>
136136
static constexpr bool LShiftCompilesFor = false;
137137
template <typename U>
138138
static constexpr bool LShiftCompilesFor<
139-
U, std::void_t<decltype(gsl::operator<< <float, void>(declval<gsl::byte>(), declval<U>()))>> = true;
140-
static_assert(LShiftCompilesFor<float>, "LShiftCompilesFor<float>");
139+
U, std::void_t<decltype(gsl::operator<< <float>(declval<gsl::byte>(), declval<U>()))>> = true;
140+
static_assert(!LShiftCompilesFor<float>, "!LShiftCompilesFor<float>");
141141

142142
template <typename U, typename = void>
143143
static constexpr bool RShiftCompilesFor = false;
144144
template <typename U>
145145
static constexpr bool RShiftCompilesFor<
146-
U, std::void_t<decltype(gsl::operator>> <U, void>(declval<gsl::byte>(), declval<U>()))>> = true;
147-
static_assert(RShiftCompilesFor<float>, "RShiftCompilesFor<float>");
146+
U, std::void_t<decltype(gsl::operator>> <U>(declval<gsl::byte>(), declval<U>()))>> = true;
147+
static_assert(!RShiftCompilesFor<float>, "!RShiftCompilesFor<float>");
148148

149149
template <typename U, typename = void>
150150
static constexpr bool LShiftAssignCompilesFor = false;
151151
template <typename U>
152152
static constexpr bool LShiftAssignCompilesFor<
153-
U, std::void_t<decltype(gsl::operator<<= <U, void>(declval<gsl::byte&>(), declval<U>()))>> = true;
154-
static_assert(LShiftAssignCompilesFor<float>, "LShiftAssignCompilesFor<float>");
153+
U, std::void_t<decltype(gsl::operator<<= <U>(declval<gsl::byte&>(), declval<U>()))>> = true;
154+
static_assert(!LShiftAssignCompilesFor<float>, "!LShiftAssignCompilesFor<float>");
155155

156156
template <typename U, typename = void>
157157
static constexpr bool RShiftAssignCompilesFor = false;
158158
template <typename U>
159159
static constexpr bool RShiftAssignCompilesFor<
160-
U, std::void_t<decltype(gsl::operator>>= <U, void>(declval<gsl::byte&>(), declval<U>()))>> = true;
161-
static_assert(RShiftAssignCompilesFor<float>, "RShiftAssignCompilesFor<float>");
160+
U, std::void_t<decltype(gsl::operator>>= <U>(declval<gsl::byte&>(), declval<U>()))>> = true;
161+
static_assert(!RShiftAssignCompilesFor<float>, "!RShiftAssignCompilesFor<float>");
162162

163163
template <typename U, typename = void>
164164
static constexpr bool ToIntegerCompilesFor = false;
165165
template <typename U>
166-
static constexpr bool ToIntegerCompilesFor<
167-
U, std::void_t<decltype(gsl::to_integer<U, void>(gsl::byte{}))>> = true;
168-
static_assert(ToIntegerCompilesFor<float>, "ToIntegerCompilesFor<float>");
166+
static constexpr bool
167+
ToIntegerCompilesFor<U, std::void_t<decltype(gsl::to_integer<U>(gsl::byte{}))>> = true;
168+
static_assert(!ToIntegerCompilesFor<float>, "!ToIntegerCompilesFor<float>");
169169

170170
} // namespace
171171

tests/pointers_tests.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ struct NotMovable
3333
template <typename U, typename = void>
3434
static constexpr bool SwapCompilesFor = false;
3535
template <typename U>
36-
static constexpr bool SwapCompilesFor<
37-
U, std::void_t<decltype(gsl::swap<U, void>(std::declval<gsl::not_null<U>&>(),
38-
std::declval<gsl::not_null<U>&>()))>> =
39-
true;
40-
static_assert(SwapCompilesFor<NotMovable>, "SwapCompilesFor<NotMovable>");
36+
static constexpr bool
37+
SwapCompilesFor<U, std::void_t<decltype(gsl::swap<U>(std::declval<gsl::not_null<U>&>(),
38+
std::declval<gsl::not_null<U>&>()))>> =
39+
true;
40+
static_assert(!SwapCompilesFor<NotMovable>, "!SwapCompilesFor<NotMovable>");
4141

4242
} // namespace

0 commit comments

Comments
 (0)