The member template is a dependent name, because its semantics depend on the type of f_type That means you should put "template" before its name (to disambiguate the use of the "less-than" token), similar to how you should put typename before dependent qualified names: template void call_with_i(f_type f) { f. Template operator()(); // f. Template foo(); } As a workaround, you may use a helper type: template struct size_t_ { }; // or boost::mpl::int_ template void call_with_i(f_type f) { f(size_t_()); } Now, you could define your operator() as follows: template void operator()(size_t_) const { // I was deduced automatically by the function argument.
} This comes handy for templated constructors, for which you cannot do f_type()() or something. They will have to be deducible in that case.
The member template is a dependent name, because its semantics depend on the type of f_type. That means you should put "template" before its name (to disambiguate the use of the "less-than" token), similar to how you should put typename before dependent qualified names: template void call_with_i(f_type f) { f. Template operator()(); // f.
Template foo(); } As a workaround, you may use a helper type: template struct size_t_ { }; // or boost::mpl::int_ template void call_with_i(f_type f) { f(size_t_()); } Now, you could define your operator() as follows: template void operator()(size_t_) const { // I was deduced automatically by the function argument. } This comes handy for templated constructors, for which you cannot do f_type()() or something. They will have to be deducible in that case.
– Konrad Rudolph Nov 19 '09 at 9:57 works great! Totally awesome. You're my meta-hero.
Ah, and your idea bout using mpl::int_ is smart too. – Lau Lau Labs Nov 19 '09 at 9:59 @laulaulabs.Mp, glad to be of help :) – Johannes Schaub - litb Nov 19 '09 at 10:18 I found like @laulaulabs. Mp that trying to pass function templates like that does not make sense.
So that workaround using size_t_ is questionable in this scenario. Modified the answer accordingly. – Johannes Schaub - litb Nov 19 '09 at 10:22.
In a case like yours I would use boost::function as functor type. You can then pass both function objects and function pointers while retaining the same interface.
Actually my bit about the templated free function is just nonsense since you can't pass a function template as an argument. – Lau Lau Labs Nov 19 '09 at 10:04.
I want "call_with_i(foo)" to be equivalent to "foo()", but I can't figure out the right syntax to make that happen. I'd be satified with a solution that does just (a) but (a)+(b) would be great. How do you invoke operator() with explicit template arguments?
Is there a way to invoke it in a way that the same syntax would also call a templated free function? If you're wondering what i'm using this for, its because I'm writing a function repeat_to where repeat_to(f) invokes f(0) then f(1) ... f(10). I'm using this to iterate through multiple boost::fusion vectors in parallel by index.
Yeah, I could use iterators, or I could just use a named member function, but I still want to know the answer. Edit note: I striked out stuff because passing a templated free function as an arg doesn't make any sense.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.