1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <iterator>
11 // template <class C> constexpr auto size(const C& c) -> decltype(c.size());         // C++17
12 // template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
13 
14 #include "test_macros.h"
15 
16 #if TEST_STD_VER <= 14
main()17 int main () {}
18 #else
19 
20 #include <iterator>
21 #include <cassert>
22 #include <vector>
23 #include <array>
24 #include <list>
25 #include <initializer_list>
26 
27 template<typename C>
test_const_container(const C & c)28 void test_const_container( const C& c )
29 {
30     assert ( std::size(c)   == c.size());
31 }
32 
33 template<typename T>
test_const_container(const std::initializer_list<T> & c)34 void test_const_container( const std::initializer_list<T>& c)
35 {
36     assert ( std::size(c)   == c.size());
37 }
38 
39 template<typename C>
test_container(C & c)40 void test_container( C& c)
41 {
42     assert ( std::size(c)   == c.size());
43 }
44 
45 template<typename T>
test_container(std::initializer_list<T> & c)46 void test_container( std::initializer_list<T>& c )
47 {
48     assert ( std::size(c)   == c.size());
49 }
50 
51 template<typename T, size_t Sz>
test_const_array(const T (& array)[Sz])52 void test_const_array( const T (&array)[Sz] )
53 {
54     assert ( std::size(array) == Sz );
55 }
56 
main()57 int main()
58 {
59     std::vector<int> v; v.push_back(1);
60     std::list<int>   l; l.push_back(2);
61     std::array<int, 1> a; a[0] = 3;
62     std::initializer_list<int> il = { 4 };
63 
64     test_container ( v );
65     test_container ( l );
66     test_container ( a );
67     test_container ( il );
68 
69     test_const_container ( v );
70     test_const_container ( l );
71     test_const_container ( a );
72     test_const_container ( il );
73 
74     static constexpr int arrA [] { 1, 2, 3 };
75     test_const_array ( arrA );
76 }
77 
78 #endif
79