Why is pop () void?

For stack, pop() is void, which means I need two lines of code whenever I want to get the top and pop:

 auto top = s.top(); s.pop(); 

It would be convenient if I could just do:

 auto top = s.pop(); 

Why is this so?

+8
c ++ stack
source share

No one has answered this question yet.

See similar questions:

88
Why doesn't std :: queue :: pop return a value.?
nine
Can the stack have a safe exception method for returning and deleting the top element with move semantics?

or similar:

23498
Why is processing a sorted array faster than processing an unsorted array?
2437
Why "use the std namespace;" considered bad practice?
2116
Why are stigment additions much faster in individual cycles than in a combined cycle?
1994
What are the basic rules and idioms for operator overloading?
1783
C ++ 11 introduced a standardized memory model. What does it mean? And how will this affect C ++ programming?
1675
Why is reading strings from stdin much slower in C ++ than Python?
1643
Why can templates be implemented only in the header file?
1518
Image Processing: Enhanced Coca-Cola Can Recognition Algorithm
950
Undefined behavior and sequence points
678
Why is my program running slower if you iterate over exactly 8192 elements?

All Articles