cxxomfort  rel.20211024
Simple backports for C++ - https://ryan.gulix.cl/fossil.cgi/cxxomfort/
List of all members
function_ref< Signature > Class Template Reference

A non-owning view of an object callable with a function signature.A function_ref is a non-owning view to a callable object or function pointer for a given signature. More...

Detailed Description

template<typename Signature>
class cxxomfort::impl::p0792::function_ref< Signature >

A non-owning view of an object callable with a function signature.

A function_ref is a non-owning view to a callable object or function pointer for a given signature.

Basically it's the equivalent to what array_ref is for contiguous sequences or what reference_wrapper and any are to normal types.

// note here we don't require a template for the functor
template <typename List>
vector<int> metafunction (function_ref<int(float)> F, List& L) {
vector<int> sideeffects;
for (typename L::reference ll : L) {
sideeffects.push_back ( F(ll) );
}
return sideeffects;
}
int foo (float x) { ... };
int bar (float r) { ... };
list<float> data = ...;
vector<int> allfoos = metafunction(foo, data);
vector<int> allbars = metafunction(bar, data);

function_ref is a _ref - hence it does not work with temporaries such as bind expressions. The following doesn't work:

metafunction ( bind(mem_fn(&string::size), foo ) );
Note
In C++03 mode, function_ref can only construct from function pointers explicitly.
See also

The documentation for this class was generated from the following file: