flex_function.hpp

Based on std::function, but holds default parameter values for calls with fewer args.

Note

Status: ALPHA

template<class R, class ...ARGS>
class flex_function<R(ARGS...)>
#include <flex_function.hpp>

A functon class that is almost identical to std::function, but is provided with default values for all parameters so that it can be called with fewer arguments, as needed.

Public Types

using size_t = std::size_t
using return_t = R
using fun_t = std::function<R(ARGS...)>
using this_t = flex_function<R(ARGS...)>
using tuple_t = std::tuple<ARGS...>

Public Functions

template<typename T>
inline flex_function(T &&fun_info)
flex_function(const this_t&) = default
flex_function(this_t&&) = default
flex_function() = default
this_t &operator=(const this_t&) = default
this_t &operator=(this_t&&) = default
inline this_t &operator=(const fun_t &_f)
inline this_t &operator=(fun_t &&_f)
template<typename T>
inline this_t &operator=(T &&arg)
template<int ID>
inline void SetDefault(pack_id<ID, ARGS...> &in_default)

Set the default value for a specific parameter.

inline void SetDefaults(ARGS... args)

Set the default values for all parameters.

inline return_t operator()(ARGS... k) const

Allow the function to be called with all args.

template<class ...IN_ARGS>
inline return_t operator()(IN_ARGS&&... k) const

All the function to be called with a subset of arguments (and the rest set to defaults)

inline operator bool() const

Determine whether this function has been set.

Public Static Attributes

static constexpr int num_args = sizeof...(ARGS)

Private Members

fun_t fun

Function to be called.

tuple_t default_args

Arguments to be used if not enough are provided in call.