2012/6/9 Nevin Liber <
ne...@eviloverlord.com>:
Its not, and I don't believe the difference is much exposed to the
user other than the requirement to declare the functor struct a public
functor. The thing the library proposes is a set of re-usable building
blocks that help attenuate your strucs. The current proposal does
require your struct declares that it implements functor so it can be
used as a constructor argument and member in templates defined in the
library. Basically declaring it for example a public
std::functor_pattern::functor<void> is the price you as a user pay for
allowing the library to define for example a quota based condition
proxy for it with the same interface:
struct One: public std::functor_pattern::functor<void>
{
template<typename F>
explicit One(F&& f) : _f(std::forward<F>(f)) {}
void operator()() const { return _f(); }
private:
std::function<void()> _f;
};
..
One one; //instantiate your functor
std::functor_pattern::quota tentimesmax(10); //instantiate a quota.
std::functor_pattern::null_sink<void> donothing; //instantiate a do
nothing functor with the same interface.
std::functor_pattern::conditional
attenuatedone(one,donothing,tentimesmax);//Create the attenuation
proxy.
Foo foo(attenuatedone); //Pass the attenuated functor to the
constructor of a sub-system.
..
Foo::Foo( std::functor_pattern::functor<void> one):mOne(one) {}
void Foo::someMethod() {
..
mOne();
..
}
If you are suggesting that it may be possible and/or useful to change
the library proposal APIs so that these declarations may evaporate
from the API, than yes, that might be interesting.
Maybe you could ilustrate based on the above how you would envision a
better API for the library to look like.