Why is allocator::rebind necessary when we have template template parameters?

前端 未结 4 2046
予麋鹿
予麋鹿 2020-11-27 17:07

Every allocator class must have an interface similar to the following:

template
class allocator
{
    ...
    template
    s         


        
4条回答
  •  粉色の甜心
    2020-11-27 17:34

    A quoted text from Foundations of Algorithms in C++11, Volume 1, chap 4, p. 35 :

    template  
    struct allocator 
    {  
       template   
       using  rebind = allocator; 
    }; 
    

    sample usage :

    allocator::rebind x;
    

    In The C++ Programming Language, 4th edition, section 34.4.1, p. 998, commenting the 'classical' rebind member in default allocator class :

    template
         struct rebind { using other = allocator;};
    

    Bjarne Stroustrup writes this:

    The curious rebind template is an archaic alias. It should have been:

    template
    using other = allocator;
    

    However, allocator was defined before such aliases were supported by C++.

提交回复
热议问题