[libsigcplusplus/variadic_mem_fun3: 143/148] Added member_method_result<>::type type trait.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsigcplusplus/variadic_mem_fun3: 143/148] Added member_method_result<>::type type trait.
- Date: Mon, 7 Mar 2016 10:09:50 +0000 (UTC)
commit a03cd30331408597439aa63f53df6f051b3cccd5
Author: Murray Cumming <murrayc murrayc com>
Date: Sun Mar 6 00:06:28 2016 +0100
Added member_method_result<>::type type trait.
This seems to be easier than std::result_of<>, which seems to need us to
explicitly specify the arguments too.
sigc++/member_method_trait.h | 32 ++++++++++++++++++++++++++++++++
tests/test_member_method_trait.cc | 16 ++++++++++++++++
2 files changed, 48 insertions(+), 0 deletions(-)
---
diff --git a/sigc++/member_method_trait.h b/sigc++/member_method_trait.h
index a7ea0e2..35ad2d1 100644
--- a/sigc++/member_method_trait.h
+++ b/sigc++/member_method_trait.h
@@ -111,6 +111,38 @@ struct member_method_class<T_result(T_obj::*)(T_arg...) const volatile>
using type = T_obj;
};
+
+//member method result:
+
+template <class T_result, class... T_arg>
+struct member_method_result
+{
+};
+
+template <class T_obj, class T_result, class... T_arg>
+struct member_method_result<T_result(T_obj::*)(T_arg...)>
+{
+ using type = T_result;
+};
+
+template <class T_obj, class T_result, class... T_arg>
+struct member_method_result<T_result(T_obj::*)(T_arg...) volatile>
+{
+ using type = T_result;
+};
+
+template <class T_obj, class T_result, class... T_arg>
+struct member_method_result<T_result(T_obj::*)(T_arg...) const>
+{
+ using type = T_result;
+};
+
+template <class T_obj, class T_result, class... T_arg>
+struct member_method_result<T_result(T_obj::*)(T_arg...) const volatile>
+{
+ using type = T_result;
+};
+
} /* namespace sigc */
#endif /* _SIGC_MEMBER_METHOD_TRAITS_H_ */
diff --git a/tests/test_member_method_trait.cc b/tests/test_member_method_trait.cc
index e8d702a..79a87d1 100644
--- a/tests/test_member_method_trait.cc
+++ b/tests/test_member_method_trait.cc
@@ -16,6 +16,9 @@ public:
void some_const_func(int a) const;
void some_volatile_func(int a) volatile;
void some_const_volatile_func(int a) const volatile;
+
+ int some_int_func();
+ bool some_bool_func();
};
} // end anonymous namespace
@@ -58,6 +61,18 @@ void test_member_method_class_type()
"member_method_class_type failed to identify the class type.");
}
+void test_member_method_result_type()
+{
+ static_assert(std::is_same<
+ sigc::member_method_result<decltype(&Something::some_int_func)>::type,
+ int>::value,
+ "member_method_result_type failed to identify the result type.");
+
+ static_assert(std::is_same<
+ sigc::member_method_result<decltype(&Something::some_bool_func)>::type,
+ bool>::value,
+ "member_method_result_type failed to identify the result type.");
+}
int main()
{
@@ -65,6 +80,7 @@ int main()
test_member_method_is_volatile();
test_member_method_class_type();
+ test_member_method_result_type();
return EXIT_SUCCESS;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]