Skip to content

Commit 6c0fcbc

Browse files
committed
Optional enhancements
1 parent 648fa27 commit 6c0fcbc

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

include/mrdox/ADT/Optional.hpp

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#define MRDOX_ADT_OPTIONAL_HPP
1414

1515
#include <mrdox/Platform.hpp>
16+
#include <concepts>
1617
#include <type_traits>
1718
#include <utility>
1819

@@ -27,9 +28,11 @@ namespace mrdox {
2728
struct DefaultEmptyPredicate
2829
{
2930
template<class T>
30-
requires
31-
requires(T t) { t.empty(); }
3231
constexpr bool operator()(T const& t) const noexcept
32+
requires requires
33+
{
34+
{ t.empty() } -> std::convertible_to<bool>;
35+
}
3336
{
3437
return t.empty();
3538
}
@@ -73,6 +76,26 @@ class Optional
7376
return t_ = T(std::forward<Args>(args)...);
7477
}
7578

79+
constexpr value_type& value() & noexcept
80+
{
81+
return t_;
82+
}
83+
84+
constexpr const value_type& value() const & noexcept
85+
{
86+
return t_;
87+
}
88+
89+
constexpr value_type&& value() && noexcept
90+
{
91+
return std::move(t_);
92+
}
93+
94+
constexpr const value_type&& value() const && noexcept
95+
{
96+
return std::move(t_);
97+
}
98+
7699
constexpr value_type& operator*() noexcept
77100
{
78101
return t_;
@@ -83,6 +106,16 @@ class Optional
83106
return t_;
84107
}
85108

109+
constexpr value_type* operator->() noexcept
110+
{
111+
return &t_;
112+
}
113+
114+
constexpr value_type const* operator->() const noexcept
115+
{
116+
return &t_;
117+
}
118+
86119
constexpr explicit operator bool() const noexcept
87120
{
88121
return has_value();

0 commit comments

Comments
 (0)