diff --git a/include/rfl/Box.hpp b/include/rfl/Box.hpp index 998be07b..6efd45c3 100644 --- a/include/rfl/Box.hpp +++ b/include/rfl/Box.hpp @@ -24,6 +24,11 @@ class Box { Box(Box&& _other) = default; + template , + bool>::type = true> + Box(Box&& _other) noexcept + : ptr_(std::make_unique(std::forward(*_other))) {} + ~Box() = default; /// Returns a pointer to the underlying object @@ -35,9 +40,23 @@ class Box { /// Move assignment operator Box& operator=(Box&& _other) noexcept = default; + /// Move assignment operator + template , + bool>::type = true> + Box& operator=(Box&& _other) noexcept { + ptr_ = std::make_unique(std::forward(*_other)); + return *this; + } + + /// Returns the underlying object. + T& operator*() { return *ptr_; } + /// Returns the underlying object. T& operator*() const { return *ptr_; } + /// Returns the underlying object. + T* operator->() { return ptr_.get(); } + /// Returns the underlying object. T* operator->() const { return ptr_.get(); } @@ -59,6 +78,18 @@ Box make_box(Args&&... _args) { return Box::make(std::forward(_args)...); } +template +inline auto operator<=>(const Box& _t1, const Box& _t2) { + return _t1.ptr() <=> _t2.ptr(); +} + +template +inline std::basic_ostream& operator<<( + std::basic_ostream& _os, const Box& _b) { + _os << _b.get(); + return _os; +} + } // namespace rfl #endif