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