summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMurray Cumming <murrayc@murrayc.com>2016-07-08 21:53:30 +0200
committerMurray Cumming <murrayc@murrayc.com>2016-09-21 08:24:22 +0200
commit9bbb94d5c9b7f7dfa7e2ae80bdef2e45bdb3ce1a (patch)
tree1162468c9c751107b718d03009bb60b3f7a3d0ad
parenta05dd26eac473cac931dd444aaa6300335c870ca (diff)
downloadsigc++-9bbb94d5c9b7f7dfa7e2ae80bdef2e45bdb3ce1a.tar.gz
C++17: Use std::invoke().
This makes code more generic. Maybe this will let us simplify code. I don't actually have a compiler (or its standard library) that supports this, so this probably does not build.
-rw-r--r--sigc++/adaptors/adaptor_trait.h7
-rw-r--r--sigc++/adaptors/bind.h5
-rw-r--r--sigc++/adaptors/bind_return.h3
-rw-r--r--sigc++/adaptors/compose.h13
-rw-r--r--sigc++/adaptors/exception_catch.h3
-rw-r--r--sigc++/adaptors/hide.h2
-rw-r--r--sigc++/adaptors/retype.h1
-rw-r--r--sigc++/adaptors/retype_return.h6
-rw-r--r--sigc++/adaptors/track_obj.h5
-rw-r--r--sigc++/functors/mem_fun.h5
-rw-r--r--sigc++/functors/ptr_fun.h5
-rw-r--r--sigc++/functors/slot.h7
-rw-r--r--sigc++/signal.h2
-rw-r--r--sigc++/visit_each.h2
14 files changed, 45 insertions, 21 deletions
diff --git a/sigc++/adaptors/adaptor_trait.h b/sigc++/adaptors/adaptor_trait.h
index 7a534e8..8fb9bb5 100644
--- a/sigc++/adaptors/adaptor_trait.h
+++ b/sigc++/adaptors/adaptor_trait.h
@@ -25,6 +25,7 @@
#include <sigc++/functors/ptr_fun.h>
#include <sigc++/functors/mem_fun.h>
#include <sigc++/adaptors/adaptor_base.h>
+#include <functional>
/*
* The idea here is simple. To prevent the need to
@@ -87,7 +88,9 @@ struct adaptor_functor : public adaptor_base
/** Invokes the wrapped functor passing on the arguments.
* @return The return value of the functor invocation.
*/
- decltype(auto) operator()() const { return functor_(); }
+ decltype(auto) operator()() const {
+ std::invoke(functor_);
+ }
/** Invokes the wrapped functor passing on the arguments.
* @param arg Arguments to be passed on to the functor.
@@ -96,7 +99,7 @@ struct adaptor_functor : public adaptor_base
template <typename... T_arg>
decltype(auto) operator()(T_arg&&... arg) const
{
- return functor_(std::forward<T_arg>(arg)...);
+ return std::invoke(functor_, std::forward<T_arg>(arg)...);
}
/// Constructs an invalid functor.
diff --git a/sigc++/adaptors/bind.h b/sigc++/adaptors/bind.h
index 08e1ee7..e93250b 100644
--- a/sigc++/adaptors/bind.h
+++ b/sigc++/adaptors/bind.h
@@ -26,6 +26,7 @@
#include <sigc++/tuple-utils/tuple_start.h>
#include <sigc++/tuple-utils/tuple_end.h>
#include <sigc++/tuple-utils/tuple_transform_each.h>
+#include <functional>
namespace sigc
@@ -171,7 +172,7 @@ private:
template <typename T, std::size_t... Is>
decltype(auto) call_functor_operator_parentheses(T&& tuple, std::index_sequence<Is...>)
{
- return (this->functor_)(std::get<Is>(std::forward<T>(tuple))...);
+ return std::invoke(this->functor_, std::get<Is>(std::forward<T>(tuple))...);
}
};
@@ -219,7 +220,7 @@ private:
template <typename T, std::size_t... Is>
decltype(auto) call_functor_operator_parentheses(T&& tuple, std::index_sequence<Is...>)
{
- return (this->functor_)(std::get<Is>(std::forward<T>(tuple))...);
+ return std::invoke(this->functor_, std::get<Is>(std::forward<T>(tuple))...);
}
};
diff --git a/sigc++/adaptors/bind_return.h b/sigc++/adaptors/bind_return.h
index 0da105e..99a4eb6 100644
--- a/sigc++/adaptors/bind_return.h
+++ b/sigc++/adaptors/bind_return.h
@@ -49,6 +49,7 @@ struct bind_return_functor : public adapts<T_functor>
template <typename... T_arg>
inline typename unwrap_reference<T_return>::type operator()(T_arg... a)
{
+ //TODO: Use std::invoke() here?
this->functor_.template operator()<type_trait_pass_t<T_arg>...>(a...);
return ret_value_.invoke();
}
@@ -71,7 +72,7 @@ template <typename T_return, typename T_functor>
typename unwrap_reference<T_return>::type
bind_return_functor<T_return, T_functor>::operator()()
{
- this->functor_();
+ std::invoke(this->functor_);
return ret_value_.invoke();
}
diff --git a/sigc++/adaptors/compose.h b/sigc++/adaptors/compose.h
index fb4e081..f8b21d1 100644
--- a/sigc++/adaptors/compose.h
+++ b/sigc++/adaptors/compose.h
@@ -19,6 +19,7 @@
#ifndef SIGC_ADAPTORS_COMPOSE_H
#define SIGC_ADAPTORS_COMPOSE_H
#include <sigc++/adaptors/adapts.h>
+#include <functional>
namespace sigc
{
@@ -61,12 +62,14 @@ namespace sigc
template <typename T_setter, typename T_getter>
struct compose1_functor : public adapts<T_setter>
{
- decltype(auto) operator()() { return this->functor_(get_()); }
+ decltype(auto) operator()() {
+ return std::invoke(this->functor_, get_());
+ }
template <typename... T_arg>
decltype(auto) operator()(T_arg&&... a)
{
- return this->functor_(get_(std::forward<T_arg>(a)...));
+ return std::invoke(this->functor_, get_(std::forward<T_arg>(a)...));
}
/** Constructs a compose1_functor object that combines the passed functors.
@@ -95,12 +98,14 @@ struct compose1_functor : public adapts<T_setter>
template <typename T_setter, typename T_getter1, typename T_getter2>
struct compose2_functor : public adapts<T_setter>
{
- decltype(auto) operator()() { return this->functor_(get1_(), get2_()); }
+ decltype(auto) operator()() {
+ return std::invoke(this->functor_, get1_(), get2_());
+ }
template <typename... T_arg>
decltype(auto) operator()(T_arg... a)
{
- return this->functor_(get1_(a...), get2_(a...));
+ return std::invoke(this->functor_, get1_(a...), get2_(a...));
}
/** Constructs a compose2_functor object that combines the passed functors.
diff --git a/sigc++/adaptors/exception_catch.h b/sigc++/adaptors/exception_catch.h
index a4c6c2c..7f7e569 100644
--- a/sigc++/adaptors/exception_catch.h
+++ b/sigc++/adaptors/exception_catch.h
@@ -80,7 +80,7 @@ struct exception_catch_functor : public adapts<T_functor>
{
try
{
- return this->functor_();
+ return std::invoke(this->functor_);
}
catch (...)
{
@@ -93,6 +93,7 @@ struct exception_catch_functor : public adapts<T_functor>
{
try
{
+ //TODO: Use std::invoke here?
return this->functor_.template operator()<type_trait_pass_t<T_arg>...>(a...);
}
catch (...)
diff --git a/sigc++/adaptors/hide.h b/sigc++/adaptors/hide.h
index 6b17cea..a6acdf3 100644
--- a/sigc++/adaptors/hide.h
+++ b/sigc++/adaptors/hide.h
@@ -122,7 +122,7 @@ private:
template <typename T_tuple, std::size_t... Is>
decltype(auto) call_functor_operator_parentheses(T_tuple& tuple, std::index_sequence<Is...>)
{
- return this->functor_.template operator()(std::get<Is>(tuple)...);
+ return std::invoke(this->functor_, std::get<Is>(tuple)...);
}
};
diff --git a/sigc++/adaptors/retype.h b/sigc++/adaptors/retype.h
index 32f778b..b006e4c 100644
--- a/sigc++/adaptors/retype.h
+++ b/sigc++/adaptors/retype.h
@@ -82,6 +82,7 @@ struct retype_functor : public adapts<T_functor>
template <typename... T_arg>
decltype(auto) operator()(T_arg... a)
{
+ //TODO: Use std::invoke() here?
return this->functor_.template operator()<type_trait_take_t<T_type>...>(
static_cast<T_type>(a)...);
}
diff --git a/sigc++/adaptors/retype_return.h b/sigc++/adaptors/retype_return.h
index 9e5df6f..2b5d776 100644
--- a/sigc++/adaptors/retype_return.h
+++ b/sigc++/adaptors/retype_return.h
@@ -41,6 +41,7 @@ struct retype_return_functor : public adapts<T_functor>
template <typename... T_arg>
inline T_return operator()(T_arg&&... a)
{
+ //TODO: Use std::invoke() here?
return T_return(this->functor_.template operator() < T_arg... > (std::forward<T_arg>(a)...));
}
@@ -60,7 +61,7 @@ template <typename T_return, typename T_functor>
T_return
retype_return_functor<T_return, T_functor>::operator()()
{
- return T_return(this->functor_());
+ return T_return(std::invoke(this->functor_));
}
/** Adaptor that performs a C-style cast on the return value of a functor.
@@ -81,6 +82,7 @@ struct retype_return_functor<void, T_functor> : public adapts<T_functor>
template <typename... T_arg>
inline void operator()(T_arg... a)
{
+ //TODO: Use std::invoke() here?
this->functor_.template operator()<T_arg...>(a...);
}
@@ -92,7 +94,7 @@ template <typename T_functor>
void
retype_return_functor<void, T_functor>::operator()()
{
- this->functor_();
+ std::invoke(this->functor_);
}
#ifndef DOXYGEN_SHOULD_SKIP_THIS
diff --git a/sigc++/adaptors/track_obj.h b/sigc++/adaptors/track_obj.h
index 9256011..dd8bf85 100644
--- a/sigc++/adaptors/track_obj.h
+++ b/sigc++/adaptors/track_obj.h
@@ -83,7 +83,9 @@ public:
/** Invokes the wrapped functor.
* @return The return value of the functor invocation.
*/
- decltype(auto) operator()() { return this->functor_(); }
+ decltype(auto) operator()() {
+ return std::invoke(this->functor_);
+ }
/** Invokes the wrapped functor passing on the arguments.
* @param arg Arguments to be passed on to the functor.
@@ -92,6 +94,7 @@ public:
template <typename... T_arg>
decltype(auto) operator()(T_arg&&... arg)
{
+ //TODO: Use std::invoke() here?
return this->functor_.template operator()<type_trait_pass_t<T_arg>...>(
std::forward<T_arg>(arg)...);
}
diff --git a/sigc++/functors/mem_fun.h b/sigc++/functors/mem_fun.h
index d53b967..813d74e 100644
--- a/sigc++/functors/mem_fun.h
+++ b/sigc++/functors/mem_fun.h
@@ -21,6 +21,7 @@
#include <sigc++/type_traits.h>
#include <sigc++/limit_reference.h>
#include <sigc++/member_method_trait.h>
+#include <functional>
// implementation notes:
// - we do not use bind here, because it would introduce
@@ -113,7 +114,7 @@ public:
*/
decltype(auto) operator()(obj_type_with_modifier& obj, type_trait_take_t<T_arg>... a) const
{
- return (obj.*func_ptr_)(a...);
+ return std::invoke(func_ptr_, obj, a...);
}
protected:
@@ -152,7 +153,7 @@ public:
*/
decltype(auto) operator()(type_trait_take_t<T_arg>... a) const
{
- return (obj_.invoke().*(this->func_ptr_))(a...);
+ return std::invoke(this->func_ptr_, obj_, a...);
}
// protected:
diff --git a/sigc++/functors/ptr_fun.h b/sigc++/functors/ptr_fun.h
index 12e2015..c680a2e 100644
--- a/sigc++/functors/ptr_fun.h
+++ b/sigc++/functors/ptr_fun.h
@@ -19,6 +19,7 @@
#ifndef SIGC_FUNCTORS_PTR_FUN_H
#define SIGC_FUNCTORS_PTR_FUN_H
#include <sigc++/type_traits.h>
+#include <functional>
namespace sigc
{
@@ -92,7 +93,9 @@ public:
* @param a Arguments to be passed on to the function.
* @return The return value of the function invocation.
*/
- T_return operator()(type_trait_take_t<T_args>... a) const { return func_ptr_(a...); }
+ T_return operator()(type_trait_take_t<T_args>... a) const {
+ return std::invoke(func_ptr_, a...);
+ }
};
/** Creates a functor of type sigc::pointer_functor which wraps an existing non-member function.
diff --git a/sigc++/functors/slot.h b/sigc++/functors/slot.h
index 419cfa2..3fb75a1 100644
--- a/sigc++/functors/slot.h
+++ b/sigc++/functors/slot.h
@@ -23,6 +23,7 @@
#include <sigc++/visit_each.h>
#include <sigc++/adaptors/adaptor_trait.h>
#include <sigc++/functors/slot_base.h>
+#include <functional>
#include <memory>
@@ -191,8 +192,10 @@ public:
*/
inline T_return operator()(type_trait_take_t<T_arg>... a) const
{
- if (!empty() && !blocked())
- return (reinterpret_cast<call_type>(slot_base::rep_->call_))(slot_base::rep_, a...);
+ if (!empty() && !blocked()) {
+ return std::invoke(reinterpret_cast<call_type>(slot_base::rep_->call_), slot_base::rep_, a...);
+ }
+
return T_return();
}
diff --git a/sigc++/signal.h b/sigc++/signal.h
index c666617..e6a6090 100644
--- a/sigc++/signal.h
+++ b/sigc++/signal.h
@@ -281,7 +281,7 @@ private:
decltype(auto) call_call_type_operator_parentheses_with_tuple(
const slot_type& slot, const std::tuple<T_arg...>& tuple, std::index_sequence<Is...>) const
{
- return (slot)(std::get<Is>(tuple)...);
+ return std::invoke(slot, std::get<Is>(tuple)...);
}
};
diff --git a/sigc++/visit_each.h b/sigc++/visit_each.h
index 51b53aa..e07abd9 100644
--- a/sigc++/visit_each.h
+++ b/sigc++/visit_each.h
@@ -44,7 +44,7 @@ struct limit_trackable_target
{
//Only call action_() if T_Type derives from trackable.
if constexpr(is_base_of_or_same_v<sigc::trackable, T_type>) {
- action_(type);
+ std::invoke(action_, type);
}
}