Skip to content

Commit 4f58bf2

Browse files
committed
Drive-by: Add a ranges::range<optional<T>> test for iterators
1 parent 3c2473d commit 4f58bf2

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

libcxx/test/std/utilities/optional/optional.iterator/iterator.pass.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,23 @@
1414
// template <class T> class optional::const_iterator;
1515

1616
#include <cassert>
17-
#include <iterator>
1817
#include <optional>
1918
#include <ranges>
2019
#include <type_traits>
2120
#include <utility>
2221

22+
template <typename T>
23+
constexpr bool test_range_concept() {
24+
return std::ranges::range<std::optional<T>>;
25+
}
26+
2327
template <typename T, std::remove_reference_t<T> __val>
2428
constexpr bool test() {
2529
std::remove_reference_t<T> v{__val};
2630
std::optional<T> opt{v};
31+
{
32+
assert(test_range_concept<T>());
33+
}
2734

2835
{ // Dereferencing an iterator of an engaged optional will return the same value that the optional holds.
2936
auto it = opt.begin();
@@ -94,6 +101,10 @@ constexpr bool tests() {
94101
assert((test<const int&, 2>()));
95102
assert((test<const char&, 'b'>()));
96103

104+
assert(!test_range_concept<int (&)()>());
105+
assert(!test_range_concept<int (&)[]>());
106+
assert(!test_range_concept<int (&)[42]>());
107+
97108
return true;
98109
}
99110

0 commit comments

Comments
 (0)