less than 1 minute read

Categories:

Tags:

1. Guaranteed Copy/Move Elision

#include <memory>
auto factory()
{
    return std::make_unique<int>();
}

int main()
{
    //widget will be created in-place
    auto widget = factory();
}

2. Beginning constexpr supprot in stblib

3. constexpr lambdas

constexpr auto l = [](){};

4. std::string_view

#include <string_view>

//non allocating view into a string
constexpr std::string_view name = "Hello";

//if we are going to view the string and don't need to pass it along to something else, string_view is a great option.

5. Class Template Argument Deduction

#include <array>
std::array<int ,5> data{1,2,3,4,5};

std::array more_data{1,2,3,4,5};

6. fold expressions

template<typename ...T>
auto add(const T& ...param)
{
    return(param + ...);
}

int main()
{
    return add(1,2,3,4,5);
}

7. structured bindings

std::pair<int, int> values{1, 2};

auto[first, second] = values;

8. if-init expression

void func(){ 
    if (auto[first, secodn] = values; 
        first >5)
    {
        //do important work
    }
}

Leave a comment