When can I have my templated typedefs?

Discussion in 'C++' started by DeMarcus, Jul 17, 2004.

  1. DeMarcus

    DeMarcus Guest

    I want to encapsulate the STL and today I use
    this solution.

    template< class T >
    struct MyVector
    {
    typedef std::vector<T> Type;
    };

    And in use it becomes

    MyVector<int>::Type someVector;

    But I'm tired of using this ::Type extension.
    Why can't I define MyVector like this?

    template< class T >
    typedef std::vector<T> MyVector;


    Thanks
    Daniel
     
    DeMarcus, Jul 17, 2004
    #1
    1. Advertising

  2. DeMarcus

    Sharad Kala Guest

    "DeMarcus" <> wrote in message
    news:40f90021$0$25582$...
    >
    > I want to encapsulate the STL and today I use
    > this solution.
    >
    > template< class T >
    > struct MyVector
    > {
    > typedef std::vector<T> Type;
    > };
    >
    > And in use it becomes
    >
    > MyVector<int>::Type someVector;
    >
    > But I'm tired of using this ::Type extension.
    > Why can't I define MyVector like this?
    >
    > template< class T >
    > typedef std::vector<T> MyVector;


    Because standard C++ as of now does not support template typedefs. In fact
    you have addressed the problem just the way Herb Sutter describes in this
    gotw article - http://gotw.ca/gotw/079.htm.
     
    Sharad Kala, Jul 17, 2004
    #2
    1. Advertising

  3. DeMarcus

    JKop Guest

    DeMarcus posted:

    > template< class T >
    > typedef std::vector<T> MyVector;



    Do you not mean:

    template <class T>
    typedef std::vector<T> MyVector<T>;


    ?


    -JKop
     
    JKop, Jul 17, 2004
    #3
  4. DeMarcus

    DeMarcus Guest

    JKop wrote:

    > DeMarcus posted:
    >
    >
    >>template< class T >
    >>typedef std::vector<T> MyVector;

    >
    >
    >
    > Do you not mean:
    >
    > template <class T>
    > typedef std::vector<T> MyVector<T>;
    >


    Yes.
     
    DeMarcus, Jul 17, 2004
    #4
  5. DeMarcus

    DeMarcus Guest

    Sharad Kala wrote:

    > "DeMarcus" <> wrote in message
    > news:40f90021$0$25582$...
    >
    >>I want to encapsulate the STL and today I use
    >>this solution.
    >>
    >>template< class T >
    >>struct MyVector
    >>{
    >> typedef std::vector<T> Type;
    >>};
    >>
    >>And in use it becomes
    >>
    >>MyVector<int>::Type someVector;
    >>
    >>But I'm tired of using this ::Type extension.
    >>Why can't I define MyVector like this?
    >>
    >>template< class T >
    >>typedef std::vector<T> MyVector;

    >
    >
    > Because standard C++ as of now does not support template typedefs. In fact
    > you have addressed the problem just the way Herb Sutter describes in this
    > gotw article - http://gotw.ca/gotw/079.htm.
    >


    But ain't the industry screaming for templated typedefs? What's the
    drawback?
     
    DeMarcus, Jul 17, 2004
    #5
  6. DeMarcus

    Sharad Kala Guest

    "DeMarcus" <> wrote in message
    news:40f91c9d$0$25582$...
    >
    >
    > But ain't the industry screaming for templated typedefs? What's the
    > drawback?


    AFAIK, perhaps it will be added in the future revision of the standard.

    -Sharad
     
    Sharad Kala, Jul 17, 2004
    #6
  7. DeMarcus

    tom_usenet Guest

    On Sat, 17 Jul 2004 12:27:15 +0200, DeMarcus <>
    wrote:

    >
    >I want to encapsulate the STL and today I use
    >this solution.
    >
    >template< class T >
    >struct MyVector
    >{
    > typedef std::vector<T> Type;
    >};
    >
    >And in use it becomes
    >
    >MyVector<int>::Type someVector;
    >
    >But I'm tired of using this ::Type extension.
    >Why can't I define MyVector like this?
    >
    >template< class T >
    >typedef std::vector<T> MyVector;


    The concept of templated typedefs doesn't quite make sense, since a
    typedef is an alias for a type, whereas MyVector above isn't a type
    alias at all, but an alias for a family of types. The proposed syntax
    looks like this:

    template <class T>
    using MyVector = std::vector<T>;

    See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1489.pdf

    Tom
     
    tom_usenet, Jul 19, 2004
    #7
  8. On Sat, 17 Jul 2004 12:27:15 +0200, DeMarcus <>
    wrote:

    >Why can't I define MyVector like this?
    >
    >template< class T >
    >typedef std::vector<T> MyVector;


    The problem is that MyVector becomes an ambiguous name whenever there
    are more than one vectors of different T types.

    At one point I thought it might be useful, too ... but then I found
    that there is probably no solution which involved less typing than
    doing it the way you suggest, or by simply supplying an alias for each
    different vector<T> type.

    Guess I should read Herb Sutter's article...maybe I'm missing
    something?

    --
    Bob Hairgrove
     
    Bob Hairgrove, Aug 7, 2004
    #8
    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. RA Scheltema
    Replies:
    3
    Views:
    404
    RA Scheltema
    Jan 6, 2004
  2. Marijn
    Replies:
    5
    Views:
    464
    Marijn
    Feb 13, 2004
  3. Replies:
    0
    Views:
    2,235
  4. Amadeus W. M.
    Replies:
    2
    Views:
    394
    Amadeus W. M.
    Jul 4, 2006
  5. Juha Nieminen

    Templated typedefs

    Juha Nieminen, Feb 26, 2008, in forum: C++
    Replies:
    1
    Views:
    263
    Michael DOUBEZ
    Feb 26, 2008
Loading...

Share This Page