blob: 07254e4544580e09b23cf8877e1cd1c90d129ebf [file] [log] [blame]
Brian Silvermanda861352019-02-02 16:42:28 -08001#include "catch.hpp"
2#include "optional.hpp"
3
4#include <tuple>
5#include <vector>
6
7struct takes_init_and_variadic {
8 std::vector<int> v;
9 std::tuple<int, int> t;
10 template <class... Args>
11 takes_init_and_variadic(std::initializer_list<int> l, Args &&... args)
12 : v(l), t(std::forward<Args>(args)...) {}
13};
14
15TEST_CASE("In place", "[in_place]") {
16 tl::optional<int> o1{tl::in_place};
17 tl::optional<int> o2(tl::in_place);
18 REQUIRE(o1);
19 REQUIRE(o1 == 0);
20 REQUIRE(o2);
21 REQUIRE(o2 == 0);
22
23 tl::optional<int> o3(tl::in_place, 42);
24 REQUIRE(o3 == 42);
25
26 tl::optional<std::tuple<int, int>> o4(tl::in_place, 0, 1);
27 REQUIRE(o4);
28 REQUIRE(std::get<0>(*o4) == 0);
29 REQUIRE(std::get<1>(*o4) == 1);
30
31 tl::optional<std::vector<int>> o5(tl::in_place, {0, 1});
32 REQUIRE(o5);
33 REQUIRE((*o5)[0] == 0);
34 REQUIRE((*o5)[1] == 1);
35
36 tl::optional<takes_init_and_variadic> o6(tl::in_place, {0, 1}, 2, 3);
37 REQUIRE(o6->v[0] == 0);
38 REQUIRE(o6->v[1] == 1);
39 REQUIRE(std::get<0>(o6->t) == 2);
40 REQUIRE(std::get<1>(o6->t) == 3);
41}