views:

110

answers:

2

Hi,

I have been reading templates,functors,callback function for the past week and have referred some good books and articles.

I however feel that, unless I can get good practice - programming in templates and use functors-callbacks there is no way I can really understand all the concepts or fluently use them while coding.

Could anyone suggest some articles or books or websites where , there is a definition of the problem and also a solution to the same. I could just write code for the problem and check later on if my solution is good enough..

I am also aware that some of our stack-overflow members are experts in templates and callback functions. It would be great if they could design a problem and also post a solution , where a lot of template beginners like me could benefit.

+3  A: 

I personally think this is the wrong way to learn anything. The kind of people that will be prepared to set such problems will almost certainly not be the kinds of people who are experts on the technology. The best way to learn is to find a real-world problem that is important to you, and then address the problem using the technology., backed up by reading text and reference books, and by posting relevant questions on sites like this.

anon
+1 Find a problem, use your new tools to solve that problem, test your solution to the problem, and if you have mentors, have them review it. If you need mentors, there's plenty of eyes here!!
glowcoder
A: 

A good exercise is to replace named functions with anonymous functors. For example, instead of using a predicate such as

bool is_overdrawn(const Account& account)
{
    return !account.is_balanced();
}

, you can synthesize a functor via std::not1(std::mem_fun_ref(&Account::is_balanced)).

FredOverflow
Why is this "good"?
anon
Because I cannot think of anything simpler that would still be nontrivial :) Whether this makes the code more or less readable is a different question, of course. Personally, I like it.
FredOverflow
@Neil It is an exercise in the sense that you learn, through practice, to translate imperative-style functions into an applicative form (coated with C++ syntax, of course). I find that enlightening by and in itself, even if you decide that you don't ever want to use that style yourself. You could even go, based on such stylistic preferences, in the opposite direction and convert anonymous functors to named functions -- but of course this is only possible if you are already accustomed to anonymous functors, hence I personally think that the exercise is quite useful :)
FredOverflow