技术

C++ 11/14/17主要特性

C++11 主要特性概念(含英文对照)

中文特性概念定义English FeatureDefinition
自动类型推断 (auto)编译器根据初始化表达式自动推断变量类型,无需显式指定类型。Auto Type DeductionCompiler deduces variable type automatically from initializer.
范围for循环基于范围的循环语法,简化数组和容器的遍历。Range-based for loopSimplified syntax for iterating over containers or arrays.
nullptr 关键字表示空指针,类型安全替代 NULL。nullptr keywordType-safe null pointer literal replacing NULL.
右值引用和移动语义引入 &&,支持资源的转移以提升性能,减少不必要复制。Rvalue references & Move semanticsEnables efficient transfer of resources by moving instead of copying.
Lambda 表达式匿名函数对象,可以在代码中内联定义函数逻辑。Lambda expressionsAnonymous functions defined inline for concise code.
constexpr 函数可在编译期求值的常量表达式函数,提高性能。constexpr functionsFunctions evaluable at compile time to optimize performance.
静态断言 (static_assert)编译期断言条件是否满足,不满足则报错。static_assertCompile-time assertion checking conditions during compilation.
强类型枚举 (enum class)定义作用域和类型安全的枚举类型,避免名称冲突。Scoped enum (enum class)Scoped and type-safe enumeration to prevent naming conflicts.
委托构造函数允许一个构造函数调用同类中另一个构造函数,减少代码重复。Delegating constructorsConstructors that call other constructors in the same class.
默认和删除函数 (=default, =delete)显式声明默认或删除某些函数,控制函数的自动生成。Defaulted and deleted functionsExplicitly default or delete special member functions.
统一初始化语法使用花括号 {} 进行统一的变量初始化,支持列表初始化。Uniform initializationBrace initialization syntax for consistent object initialization.
变长模板参数模板支持任意数量参数的定义和展开。Variadic templatesTemplates accepting variable number of template arguments.
内联命名空间支持版本化和符号重载的命名空间,减少名称冲突。Inline namespacesNamespaces that can be versioned and merged inline.
用户自定义字面量自定义字面量语法,实现自定义类型的字面量转换。User-defined literalsDefining custom literal suffixes for user types.
线程库标准线程和同步原语支持,实现多线程编程基础。Thread librarySupport for threads and synchronization primitives.
智能指针新增 unique_ptr, shared_ptr, weak_ptr 管理动态内存。Smart pointersRAII-style pointers for automatic memory management.
移动构造和移动赋值支持移动语义的构造函数和赋值操作符,提高性能。Move constructors & assignmentsConstructors/operators that move resources instead of copying.
内存模型和原子操作定义多线程内存访问顺序和原子操作,保障线程安全。Memory model and atomicsDefines memory ordering and atomic operations for concurrency.

C++14 主要特性概念(含英文对照)

中文特性概念定义English FeatureDefinition
泛型 LambdaLambda 参数支持自动类型推断,使写法更简洁灵活。Generic lambdasLambdas with auto-typed parameters for generic code.
constexpr 函数增强constexpr 函数支持更多语句和更复杂逻辑。Relaxed constexpr functionsconstexpr functions can contain more complex code.
变量模板模板不仅限于函数和类,也支持变量模板定义。Variable templatesTemplates for variables enabling generic constant definitions.
二进制字面量和数字分隔符支持二进制数字表示和数字间下划线分隔,提高数字字面量可读性。Binary literals & digit separatorsBinary numeric literals and underscore separators for readability.
函数返回类型自动推断普通函数支持根据返回语句自动推断返回类型,无需显式写明。Return type deductionAutomatic deduction of function return types.
decltype(auto)增强类型推导,自动推断表达式的准确类型(包含引用与常量性)。decltype(auto)Deduces exact type including references and cv-qualifiers.
std::make_unique提供安全创建 unique_ptr 的工厂函数,防止裸指针泄漏。std::make_uniqueFactory function to safely create unique_ptr instances.
std::shared_timed_mutex支持多读单写的共享互斥锁。std::shared_timed_mutexShared mutex allowing multiple readers or one writer lock.
元编程工具引入 std::integer_sequence 等模板工具简化模板元编程。Metaprogramming utilitiesTools like integer_sequence to simplify template metaprogramming.

C++17 主要特性概念(含英文对照)

中文特性概念定义English FeatureDefinition
结构化绑定声明允许用多个变量绑定元组或结构体的多个成员,简化拆包操作。Structured bindingsBinding multiple variables to tuple/struct elements.
if constexpr编译期条件语句,根据常量条件选择代码分支,未选分支不生成代码。if constexprCompile-time conditional branching in templates.
内联变量支持定义 inline 变量避免多重定义,便于头文件中常量定义。Inline variablesVariables declared inline to avoid multiple definitions.
折叠表达式支持模板参数包的折叠计算,简化变参模板编写。Fold expressionsExpression folds to combine parameter packs easily.
类模板参数推导 (CTAD)支持根据构造函数参数自动推导类模板参数类型,减少显式指定。Class template argument deductionAutomatic deduction of class template parameters.
std::optional表示可能有值或无值的对象类型,替代空指针或特殊值。std::optionalWrapper representing optional values.
std::variant类型安全的联合体,能存储多种可能类型之一。std::variantType-safe union holding one of multiple types.
std::any类型擦除容器,可存储任意类型的值。std::anyType-erased container for single values of any type.
并行算法标准算法支持并行执行策略,提高性能。Parallel algorithmsAlgorithms supporting parallel execution policies.
文件系统库 (<filesystem>)标准化跨平台文件和目录操作的API。Filesystem libraryStandardized API for file and directory management.
字符串视图 (std::string_view)轻量级、非拥有的字符串视图,避免复制字符串数据。std::string_viewLightweight non-owning string reference type.
内存模型增强对原子操作和内存顺序支持增强,提升多线程安全。Enhanced memory modelImproved support for atomic operations and memory ordering.