Permalink
Browse files

C++17: Use std::invoke().

This makes code more generic. Maybe this will let us simplify code.
  • Loading branch information...
murraycu committed Apr 7, 2018
1 parent 5a4164b commit f3da00bcbc68145092c4977604b997fcd53bcd09
@@ -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
@@ -96,7 +97,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.
View
@@ -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
@@ -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();
}
View
@@ -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.
@@ -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 (...)
View
@@ -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)...);
}
@@ -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
@@ -83,7 +83,9 @@ class track_obj_functor : public adapts<T_functor>
/** 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 @@ class track_obj_functor : public adapts<T_functor>
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)...);
}
@@ -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 @@ class mem_functor
*/
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 @@ class bound_mem_functor : mem_functor<T_func, T_arg...>
*/
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_.invoke(), a...);
}
// protected:
@@ -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 @@ class pointer_functor<T_return(T_args...)>
* @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.
View
@@ -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>
@@ -190,8 +191,10 @@ class slot<T_return(T_arg...)> : public slot_base
*/
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();
}
View
@@ -21,6 +21,7 @@
#include <sigc++/type_traits.h>
#include <type_traits>
#include <utility> // std::forward
#include <functional>
namespace sigc
{
@@ -45,7 +46,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);
}
}

0 comments on commit f3da00b

Please sign in to comment.