Flexibility of template alias in C++0x

后端 未结 2 2155
夕颜
夕颜 2021-02-12 16:27

As I understand, template aliases in C++0x will allow us to do the following:

template 
using Dictionary = std::map< std::string, T >;

D         


        
相关标签:
2条回答
  • 2021-02-12 17:08

    The syntax is:

    template <typename Iter>
    using ValueType = typename std::iterator_traits<Iter>::value_type;
    

    as with your second one.

    Source: http://www2.research.att.com/~bs/C++0xFAQ.html#template-alias

    Their example is:

    template<int N>
        using int_exact = typename int_exact_traits<N>::type;  // define alias for convenient notation
    
    0 讨论(0)
  • 2021-02-12 17:13

    typename is required when a member type follows the :: operator and a template-id precedes it.

    The usage of typename you mention isn't specific to template aliases nor is it required unless you're aliasing to a member such as ::type, but that is a common use case.

    For example, there's no typename when introducing a simple alias name to an existing template.

    template< typename x >
    class bar;
    
    template< typename x >
    using foo = bar< x >; // no typename needed
    
    0 讨论(0)
提交回复
热议问题