File: emplace.cpp

package info (click to toggle)
tl-optional 1.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 344 kB
  • sloc: cpp: 2,570; sh: 26; makefile: 8
file content (24 lines) | stat: -rw-r--r-- 621 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <catch2/catch_all.hpp>
#include <tl/optional.hpp>
#include <utility>
#include <tuple>

TEST_CASE("Emplace", "[emplace]") {
    tl::optional<std::pair<std::pair<int,int>, std::pair<double, double>>> i;
    i.emplace(std::piecewise_construct, std::make_tuple(0,2), std::make_tuple(3,4));
    REQUIRE(i->first.first == 0);
    REQUIRE(i->first.second == 2);
    REQUIRE(i->second.first == 3);
    REQUIRE(i->second.second == 4);    
}

struct A {
    A() {
        throw std::exception();
    }
};

TEST_CASE("Emplace with exception thrown", "[emplace]") {
    tl::optional<A> a;
    REQUIRE_THROWS(a.emplace());
}