CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 3 of 3 FirstFirst 123
Results 31 to 34 of 34
  1. #31
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: C++ Templates: The Complete Guide

    This seems to be a key point in the article.

    Quote Originally Posted by Herb Sutter
    Nontemplate functions are first-class citizens. A plain old nontemplate function that matches the parameter types as well as any function template will be selected over an otherwise-just-as-good function template.
    "It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
    Richard P. Feynman

  2. #32
    Join Date
    Mar 2007
    Posts
    45

    Re: C++ Templates: The Complete Guide

    The 3 functions in that article arent nontemplate functions. And again, im discussing order here, which i believe is the source of confusion.

    If we had a strict rule about template ordering that all compilers were to obey by then the different results we have gotten here wouldnt have occurred.

    From my understanding, GCC follows the rule, (that is also set in Joshutis's book), that templates have to be seen by the *calling template* before they can be called, otherwise, they're not taken into consideration.

    From my experience:-

    - GCC requires ordered template functions. In that a template has to have been seen by a *calling template* before another can call it. That is -

    template Func A;
    template Func B;
    template Func C;

    With regard to GCC, Func B only knows about, and can only call A



    - Visual Studio does not require ordered template functions.

    template Func A;
    template Func B;
    template Func C;

    With regard to VS, Func B can call A and C.

    Again, this is from my experience with codeblocks and VS. I dont know how compliant GCC is, but its what ive come to understand.

  3. #33
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: C++ Templates: The Complete Guide

    Quote Originally Posted by wheelie View Post
    The 3 functions in that article arent nontemplate functions.
    In Example 1, function (f) is a non-template function.

    Code:
    // A function template with two overloads
    template<class T> void f( T );              // (b)
    
    template<class T> void f( int, T, double ); // (c)
    
    // A separate base template that overloads (b) and (c) 
    // -- NOT a partial specialization of (b), because 
    // there's no such thing as a partial specialization 
    // of a function template! 
    template<class T> void f( T* );             // (d)
    
    // A full specialization of (b) for int 
    template<> void f<int>( int );              // (e)
    
    // A plain old function that happens to overload with 
    // (b), (c), and (d) -- but not (e), which we'll 
    // discuss in a moment 
    void f( double );                           // (f)
    "It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
    Richard P. Feynman

  4. #34
    Join Date
    Mar 2007
    Posts
    45

    Re: C++ Templates: The Complete Guide

    :P

    well ok, but i was meaning the main chunk of the article rather than the introductory stuff, under the title

    Why Not Specialize: The Dimov/Abrahams Example

Page 3 of 3 FirstFirst 123

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured