Skip to content

Commit c93598a

Browse files
committed
fixed compile error on test case:"invoke_test"
1 parent 4fa1489 commit c93598a

File tree

2 files changed

+17
-34
lines changed

2 files changed

+17
-34
lines changed

include/kaguya/utility_cxx11.hpp

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -116,44 +116,14 @@ namespace kaguya
116116

117117
namespace detail
118118
{
119-
template<class ThisType, class Res, class... FArgs, class... Args>
120-
Res invoke_helper(Res(ThisType::*f)(FArgs...), ThisType& this_, Args&&... args)
119+
template<class F, class ThisType, class... Args>
120+
auto invoke_helper(F&& f, ThisType&& this_, Args&&... args) -> decltype((std::forward<ThisType>(this_).*f)(std::forward<Args>(args)...))
121121
{
122-
return (this_.*f)(std::forward<Args>(args)...);
122+
return (std::forward<ThisType>(this_).*f)(std::forward<Args>(args)...);
123123
}
124124

125-
template<class ThisType, class Res, class... FArgs, class... Args>
126-
Res invoke_helper(Res(ThisType::*f)(FArgs...)const, const ThisType& this_, Args&&... args)
127-
{
128-
return (this_.*f)(std::forward<Args>(args)...);
129-
}
130-
#if defined(_MSC_VER) && _MSC_VER >= 1900 || defined(__cpp_ref_qualifiers)
131-
template<class ThisType, class Res, class... FArgs, class... Args>
132-
Res invoke_helper(Res(ThisType::*f)(FArgs...) &, ThisType& this_, Args&&... args)
133-
{
134-
return (this_.*f)(std::forward<Args>(args)...);
135-
}
136-
137-
template<class ThisType, class Res, class... FArgs, class... Args>
138-
Res invoke_helper(Res(ThisType::*f)(FArgs...)const &, const ThisType& this_, Args&&... args)
139-
{
140-
return (this_.*f)(std::forward<Args>(args)...);
141-
}
142-
template<class ThisType, class Res, class... FArgs, class... Args>
143-
Res invoke_helper(Res(ThisType::*f)(FArgs...) && , ThisType&& this_, Args&&... args)
144-
{
145-
return (this_.*f)(std::forward<Args>(args)...);
146-
}
147-
148-
template<class ThisType, class Res, class... FArgs, class... Args>
149-
Res invoke_helper(Res(ThisType::*f)(FArgs...)const &&, const ThisType& this_, Args&&... args)
150-
{
151-
return (this_.*f)(std::forward<Args>(args)...);
152-
}
153-
#endif
154-
155125
template<class F, class... Args>
156-
typename FunctionResultType<typename traits::decay<F>::type>::type invoke_helper(F&& f, Args&&... args)
126+
auto invoke_helper(F&& f, Args&&... args) -> decltype(f(std::forward<Args>(args)...))
157127
{
158128
return f(std::forward<Args>(args)...);
159129
}

test/test_11_cxx11_feature.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,19 @@ KAGUYA_TEST_FUNCTION_DEF(self_refcount_object)(kaguya::State&)
328328
}
329329

330330

331+
332+
KAGUYA_TEST_FUNCTION_DEF(invoke_test)(kaguya::State&)
333+
{
334+
TestClass c(2);
335+
TEST_EQUAL(c.getInt(), 2);
336+
kaguya::util::invoke(&TestClass::setInt, c, 4);
337+
TEST_EQUAL(c.getInt(), 4);
338+
int a = kaguya::util::invoke(&TestClass::getInt, c);
339+
340+
TEST_EQUAL(a, 4);
341+
}
342+
343+
331344
KAGUYA_TEST_GROUP_END(test_11_cxx11_feature)
332345

333346

0 commit comments

Comments
 (0)