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