File: bases.cpp

package info (click to toggle)
gringo 5.8.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 32,128 kB
  • sloc: cpp: 210,867; ansic: 37,507; python: 11,271; yacc: 825; javascript: 627; sh: 368; xml: 364; makefile: 102
file content (107 lines) | stat: -rw-r--r-- 4,076 bytes parent folder | download | duplicates (3)
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 <catch2/catch.hpp>
#include <tl/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