原文 https://en.cppreference.com/w/cpp/20

1. C++版本衍进


1.1 Core language features

特性 版本 说明
auto and decltype C++11 auto类型推导与decltype
defaulted and deleted functions C++11 显示默认和删除的函数
final and override C++11  
trailing return type C++11  
rvalue references C++11  
move constructors and move assignment operators C++11  
scoped enums C++11 强类型枚举
constexpr and literal types C++11  
list initialization C++11  
delegating and inherited constructors C++11  
brace-or-equal initializers C++11  
nullptr C++11 指针空值
long long C++11 long long 整形
char16_t and char32_t C++11  
type aliases C++11  
variadic templates C++11  
generalized (non-trivial) unions C++11  
generalized PODs (trivial types and standard-layout types) C++11  
Unicode string literals C++11  
user-defined literals C++11  
attributes C++11  
lambda expressions C++11 lambda 函数
noexcept specifier and noexcept operator C++11  
alignof and alignas C++11  
multithreaded memory model C++11  
thread-local storage C++11  
GC interface C++11  
range-for (based on a Boost library) C++11 基于范围的for语句
static_assert (based on a Boost library) C++11  
variable templates C++14  
generic lambdas C++14  
lambda init-capture C++14  
new/delete elision C++14  
relaxed restrictions on constexpr functions C++14  
binary literals C++14  
digit separators C++14  
return type deduction for functions C++14  
aggregate classes with default non-static member initializers. C++14  
fold-expressions C++17  
class template argument deduction C++17  
non-type template parameters declared with auto C++17  
compile-time if constexpr C++17  
inline variables C++17  
structured bindings C++17  
initializers for if and switch C++17  
u8 character literal C++17  
simplified nested namespaces C++17  
using-declaration declaring multiple names C++17  
made noexcept part of type system C++17  
new order of evaluation rules C++17  
guaranteed copy elision C++17  
lambda capture of *this C++17  
constexpr lambda C++17  
attribute namespaces don’t have to repeat C++17  
new attributes:[[fallthrough]], [[nodiscard]], [[maybe_unused]] C++17  
__has_include C++17  
Feature test macros C++20  
3-way comparison operator <=> and operator==() = default C++20  
designated initializers C++20  
init-statements and initializers in range-for C++20  
char8_t C++20  
New attributes: [[no_unique_address]], [[likely]], [[unlikely]] C++20  
pack-expansions in lambda init-captures C++20  
removed the requirement to use typename to disambiguate types in many contexts C++20  
consteval, constinit C++20  
further relaxed constexpr C++20  
signed integers are 2’s complement C++20  
aggregate initialization using parentheses C++20  
Coroutines C++20  
Modules C++20  
Constraints and concepts C++20  
Abbreviated function templates C++20  
DR: array new can deduce array size C++20  


2. GCC支持 10.2

C++ GENERAL

特征 实现 说明
__cplusplus 201402 __cplusplus宏 1.
__cpp_exceptions 199711  
__cpp_rtti 199711  

C++11 CORE

特征 实现 说明
__cpp_alias_templates 200704  
__cpp_attributes 200809  
__cpp_constexpr 201304  
__cpp_decltype 200707  
__cpp_delegating_constructors 200604  
__cpp_inheriting_constructors 201511  
__cpp_initializer_lists 200806  
__cpp_lambdas 200907  
__cpp_nsdmi 200809  
__cpp_range_based_for 200907  
__cpp_raw_strings 200710  
__cpp_ref_qualifiers 200710  
__cpp_rvalue_references 200610  
__cpp_static_assert 200410  
__cpp_threadsafe_static_init 200806  
__cpp_unicode_characters 200704  
__cpp_unicode_literals 200710  
__cpp_user_defined_literals 200809  
__cpp_variadic_templates 200704  

C++14 CORE

特征 实现 说明
__cpp_aggregate_nsdmi 201304  
__cpp_binary_literals 201304  
__cpp_constexpr 201304  
__cpp_decltype_auto 201304  
__cpp_generic_lambdas 201304  
__cpp_init_captures 201304  
__cpp_return_type_deduction 201304  
__cpp_sized_deallocation 201309  
__cpp_variable_templates 201304  

