Constantinos
Constantinos

Reputation: 25

stack container adaptor construction

From cppreference.

  1. How do i initialize 5-9 constructors?
  2. What the purpose of member template constructor template< class Alloc > ?

For 1st question I have tried various ways but I just cant get it right. For example std::stack<int> first; first.push(1); first.push(2); std::stack<int> second {first, std::allocator<int>()}; // error

For 2nd question I do not understand what is the purpose of member template constructor template< class Alloc> anyway. For example vector has a constructor vector( const vector& other, const Allocator& alloc ); which makes it clear that the second parameter is an allocator and it can be initialized as simple as std::vector<int> first {1, 2, 3}; std::vector<int> second {first, std::allocator<int>()};

Upvotes: 0

Views: 111

Answers (1)

user3920237
user3920237

Reputation:

Like T.C. suspects, it looks like libstdc++ doesn't have those constructors implemented yet. Here is the source from their 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

On the other hand, here's a snippet from my Clang's include:

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)

Upvotes: 3

Related Questions