On Sunday, 21 August 2016 06:43:50 UTC+3, eva galois wrote:
> Is it possible, through templates/aliasing('using')/etc, to create a
> container of functions with arbitrary return value and parameters?
It is hard to tell from one sentence what it is that you want.
People have several times made container of one of anything in C++.
Most popular of those is perhaps 'boost::any'. IMHO that thing is
bordering on uselessness, but we can certainly make a 'vector' of those
resulting with 'vector' of anything.
C++ thing borrowed from C that can be one of compile-time known set
is 'union'. Like most things borrowed from C it is constrained
and unsafe, but union of function pointers can still be what you want
and those can be put into 'vector'.
Lot of libraries have invented 'variant' classes that do same what 'union'
but more safely and with less constraints. Those are rather useful; I have
used 'boost::variant' in several projects.
>
> I know this code is basically gibberish, but the idea would be something
> like:
>
> | template <typename T, typename ...Args>
> | typedef std::vector<std::function<T(Args...)>> functions;
>
> Maybe through aliasing (since I know you can't template a typedef
> statement)?
That code tries to declare that "something" you want. That does not
actually illustrate what it is what you want. Also it is the angle
from what I rarely approach a problem. I commonly try to write down
how I want to use that "something". IOW ... what is the motivating
example to have that thing at all?