Botcraft 1.21.4
Loading...
Searching...
No Matches
RecursiveWrapper.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4
5
6namespace ProtocolCraft
7{
8 namespace Internal
9 {
10 /// @brief Template magic to have a full type instead of an incomplete one as required for example by std::variant
11 /// @tparam T Any incomplete class we want to wrap
12 template<typename T>
14 {
15 public:
16 RecursiveWrapper() = delete;
17 ~RecursiveWrapper() = default;
18
20 {
21 p = std::make_unique<T>(*r.p);
22 }
23
25 {
26 p = std::move(r.p);
27 }
28
29 RecursiveWrapper(const T& r) noexcept
30 {
31 p = std::make_unique<T>(r);
32 }
33
34 RecursiveWrapper(T&& r) noexcept
35 {
36 p = std::make_unique<T>(std::move(r));
37 }
38
39 const T& get() const noexcept
40 {
41 return *p.get();
42 }
43
44 T& get() noexcept
45 {
46 return *p.get();
47 }
48
50 {
51 p = std::make_unique<T>(*other.p);
52 return *this;
53 }
54
56 {
57 p = std::move(other.p);
58 return *this;
59 }
60
61 private:
62 std::unique_ptr<T> p;
63 };
64 }
65}
Template magic to have a full type instead of an incomplete one as required for example by std::varia...
RecursiveWrapper(RecursiveWrapper &&r) noexcept
RecursiveWrapper(const RecursiveWrapper &r) noexcept
RecursiveWrapper & operator=(const RecursiveWrapper &other) noexcept
RecursiveWrapper & operator=(RecursiveWrapper &&other) noexcept