12
지금까지 gcc 4.7.0에서 구현 된 C++ 11 std::scoped_allocator_adaptor
을 실험하면서 C++ 11 FDIS는 튜플 (20.4.2.8[tuple.traits]
)에 대한 std::uses_allocator
의 특수화를 정의했지만 다른 모든 용도 쌍은 마치 튜플과 같이 보이고 행동합니다 (std::get
, std::tuple_size
등의 특수화가 있음).튜플에 uses_allocator가 있지만 쌍이 아닌 이유는 무엇입니까?
이러한 내용을 소개 한 N2554은 allocator_arg
생성자와 uses_allocator
전문화를 정의했습니다 (23-24 페이지).
왜 그들은 쌍으로 떨어 뜨 렸지? 볼 수없는 또 다른 방법이 있나요? 아니면 튜플에 찬성하여 쌍을 비추 게 될 것입니까?
내 테스트 코드이었다 :
// myalloc is like std::allocator, but has a single-argument
// constructor that takes an int, and has NO default constructor
typedef std::vector<int, myalloc<int>> innervector_t;
typedef std::tuple<int, innervector_t> elem_t;
typedef std::scoped_allocator_adaptor<myalloc<elem_t>, myalloc<int>> Alloc;
Alloc a(1,2);
std::vector<elem_t, Alloc> v(a);
v.resize(1); // uses allocator #1 for elements of v
// the following line fails to compile if pair is used instead of tuple
// because it attempts to default-construct myalloc<int> for innervector_t
std::get<1>(v[0]).resize(10); // uses allocator #2 for elements of innervector_t
4.7.0의'scoped_allocator_adaptor' 구현은 (지난 주) 불완전하며, (constructwise를 사용하는) 쌍에 대한'construct()'의 오버로드가 부족합니다. 실용적인 사례가 생길만큼 충분합니다. – Cubbi