Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add constexpr #392

Merged
merged 10 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions include/mitama/boolinators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@

namespace mitama
{
inline maybe<std::monostate>
inline constexpr maybe<std::monostate>
as_maybe(bool b)
{
return b ? maybe<std::monostate>{ std::in_place } : nothing;
}

template <class T>
inline maybe<T>
inline constexpr maybe<T>
as_just(bool b, T&& some)
{
return b ? maybe<T>{ std::forward<T>(some) } : nothing;
}

template <class F>
inline maybe<std::invoke_result_t<F&&>>
inline constexpr maybe<std::invoke_result_t<F&&>>
as_just_from(bool b, F&& some)
{
return b ? maybe{ std::invoke(std::forward<F>(some)) } : nothing;
}

template <class T>
inline maybe<T>
inline constexpr maybe<T>
and_maybe(bool b, const maybe<T>& may)
{
return b ? may : nothing;
Expand All @@ -38,29 +38,29 @@ and_maybe(bool b, const maybe<T>& may)
template <class F>
requires std::is_invocable_v<F&&>
&& is_maybe<std::invoke_result_t<F&&>>::value
inline auto
inline constexpr auto
and_maybe_from(bool b, F&& may) -> std::invoke_result_t<F&&>
{
return b ? std::invoke(std::forward<F>(may)) : nothing;
}

template <class T>
inline result<T>
inline constexpr result<T>
as_ok(bool b, T&& ok)
{
return b ? result<T>(success(std::forward<T>(ok))) : failure();
}

template <class T, class E>
inline result<T, E>
inline constexpr result<T, E>
as_result(bool b, T&& ok, E&& err)
{
return b ? result<T, E>{ success(std::forward<T>(ok)) }
: result<T, E>{ failure(std::forward<E>(err)) };
}

template <class F, class G>
inline result<std::invoke_result_t<F>, std::invoke_result_t<G&&>>
inline constexpr result<std::invoke_result_t<F>, std::invoke_result_t<G&&>>
as_result_from(bool b, F&& ok, G&& err)
{
using result_type =
Expand All @@ -70,15 +70,15 @@ as_result_from(bool b, F&& ok, G&& err)
}

template <class E>
inline result<void, E>
inline constexpr result<void, E>
ok_or(bool b, E&& err)
{
return b ? result<void, E>{ success() }
: result<void, E>{ failure(std::forward<E>(err)) };
}

template <class G>
inline result<void, std::invoke_result_t<G&&>>
inline constexpr result<void, std::invoke_result_t<G&&>>
ok_or_else(bool b, G&& err)
{
using result_type = result<void, std::invoke_result_t<G>>;
Expand Down
74 changes: 37 additions & 37 deletions include/mitama/maybe/factory/just_nothing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,14 @@ class [[nodiscard]] just_t<T>

template <class U>
requires meta::is_comparable_with<T, U>::value
friend bool operator==(const maybe<U>& lhs, const just_t& rhs)
friend constexpr bool operator==(const maybe<U>& lhs, const just_t& rhs)
{
return lhs && (lhs.unwrap() == rhs.get());
}

template <class U>
requires meta::is_comparable_with<T, U>::value
friend bool operator==(const just_t& lhs, const maybe<U>& rhs)
friend constexpr bool operator==(const just_t& lhs, const maybe<U>& rhs)
{
return rhs && (lhs.get() == rhs.unwrap());
}
Expand All @@ -218,14 +218,14 @@ class [[nodiscard]] just_t<T>

template <class U>
requires meta::is_comparable_with<T, U>::value
friend bool operator!=(const maybe<U>& lhs, const just_t& rhs)
friend constexpr bool operator!=(const maybe<U>& lhs, const just_t& rhs)
{
return lhs.is_nothing() || !(lhs.unwrap() == rhs.get());
}

template <class U>
requires meta::is_comparable_with<T, U>::value
friend bool operator!=(const just_t& lhs, const maybe<U>& rhs)
friend constexpr bool operator!=(const just_t& lhs, const maybe<U>& rhs)
{
return rhs.is_nothing() || !(lhs.get() == rhs.unwrap());
}
Expand All @@ -249,14 +249,14 @@ class [[nodiscard]] just_t<T>

template <class U>
requires meta::is_less_comparable_with<T, U>::value
friend bool operator<(const just_t& lhs, const maybe<U>& rhs)
friend constexpr bool operator<(const just_t& lhs, const maybe<U>& rhs)
{
return rhs ? lhs.get() < rhs.unwrap() : false;
}

template <class U>
requires meta::is_less_comparable_with<T, U>::value
friend bool operator<(const maybe<U>& lhs, const just_t& rhs)
friend constexpr bool operator<(const maybe<U>& lhs, const just_t& rhs)
{
return lhs ? lhs.unwrap() < rhs.get() : true;
}
Expand All @@ -282,7 +282,7 @@ class [[nodiscard]] just_t<T>
template <class U>
requires meta::is_less_comparable_with<T, U>::value
&& meta::is_comparable_with<T, U>::value
friend bool operator<=(const just_t& lhs, const maybe<U>& rhs)
friend constexpr bool operator<=(const just_t& lhs, const maybe<U>& rhs)
{
return rhs ? (lhs.get() < rhs.unwrap() || lhs.get() == rhs.unwrap())
: false;
Expand All @@ -291,7 +291,7 @@ class [[nodiscard]] just_t<T>
template <class U>
requires meta::is_less_comparable_with<T, U>::value
&& meta::is_comparable_with<T, U>::value
friend bool operator<=(const maybe<U>& lhs, const just_t& rhs)
friend constexpr bool operator<=(const maybe<U>& lhs, const just_t& rhs)
{
return lhs ? (lhs.unwrap() < rhs.get() || lhs.unwrap() == rhs.get()) : true;
}
Expand All @@ -308,21 +308,21 @@ class [[nodiscard]] just_t<T>

template <class U>
requires meta::is_comparable_with<T, U>::value
bool operator>(const just_t<U>& rhs) const
constexpr bool operator>(const just_t<U>& rhs) const
{
return rhs < *this;
}

template <class U>
requires meta::is_less_comparable_with<T, U>::value
friend bool operator>(const just_t& lhs, const maybe<U>& rhs)
friend constexpr bool operator>(const just_t& lhs, const maybe<U>& rhs)
{
return rhs < lhs;
}

template <class U>
requires meta::is_less_comparable_with<T, U>::value
friend bool operator>(const maybe<U>& lhs, const just_t& rhs)
friend constexpr bool operator>(const maybe<U>& lhs, const just_t& rhs)
{
return rhs < lhs;
}
Expand All @@ -340,36 +340,36 @@ class [[nodiscard]] just_t<T>
template <class U>
requires meta::is_less_comparable_with<T, U>::value
&& meta::is_comparable_with<T, U>::value
bool operator>=(const just_t<U>& rhs) const
constexpr bool operator>=(const just_t<U>& rhs) const
{
return rhs <= *this;
}

template <class U>
requires meta::is_less_comparable_with<T, U>::value
&& meta::is_comparable_with<T, U>::value
friend bool operator>=(const just_t& lhs, const maybe<U>& rhs)
friend constexpr bool operator>=(const just_t& lhs, const maybe<U>& rhs)
{
return rhs <= lhs;
}

template <class U>
requires meta::is_less_comparable_with<T, U>::value
&& meta::is_comparable_with<T, U>::value
friend bool operator>=(const maybe<U>& lhs, const just_t& rhs)
friend constexpr bool operator>=(const maybe<U>& lhs, const just_t& rhs)
{
return rhs <= lhs;
}

T& get() &
constexpr T& get() &
{
return x;
}
const T& get() const&
constexpr const T& get() const&
{
return x;
}
T&& get() &&
constexpr T&& get() &&
{
return std::move(x);
}
Expand Down Expand Up @@ -427,14 +427,14 @@ class [[nodiscard]] just_t<T&>

template <class U>
requires meta::is_comparable_with<T, U>::value
friend bool operator==(const maybe<U>& lhs, const just_t& rhs)
friend constexpr bool operator==(const maybe<U>& lhs, const just_t& rhs)
{
return lhs && (lhs.unwrap() == rhs.get());
}

template <class U>
requires meta::is_comparable_with<T, U>::value
friend bool operator==(const just_t& lhs, const maybe<U>& rhs)
friend constexpr bool operator==(const just_t& lhs, const maybe<U>& rhs)
{
return rhs && (lhs.get() == rhs.unwrap());
}
Expand All @@ -458,14 +458,14 @@ class [[nodiscard]] just_t<T&>

template <class U>
requires meta::is_comparable_with<T, U>::value
friend bool operator!=(const maybe<U>& lhs, const just_t& rhs)
friend constexpr bool operator!=(const maybe<U>& lhs, const just_t& rhs)
{
return lhs.is_nothing() || !(lhs.unwrap() == rhs.get());
}

template <class U>
requires meta::is_comparable_with<T, U>::value
friend bool operator!=(const just_t& lhs, const maybe<U>& rhs)
friend constexpr bool operator!=(const just_t& lhs, const maybe<U>& rhs)
{
return rhs.is_nothing() || !(lhs.get() == rhs.unwrap());
}
Expand All @@ -489,14 +489,14 @@ class [[nodiscard]] just_t<T&>

template <class U>
requires meta::is_less_comparable_with<T, U>::value
friend bool operator<(const just_t& lhs, const maybe<U>& rhs)
friend constexpr bool operator<(const just_t& lhs, const maybe<U>& rhs)
{
return rhs ? lhs.get() < rhs.unwrap() : false;
}

template <class U>
requires meta::is_less_comparable_with<T, U>::value
friend bool operator<(const maybe<U>& lhs, const just_t& rhs)
friend constexpr bool operator<(const maybe<U>& lhs, const just_t& rhs)
{
return lhs ? lhs.unwrap() < rhs.get() : true;
}
Expand All @@ -522,7 +522,7 @@ class [[nodiscard]] just_t<T&>
template <class U>
requires meta::is_less_comparable_with<T, U>::value
&& meta::is_comparable_with<T, U>::value
friend bool operator<=(const just_t& lhs, const maybe<U>& rhs)
friend constexpr bool operator<=(const just_t& lhs, const maybe<U>& rhs)
{
return rhs ? (lhs.get() < rhs.unwrap() || lhs.get() == rhs.unwrap())
: false;
Expand All @@ -531,7 +531,7 @@ class [[nodiscard]] just_t<T&>
template <class U>
requires meta::is_less_comparable_with<T, U>::value
&& meta::is_comparable_with<T, U>::value
friend bool operator<=(const maybe<U>& lhs, const just_t& rhs)
friend constexpr bool operator<=(const maybe<U>& lhs, const just_t& rhs)
{
return lhs ? (lhs.unwrap() < rhs.get() || lhs.unwrap() == rhs.get()) : true;
}
Expand All @@ -548,21 +548,21 @@ class [[nodiscard]] just_t<T&>

template <class U>
requires meta::is_comparable_with<T, U>::value
bool operator>(const just_t<U>& rhs) const
constexpr bool operator>(const just_t<U>& rhs) const
{
return rhs < *this;
}

template <class U>
requires meta::is_less_comparable_with<T, U>::value
friend bool operator>(const just_t& lhs, const maybe<U>& rhs)
friend constexpr bool operator>(const just_t& lhs, const maybe<U>& rhs)
{
return rhs < lhs;
}

template <class U>
requires meta::is_less_comparable_with<T, U>::value
friend bool operator>(const maybe<U>& lhs, const just_t& rhs)
friend constexpr bool operator>(const maybe<U>& lhs, const just_t& rhs)
{
return rhs < lhs;
}
Expand All @@ -580,36 +580,36 @@ class [[nodiscard]] just_t<T&>
template <class U>
requires meta::is_less_comparable_with<T, U>::value
&& meta::is_comparable_with<T, U>::value
bool operator>=(const just_t<U>& rhs) const
constexpr bool operator>=(const just_t<U>& rhs) const
{
return rhs <= *this;
}

template <class U>
requires meta::is_less_comparable_with<T, U>::value
&& meta::is_comparable_with<T, U>::value
friend bool operator>=(const just_t& lhs, const maybe<U>& rhs)
friend constexpr bool operator>=(const just_t& lhs, const maybe<U>& rhs)
{
return rhs <= lhs;
}

template <class U>
requires meta::is_less_comparable_with<T, U>::value
&& meta::is_comparable_with<T, U>::value
friend bool operator>=(const maybe<U>& lhs, const just_t& rhs)
friend constexpr bool operator>=(const maybe<U>& lhs, const just_t& rhs)
{
return rhs <= lhs;
}

T& get() &
constexpr T& get() &
{
return x.get();
}
const T& get() const&
constexpr const T& get() const&
{
return x.get();
}
T& get() &&
constexpr T& get() &&
{
return x.get();
}
Expand All @@ -623,7 +623,7 @@ operator<<(std::ostream& os, const just_t<T>& j)
}

template <class Target = void, class... Types>
auto
constexpr auto
just(Types&&... v)
{
if constexpr (sizeof...(Types) > 1)
Expand All @@ -644,7 +644,7 @@ just(Types&&... v)
}

template <class Target = void, class T, class... Types>
auto
constexpr auto
just(std::initializer_list<T> il, Types&&... v)
{
return just_t<
Expand All @@ -661,7 +661,7 @@ class [[nodiscard]] just_t<_just_detail::forward_mode<T>, Args...>
public:
constexpr explicit just_t(Args... args) : args(std::forward<Args>(args)...) {}

auto operator()() &&
constexpr auto operator()() &&
{
return std::apply(
[](auto&&... fwd)
Expand Down
Loading
Loading