xref: /llvm-project/libcxx/test/std/iterators/iterator.range/begin-end.initializer_list.pass.cpp (revision 000940e2964d27ea2ce29c107198e718f7de3d63)
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++03, c++11
10 
11 // <iterator>
12 //
13 // Note that begin and end are tested in libcxx/test/std/language.support/support.initlist/support.initlist.range/begin_end.pass.cpp
14 //
15 // template <class E> constexpr reverse_iterator<const E*> rbegin(initializer_list<E> il); // C++14, constexpr since C++17
16 // template <class E> constexpr reverse_iterator<const E*> rend(initializer_list<E> il);   // C++14, constexpr since C++17
17 
18 #include <cassert>
19 #include <initializer_list>
20 #include <iterator>
21 
22 #include "test_macros.h"
23 
test()24 TEST_CONSTEXPR_CXX17 bool test() {
25   std::initializer_list<int> il = {1, 2, 3};
26   ASSERT_SAME_TYPE(decltype(std::rbegin(il)), std::reverse_iterator<const int*>);
27   ASSERT_SAME_TYPE(decltype(std::rend(il)), std::reverse_iterator<const int*>);
28   assert(std::rbegin(il).base() == il.end());
29   assert(std::rend(il).base() == il.begin());
30 
31   const auto& cil = il;
32   ASSERT_SAME_TYPE(decltype(std::rbegin(cil)), std::reverse_iterator<const int*>);
33   ASSERT_SAME_TYPE(decltype(std::rend(cil)), std::reverse_iterator<const int*>);
34   assert(std::rbegin(cil).base() == il.end());
35   assert(std::rend(cil).base() == il.begin());
36   return true;
37 }
38 
main(int,char **)39 int main(int, char**) {
40   test();
41 #if TEST_STD_VER >= 17
42   static_assert(test());
43 #endif
44 
45   return 0;
46 }
47