Skip to content

Commit 17f47f0

Browse files
CopilotcarsonRadtke
andcommitted
Add constexpr to not_null comparison operators
Co-authored-by: carsonRadtke <10507970+carsonRadtke@users.noreply.github.com>
1 parent 556fa41 commit 17f47f0

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

include/gsl/pointers

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,47 +173,47 @@ std::ostream& operator<<(std::ostream& os, const not_null<T>& val)
173173
#endif // !defined(GSL_NO_IOSTREAMS)
174174

175175
template <class T, class U>
176-
auto operator==(const not_null<T>& lhs,
176+
constexpr auto operator==(const not_null<T>& lhs,
177177
const not_null<U>& rhs) noexcept(noexcept(lhs.get() == rhs.get()))
178178
-> decltype(lhs.get() == rhs.get())
179179
{
180180
return lhs.get() == rhs.get();
181181
}
182182

183183
template <class T, class U>
184-
auto operator!=(const not_null<T>& lhs,
184+
constexpr auto operator!=(const not_null<T>& lhs,
185185
const not_null<U>& rhs) noexcept(noexcept(lhs.get() != rhs.get()))
186186
-> decltype(lhs.get() != rhs.get())
187187
{
188188
return lhs.get() != rhs.get();
189189
}
190190

191191
template <class T, class U>
192-
auto operator<(const not_null<T>& lhs,
192+
constexpr auto operator<(const not_null<T>& lhs,
193193
const not_null<U>& rhs) noexcept(noexcept(std::less<>{}(lhs.get(), rhs.get())))
194194
-> decltype(std::less<>{}(lhs.get(), rhs.get()))
195195
{
196196
return std::less<>{}(lhs.get(), rhs.get());
197197
}
198198

199199
template <class T, class U>
200-
auto operator<=(const not_null<T>& lhs,
200+
constexpr auto operator<=(const not_null<T>& lhs,
201201
const not_null<U>& rhs) noexcept(noexcept(std::less_equal<>{}(lhs.get(), rhs.get())))
202202
-> decltype(std::less_equal<>{}(lhs.get(), rhs.get()))
203203
{
204204
return std::less_equal<>{}(lhs.get(), rhs.get());
205205
}
206206

207207
template <class T, class U>
208-
auto operator>(const not_null<T>& lhs,
208+
constexpr auto operator>(const not_null<T>& lhs,
209209
const not_null<U>& rhs) noexcept(noexcept(std::greater<>{}(lhs.get(), rhs.get())))
210210
-> decltype(std::greater<>{}(lhs.get(), rhs.get()))
211211
{
212212
return std::greater<>{}(lhs.get(), rhs.get());
213213
}
214214

215215
template <class T, class U>
216-
auto operator>=(const not_null<T>& lhs,
216+
constexpr auto operator>=(const not_null<T>& lhs,
217217
const not_null<U>& rhs) noexcept(noexcept(std::greater_equal<>{}(lhs.get(), rhs.get())))
218218
-> decltype(std::greater_equal<>{}(lhs.get(), rhs.get()))
219219
{

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ add_executable(gsl_tests
204204
assertion_tests.cpp
205205
at_tests.cpp
206206
byte_tests.cpp
207+
constexpr_notnull_tests.cpp
207208
notnull_tests.cpp
208209
owner_tests.cpp
209210
pointers_tests.cpp

0 commit comments

Comments
 (0)