C++ 为什么元组有uses#u分配器,而对没有';T

C++ 为什么元组有uses#u分配器,而对没有';T,c++,c++11,allocator,C++,C++11,Allocator,到目前为止,在使用GCC4.7.0中实现的C++11std::scoped_分配器_适配器进行实验时,我注意到C++11 FDI为元组(20.4.2.8[tuple.traits])定义了std::uses_分配器的专门化,但不适用于对,尽管出于所有其他目的,对的外观和行为与元组一样(它们有std::get,std::tuple\u size等专门化) 在介绍这些内容的进一步阅读中,定义了allocator\u argconstructor,并且还使用了\u allocator对这些对进行专门化

到目前为止,在使用GCC4.7.0中实现的C++11
std::scoped_分配器_适配器
进行实验时,我注意到C++11 FDI为元组(
20.4.2.8[tuple.traits]
)定义了
std::uses_分配器
的专门化,但不适用于对,尽管出于所有其他目的,对的外观和行为与元组一样(它们有
std::get
std::tuple\u size
等专门化)

在介绍这些内容的进一步阅读中,定义了
allocator\u arg
constructor,并且
还使用了\u 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
//myalloc类似于std::allocator,但只有一个参数
//构造函数,该构造函数接受int,并且没有默认构造函数
typedef std::vector innervector\u t;
typedef std::元组元素;
typedef std::作用域分配程序适配器Alloc;
alloca(1,2);
std::向量v(a);
v、 resize(1);//对v的元素使用分配器#1
//如果使用pair而不是tuple,则以下代码行无法编译
//因为它试图为innervector\u t默认构造myalloc
std::get(v[0]).resize(10);//对innervector的元素使用分配器#2

一个原因是,对于std::pair这样看似简单的类,我们希望避免使用15个构造函数(如in)

我们现在有了一个“通用”构造函数

template <class... Args1, class... Args2>
pair(piecewise_construct_t,
     tuple<Args1...> first_args, tuple<Args2...> second_args);
模板
成对(分段构造),
元组第一个参数,元组第二个参数);

在这里,您可以向每个pair成员的构造函数(包括分配器)传递任何您喜欢的内容。

我现在看到,4.7.0的
作用域分配器适配器的实现是不完整的(截至上周),并且缺少pair的
construct()
重载(使用分段构造).对于我能想到的任何实际用例来说,这确实足够了。