Do nonmember nonfriend functions improve genericity?

Discussion in 'C++' started by bluekite2000@gmail.com, Jul 29, 2005.

  1. Guest

    The author's reason is "because its hard to write templates that dont
    know whether or not an operation is a member for a given type". What
    does he mean by this? An example is appreciated.
    , Jul 29, 2005
    #1
    1. Advertising

  2. wrote:
    > The author's


    The author of what?

    > reason is "because its hard to write templates that dont
    > know whether or not an operation is a member for a given type". What
    > does he mean by this? An example is appreciated.


    What is the context?

    If I had to speculate, the "author" you're quoting (?) speaks of template
    code similar to

    template<class T> void foo(T t)
    {
    // if T has a member 'bar', use it
    t.bar();
    // else, don't use it, use some global function
    ::bar(t);
    }

    Such template is rather difficult to implement, but possible, using SFINAE
    technique. Look up "has_member" in the archives.

    V
    Victor Bazarov, Jul 29, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    9
    Views:
    499
    Benji
    Nov 23, 2005
  2. Erik Haugen

    nonmember vs member?

    Erik Haugen, Oct 24, 2003, in forum: C++
    Replies:
    13
    Views:
    625
    jeffc
    Oct 24, 2003
  3. E. Robert Tisdale

    Genericity is *not* templates

    E. Robert Tisdale, Apr 6, 2004, in forum: C++
    Replies:
    11
    Views:
    537
    tom_usenet
    Apr 7, 2004
  4. nonmember function

    , Aug 1, 2005, in forum: C++
    Replies:
    3
    Views:
    290
    msalters
    Aug 3, 2005
  5. desktop

    nonmember functions?

    desktop, May 23, 2007, in forum: C++
    Replies:
    8
    Views:
    379
    Gennaro Prota
    May 25, 2007
Loading...

Share This Page