2021年最新整理,500个c++11/14/17/20/23的新特性代码案例,包含lambda匿名函数,右值引用,auto,coroutine库,synchronization库等

Overview

cpp_new_features

2021年最新整理,500个c++11/14/17/20/23的新特性代码案例,包含lambda匿名函数,右值引用,auto,coroutine库,synchronization库,持续更新中......


C++新特性


C++11新特性

关键字

新增关键字

含义变化或者新增含义关键字(meaning changed or new meaning added)

类型支持(基本类型、RTTI、类型特性)

Primary type categories

Composite type categories

Type categories

Supported operations

STL容器

无序容器

元组std::tuple

hash

智能指针


正则表达式


函数

非静态成员函数

函数对象模板


模板


原子操作


线程


异常


错误


新语法

预处理

C++宏(cplusplus macro)

基于范围的for语句

对齐支持(alignment support)

显式转换操作符(explicit conversion operators)

静态断言(static assert)
  • 语法:static_assert(常量表达式,"提示字符串")

  • static assert

数字限制(numeric limits)

原始字符串(raw string)

追踪返回类型语法(trailing return type syntax)

扩展的friend语法(extended friend syntax)

扩展的整型(extended integer types)

非受限联合体(unrestricted union)

内联名字空间(lnline namespace)

用户定义的字面量(user-defined literals)

强类型枚举(scoped and strongly typed enums)

随机装置(random device)

std::ref和std::cref

常量表达式(constexpr)

lamda表达式

指针空值(nullptr)

防止类型收窄(Preventing narrowing)

初始化列表(initializer lists)

统一的初始化语法和语义(Uniform initialization syntax and semantics)

POD(plain old data)

long long整型

移动语义(move semantics)

右值引用(rvalue reference)

c99特性(c99)

一般化的SFINAE规则(generalized SFINAE rules)

C++14新特性

类型支持(基本类型、RTTI、类型特性)

定义于头文件<type_traits>

定义于头文件<utility>

定义于头文件<initializer_list>

定义于头文件<iterator>

定义于命名空间std

定义于头文件 <array>

定义于头文件 <deque>

定义于头文件 <forward_list>

定义于头文件 <iterator>

定义于头文件 <list>

定义于头文件 <map>

定义于头文件 <regex>

定义于头文件 <set>

定义于头文件 <span>

定义于头文件 <string>

定义于头文件 <string_view>

定义于头文件 <unordered_map>

定义于头文件 <unordered_set>

定义于头文件 <vector>

定义于命名空间 std

C++17新特性

关键字

含义变化或者新增含义关键字(meaning changed or new meaning added)

类型支持(基本类型、RTTI、类型特性)

定义于头文件<type_traits>

定义于头文件<utility>

定义于头文件<tuple>

定义于头文件<optional>

定义于头文件<variant>

定义于头文件<any>

定义于头文件<charconv>

定义于头文件<initializer_list>

容器库

定义于头文件<map>

定义于头文件<unordered_map>

定义于头文件 <array>

定义于头文件 <deque>

定义于头文件 <forward_list>

定义于头文件 <iterator>

定义于头文件 <list>

定义于头文件 <map>

定义于头文件 <regex>

定义于头文件 <set>

定义于头文件 <span>

定义于头文件 <string>

定义于头文件 <string_view>

定义于头文件 <unordered_map>

定义于头文件 <unordered_set>

定义于头文件 <vector>

定义于命名空间 std

C++20新特性

关键字

新增关键字

含义变化或者新增含义关键字(meaning changed or new meaning added)

类型支持(基本类型、RTTI、类型特性)

定义于头文件<type_traits>

协程支持

定义于头文件<coroutine>

三路比较

定义于头文件<compare>

定义于头文件<concepts>

定义于头文件<utility>

定义于头文件<format>

定义于头文件<memory>

定义于头文件<memory_resource>

Concepts library(概念库)

定义于头文件<concepts>

动态内存管理

定义于头文件<memory>

日期和时间工具

定义于头文件<chrono>

字符串

定义于头文件<string>

定义于头文件<string_view>

定义于头文件<cuchar>

容器库

定义于头文件<array>

定义于头文件<vector>

定义于头文件<map>

定义于头文件<unordered_map>

定义于头文件<span>

定义于命名空间 std

定义于命名空间 std::ranges

定义于命名空间 std

定义于头文件

定义于命名空间 std

定义于头文件

定义于头文件 <array>

定义于头文件 <deque>

定义于头文件 <forward_list>

定义于头文件 <iterator>

定义于头文件 <list>

定义于头文件 <map>

定义于头文件 <regex>

定义于头文件 <set>

定义于头文件 <span>

定义于头文件 <string>

定义于头文件 <string_view>

定义于头文件 <unordered_map>

定义于头文件 <unordered_set>

定义于头文件 <vector>

定义于命名空间 std

定义于头文件 <ranges>

定义于头文件 <iterator>

定义于命名空间 std::ranges

C++23新特性

类型支持(基本类型、RTTI、类型特性)

定义于头文件<type_traits>

定义于头文件<utility>

定义于头文件<stacktrace>

动态内存管理

定义于头文件<memory>

字符串

定义于头文件<string>

定义于头文件<string_view>
You might also like...
Parca-agent - eBPF based always-on profiler auto-discovering targets in Kubernetes and systemd, zero code changes or restarts needed!
Parca-agent - eBPF based always-on profiler auto-discovering targets in Kubernetes and systemd, zero code changes or restarts needed!

Parca Agent Parca Agent is an always-on sampling profiler that uses eBPF to capture raw profiling data with very low overhead. It observes user-space

RobotChess - Auto Chess simulator using C++ with some reinforcement learning
RobotChess - Auto Chess simulator using C++ with some reinforcement learning

