blob: 1ad3a6d537650188f5be4901069e7fa17dd16378 (
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
|
#pragma once
namespace crepe {
/**
* \brief Optional reference utility
*
* This class doesn't need to know the full definition of \c T to be used.
*
* \tparam T Value type
*/
template <typename T>
class OptionalRef {
public:
OptionalRef() = default;
OptionalRef(T &);
OptionalRef<T> & operator=(T &);
explicit operator bool() const noexcept;
void set(T &) noexcept;
T & get() const;
void clear() noexcept;
OptionalRef(const OptionalRef<T> &);
OptionalRef(OptionalRef<T> &&);
OptionalRef<T> & operator=(const OptionalRef<T> &);
OptionalRef<T> & operator=(OptionalRef<T> &&);
private:
/**
* \brief Reference to the value of type \c T
*
* \note This raw pointer is *not* managed, and only used as a reference!
*/
T * ref = nullptr;
};
}
#include "OptionalRef.hpp"
|