Why do I use a lot of typeef in the STL container of C++ to define member types?

Asked 1 years ago, Updated 1 years ago, 248 views

Why do C++ STL containers (vector in the example above) use a lot of typeef internally?
I thought that the possibility of misuse would increase by defining member types as new model names in typeef.
I would like to know the reason why I have to redefine it with a different model name.

template<class T,class Allocator=std::allocator<T>>
    class vector {
    public:
        /* member types*/
        typeedefT value_type;
        typeedef Allocator allocator_type;
        typeef std::size_t size_type;
        typeef std::ptrdiff_t difference_ptr;
        typeef value_type&reference;
        typeef const value_type&const_reference;
        typeedef typename Allocator::pointer pointer;
        typeedef typenameAllocator::const_pointer const_pointer;
        typeedef pointerator;
        typeedef const_pointer const_iterator;
        typeefft::reverse_iterator<iterator>reverse_iterator;
        typeefft::reverse_iterator<const_iterator>const_reverse_iterator;

c++

2022-12-24 15:50

1 Answers

The processing system (the library provided with ) is designed to allow you to choose the appropriate type for your running environment.

For example, std::vector<T>::size_type is only implemented in that environment, and language specifications do not dictate that you should.


2022-12-24 18:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.