CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2007
    Posts
    4

    Question Problem with trick to overcome the absence of template typedefs

    Hi there,

    Can anyone see the problem with this code? http://codepad.org/ODBfNNW2

    Thanks a lot,
    Ricardo Abreu

  2. #2
    Join Date
    Nov 2003
    Posts
    1,902

    Re: Problem with trick to overcome the absence of template typedefs

    Put all relevant information here in this thread. Do you think that link will work in 5 years?
    Code:
    #include <utility>
    #include <iostream>
    
    namespace Testing
    {
        template<typename T>
        struct CmdArg
        {
            typedef std::pair<T, bool> type;
        };
        
        template<typename T>
        typename CmdArg<T>::type f(const T& t)
        {
            return CmdArg<T>::type(t, false);
        }
    }
    
    int main()
    {
        Testing::CmdArg<int>::type arg = Testing::f(11);
        
        std::cout << arg.first << " " << arg.second << std::endl;
        return 0;
    }
    Fixes are in red.

    gg

  3. #3
    Join Date
    Apr 2007
    Posts
    4

    Resolved Re: Problem with trick to overcome the absence of template typedefs

    OK, its solved. I actually had to add another 'typename' for it to work:

    Code:
    #include <utility>
    #include <iostream>
    
    namespace Testing
    {
        template<typename T>
        struct CmdArg
        {
            typedef std::pair<T, bool> type;
        };
        
        template<typename T>
        typename CmdArg<T>::type f(const T& t)
        {
            return typename CmdArg<T>::type(t, false);
        }
    }
    
    int main()
    {
        Testing::CmdArg<int>::type arg = Testing::f(11);
        
        std::cout << arg.first << " " << arg.second << std::endl;
        return 0;
    }
    Thank you and sorry for not posting the code here before - I assumed IRC rules. Also, hopefully in 5 years C++ will already have template typedefs

    Again, many thanks,
    gumbers

  4. #4
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Problem with trick to overcome the absence of template typedefs

    Quote Originally Posted by gumbers
    Also, hopefully in 5 years C++ will already have template typedefs
    C++0x (which might be finalised this year) will have template typedefs via a template "using" statement. Now, whether or not compilers have implemented or will soon implement it is another matter, but hopefully they will take less than 5 years to get it done

    (Incidentally, if you read the recent C++0x "slow chat" forum, template typedefs will not be supported by the up and coming MSVC10.)
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  5. #5
    Join Date
    Apr 1999
    Location
    Altrincham, England
    Posts
    4,470

    Re: Problem with trick to overcome the absence of template typedefs

    Quote Originally Posted by laserlight View Post
    C++0x (which might be finalised this year) [...]
    If it isn't, they'll have to start calling it "C++1x".
    Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
    --
    Sutter and Alexandrescu, C++ Coding Standards

    Programs must be written for people to read, and only incidentally for machines to execute.

    --
    Harold Abelson and Gerald Jay Sussman

    The cheapest, fastest and most reliable components of a computer system are those that aren't there.
    -- Gordon Bell


  6. #6
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Problem with trick to overcome the absence of template typedefs

    Quote Originally Posted by Graham View Post
    If it isn't, they'll have to start calling it "C++1x".
    Nahhh. we will just call the coming years 200A,200B,200C....
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

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