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// <optional>
11
12// template <class U> optional<T>& operator=(U&& v);
13
14#include <experimental/optional>
15#include <type_traits>
16#include <cassert>
17#include <memory>
18
19#if _LIBCPP_STD_VER > 11
20
21using std::experimental::optional;
22
23struct X
24{
25};
26
27#endif  // _LIBCPP_STD_VER > 11
28
29int main()
30{
31#if _LIBCPP_STD_VER > 11
32    static_assert(std::is_assignable<optional<int>, int>::value, "");
33    static_assert(std::is_assignable<optional<int>, int&>::value, "");
34    static_assert(std::is_assignable<optional<int>&, int>::value, "");
35    static_assert(std::is_assignable<optional<int>&, int&>::value, "");
36    static_assert(std::is_assignable<optional<int>&, const int&>::value, "");
37    static_assert(!std::is_assignable<const optional<int>&, const int&>::value, "");
38    static_assert(!std::is_assignable<optional<int>, X>::value, "");
39    {
40        optional<int> opt;
41        opt = 1;
42        assert(static_cast<bool>(opt) == true);
43        assert(*opt == 1);
44    }
45    {
46        optional<int> opt;
47        const int i = 2;
48        opt = i;
49        assert(static_cast<bool>(opt) == true);
50        assert(*opt == i);
51    }
52    {
53        optional<int> opt(3);
54        const int i = 2;
55        opt = i;
56        assert(static_cast<bool>(opt) == true);
57        assert(*opt == i);
58    }
59    {
60        optional<std::unique_ptr<int>> opt;
61        opt = std::unique_ptr<int>(new int(3));
62        assert(static_cast<bool>(opt) == true);
63        assert(**opt == 3);
64    }
65    {
66        optional<std::unique_ptr<int>> opt(std::unique_ptr<int>(new int(2)));
67        opt = std::unique_ptr<int>(new int(3));
68        assert(static_cast<bool>(opt) == true);
69        assert(**opt == 3);
70    }
71#endif  // _LIBCPP_STD_VER > 11
72}
73