来自优先选择。
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>()};一样简单地初始化它。
发布于 2015-02-15 18:46:37
就像T.C.怀疑的那样,看起来libstdc++还没有实现这些构造函数。下面是他们的doxygen中的来源:
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的片段:
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)https://stackoverflow.com/questions/28529517
复制相似问题