Copy std::stack into an std::vector

后端 未结 6 872
不思量自难忘°
不思量自难忘° 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:37

    Edit: initial statement redacted, the standard actually does provide a full definition for the stack adaptor, nothing left to implentors. see top answer.

    You want a container that has a push and pop method and allows you to inspect elements anywhere in the container and uses a std::vector for storage. There is such a container in the standard template library

    it is called std::vector.

    Use std::stack only for bondage purposes

提交回复
热议问题