2011-08-31 7 views
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가 있지만 쌍이 아닌 이유는 무엇입니까?

이러한 내용을 소개 한 N2554allocator_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

이유 중 하나는 우리가 표준 : : 쌍과 같은 단순 해 보이는 클래스 (N3000처럼) (15 개) 생성자를하지 않으려는 것이다.

우리는 지금 대신에 당신은 당신이 할당 자 포함하여 각 쌍 멤버의 생성자에 좋아하는 무엇이든 통과 할 수있는 하나의 "범용"생성자

template <class... Args1, class... Args2> 
pair(piecewise_construct_t, 
    tuple<Args1...> first_args, tuple<Args2...> second_args); 

을 가지고있다.

+0

4.7.0의'scoped_allocator_adaptor' 구현은 (지난 주) 불완전하며, (constructwise를 사용하는) 쌍에 대한'construct()'의 오버로드가 부족합니다. 실용적인 사례가 생길만큼 충분합니다. – Cubbi

관련 문제