Skip to content

Commit

Permalink
Store reference_wrapper<T> instead of T & to make sure `unary_equ…
Browse files Browse the repository at this point in the history
…al_to` maintains assignability.
  • Loading branch information
davidstone committed Nov 29, 2023
1 parent 6dcb2e0 commit 2540f3e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions source/bounded/comparison_function_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,19 @@ struct unary_equal_to {
{
}
constexpr auto operator()(auto const & other) const {
return m_bound == other;
if constexpr (std::is_reference_v<Bound>) {
return m_bound.get() == other;
} else {
return m_bound == other;
}
}
private:
Bound m_bound;
using storage = std::conditional_t<
std::is_reference_v<Bound>,
std::reference_wrapper<std::remove_reference_t<Bound>>,
Bound
>;
storage m_bound;
};

export constexpr auto equal_to() {
Expand Down

0 comments on commit 2540f3e

Please sign in to comment.