1

I have a struct, one of whose members is a std::stack using a std::array as its underlying container:

struct S {
  int a, b; // dummy members
  std::stack<
    int, 
    std::array<int, 10>
  > st;
};

I would like to use brace initialization to initialize all members of an S struct, something like:

S const obj {
  1, // a
  2, // b
  {1, 2, 3} /* st
         ^
         I want this at the top of the stack */
};

Is this kind of initialization possible for std::stack? If yes, what would the syntax be?

nluka
  • 91
  • 6
  • Note that a stack only allows you to inspect the top element. So a constant stack is not likely to be useful. Additionally, using a `std::array` as the backing container will prevent you from ever poping an element off the top, making the stack equally unlikely to be useful. – François Andrieux Oct 07 '22 at 23:39
  • 1
    You cannot use a std::array as the underlying container of a std::stack because std::array does not support push_back() and pop_back(). – Eric M Schmidt Oct 08 '22 at 01:37

0 Answers0