C++14 LIB

特征 实现 说明
__cpp_lib_chrono_udls 201304  
__cpp_lib_complex_udls 201309  
__cpp_lib_exchange_function 201304  
__cpp_lib_generic_associative_lookup 201304  
__cpp_lib_integer_sequence 201304  
__cpp_lib_integral_constant_callable 201304  
__cpp_lib_is_final 201402  
__cpp_lib_is_null_pointer 201309  
__cpp_lib_make_reverse_iterator 201402  
__cpp_lib_make_unique 201304  
__cpp_lib_null_iterators 201304  
__cpp_lib_quoted_string_io 201304  
__cpp_lib_result_of_sfinae 201210  
__cpp_lib_robust_nonmodifying_seq_ops 201304  
__cpp_lib_shared_timed_mutex 201402  
__cpp_lib_string_udls 201304  
__cpp_lib_transformation_trait_aliases 201304  
__cpp_lib_transparent_operators 201510  
__cpp_lib_tuple_element_t 201402  
__cpp_lib_tuples_by_type 201304  

C++17 CORE

特征 实现 说明
__cpp_aggregate_bases    
__cpp_aligned_new    
__cpp_capture_star_this    
__cpp_constexpr 201304  
__cpp_deduction_guides    
__cpp_enumerator_attributes    
__cpp_fold_expressions    
__cpp_guaranteed_copy_elision    
__cpp_hex_float 201603  
__cpp_if_constexpr    
__cpp_inheriting_constructors 201511  
__cpp_inline_variables    
__cpp_namespace_attributes    
__cpp_noexcept_function_type    
__cpp_nontype_template_args    
__cpp_nontype_template_parameter_auto    
__cpp_range_based_for 200907  
__cpp_static_assert 200410  
__cpp_structured_bindings    
__cpp_template_template_args    
__cpp_variadic_using    

C++17 LIB

特征 实现 说明
__cpp_lib_addressof_constexpr    
__cpp_lib_allocator_traits_is_always_equal 201411  
__cpp_lib_any    
__cpp_lib_apply    
__cpp_lib_array_constexpr    
__cpp_lib_as_const    
__cpp_lib_atomic_is_always_lock_free    
__cpp_lib_bool_constant    
__cpp_lib_boyer_moore_searcher    
__cpp_lib_byte    
__cpp_lib_chrono    
__cpp_lib_clamp    
__cpp_lib_enable_shared_from_this 201603  
__cpp_lib_execution    
__cpp_lib_filesystem    
__cpp_lib_gcd_lcm    
__cpp_lib_hardware_interference_size    
__cpp_lib_has_unique_object_representations    
__cpp_lib_hypot    
__cpp_lib_incomplete_container_elements 201505  
__cpp_lib_invoke    
__cpp_lib_is_aggregate    
__cpp_lib_is_invocable    
__cpp_lib_is_swappable 201603  
__cpp_lib_launder    
__cpp_lib_logical_traits    
__cpp_lib_make_from_tuple    
__cpp_lib_map_try_emplace    
__cpp_lib_math_special_functions    
__cpp_lib_memory_resource    
__cpp_lib_node_extract    
__cpp_lib_nonmember_container_access    
__cpp_lib_not_fn    
__cpp_lib_optional    
__cpp_lib_parallel_algorithm    
__cpp_lib_raw_memory_algorithms    
__cpp_lib_sample    
__cpp_lib_scoped_lock    
__cpp_lib_shared_mutex    
__cpp_lib_shared_ptr_arrays 201611  
__cpp_lib_shared_ptr_weak_type    
__cpp_lib_string_view    
__cpp_lib_to_chars    
__cpp_lib_transparent_operators 201510  
__cpp_lib_type_trait_variable_templates    
__cpp_lib_uncaught_exceptions 201411  
__cpp_lib_unordered_map_try_emplace    
__cpp_lib_variant    
__cpp_lib_void_t 201411  

C++20 CORE

