Home | History | Annotate | Download | only in array.data
      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 // <array>
     11 
     12 // const T* data() const;
     13 
     14 #include <array>
     15 #include <cassert>
     16 
     17 #include "test_macros.h"
     18 
     19 // std::array is explicitly allowed to be initialized with A a = { init-list };.
     20 // Disable the missing braces warning for this reason.
     21 #include "disable_missing_braces_warning.h"
     22 
     23 int main()
     24 {
     25     {
     26         typedef double T;
     27         typedef std::array<T, 3> C;
     28         const C c = {1, 2, 3.5};
     29         const T* p = c.data();
     30         assert(p[0] == 1);
     31         assert(p[1] == 2);
     32         assert(p[2] == 3.5);
     33     }
     34     {
     35         typedef double T;
     36         typedef std::array<T, 0> C;
     37         const C c = {};
     38         const T* p = c.data();
     39         (void)p; // to placate scan-build
     40     }
     41 #if TEST_STD_VER > 14
     42     {
     43         typedef std::array<int, 5> C;
     44         constexpr C c1{0,1,2,3,4};
     45         constexpr const C c2{0,1,2,3,4};
     46 
     47         static_assert (  c1.data()  == &c1[0], "");
     48         static_assert ( *c1.data()  ==  c1[0], "");
     49         static_assert (  c2.data()  == &c2[0], "");
     50         static_assert ( *c2.data()  ==  c2[0], "");
     51     }
     52 #endif
     53 }
     54