2022年7月2日 星期六

C++11 Review on 2022 + C++14

 C++ Weekly EP 176 C++11 in 12 Minutes by Jason Turner 85.6K

1. auto

2. range based for loop

3. lambda [](int i){return i<3;}

4. variadic templates

template<class Pack>
Pack call(const Pack& v) {
return v;
}

template<class Pack, class... Packs>
Pack call(const Pack& pack, const Packs&... packs) {
std::cout << __PRETTY_FUNCTION__ << "\n";
return pack + call(packs...);
}

5. unique_ptr

6. constexpr int get_value() {return 5*3; }

That's all 6 of them.

But not mentioned

std::move
T&&
thread, mutex, condition_variable, packaged_task, std::future
std::tuple, chrono, decltype, override, nullptr, enum class, unordered_map, std::ref

C++ Weekly EP 178 C++14 in 9 Minutes by Jason Turner 85.6K

Like a bugfix to C++11

1. auto return type for template

template<typename T>
auto function(const T& vec, int value) {
const auto count = std::count(begin(vec), end(vec), value);
return count
}

2. lambda generic

const auto count = std::count(begin(vec), end(vec), [](const auto i){return i<3;});

3. lambda generailized capture

[value = [](){return 3;}](const auto i){return i<value;};

4. make_unique

auto pointer(std::make_unique<int>(5));

5. constexpr with loops, switch, multiple returns

constexpr int get_value() {
int x = 5;
int y = 3;
return x*y;  // C++14 more statements ok, C++11 only 1 statement
}

C++ Weekly EP 190 C++17 in 10 Minutes by Jason Turner 85.6K

1. Guaranteed copy or move elision

#include <memory>
auto factory() {return std::make_unqiue<int>();}
int main() {auto object=factory();}  // must have no copy here

2. non const constexpr reference

reference operator[](size_type pos);
constexpr reference operator[](size_type pos);
const_reference operator[](size_type pos) const;
constexpr const_reference operator[](size_type pos) const;

3. constexpr lambdas

constexpr auto l = [](){};

4. std::string_view

constexpr std::string_view name = "hello";




a

sfd

sadf

safs

df

sadf

sadf

sad

asdads















End

沒有留言:

張貼留言

2007 to 2023 HP and Dell Servers Comparison

  HP Gen5 to Gen11  using ChatGPT HP ProLiant Gen Active Years CPU Socket Popular HP CPUs Cores Base Clock Max RAM Capacity Comparable Dell ...