1// { dg-options "-std=gnu++14" }
2// { dg-do run }
3
4// Copyright (C) 2013-2015 Free Software Foundation, Inc.
5//
6// This file is part of the GNU ISO C++ Library.  This library is free
7// software; you can redistribute it and/or modify it under the
8// terms of the GNU General Public License as published by the
9// Free Software Foundation; either version 3, or (at your option)
10// any later version.
11
12// This library is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15// GNU General Public License for more details.
16
17// You should have received a copy of the GNU General Public License along
18// with this library; see the file COPYING3.  If not see
19// <http://www.gnu.org/licenses/>.
20
21#include <experimental/optional>
22#include <testsuite_hooks.h>
23
24#include <vector>
25
26int main()
27{
28  // [20.5.5] In-place construction
29  static_assert( std::is_same<decltype(std::experimental::in_place), const std::experimental::in_place_t>(), "" );
30  static_assert( std::is_empty<std::experimental::in_place_t>(), "" );
31
32  {
33    std::experimental::optional<int> o { std::experimental::in_place };
34    VERIFY( o );
35    VERIFY( *o == int() );
36
37    static_assert( !std::is_convertible<std::experimental::in_place_t, std::experimental::optional<int>>(), "" );
38  }
39
40  {
41    std::experimental::optional<int> o { std::experimental::in_place, 42 };
42    VERIFY( o );
43    VERIFY( *o == 42 );
44  }
45
46  {
47    std::experimental::optional<std::vector<int>> o { std::experimental::in_place, 18, 4 };
48    VERIFY( o );
49    VERIFY( o->size() == 18 );
50    VERIFY( (*o)[17] == 4 );
51  }
52
53  {
54    std::experimental::optional<std::vector<int>> o { std::experimental::in_place, { 18, 4 } };
55    VERIFY( o );
56    VERIFY( o->size() == 2 );
57    VERIFY( (*o)[0] == 18 );
58  }
59
60  {
61    std::experimental::optional<std::vector<int>> o { std::experimental::in_place, { 18, 4 }, std::allocator<int> {} };
62    VERIFY( o );
63    VERIFY( o->size() == 2 );
64    VERIFY( (*o)[0] == 18 );
65  }
66}
67