RobotChess RobotChess is Auto Chess simulator using C++ with some reinforcement learning. The code is built on C++17 and can be compiled with commonly

Library for auto Light Emitting Diode (LED) control based on the timer function of the ESP8266

Library for auto Light Emitting Diode (LED) control based on the timer function of the ESP8266. The purpose is to have LED running for their own without the need to to such things like blinking on your own.

This is a manga compressed file auto-resize tool

This is a manga compressed file auto-resize tool Are you still bothered by the size of your comic compressed files? Still doing the tedious operation

Comments
  • lambda使用错误:章节”C++11常用新特性(二)“

    lambda使用错误:章节”C++11常用新特性(二)“

    在 ”C++11常用新特性(二)“ 章节中,说道: `class Filter { public: Filter(int divisorVal): divisor{divisorVal} {}

    std::function<bool(int)> getFilter() 
    {
        return [=](int value) {return value % divisor == 0; };
    }
    

    private: int divisor; };`

    这个类中有一个成员方法,可以返回一个lambda表达式,这个表达式使用了类的数据成员divisor。而且采用默认值方式捕捉所有变量。你可能认为这个lambda表达式也捕捉了divisor的一份副本,但是实际上并没有。因为数据成员divisor对lambda表达式并不可见,你可以用下面的代码验证:*******.


    我验证过了, [=] 能捕获到 类数据成员,比如下面没问题: `#include #include

    using namespace std;

    class Demo { public: Demo():m_i(100) {} virtual ~Demo() {}

    void func(int x) { auto f1 = [=]{ std::cout << &m_i << std::endl; return m_i + x; }; std::cout << f1() << std::endl; std::cout << &m_i << std::endl; } std::function<int(int)> getFunc() { return [=](int val) { return val + m_i; }; } void setData(int d) { m_i = d; }

    private: int m_i; };

    int main() { Demo d; d.func(10); std::function<int(int)> ff; { Demo dd; ff = dd.getFunc(); dd.setData(400); } std::cout << "-------" << std::endl; // std::cout << ff(200) << std::endl; return 0;

    }`

    opened by achilsh 0
  • 7.7 指针和函数 输出最好修改一下哟

    7.7 指针和函数 输出最好修改一下哟

    `int main() {

    int a = 10;
    int b = 20;
    swap1(a, b); // 值传递不会改变实参
    
    swap2(&a, &b); //地址传递会改变实参
    
    cout << "a = " << a << endl;
    
    cout << "b = " << b << endl;
    
    system("pause");
    
    return 0;
    

    }修改成这样子会不会更好点呢?int main() {

    int a = 10;
    int b = 20;
    swap1(a, b); // 值传递不会改变实参
    
    cout << "swap1 a = " << a << endl;
    
    cout << "swap1 b = " << b << endl;
    
    swap2(&a, &b); //地址传递会改变实参
    
    cout << "swap2 a = " << a << endl;
    
    cout << "swap2 b = " << b << endl;
    
    system("pause");
    
    return 0;
    

    }`

    opened by xiaoerjason 0
Owner
0voice
整理it资料的百科全库,欢迎大家一起commit。
0voice
A python script loader for Grand Theft Auto San Andreas

PyLoader Introduction This is a .asi plugin that allows writing custom Python scripts for GTA SanAndreas. This plugin is still in the early stages of

Grinch_ 25 Nov 28, 2022
Watch for file changes and auto restart an application using fork checkpoints to continue the process (for quick live development)

Forkmon Watch for file changes and auto restart an application using fork checkpoints to continue. Intended for quick live development. This works onl

Eduardo Bart 12 Aug 27, 2022
Grand Theft Auto V + FidelityFx Super Resolution 1.0

Grand Theft Auto V + FidelityFx Super Resolution 1.0 This mod replaces original Grand Theft Auto V upscaler with FidelityFx Super Resolution 1.0 Origi

null 403 Jan 2, 2023
Single-header header-only C++11 / C++14 / C++17 library for easily managing set of auto-generated type-safe flags.

Single-header header-only C++11 / C++14 / C++17 library for easily managing set of auto-generated type-safe flags. Quick start #include <bitflags/bitf

Marin Peko 76 Nov 22, 2022
Auto updating integrity check bypass for Roblox

auto-updating-memcheck Auto updating integrity check bypass for Roblox Before you use Put the "zylib" folder in your include directory Place the "util

Jayden 7 Nov 4, 2022
testing joystick under Linux environment, support monitoring disconnection state and auto recovery mode

qjoystick This qjoystick class is rewritten based on the library: https://github.com/drewnoakes/joystick. Please look at this library if you want to s

ibov 1 Oct 30, 2021
This plugin allows Flutter desktop apps to Auto launch on startup / login.

This plugin allows Flutter desktop apps to Auto launch on startup / login.

LeanFlutter 45 Dec 18, 2022
Tesla cheat trainers for Grand Theft Auto: The Trilogy - The Definitive Edition for the Nintendo Switch.

nxGTA-Trainers This is a set of tools for cheating in Grand Theft Auto: The Trilogy - The Definitive Edition for the Nintendo Switch. While I will try

null 26 Oct 4, 2022
A plug which auto turns off when it's Shabbos or Yom Tov.

Melacha Plug A Melacha aware plug which turns off when it's Shabbos or Yom Tov. This project is using ESPHome. Looking to disable a smart doorbell for

Chabad Source 7 Oct 23, 2022
A matrix header-only library, uses graphs internally, helpful when your matrix is part of a simulation where it needs to grow many times (or auto expand)

GraphMat Header-only Library Matrix implemented as a graph, specially for the use case when it should be auto expanding at custom rate, specially in s

Aditya Gupta 3 Oct 25, 2021