I'm not sure about this piece of code:
someClass(std::list<std::function<void(std::vector<someType>&)>>(&)(const std::vector<someType>&)) {
...
}
The constructor for someClass
, I believe, takes a reference to a list of functions, each of which will return void
and take a reference to a vector of someType
.
What I'm not sure about is the last pair of parentheses, (const std::vector<someType>&)
. Is operator()
of std::list
being overloaded here?
In addition, I'd like to name the std::list
parameter, but my initial guess of someClass(std::list<...>(& nameOfList)(...))
did not work, as I cannot access nameOfList.begin()
, for example. What would I do here?
Thank you.
It is a function by itself.
std::list<
std::function<
void(std::vector<someType>&)
>
> (&)(const std::vector<someType>&)
This is a reference to a function that takes as an argument a reference to const std::vector
of someType
and returns a list of std::function
s that take a reference to a std::vector
of someType
and return void
.
Usage example:
#include <vector>
#include <list>
#include <functional>
class someType {};
void func(std::list<std::function<void(std::vector<someType>&)>> (& par)(const std::vector<someType>&)) {
// some input
const std::vector<someType> input;
// the function returns the list
std::list<std::function<void(std::vector<someType>&)>> res = par(input);
// we can iterate over the list
for (auto & i : res) {
std::vector<someType> other;
// and call the functions inside
i(other);
}
}
The parameter of the constructor
someClass( std::list<std::function<void(std::vector<someType>&)>>(&)(const std::vector<someType>&)) {
is a reference to a function that has the return type std::list<std::function<void(std::vector<someType>&)>>
and one parameter of the type const std::vector<someType>&
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With