
(Please don't top-post. Rearranging...) On 1/16/2011 9:36 PM, Hossein Haeri wrote:
On 16/1/11, Eric Niebler wrote:
On 1/15/2011 6:31 PM, Hossein Haeri wrote:
I have a syntax like
((_1 >> &f1 >> &f2) || (_2 >> &f3) || (_3 >> &f4 >> &f5 >> &f6)) >> g
for which I already have a small grammar which along with my context do their job fine. The above expression is to act like
g(f2(f1(x)), f3(y), f6(f5(f4(z))))
once invoked with _1 == x, _2 == y, and _3 == z. I am currently trying to add a safety layer on top of that which can emit a compile-error -- at the appropriate corner of my code -- that can prevent pass of functions with wrong arities. For example, g above needs to be a ternary.
Although my context will notice it if g is not a ternary and produce a meaningful error message, that's too late. My poor user needs to be informed right at the instantiation time. So, I thought I'm going to use transforms to get my grammar manage that.
<snip>
Below is a grammar Stream that only matches these function stream expressions where the number of arguments to each callable matches the arity of the callable. It's a short hop from here to where you want to be, using is_callable_with_args.
<snip>
Dear Eric,
This is great, thanks. But, it's still not quite what I'm after; what wasn't obvious from my last explanation was that I don't want to restrict these f's and g's to only functions (function pointers). I'm about to also include function objects, or, in fact, whatever callable with that arity.
Any idea now?
As I said, "It's a short hop from here to where you want to be, using is_callable_with_args." I've gotten you 90% of the way there. The rest is an exercise for the reader. -- Eric Niebler BoostPro Computing http://www.boostpro.com