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