[ox/std] Fix Optional deref operator, in_place constructor

This commit is contained in:
Gary Talent 2023-12-22 04:41:39 -06:00
parent 8526b3fa51
commit 907ead2948
2 changed files with 12 additions and 6 deletions

View File

@ -28,7 +28,7 @@ class Optional {
constexpr Optional() noexcept = default; constexpr Optional() noexcept = default;
template<typename ...Args> template<typename ...Args>
explicit constexpr Optional(Args &&... args); explicit constexpr Optional(ox::in_place_t, Args &&... args);
constexpr Optional(const Optional &other) { constexpr Optional(const Optional &other) {
if (other.m_ptr) { if (other.m_ptr) {
@ -65,19 +65,19 @@ class Optional {
} }
constexpr T &operator*() & noexcept { constexpr T &operator*() & noexcept {
return m_ptr; return *m_ptr;
} }
constexpr const T &operator*() const & noexcept { constexpr const T &operator*() const & noexcept {
return m_ptr; return *m_ptr;
} }
constexpr T &&operator*() && noexcept { constexpr T &&operator*() && noexcept {
return m_ptr; return *m_ptr;
} }
constexpr const T &&operator*() const && noexcept { constexpr const T &&operator*() const && noexcept {
return m_ptr; return *m_ptr;
} }
constexpr T *operator->() noexcept { constexpr T *operator->() noexcept {
@ -163,7 +163,7 @@ class Optional {
template<typename T, std::size_t buffSize> template<typename T, std::size_t buffSize>
template<typename... Args> template<typename... Args>
constexpr Optional<T, buffSize>::Optional(Args &&... args) { constexpr Optional<T, buffSize>::Optional(ox::in_place_t, Args &&... args) {
emplace(ox::forward<Args>(args)...); emplace(ox::forward<Args>(args)...);
} }

View File

@ -12,6 +12,12 @@
namespace ox { namespace ox {
struct in_place_t {
explicit constexpr in_place_t() = default;
};
inline constexpr ox::in_place_t in_place;
template<class T> template<class T>
constexpr T &&forward(remove_reference_t<T> &t) noexcept { constexpr T &&forward(remove_reference_t<T> &t) noexcept {
return static_cast<T&&>(t); return static_cast<T&&>(t);