Implement the Combine function using templates
        Posted  
        
            by gkid123
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by gkid123
        
        
        
        Published on 2010-03-26T19:06:43Z
        Indexed on 
            2010/03/26
            19:13 UTC
        
        
        Read the original article
        Hit count: 350
        
any idea on how to do it for template? thanks
Implement the Combine function using templates. The Combine fn applies a function of two arguments cumulatively to the items of an STL container, from begin() to end(), so as to reduce the sequence to a single value.
For example, Combine(<list containing 6,3,1,9,7>, std::plus<int>())
should calculate ((((6+3)+1)+9)+7).
class NotEnoughElements {};
template <typename Container, typename Function>
typename Container::value_type
Combine(const Container& c, Function fn) throw (NotEnoughElements)
{
   your code goes here
}
© Stack Overflow or respective owner