Relax template matching rules for std::bind and GNU C++ >= 7.1 (#484)

* Relax template matching rules for std::bind and GNU C++ >= 7.1

* Document reason test was added
This commit is contained in:
Esteve Fernandez 2018-06-01 19:28:45 +02:00 committed by dhood
parent d6057270f2
commit 97575fd59b
2 changed files with 21 additions and 1 deletions

View file

@ -83,7 +83,7 @@ template<typename ClassT, typename ReturnTypeT, typename ... Args, typename ...
#if defined _LIBCPP_VERSION // libc++ (Clang)
struct function_traits<std::__1::__bind<ReturnTypeT (ClassT::*)(Args ...), FArgs ...>>
#elif defined _GLIBCXX_RELEASE // glibc++ (GNU C++ >= 7.1)
struct function_traits<std::_Bind<ReturnTypeT(ClassT::*(ClassT *, FArgs ...))(Args ...)>>
struct function_traits<std::_Bind<ReturnTypeT(ClassT::*(FArgs ...))(Args ...)>>
#elif defined __GLIBCXX__ // glibc++ (GNU C++)
struct function_traits<std::_Bind<std::_Mem_fn<ReturnTypeT (ClassT::*)(Args ...)>(FArgs ...)>>
#elif defined _MSC_VER // MS Visual Studio

View file

@ -706,3 +706,23 @@ TEST(TestFunctionTraits, sfinae_match) {
EXPECT_EQ("foo", func_accept_callback_return_type(lambda_no_args_string));
}
class TestMember : public ::testing::Test
{
public:
void MemberFunctor(int, float, std::string) {}
};
/*
Regression test for https://github.com/ros2/rclcpp/issues/479, specific to classes using the
TEST_F GTest macro.
*/
TEST_F(TestMember, bind_member_functor) {
auto bind_member_functor = std::bind(&TestMember::MemberFunctor, this, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3);
static_assert(
rclcpp::function_traits::check_arguments<decltype(bind_member_functor), int, float,
std::string>::value,
"Functor accepts an int, a float and a string as arguments");
}