use*_*538 3 c++ stl c++11 c++-concepts c++14
我已经在标准(n4296),23.2.3/4(表100)中看到了对序列stl容器的要求,并且读过一个带有参数迭代器的构造函数(X - 容器,i和j - 输入迭代器)
X(i, j)
X a(i, j)
Run Code Online (Sandbox Code Playgroud)
要求容器的元素类型为EmplaceConstructible.
Requires: T shall be EmplaceConstructible into X from *i
Run Code Online (Sandbox Code Playgroud)
我认为构造函数可以通过为范围中的每个迭代器调用std :: allocator_traits :: construct(m,p,*it)方法来实现(其中m - 类型A的分配器,p - 指向内存的指针,它 - 迭代器in [i; j],并且只需要CopyInsertable元素的概念,因为只提供一个参数用于复制/移动,而EmplaceConstructible概念要求元素由一组参数构造.这个决定有什么理由吗?
CopyInsertable是一个二进制概念 - 给定一个容器,X它适用于单个类型T,需要有一个复制构造函数.然而,*i允许是由不同类型的T,只要有一种方法,以(隐式地)构造T从*i:
char s[] = "hello world!";
std::vector<int> v(std::begin(s), std::end(s));
// int is EmplaceConstructible from char
Run Code Online (Sandbox Code Playgroud)
A(人为)示例,其中T是不 CopyInsertable:
struct nocopy {
nocopy(int) {}
nocopy(nocopy const&) = delete;
nocopy(nocopy&&) = delete;
};
int a[]{1, 2, 3};
std::vector<nocopy> v(std::begin(a), std::end(a));
Run Code Online (Sandbox Code Playgroud)