特征 实现 说明
__cpp_aggregate_paren_init    
__cpp_char8_t    
__cpp_concepts    
__cpp_conditional_explicit    
__cpp_consteval    
__cpp_constexpr 201304  
__cpp_constexpr_dynamic_alloc    
__cpp_constexpr_in_decltype    
__cpp_constinit    
__cpp_deduction_guides    
__cpp_designated_initializers    
__cpp_generic_lambdas 201304  
__cpp_impl_coroutine    
__cpp_impl_destroying_delete    
__cpp_impl_three_way_comparison    
__cpp_init_captures 201304  
__cpp_modules    
__cpp_nontype_template_args    
__cpp_using_enum    

C++20 LIB

特征 实现 说明
__cpp_lib_array_constexpr    
__cpp_lib_assume_aligned    
__cpp_lib_atomic_flag_test    
__cpp_lib_atomic_float    
__cpp_lib_atomic_lock_free_type_aliases    
__cpp_lib_atomic_ref    
__cpp_lib_atomic_shared_ptr    
__cpp_lib_atomic_value_initialization    
__cpp_lib_atomic_wait    
__cpp_lib_barrier    
__cpp_lib_bind_front    
__cpp_lib_bit_cast    
__cpp_lib_bitops    
__cpp_lib_bounded_array_traits    
__cpp_lib_char8_t    
__cpp_lib_chrono    
__cpp_lib_concepts    
__cpp_lib_constexpr_algorithms    
__cpp_lib_constexpr_complex    
__cpp_lib_constexpr_dynamic_alloc    
__cpp_lib_constexpr_functional    
__cpp_lib_constexpr_iterator    
__cpp_lib_constexpr_memory    
__cpp_lib_constexpr_numeric    
__cpp_lib_constexpr_string    
__cpp_lib_constexpr_string_view    
__cpp_lib_constexpr_tuple    
__cpp_lib_constexpr_utility    
__cpp_lib_constexpr_vector    
__cpp_lib_coroutine    
__cpp_lib_destroying_delete    
__cpp_lib_endian    
__cpp_lib_erase_if    
__cpp_lib_execution    
__cpp_lib_format    
__cpp_lib_generic_unordered_lookup    
__cpp_lib_int_pow2    
__cpp_lib_integer_comparison_functions    
__cpp_lib_interpolate    
__cpp_lib_is_constant_evaluated    
__cpp_lib_is_layout_compatible    
__cpp_lib_is_nothrow_convertible    
__cpp_lib_is_pointer_interconvertible    
__cpp_lib_jthread    
__cpp_lib_latch    
__cpp_lib_list_remove_return_type    
__cpp_lib_math_constants    
__cpp_lib_polymorphic_allocator    
__cpp_lib_ranges    
__cpp_lib_remove_cvref    
__cpp_lib_semaphore    
__cpp_lib_shared_ptr_arrays 201611  
__cpp_lib_shift    
__cpp_lib_smart_ptr_for_overwrite    
__cpp_lib_source_location    
__cpp_lib_span    
__cpp_lib_ssize    
__cpp_lib_starts_ends_with    
__cpp_lib_string_view    
__cpp_lib_syncbuf    
__cpp_lib_three_way_comparison    
__cpp_lib_to_address    
__cpp_lib_to_array    
__cpp_lib_type_identity    
__cpp_lib_unwrap_ref    

C++23 CORE

特征 实现 说明
__cpp_size_t_suffix    

C++23 LIB

特征 实现 说明
__cpp_lib_is_scoped_enum    
__cpp_lib_stacktrace    
__cpp_lib_stdatomic_h    
__cpp_lib_string_contains    

ATTRIBUTES

特征 实现 说明
carries_dependency    
deprecated 201309  
fallthrough 201603  
likely 201803  
maybe_unused 201603  
nodiscard 201907  
noreturn 200809  
no_unique_address 201803  
unlikely 201803  


3. 例

3.1 __cplusplus

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char* argv[])
{
#ifdef __cplusplus
  printf("cpp %dL\n", __cplusplus);
#else
  printf("c\n");
#endif
  return 0;
}
$ gcc a1.c 
$ ./a.out 
c

$ g++ a1.c 
$ ./a.out 
cpp 201402

$ g++ -std=c++98 a1.c 
$ ./a.out 
cpp 199711L

$ g++ -std=c++11 a1.c 
$ ./a.out 
cpp 201103L

3.2