Thread: How properly inherit from template?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #10
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Quote Originally Posted by Elysia View Post
    Perhaps it is, but they should both do the same thing (if the algorithm is used in such a way) and the to_lower member is simply less to type and therefore preferred (also less error prone).
    I would like to point out that the free function to_lower requires you to type one character less than the member function string::to_lower (or generally any free function vs member function), namely the dot character.

    Now, if an API provided a key_exists function for containers with find member, exactly how does the following not abstract the algorithm away for the user less than a member function of set, map etc. would?
    Code:
    template <class Container, class Type>
    bool key_exists(const Container& c, const Type& t)
    {
        return c.find(t) != c.end();
    }
    Edit:
    Free functions are simple "worse" (if you could call it that), because it's exactly that - free. It's not a member function.
    Yeah, in Western society the word "free" has clearly negative connotations. Anybody should see immediately that free things are bad.
    Last edited by anon; 04-24-2008 at 09:46 AM.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Specialising a member function with a template template parameter
    By the4thamigo_uk in forum C++ Programming
    Replies: 10
    Last Post: 10-12-2007, 04:37 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  4. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 12:54 PM