[libsigc++2/variadic_mem_fun2] Add member_method_class<>::type type trait.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsigc++2/variadic_mem_fun2] Add member_method_class<>::type type trait.
- Date: Sat, 5 Mar 2016 23:10:37 +0000 (UTC)
commit 83c6b74ca7ff669a522f0796d69e8b3f8f5ad515
Author: Murray Cumming <murrayc murrayc com>
Date: Sat Mar 5 23:46:57 2016 +0100
Add member_method_class<>::type type trait.
sigc++/member_method_trait.h | 29 +++++++++++++++++++++++++++++
tests/test_member_method_trait.cc | 25 +++++++++++++++++++++++--
2 files changed, 52 insertions(+), 2 deletions(-)
---
diff --git a/sigc++/member_method_trait.h b/sigc++/member_method_trait.h
index 7517ab4..a7ea0e2 100644
--- a/sigc++/member_method_trait.h
+++ b/sigc++/member_method_trait.h
@@ -80,7 +80,36 @@ struct member_method_is_volatile<T_result (T_obj::*)(T_arg...) const volatile>
};
+//member method class:
+template <class T_result, class... T_arg>
+struct member_method_class
+{
+};
+
+template <class T_obj, class T_result, class... T_arg>
+struct member_method_class<T_result(T_obj::*)(T_arg...)>
+{
+ using type = T_obj;
+};
+
+template <class T_obj, class T_result, class... T_arg>
+struct member_method_class<T_result(T_obj::*)(T_arg...) volatile>
+{
+ using type = T_obj;
+};
+
+template <class T_obj, class T_result, class... T_arg>
+struct member_method_class<T_result(T_obj::*)(T_arg...) const>
+{
+ using type = T_obj;
+};
+
+template <class T_obj, class T_result, class... T_arg>
+struct member_method_class<T_result(T_obj::*)(T_arg...) const volatile>
+{
+ using type = T_obj;
+};
} /* namespace sigc */
diff --git a/tests/test_member_method_trait.cc b/tests/test_member_method_trait.cc
index 8f7d2d6..e8d702a 100644
--- a/tests/test_member_method_trait.cc
+++ b/tests/test_member_method_trait.cc
@@ -4,6 +4,7 @@
#include <cstdlib>
#include <sigc++/member_method_trait.h>
+#include <type_traits>
namespace
{
@@ -19,7 +20,7 @@ public:
} // end anonymous namespace
-int main()
+void test_member_method_is_const()
{
static_assert(!sigc::member_method_is_const<decltype(&Something::some_func)>::value,
"member_method_is_const failed to identify a non-const member method.");
@@ -32,18 +33,38 @@ int main()
static_assert(sigc::member_method_is_const<decltype(&Something::some_const_volatile_func)>::value,
"member_method_is_const failed to identify a const member method.");
+}
-
+void test_member_method_is_volatile()
+{
static_assert(!sigc::member_method_is_volatile<decltype(&Something::some_func)>::value,
"member_method_is_const failed to identify a non-volatile member method.");
+ static_assert(!sigc::member_method_is_volatile<decltype(&Something::some_const_func)>::value,
+ "member_method_is_const failed to identify a non-volatile member method.");
+
static_assert(sigc::member_method_is_volatile<decltype(&Something::some_volatile_func)>::value,
"member_method_is_const failed to identify a volatile member method.");
static_assert(sigc::member_method_is_volatile<decltype(&Something::some_const_volatile_func)>::value,
"member_method_is_const failed to identify a volatile member method.");
+}
+void test_member_method_class_type()
+{
+ static_assert(std::is_same<
+ sigc::member_method_class<decltype(&Something::some_func)>::type,
+ Something>::value,
+ "member_method_class_type failed to identify the class type.");
+}
+
+
+int main()
+{
+ test_member_method_is_const();
+ test_member_method_is_volatile();
+ test_member_method_class_type();
return EXIT_SUCCESS;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]