Copy std::stack into an std::vector

后端 未结 6 867
不思量自难忘°
不思量自难忘° 2021-02-07 09:02

Is the following code guaranteed by the standard to work(assuming st is not empty)?

#include 
#include 
int main()
{
   extern std::st         


        
6条回答
  •  清歌不尽
    2021-02-07 09:23

    According to this page, std::stack uses a container class to store elements.

    I guess what you suggest works only if the containter store its elements in a linear way (std::vector).

    As a default, std::stack uses a std::deque which, as far as I know, doesn't meet this requirement. But If you specify a std::vector as a container class, I can't see a reason why it shoudln't work.

提交回复
热议问题