File: bases.cpp

package info (click to toggle)
librepcb 1.2.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 58,484 kB
  • sloc: cpp: 267,986; python: 12,100; ansic: 6,899; xml: 234; sh: 215; makefile: 115; perl: 73
file content (107 lines) | stat: -rw-r--r-- 4,066 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "catch.hpp"
#include "optional.hpp"

// Old versions of GCC don't have the correct trait names. Could fix them up if needs be.
#if (defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ <= 9 &&              \
     !defined(__clang__))
// nothing for now
#else
TEST_CASE("Triviality", "[bases.triviality]") {
    REQUIRE(std::is_trivially_copy_constructible<tl::optional<int>>::value);
    REQUIRE(std::is_trivially_copy_assignable<tl::optional<int>>::value);
    REQUIRE(std::is_trivially_move_constructible<tl::optional<int>>::value);
    REQUIRE(std::is_trivially_move_assignable<tl::optional<int>>::value);
    REQUIRE(std::is_trivially_destructible<tl::optional<int>>::value);

    {
        struct T {
            T(const T&) = default;
            T(T&&) = default;
            T& operator=(const T&) = default;
            T& operator=(T&&) = default;
            ~T() = default;
        };
        REQUIRE(std::is_trivially_copy_constructible<tl::optional<T>>::value);
        REQUIRE(std::is_trivially_copy_assignable<tl::optional<T>>::value);
        REQUIRE(std::is_trivially_move_constructible<tl::optional<T>>::value);
        REQUIRE(std::is_trivially_move_assignable<tl::optional<T>>::value);
        REQUIRE(std::is_trivially_destructible<tl::optional<T>>::value);
    }

    {
        struct T {
            T(const T&){}
            T(T&&) {};
            T& operator=(const T&) { return *this; }
            T& operator=(T&&) { return *this; };
            ~T(){}
        };
        REQUIRE(!std::is_trivially_copy_constructible<tl::optional<T>>::value);
        REQUIRE(!std::is_trivially_copy_assignable<tl::optional<T>>::value);
        REQUIRE(!std::is_trivially_move_constructible<tl::optional<T>>::value);
        REQUIRE(!std::is_trivially_move_assignable<tl::optional<T>>::value);
        REQUIRE(!std::is_trivially_destructible<tl::optional<T>>::value);
    }

}

TEST_CASE("Deletion", "[bases.deletion]") {
    REQUIRE(std::is_copy_constructible<tl::optional<int>>::value);
    REQUIRE(std::is_copy_assignable<tl::optional<int>>::value);
    REQUIRE(std::is_move_constructible<tl::optional<int>>::value);
    REQUIRE(std::is_move_assignable<tl::optional<int>>::value);
    REQUIRE(std::is_destructible<tl::optional<int>>::value);

    {
        struct T {
            T(const T&) = default;
            T(T&&) = default;
            T& operator=(const T&) = default;
            T& operator=(T&&) = default;
            ~T() = default;
        };
        REQUIRE(std::is_copy_constructible<tl::optional<T>>::value);
        REQUIRE(std::is_copy_assignable<tl::optional<T>>::value);
        REQUIRE(std::is_move_constructible<tl::optional<T>>::value);
        REQUIRE(std::is_move_assignable<tl::optional<T>>::value);
        REQUIRE(std::is_destructible<tl::optional<T>>::value);
    }

    {
        struct T {
            T(const T&)=delete;
            T(T&&)=delete;
            T& operator=(const T&)=delete;
            T& operator=(T&&)=delete;
        };
        REQUIRE(!std::is_copy_constructible<tl::optional<T>>::value);
        REQUIRE(!std::is_copy_assignable<tl::optional<T>>::value);
        REQUIRE(!std::is_move_constructible<tl::optional<T>>::value);
        REQUIRE(!std::is_move_assignable<tl::optional<T>>::value);
    }

    {
        struct T {
            T(const T&)=delete;
            T(T&&)=default;
            T& operator=(const T&)=delete;
            T& operator=(T&&)=default;
        };
        REQUIRE(!std::is_copy_constructible<tl::optional<T>>::value);
        REQUIRE(!std::is_copy_assignable<tl::optional<T>>::value);
        REQUIRE(std::is_move_constructible<tl::optional<T>>::value);
        REQUIRE(std::is_move_assignable<tl::optional<T>>::value);
    }

    {
        struct T {
            T(const T&)=default;
            T(T&&)=delete;
            T& operator=(const T&)=default;
            T& operator=(T&&)=delete;
        };
        REQUIRE(std::is_copy_constructible<tl::optional<T>>::value);
        REQUIRE(std::is_copy_assignable<tl::optional<T>>::value);
    }
}
#endif