小编lin*_*x40的帖子

std :: scoped_allocator_adaptor和一个使用std :: allocator_arg_t的构造函数的类

我在这里找到一些词语http://en.cppreference.com/w/cpp/memory/scoped_allocator_adaptor/construct

if std::uses_allocator<T, inner_allocator_type>::value==true(类型T使用分配器,例如它是一个容器)

如果 std::is_constructible<T, std::allocator_arg_t, inner_allocator_type, Args...>::value==true,

然后打电话

std::allocator_traits<OUTERMOST>::construct( OUTERMOST(*this),
                                             p,
                                             std::allocator_arg,
                                             inner_allocator(),
                                             std::forward<Args>(args)... );
Run Code Online (Sandbox Code Playgroud)

所以,我做了一个简单的测试

struct use_arg {
    template <typename Alloc>
    use_arg(std::allocator_arg_t, Alloc &, int i)
        { std::cout << i << " in use_arg()\n"; }
};

namespace std {

template <typename A> struct uses_allocator<use_arg, A>: true_type {};

} // namespace std

void test_scoped()
{
    std::scoped_allocator_adaptor<std::allocator<use_arg>> sa;
    auto p = sa.allocate(1);
    sa.construct(p, 4);
    sa.destroy(p);
    sa.deallocate(p, 1);
}
Run Code Online (Sandbox Code Playgroud)

但是gcc和clang给了我这些错误https://gist.github.com/anonymous/3e72754a7615162280fb

我也写use_a了替换use_arg.它可以成功运行.

struct …
Run Code Online (Sandbox Code Playgroud)

c++ stl allocator c++11

5
推荐指数
1
解决办法
227
查看次数

标签 统计

allocator ×1

c++ ×1

c++11 ×1

stl ×1