std::vector performance regression when enabling C++11

I have found an interesting performance regression in a small C++ snippet, when I enable C++11: #include <vector> struct Item { int a; int b; }; int main() { const std::size_t num_items = 10000000; std::vector<Item> container; container.reserve(num_items); for (std::size_t i = 0; i < num_items; ++i) { container.push_back(Item()); } return 0; } With g++ (GCC) … Read more

Is it possible to use std::string in a constexpr?

Using C++11, Ubuntu 14.04, GCC default toolchain. This code fails: constexpr std::string constString = “constString”; error: the type ‘const string {aka const std::basic_string}’ of constexpr variable ‘constString’ is not literal… because… ‘std::basic_string’ has a non-trivial destructor Is it possible to use std::string in aconstexpr? (apparently not…) If so, how? Is there an alternative way to … Read more