std::scoped_allocator_adaptorこれまでに gcc 4.7.0 で実装された C++11 を試しているときに、C++11 FDIS はstd::uses_allocatorタプル ( 20.4.2.8[tuple.traits]) の特殊化を定義しているが、ペアには定義していないことに気付きました。タプルと同じです ( 、 などの特殊化がありstd::getますstd::tuple_size)。
さらに読むと、これらのことを紹介した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