11 #ifndef INCLUDE_MOLASSEMBLER_TEMPLE_INVOKE_H
12 #define INCLUDE_MOLASSEMBLER_TEMPLE_INVOKE_H
14 #include <boost/tuple/tuple.hpp>
20 namespace Molassembler {
26 template<
typename TupleType,
typename Function,
size_t ... Inds>
27 auto boostTupleInvokeHelper(
29 const TupleType& tuple,
30 std::index_sequence<Inds...>
33 boost::get<Inds>(tuple)...
46 const boost::tuples::cons<HT, TT>& tuple
48 return Detail::boostTupleInvokeHelper(
51 std::make_index_sequence<
53 boost::tuples::length<
54 boost::tuples::cons<HT, TT>
62 template<
class>
struct sfinae_true : std::true_type {};
68 template<
typename Function,
typename TupleType,
size_t ... Inds>
71 const TupleType& tuple,
72 std::index_sequence<Inds...>
74 return std::invoke(
function, std::get<Inds>(tuple)...);
82 template<
typename Function,
typename TupleType, std::size_t ... Inds>
83 constexpr
auto operator() (
85 const TupleType& tuple,
86 std::index_sequence<Inds...>
90 std::tuple_element_t<Inds, TupleType>
104 template<
typename Function,
typename TupleType>
105 static auto isTupleCallableTest(
int) -> sfinae_true<
107 std::declval<InvokeTester>()(
108 std::declval<Function>(),
109 std::declval<TupleType>(),
110 std::make_index_sequence<std::tuple_size<TupleType>::value>()
115 template<
typename Function,
typename TupleType,
typename... Args>
116 static auto isTupleCallableTest(
long) -> std::false_type;
124 template<
typename Function,
typename TupleType,
typename... Args>
125 struct isTupleCallable : decltype(isTupleCallableTest<Function, TupleType, Args...>(0)) {};
140 std::enable_if_t<Detail::isTupleCallable<Fn, TupleType>::value,
int> = 0
143 const TupleType& tuple
145 return Detail::invokeHelper(
146 std::forward<Fn>(
function),
148 std::make_index_sequence<
149 std::tuple_size<TupleType>::value
158 sizeof...(Args) != 1 || !Detail::isTupleCallable<Fn, Args...>::value,
162 auto invoke(Fn&&
function, Args&& ... args) {
163 return std::invoke(
function, std::forward<Args>(args)...);
168 template<
typename Functor>
172 Invoker(
Functor&& passFunction) : function(passFunction) {}
174 template<
typename TupleType>
175 constexpr
auto operator() (
const TupleType& tuple)
const noexcept(noexcept(
invoke(
function, tuple))) {
176 return invoke(
function, tuple);
182 template<
typename Functor>
183 auto make_tuple_callable(
Functor&& functor) {
184 return Detail::Invoker<Functor>(std::forward<Functor>(functor));
auto invoke(Function &&function, const boost::tuples::cons< HT, TT > &tuple)
Invokes a function with all values in a given boost tuple.
Definition: Invoke.h:44