[libsigc++2/variadic_mem_fun2] Add member_method_is_const<> and member_method_is_volatile.



commit 1a41ac996828f3d897168535b4e161e831ebb9f9
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Mar 4 21:58:16 2016 +0100

    Add member_method_is_const<> and member_method_is_volatile.
    
    And some tests for them.

 sigc++/filelist.am                |    1 +
 sigc++/member_method_trait.h      |   87 +++++++++++++++++++++++++++++++++++++
 tests/Makefile.am                 |    2 +
 tests/test_member_method_trait.cc |   49 +++++++++++++++++++++
 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;
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]