summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMurray Cumming <murrayc@murrayc.com>2016-03-04 21:58:16 +0100
committerMurray Cumming <murrayc@murrayc.com>2016-03-04 22:21:12 +0100
commit1a41ac996828f3d897168535b4e161e831ebb9f9 (patch)
tree83ba51162fc90c1eefe073bf5555f7a41bdd4270
parent8bf3fa43ea07c65319906152dd4ef97645a3d4b4 (diff)
downloadsigc++-1a41ac996828f3d897168535b4e161e831ebb9f9.tar.gz
Add member_method_is_const<> and member_method_is_volatile.
And some tests for them.
-rw-r--r--sigc++/filelist.am1
-rw-r--r--sigc++/member_method_trait.h87
-rw-r--r--tests/Makefile.am2
-rw-r--r--tests/test_member_method_trait.cc49
4 files changed, 139 insertions, 0 deletions
diff --git a/sigc++/filelist.am b/sigc++/filelist.am
index 2aa8707..93bd7d1 100644
--- a/sigc++/filelist.am
+++ b/sigc++/filelist.am
@@ -37,6 +37,7 @@ sigc_public_h = \
bind.h \
bind_return.h \
connection.h \
+ member_method_trait.h \
reference_wrapper.h \
retype_return.h \
signal.h \
diff --git a/sigc++/member_method_trait.h b/sigc++/member_method_trait.h
new file mode 100644
index 0000000..7517ab4
--- /dev/null
+++ b/sigc++/member_method_trait.h
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2002, The libsigc++ Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#ifndef _SIGC_MEMBER_METHOD_TRAITS_H_
+#define _SIGC_MEMBER_METHOD_TRAITS_H_
+
+#include <sigc++config.h>
+
+
+namespace sigc {
+
+template <class>
+struct member_method_is_const;
+
+template <class T_obj, class T_result, class... T_arg>
+struct member_method_is_const<T_result (T_obj::*)(T_arg...)>
+{
+ constexpr static bool value = false;
+};
+
+template <class T_obj, class T_result, class... T_arg>
+struct member_method_is_const<T_result (T_obj::*)(T_arg...) volatile>
+{
+ constexpr static bool value = false;
+};
+
+template <class T_obj, class T_result, class... T_arg>
+struct member_method_is_const<T_result (T_obj::*)(T_arg...) const>
+{
+ constexpr static bool value = true;
+};
+
+template <class T_obj, class T_result, class... T_arg>
+struct member_method_is_const<T_result (T_obj::*)(T_arg...) const volatile>
+{
+ constexpr static bool value = true;
+};
+
+
+template <class>
+struct member_method_is_volatile;
+
+template <class T_obj, class T_result, class... T_arg>
+struct member_method_is_volatile<T_result (T_obj::*)(T_arg...)>
+{
+ constexpr static bool value = false;
+};
+
+template <class T_obj, class T_result, class... T_arg>
+struct member_method_is_volatile<T_result (T_obj::*)(T_arg...) const>
+{
+ constexpr static bool value = false;
+};
+
+template <class T_obj, class T_result, class... T_arg>
+struct member_method_is_volatile<T_result (T_obj::*)(T_arg...) volatile>
+{
+ constexpr static bool value = true;
+};
+
+template <class T_obj, class T_result, class... T_arg>
+struct member_method_is_volatile<T_result (T_obj::*)(T_arg...) const volatile>
+{
+ constexpr static bool value = true;
+};
+
+
+
+
+} /* namespace sigc */
+
+#endif /* _SIGC_MEMBER_METHOD_TRAITS_H_ */
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 09ae62e..4039ef3 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -37,6 +37,7 @@ check_PROGRAMS = \
test_functor_trait \
test_hide \
test_limit_reference \
+ test_member_method_trait \
test_mem_fun \
test_ptr_fun \
test_retype \
@@ -79,6 +80,7 @@ test_exception_catch_SOURCES = test_exception_catch.cc $(sigc_test_util)
test_functor_trait_SOURCES = test_functor_trait.cc $(sigc_test_util)
test_hide_SOURCES = test_hide.cc $(sigc_test_util)
test_limit_reference_SOURCES = test_limit_reference.cc $(sigc_test_util)
+test_member_method_trait_SOURCES = test_member_method_trait.cc $(sigc_test_util)
test_mem_fun_SOURCES = test_mem_fun.cc $(sigc_test_util)
test_ptr_fun_SOURCES = test_ptr_fun.cc $(sigc_test_util)
test_retype_SOURCES = test_retype.cc $(sigc_test_util)
diff --git a/tests/test_member_method_trait.cc b/tests/test_member_method_trait.cc
new file mode 100644
index 0000000..8f7d2d6
--- /dev/null
+++ b/tests/test_member_method_trait.cc
@@ -0,0 +1,49 @@
+/* Copyright 2016, The libsigc++ Development Team
+ * Assigned to public domain. Use as you wish without restriction.
+ */
+
+#include <cstdlib>
+#include <sigc++/member_method_trait.h>
+
+namespace
+{
+
+class Something
+{
+public:
+ void some_func(int a);
+ void some_const_func(int a) const;
+ void some_volatile_func(int a) volatile;
+ void some_const_volatile_func(int a) const volatile;
+};
+
+} // end anonymous namespace
+
+int main()
+{
+ static_assert(!sigc::member_method_is_const<decltype(&Something::some_func)>::value,
+ "member_method_is_const failed to identify a non-const member method.");
+
+ static_assert(!sigc::member_method_is_const<decltype(&Something::some_volatile_func)>::value,
+ "member_method_is_const failed to identify a non-const member method.");
+
+ static_assert(sigc::member_method_is_const<decltype(&Something::some_const_func)>::value,
+ "member_method_is_const failed to identify a const member method.");
+
+ 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.");
+
+
+ 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_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.");
+
+
+
+ return EXIT_SUCCESS;
+}