Skip to content

Container improvements

  • constexpr is supported by std::vector, std::string and many algorithms
    this allows e.g. sorting a vector at compile time:
    constexpr int maxVal = [](){
    std::vector vec = {2,1,6,3};
    std::sort(vec.begin(), vec.end());
    return vec.back();}()
  • simple construction of std::array:
    auto arrString = std::to_array("Some text");
    auto arrDouble = std::to_array<double>({3.14, 2.78});
    auto arrPair = std::to_array<std::pair<int,double>>({{4711, 3.14}, {1508, 2.78}});
  • simplified erasing from any STL container with std::erase/erase_if
    old style erase remove idiom:
    vec.erase(std::remove(vec.begin(), vec.end(), someVal), vec.end());
    vec.erase(std::remove_if(vec.begin(), vec.end(), HasSomePropertyPred), vec.end());
    new simplified syntax:
    std:erase(vec, someVal);
    std::erase_if(vec, HasSomePropertyPred);
  • new member function contains for map/set
    if (myMap.contains(someKey)) ...
  • Prefix/suffix checking for std::string
    if (myString.starts_with/ends_with("someLetters") ...