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 #if __cplusplus <= 201402L
15 int main () {}
16 #else
17 
18 
19 #include <__config>
20 
21 #include <iterator>
22 #include <cassert>
23 #include <vector>
24 #include <array>
25 #include <list>
26 #include <initializer_list>
27 
28 template<typename C>
29 void test_const_container( const C& c )
30 {
31     assert ( std::size(c)   == c.size());
32 }
33 
34 template<typename T>
35 void test_const_container( const std::initializer_list<T>& c)
36 {
37     assert ( std::size(c)   == c.size());
38 }
39 
40 template<typename C>
41 void test_container( C& c)
42 {
43     assert ( std::size(c)   == c.size());
44 }
45 
46 template<typename T>
47 void test_container( std::initializer_list<T>& c )
48 {
49     assert ( std::size(c)   == c.size());
50 }
51 
52 template<typename T, size_t Sz>
53 void test_const_array( const T (&array)[Sz] )
54 {
55     assert ( std::size(array) == Sz );
56 }
57 
58 int main()
59 {
60     std::vector<int> v; v.push_back(1);
61     std::list<int>   l; l.push_back(2);
62     std::array<int, 1> a; a[0] = 3;
63     std::initializer_list<int> il = { 4 };
64 
65     test_container ( v );
66     test_container ( l );
67     test_container ( a );
68     test_container ( il );
69 
70     test_const_container ( v );
71     test_const_container ( l );
72     test_const_container ( a );
73     test_const_container ( il );
74 
75     static constexpr int arrA [] { 1, 2, 3 };
76     test_const_array ( arrA );
77 }
78 
79 #endif
80