summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMurray Cumming <murrayc@murrayc.com>2016-03-04 22:24:18 +0100
committerMurray Cumming <murrayc@murrayc.com>2016-03-04 22:25:47 +0100
commit05ef8acb289608f83ae64104fe2e07ee6fc7394f (patch)
tree86ea35b774c78766a294f28b4dde20051ddce9c1
parent1a41ac996828f3d897168535b4e161e831ebb9f9 (diff)
downloadsigc++-05ef8acb289608f83ae64104fe2e07ee6fc7394f.tar.gz
(bound_)mem_functor_base: Remove T_obj_with_modifier template parameter.
Remove the need for this by using std::conditional_t<> and our member_method_is_const<>::value instead.
-rw-r--r--sigc++/adaptors/retype.h12
-rw-r--r--sigc++/functors/macros/mem_fun.h.m448
2 files changed, 31 insertions, 29 deletions
diff --git a/sigc++/adaptors/retype.h b/sigc++/adaptors/retype.h
index 9a36fd7..ffb2197 100644
--- a/sigc++/adaptors/retype.h
+++ b/sigc++/adaptors/retype.h
@@ -138,10 +138,10 @@ retype(const pointer_functor<T_return, T_arg...>& _A_functor)
*
* @ingroup retype
*/
-template <class T_func, class T_obj_with_modifier, class T_return, class T_obj, class... T_arg>
+template <class T_func, class T_return, class T_obj, class... T_arg>
inline decltype(auto)
-retype(const mem_functor_base<T_func, T_obj_with_modifier, T_return, T_obj, T_arg...>& _A_functor)
-{ return retype_functor<mem_functor_base<T_func, T_obj_with_modifier, T_return, T_obj, T_arg...>, T_arg...>
+retype(const mem_functor_base<T_func, T_return, T_obj, T_arg...>& _A_functor)
+{ return retype_functor<mem_functor_base<T_func, T_return, T_obj, T_arg...>, T_arg...>
(_A_functor);
}
@@ -154,11 +154,11 @@ retype(const mem_functor_base<T_func, T_obj_with_modifier, T_return, T_obj, T_ar
* @ingroup retype
*/
template <class T_limit_reference,
- class T_func, class T_obj_with_modifier,
+ class T_func,
class T_return, class T_obj, class... T_arg>
inline decltype(auto)
-retype(const bound_mem_functor_base<T_limit_reference, T_func, T_obj_with_modifier, T_return, T_obj, T_arg...>& _A_functor)
-{ return retype_functor<bound_mem_functor_base<T_limit_reference, T_func, T_obj_with_modifier, T_return, T_obj, T_arg...>, T_arg...>
+retype(const bound_mem_functor_base<T_limit_reference, T_func, T_return, T_obj, T_arg...>& _A_functor)
+{ return retype_functor<bound_mem_functor_base<T_limit_reference, T_func, T_return, T_obj, T_arg...>, T_arg...>
(_A_functor);
}
diff --git a/sigc++/functors/macros/mem_fun.h.m4 b/sigc++/functors/macros/mem_fun.h.m4
index 539245b..78780a0 100644
--- a/sigc++/functors/macros/mem_fun.h.m4
+++ b/sigc++/functors/macros/mem_fun.h.m4
@@ -19,7 +19,7 @@ divert(-1)
include(template.macros.m4)
define([MEMBER_FUNCTOR],[dnl
-/** [$1]mem_functor wraps $3 methods with argument(s).
+/** [$1]mem_functor wraps $2 methods with argument(s).
* Use the convenience function mem_fun() to create an instance of [$1]mem_functor.
*
* The following template arguments are used:
@@ -32,14 +32,13 @@ define([MEMBER_FUNCTOR],[dnl
template<class T_return, class T_obj, class... T_arg>
using [$1]mem_functor =
mem_functor_base<
- T_return (T_obj::*)(T_arg...) $3,
- $2 T_obj,
+ T_return (T_obj::*)(T_arg...) $2,
T_return, T_obj, T_arg...>;
])
define([BOUND_MEMBER_FUNCTOR],[dnl
-/** bound_[$1]mem_functor encapsulates a $3 method with arguments and an object instance.
+/** bound_[$1]mem_functor encapsulates a $2 method with arguments and an object instance.
* Use the convenience function mem_fun() to create an instance of bound_[$1]mem_functor.
*
* The following template arguments are used:
@@ -53,8 +52,7 @@ template<class T_return, class T_obj, class... T_arg>
using bound_[$1]mem_functor =
bound_mem_functor_base<
[$1]limit_reference<T_obj>,
- T_return (T_obj::*)(T_arg...) $3,
- $2 T_obj,
+ T_return (T_obj::*)(T_arg...) $2,
T_return, T_obj, T_arg...>;
])
@@ -70,7 +68,6 @@ inline decltype(auto)
mem_fun(T_return (T_obj::*_A_func)(T_arg...) $3)
{ return mem_functor_base<
T_return (T_obj::*)(T_arg...) $3,
- [$2] T_obj,
T_return, T_obj, T_arg...>(_A_func); }
])
@@ -89,7 +86,6 @@ mem_fun(/*$2*/ T_obj* _A_obj, T_return (T_obj2::*_A_func)(T_arg...) $3)
return bound_mem_functor_base<
[$1]limit_reference<T_obj>,
T_return (T_obj::*)(T_arg...) $3,
- $2 T_obj,
T_return, T_obj, T_arg...>(_A_obj, _A_func);
}
@@ -107,7 +103,6 @@ mem_fun(/*$2*/ T_obj& _A_obj, T_return (T_obj2::*_A_func)(T_arg...) $3)
return bound_mem_functor_base<
[$1]limit_reference<T_obj>,
T_return (T_obj::*)(T_arg...) $3,
- $2 T_obj,
T_return, T_obj, T_arg...>(_A_obj, _A_func);
}
@@ -122,6 +117,7 @@ divert(0)
_FIREWALL([FUNCTORS_MEM_FUN])
#include <sigc++/type_traits.h>
#include <sigc++/limit_reference.h>
+#include <sigc++/member_method_trait.h>
namespace sigc {
@@ -175,13 +171,16 @@ namespace sigc {
* @ingroup sigcfunctors
*/
-template <class T_func, class T_obj_with_modifier, class T_return, class T_obj, class... T_arg>
+template <class T_func, class T_return, class T_obj, class... T_arg>
class mem_functor_base : public functor_base
{
public:
using function_type = T_func;
using result_type = T_return;
+ using obj_type_with_modifier = typename std::conditional_t<
+ member_method_is_const<T_func>::value, const T_obj, T_obj>;
+
/// Constructs an invalid functor.
mem_functor_base() : func_ptr_(nullptr) {}
@@ -196,7 +195,7 @@ public:
* @return The return value of the method invocation.
*/
decltype(auto)
- operator()(T_obj_with_modifier* _A_obj, type_trait_take_t<T_arg>... _A_a) const
+ operator()(obj_type_with_modifier* _A_obj, type_trait_take_t<T_arg>... _A_a) const
{ return (_A_obj->*(this->func_ptr_))(_A_a...); }
/** Execute the wrapped method operating on the passed instance.
@@ -205,7 +204,7 @@ public:
* @return The return value of the method invocation.
*/
decltype(auto)
- operator()(T_obj_with_modifier& _A_obj, type_trait_take_t<T_arg>... _A_a) const
+ operator()(obj_type_with_modifier& _A_obj, type_trait_take_t<T_arg>... _A_a) const
{ return (_A_obj.*func_ptr_)(_A_a...); }
protected:
@@ -215,28 +214,31 @@ protected:
//mem_functor and const_mem_functor are just convenience aliases used in the
//definition of functor_trait<> specializations. TODO: Remove them?
-MEMBER_FUNCTOR([],[],[])
-MEMBER_FUNCTOR([const_],[const],[const])
+MEMBER_FUNCTOR([],[])
+MEMBER_FUNCTOR([const_],[const])
//TODO: Change T_limit_reference to a template template parameter,
//but without having to specify both of the limit_reference<typename, typename>
//typenames?
template <class T_limit_reference,
- class T_func, class T_obj_with_modifier,
+ class T_func,
class T_return, class T_obj, class... T_arg>
class bound_mem_functor_base
-: mem_functor_base<T_func, T_obj_with_modifier, T_return, T_obj, T_arg...>
+: mem_functor_base<T_func, T_return, T_obj, T_arg...>
{
- using base_type = mem_functor_base<T_func, T_obj_with_modifier, T_return, T_obj, T_arg...>;
+ using base_type = mem_functor_base<T_func, T_return, T_obj, T_arg...>;
public:
using function_type = typename base_type::function_type;
using result_type = typename base_type::result_type;
+ using obj_type_with_modifier = typename std::conditional_t<
+ member_method_is_const<T_func>::value, const T_obj, T_obj>;
+
/** Constructs a bound_mem_functor_base object that wraps the passed method.
* @param _A_obj Pointer to instance the method will operate on.
* @param _A_func Pointer to method will be invoked from operator()().
*/
- bound_mem_functor_base(T_obj_with_modifier* _A_obj, function_type _A_func)
+ bound_mem_functor_base(obj_type_with_modifier* _A_obj, function_type _A_func)
: base_type(_A_func),
obj_(*_A_obj)
{}
@@ -245,7 +247,7 @@ public:
* @param _A_obj Reference to instance the method will operate on.
* @param _A_func Pointer to method will be invoked from operator()().
*/
- bound_mem_functor_base(T_obj_with_modifier& _A_obj, function_type _A_func)
+ bound_mem_functor_base(obj_type_with_modifier& _A_obj, function_type _A_func)
: base_type(_A_func),
obj_(_A_obj)
{}
@@ -274,12 +276,12 @@ public:
*
* @ingroup mem_fun
*/
-template <class T_func, class T_obj_with_modifier, class T_return, class T_obj, class... T_arg>
-struct visitor<bound_mem_functor_base<T_func, T_obj_with_modifier, T_return, T_obj, T_arg...> >
+template <class T_func, class T_return, class T_obj, class... T_arg>
+struct visitor<bound_mem_functor_base<T_func, T_return, T_obj, T_arg...> >
{
template <class T_action>
static void do_visit_each(const T_action& _A_action,
- const bound_mem_functor_base<T_func, T_obj_with_modifier, T_return, T_obj, T_arg...>& _A_target)
+ const bound_mem_functor_base<T_func, T_return, T_obj, T_arg...>& _A_target)
{
sigc::visit_each(_A_action, _A_target.obj_);
}
@@ -290,7 +292,7 @@ struct visitor<bound_mem_functor_base<T_func, T_obj_with_modifier, T_return, T_o
//bound_const_mem_functor is just a convenience aliases used in the
//definition of make_slot(). TODO: Remove it?
-BOUND_MEMBER_FUNCTOR([const_],[const],[const])
+BOUND_MEMBER_FUNCTOR([const_],[const])
MEM_FUN([],[],[])