Activators: are standard containers expected to operate domestically?

As an example for this question I will use std::vector.
Its definition from the documentation follows:

template<class T, class Allocator = std::allocator<T>>
class vector;

As expected, if T- its type, the distributor should be shifted to the side T.
In any case, the code below compiles without errors (at least using GCC) and runs :

#include<vector>
#include<memory>
#include<string>

struct S {
    int i;
    double d;
    std::string s;
};

int main() {
    std::allocator<int> alloc;
    std::vector<S, std::allocator<int>> v{alloc};
    v.push_back(S{});
}

Here I create a vector S using an int focused focus allocator.

? undefined? ?
, STL .
, , rebind, std::list, , .

, , , ( rebind ?), , .

+4
2

98. , , :

: allocator_type::value_type X::value_type

Requires undefined.

gcc VS . , . lib++ static_assert.

http://melpon.org/wandbox/permlink/LVYEHfVIGoyZsii8

vector .

lib++ , ( ). , : vector<int, some_allocator<int>> vector<int, some_allocator<long>>, , .

+7

, , , :

. allocator allocator<T> cite cppreference, :

a.allocate(n) | , n T, . .

std::allocator<int> S , sizeof(int)!= sizeof(S).

,

, .

. , .

@AlbertoM :

cppreference std::vector: " undefined, Allocator::value_type T.", T .

.. undefined.

+2

Source: https://habr.com/ru/post/1627673/


All Articles