Skip to content

Making overload_t's copy constructor have priority #413

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion include/boost/hana/functional/overload.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Distributed under the Boost Software License, Version 1.0.

#include <boost/hana/config.hpp>
#include <boost/hana/detail/decay.hpp>
#include <type_traits>


BOOST_HANA_NAMESPACE_BEGIN
Expand Down Expand Up @@ -47,7 +48,10 @@ BOOST_HANA_NAMESPACE_BEGIN
using overload_t<F>::type::operator();
using overload_t<G...>::type::operator();

template <typename F_, typename ...G_>
template <typename F_, typename ...G_,
typename = std::enable_if_t<
!std::is_same<overload_t,std::decay_t<F_>>::value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Please add a space between overload_t and std::decay_t<F_>.

>>
constexpr explicit overload_t(F_&& f, G_&& ...g)
: overload_t<F>::type(static_cast<F_&&>(f))
, overload_t<G...>::type(static_cast<G_&&>(g)...)
Expand Down
17 changes: 17 additions & 0 deletions test/issues/github_412.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "boost/hana.hpp"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use <> to include Hana's headers in the tests. Also, we try to include the most specific header. #include <boost/hana/functional/overload.hpp>


constexpr int f() { return 12; }
constexpr int g(int) { return 42; }



// This test makes sure that overload can
// be copy constructed
int main() {
auto a = boost::hana::overload(f,g);
auto b(a);


BOOST_HANA_RUNTIME_CHECK(b() == 12);
BOOST_HANA_RUNTIME_CHECK(b(1) == 42);
}