summaryrefslogtreecommitdiff
path: root/asl/tests/types.hpp
blob: d47c237e70573e59d7d79141816072e12c066035 (plain)
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
// Copyright 2025 Steven Le Rouzic
//
// SPDX-License-Identifier: BSD-3-Clause

#pragma once

#include "asl/base/utility.hpp"

struct TrivialType
{
    int x;
    TrivialType() = default;
    TrivialType(const TrivialType&) = default;
    TrivialType(TrivialType&&) = default;
    TrivialType& operator=(const TrivialType&) = default;
    TrivialType& operator=(TrivialType&&) = default;
    ~TrivialType() = default;
};

struct TrivialTypeDefaultValue
{
    int x{};
    TrivialTypeDefaultValue() = default;
    TrivialTypeDefaultValue(const TrivialTypeDefaultValue&) = default;
    TrivialTypeDefaultValue(TrivialTypeDefaultValue&&) = default;
    TrivialTypeDefaultValue& operator=(const TrivialTypeDefaultValue&) = default;
    TrivialTypeDefaultValue& operator=(TrivialTypeDefaultValue&&) = default;
    ~TrivialTypeDefaultValue() = default;
};

struct WithDestructor
{
    WithDestructor() = default;
    WithDestructor(const WithDestructor&) = default;
    WithDestructor(WithDestructor&&) = default;
    WithDestructor& operator=(const WithDestructor&) = default;
    WithDestructor& operator=(WithDestructor&&) = default;
    ~WithDestructor() {} // NOLINT
};

struct Copyable // NOLINT
{
    Copyable(const Copyable&) {} // NOLINT
    Copyable& operator=(const Copyable&); // NOLINT
};

struct MoveableOnly // NOLINT
{
    MoveableOnly(const MoveableOnly&) = delete;
    MoveableOnly& operator=(const MoveableOnly&) = delete;
    MoveableOnly(MoveableOnly&&);
    MoveableOnly& operator=(MoveableOnly&&); // NOLINT
};

struct Pinned // NOLINT
{
    Pinned(const Pinned&) = delete;
    Pinned& operator=(const Pinned&) = delete;
    Pinned(Pinned&&) = delete;
    Pinned& operator=(Pinned&&) = delete;
};

struct DestructorObserver
{
    bool* destroyed;

    explicit DestructorObserver(bool* destroyed_) : destroyed{destroyed_} {}

    DestructorObserver(const DestructorObserver&) = delete;
    DestructorObserver& operator=(const DestructorObserver&) = delete;

    DestructorObserver(DestructorObserver&& other)
        : destroyed{asl::exchange(other.destroyed, nullptr)}
    {}

    DestructorObserver& operator=(DestructorObserver&& other)
    {
        if (this != &other)
        {
            destroyed = asl::exchange(other.destroyed, nullptr);
        }
        return *this;
    }

    ~DestructorObserver()
    {
        if (destroyed != nullptr)
        {
            ASL_ASSERT_RELEASE(*destroyed == false);
            *destroyed = true;
        }
    }
};