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 #include <memory>
11 #include <string>
12 #include <cassert>
13 
14 //    The only way to create an unique_ptr<T[]> is to default construct them.
15 
16 class foo {
17 public:
18     foo () : val_(3) {}
19     int get () const { return val_; }
20 private:
21     int val_;
22     };
23 
24 int main()
25 {
26 #if _LIBCPP_STD_VER > 11
27     {
28     auto p1 = std::make_unique<int[]>(5);
29     for ( int i = 0; i < 5; ++i )
30         assert ( p1[i] == 0 );
31     }
32 
33     {
34     auto p2 = std::make_unique<std::string[]>(5);
35     for ( int i = 0; i < 5; ++i )
36         assert ( p2[i].size () == 0 );
37     }
38 
39     {
40     auto p3 = std::make_unique<foo[]>(7);
41     for ( int i = 0; i < 7; ++i )
42         assert ( p3[i].get () == 3 );
43     }
44 #endif  // _LIBCPP_STD_VER > 11
45 }
46