首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >堆栈容器适配器构造

堆栈容器适配器构造
EN

Stack Overflow用户
提问于 2015-02-15 18:26:27
回答 1查看 97关注 0票数 0

来自优先选择

  1. 如何初始化5-9构造函数?
  2. 成员模板构造函数template< class Alloc >的目的是什么?

对于第一个问题,我已经尝试了各种方法,但我就是搞不好。例如,std::stack<int> first; first.push(1); first.push(2); std::stack<int> second {first, std::allocator<int>()}; // error

对于第二个问题,我不明白成员模板构造函数template< class Alloc>的目的是什么。例如,向量有一个构造函数vector( const vector& other, const Allocator& alloc );,它清楚地表明第二个参数是一个分配器,可以像std::vector<int> first {1, 2, 3}; std::vector<int> second {first, std::allocator<int>()};一样简单地初始化它。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-02-15 18:46:37

就像T.C.怀疑的那样,看起来libstdc++还没有实现这些构造函数。下面是他们的doxygen中的来源

代码语言:javascript
复制
128 #if __cplusplus < 201103L
129  explicit
130  stack(const _Sequence& __c = _Sequence())
131  : c(__c) { }
132 #else
133  explicit
134  stack(const _Sequence& __c)
135  : c(__c) { }
136 
137  explicit
138  stack(_Sequence&& __c = _Sequence())
139  : c(std::move(__c)) { }
140 #endif

另一方面,这里有一个来自我的Clang的片段:

代码语言:javascript
复制
template <class _Alloc>
    _LIBCPP_INLINE_VISIBILITY
    stack(const container_type& __c, const _Alloc& __a,
          typename enable_if<uses_allocator<container_type,
                                            _Alloc>::value>::type* = 0)
        : c(__c, __a) {}
template <class _Alloc>
    _LIBCPP_INLINE_VISIBILITY
    stack(const stack& __s, const _Alloc& __a,
          typename enable_if<uses_allocator<container_type,
                                            _Alloc>::value>::type* = 0)
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28529517

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档