Skip to content

Commit

Permalink
fix comparable_with and added meta-mixins for comparable/
Browse files Browse the repository at this point in the history
  • Loading branch information
viboes committed May 6, 2019
1 parent 83ee086 commit b498cd1
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion include/experimental/fundamental/v3/strong/mixins/comparable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,32 @@ namespace std
};
template <class Final, class Other>
struct comparable_with : comparable<Final>, equality_comparable_with<Final, Other>
{
static_assert(is_same<Final, Other>::value==false, "Final and Other must be different");
//!@{
//! relational operators
//!
//! Forwards to the underlying value
friend constexpr bool operator<(Final const& x, Other const& y) noexcept
{ return x.underlying() < y;}
friend constexpr bool operator<(Other const& x, Final const& y) noexcept
{ return x < y.underlying();}
friend constexpr bool operator>(Final const& x, Other const& y) noexcept
{ return x.underlying() > y;}
friend constexpr bool operator>(Other const& x, Final const& y) noexcept
{ return x > y.underlying();}
friend constexpr bool operator<=(Final const& x, Other const& y) noexcept
{ return x.underlying() <= y;}
friend constexpr bool operator<=(Other const& x, Final const& y) noexcept
{ return x <= y.underlying();}
friend constexpr bool operator>=(Final const& x, Other const& y) noexcept
{ return x.underlying() >= y;}
friend constexpr bool operator>=(Other const& x, Final const& y) noexcept
{ return x >= y.underlying();}
//!@}
};
template <class Final, class Other>
struct comparable_with2 : comparable<Final>, equality_comparable_with<Final, Other>
{
static_assert(is_same<Final, Other>::value==false, "Final and Other must be different");
//!@{
Expand All @@ -60,7 +86,7 @@ namespace std
friend constexpr bool operator>=(Other const& x, Final const& y) noexcept
{ return x.underlying() >= y.underlying();}
//!@}
};
};
template <class Final, template <class, class> class Pred=is_compatible_with>
struct comparable_with_if
: equality_comparable_with_if<Final, Pred>
Expand Down Expand Up @@ -93,6 +119,12 @@ namespace std
template <class Final>
using type = mixin::comparable<Final>;
};
template <class Other>
struct comparable_with
{
template <class Final>
using type = mixin::comparable_with<Final, Other>;
};
template <template <class, class> class Pred=mixin::is_compatible_with>
struct comparable_with_if
{
Expand Down

0 comments on commit b498cd1

Please sign in to comment.