1111#include < cassert>
1212#include < ranges>
1313#include < type_traits>
14- #include < vector>
15-
16- constexpr int buff[] = {1 , 2 , 3 , 4 };
1714
1815struct DefaultConstructibleView : std::ranges::view_base {
1916 constexpr DefaultConstructibleView () : begin_(buff), end_(buff + 4 ) {}
@@ -31,94 +28,14 @@ struct NoDefaultView : std::ranges::view_base {
3128 int * end () const ;
3229};
3330
34- struct NoexceptView : std::ranges::view_base {
35- NoexceptView () noexcept ;
36- int const * begin () const ;
37- int const * end () const ;
38- };
39-
40- struct HelperView : std::ranges::view_base {
41- constexpr HelperView (const int * begin, const int * end) : begin_(begin), end_(end) {}
42- constexpr int const * begin () const { return begin_; }
43- constexpr int const * end () const { return end_; }
44-
45- private:
46- int const * begin_;
47- int const * end_;
48- };
49-
50- constexpr void test_with_one_view () {
51- {
52- using View = std::ranges::concat_view<DefaultConstructibleView>;
53- View view;
54- auto it = view.begin ();
55- auto end = view.end ();
56- assert (*it++ == 1 );
57- assert (*it++ == 2 );
58- assert (*it++ == 3 );
59- assert (*it++ == 4 );
60- assert (it == end);
61- }
62- }
63-
64- constexpr void test_with_more_than_one_view () {
65- {
66- // 2 views are of same type
67- using View = std::ranges::concat_view<HelperView, HelperView>;
68- int arr1[] = {1 , 2 };
69- int arr2[] = {3 , 4 };
70- HelperView range1 (arr1, arr1 + 2 );
71- HelperView range2 (arr2, arr2 + 2 );
72- View view (range1, range2);
73- auto it = view.begin ();
74- auto end = view.end ();
75- assert (*it++ == 1 );
76- assert (*it++ == 2 );
77- assert (*it++ == 3 );
78- assert (*it++ == 4 );
79- assert (it == end);
80- }
81-
82- {
83- // 2 views are of different types
84- using View = std::ranges::concat_view<HelperView, DefaultConstructibleView>;
85- int arr1[] = {1 , 2 };
86- HelperView range1 (arr1, arr1 + 2 );
87- DefaultConstructibleView range2;
88- View view (range1, range2);
89- auto it = view.begin ();
90- auto end = view.end ();
91- assert (*it++ == 1 );
92- assert (*it++ == 2 );
93- assert (*it++ == 1 );
94- assert (*it++ == 2 );
95- assert (*it++ == 3 );
96- assert (*it++ == 4 );
97- assert (it == end);
98- }
99- }
100-
101- constexpr bool tests () {
102- test_with_one_view ();
103- test_with_more_than_one_view ();
104-
105- // Check cases where the default constructor isn't provided
106- {
107- static_assert (!std::is_default_constructible_v<std::ranges::concat_view<NoDefaultView >>);
108- }
109-
110- // Check noexcept-ness
111- {
112- {
113- using View = std::ranges::concat_view<DefaultConstructibleView>;
114- static_assert (!noexcept (View ()));
115- }
116- {
117- using View = std::ranges::concat_view<NoexceptView>;
118- static_assert (noexcept (View ()));
119- }
120- }
31+ using DefaultView = std::ranges::concat_view<DefaultConstructibleView, DefaultConstructibleView>;
32+ using BadView1 = std::ranges::concat_view<DefaultConstructibleView, NoDefaultView>;
33+ using BadView2 = std::ranges::concat_view<NoDefaultView, NoDefaultView>;
12134
35+ constexpr bool test () {
36+ static_assert (std::is_default_constructible_v<DefaultView>);
37+ static_assert (!std::is_default_constructible_v<BadView1>);
38+ static_assert (!std::is_default_constructible_v<BadView2>);
12239 return true ;
12340}
12441
0 commit comments