FAQ Database Discussion Community


Why is it not possible to remove elements from a std::map using reverse iterators?

c++,c++11,associative-array,c++-standard-library
I was looking for the most efficient and expressive way to remove the last element from a std::map. I tried: #include <map> int main() { std::map<int, int> m; m.insert(std::make_pair(1,1)); m.erase(m.crbegin()); return 0; } The code does not compile, since std::map::erase can take only std::map::const_iterator. Moreover, prior to C++11 it could...

std::shared_ptr(new DerivedType(…)) != std::make_shared(DerivedType(…))?

c++,c++11,shared-ptr,c++-standard-library,make-shared
I haven't found any issues quite like this yet: but if someone finds one then sorry. I've been trying to use std::shared_ptr to greatly simplify memory management, however I've come across what must be some sort of bug. When I create a DerivedType pointer with std::make_shared<type>(DerivedType(...)) It can only be...

Why is “Init” in std::ios_base::Init uppercase?

c++,design,naming-conventions,iostream,c++-standard-library
All the names in the standard C++ library are lowercase except std::ios_base::Init. Why is this?

C++: Printing or cout a standard library container to console

c++,printing,cout,c++-standard-library
What's the C++ way to print or cout a C++ standard library container to the console, to view its contents? On a separate note, why doesn't the C++ library actually overload the << operator for you? Any history behind it?...