Namespaces
Variants
Actions

feature test macros

From cppreference.com

Provide a set of preprocessor macros which give a simple and portable way to detect the presence of C++ standards and experimantal features.

The presence of a certain header can be detected using __has_include.

Standard library macros are defined both in the corresponding header for the library facility and in <version>.

(since C++20)

Contents

Table of Contents

This page is based on P0096R5.

C++20

Paper(s) Feature Macro name Value Header
P0912R5 Coroutines __cpp_coroutines 201902 predefined
P0722R3 Efficient sized delete for variable sized classes (for the use of standard library implementors) __cpp_impl_destroying_delete 201806 predefined
P0722R3 Efficient sized delete for variable sized classes __cpp_lib_destroying_delete 201806 <new>
P0482R6 char8_t: A type for UTF-8 characters and strings __cpp_char8_t 201811 predefined
P0784R7 More constexpr containers __cpp_constexpr_dynamic_alloc 201907 predefined
P0515R3 P1185R2 P1186R3 P1630R1 Three-way comparison (for the use of standard library implementors) __cpp_impl_three_way_comparison 201907 predefined
P0515R3 P0768R1 Three-way comparison __cpp_lib_three_way_comparison 201711 <compare>
P1331R2 P1668R1 Permitting trivial default initialization and unevaluated inline-assembly in constexpr contexts __cpp_constexpr (value increased) 201907 predefined
P1021R4 P1816R0 P1814R0 class template argument deduction for aggregates and alias templates __cpp_deduction_guides (value increased) 201907 predefined
P0892R2 explicit(bool) __cpp_conditional_explicit 201806 predefined
P1143R2 Adding the constinit keyword __cpp_constinit 201907 predefined
P1099R5 Using enum __cpp_using_enum 201907 predefined
P0960R3 Aggregate initialization from a parenthesized list __cpp_aggregate_paren_init 201902 predefined
P0479R5 likely and unlikely attributes __has_cpp_attribute(likely) 201803 predefined
__has_cpp_attribute(unlikely) 201803 predefined
P1301R4 [[nodiscard("should have a reason")]] __has_cpp_attribute(nodiscard) (value increased) 201907 predefined
P1771R1 [[nodiscard]] for constructors
P0840R2 Language support for empty objects ([[no_unique_address]]) __has_cpp_attribute(no_unique_address) 201803 predefined
P1103R3 P1811R0 Modules __cpp_modules 201907 predefined
P0732R2 Class types in non-type template parameters __cpp_nontype_template_parameter_class 201806 predefined
N4417 P1208R6 std::source_location __cpp_lib_source_location 201907 <source_location>
P1614R2 Adding <=> to the library __cpp_lib_spaceship 201907 <compare>
P0482R6 P1423R3 Library support for char8_t (std::u8string, etc) __cpp_lib_char8_t 201907 <atomic> <filesystem> <istream> <limits> <locale> <ostream> <string> <string_view>
P0898R3 Standard library concepts __cpp_lib_concepts 201806 <concepts>
P0879R0 Constexpr for swap and swap related functions __cpp_lib_constexpr_swap_algorithms 201806 <algorithm>
P1032R1 Misc constexpr bits (constexpr std::pair::operator=, std::tuple::operator=, std::array::fill, std::string_view::copy, std::default_searcher, etc) __cpp_lib_constexpr 201811 All standard library headers except <*.h>
P0784R7 More constexpr containers __cpp_lib_constexpr_dynamic_alloc 201907 <memory>
P1065R2 Constexpr INVOKE __cpp_lib_constexpr_invoke 201907 <functional>
P0356R5 P1651R0 Simplified partial function application (std::bind_front) __cpp_lib_bind_front 201907 <functional>
P1357R1 std::is_bounded_array and std::is_unbounded_array __cpp_lib_bounded_array_traits 201902 <type_traits>
p0466R5 Layout-compatibility and pointer-interconvertibility traits __cpp_lib_is_layout_compatible 201907 <type_traits>
__cpp_lib_is_pointer_interconvertible 201907 <type_traits>
P0595R2 std::is_constant_evaluated() __cpp_lib_is_constant_evaluated 201811 <type_traits>
P1001R2 Vectorization execution policy __cpp_lib_execution (value increased) 201902 <execution>
P0645R10 P1361R2 P1652R1 Text formatting __cpp_lib_format 201907 <format>
P0980R1 Making std::string constexpr __cpp_lib_constexpr_string 201907 <string>
P1004R2 Making std::vector constexpr __cpp_lib_constexpr_vector 201907 <vector>
P0325R4 std::to_array __cpp_lib_to_array 201907 <array>
P1209R0 Adopt Consistent Container Erasure from Library Fundamentals 2 for C++20 (std::erase for standard sequence containers, std::erase_if for standard containers except std::array) __cpp_lib_erase_if 201811 <string> <deque> <forward_list> <list> <vector> <map> <set> <unordered_map> <unordered_set>
P0646R1 Change the return type of the remove(), remove_if() and unique() members of std::forward_list and std::list __cpp_lib_list_remove_return_type 201806 <forward_list> <list>
P0919R3 Heterogeneous lookup for unordered containers __cpp_lib_generic_unordered_lookup 201811 <unordered_map> <unordered_set>
P0896R4 Ranges library __cpp_lib_ranges 201811 <algorithm> <functional> <iterator> <memory> <ranges>
P0811R3 Well-behaved interpolation for numbers and pointers (std::midpoint and std::lerp) __cpp_lib_interpolate 201902 <cmath> <numeric>
P0476R2 std::bit_cast __cpp_lib_bit_cast 201806 <bit>
P0553R4 Bit operations __cpp_lib_bitops 201907 <bit>
P0463R1 P1612R1 std::endian __cpp_lib_endian 201907 <bit>
P0631R8 Math constants __cpp_lib_math_constants 201907 <numbers>
P1466R3 Miscellaneous fixes for chrono __cpp_lib_chrono (value_increased) 201907 <chrono>
P0019R8 std::atomic_ref __cpp_lib_atomic_ref 201806 <atomic>
P1135R6 P0514R4 Efficient std::atomic waiting and semaphores __cpp_lib_atomic_wait 201907 <atomic>
__cpp_lib_semaphore 201907 <semaphore>
P1135R6 P0666R2 Latches and barriers __cpp_lib_latch 201907 <latch>
__cpp_lib_barrier 201907 <barrier>
P1135R6 std::atomic_flag::test and lockfree integral types __cpp_lib_atomic_flag_test 201907 <atomic>
__cpp_lib_atomic_lock_free_type_aliases 201907 <atomic>
P0660R10 Stop token and joining thread __cpp_lib_jthread 201907 <stop_token> <thread>

C++17

Paper(s) Feature Macro name Value Header
P0245R1 Hexadecimal floating literals __cpp_hex_float 201603 predefined
P0386R2 Inline Variables __cpp_inline_variables 201606 predefined
P0035R4 Dynamic memory allocation for over-aligned data __cpp_aligned_new 201606 predefined
P0135R1 Guaranteed copy elision through simplified value categories __cpp_guaranteed_copy_elision 201606 predefined
P0012R1 Make exception specifications be part of the type system __cpp_noexcept_function_type 201510 predefined
N4191 N4295 P0036R0 Fold expressions __cpp_fold_expressions 201603 predefined
P0018R3 Lambda Capture of *this by Value as [=,*this] __cpp_capture_star_this 201603 predefined
P0170R1 Constexpr Lambda __cpp_constexpr (value increased) 201603 predefined
P0292R2 constexpr if __cpp_if_constexpr 201606 predefined
P0184R0 Generalizing the Range-Based For Loop __cpp_range_based_for (value increased) 201603 predefined
N3928 Extended static_assert __cpp_static_assert (value increased) 201411 predefined
P0091R3 P0512R0 P0620R0 Class Template Argument Deduction __cpp_deduction_guides 201703 predefined
P0127R2 Declaring non-type template parameters with auto __cpp_nontype_template_parameter_auto 201606 predefined
N4196 N4266 Attributes for namespaces and enumerators __cpp_namespace_attributes 201411 predefined
__cpp_enumerator_attributes 201411 predefined
P0136R1 Rewording inheriting constructors __cpp_inheriting_constructors (value increased) 201511 predefined
P0195R2 Pack expansions in using-declarations __cpp_variadic_using 201611 predefined
P0188R1 [[fallthrough]] attribute __has_cpp_attribute(fallthrough) 201603 predefined
P0189R1 [[nodiscard]] attribute __has_cpp_attribute(nodiscard) 201603 predefined
P0212R1 [[maybe_unused]] attribute __has_cpp_attribute(maybe_unused) 201603 predefined
P0217R3 structured bindings __cpp_structured_bindings 201606 predefined
P0017R1 Extension to aggregate initialization __cpp_aggregate_bases 201603 predefined
N4198 N4268 Allow constant evaluation for all non-type template arguments __cpp_nontype_template_args 201411 predefined
P0522R0 Matching of template template-arguments __cpp_template_template_args 201611 predefined
P0298R3 A byte type definition __cpp_lib_byte 201603 <cstddef>
P0154R1 constexpr std::hardware_{constructive, destructive}_interference_size __cpp_lib_hardware_interference_size 201703 <new>
P0137R1 Core Issue 1776: Replacement of class objects containing reference members (std::launder) __cpp_lib_launder 201606 <new>
N4152 N4259 std::uncaught_exceptions __cpp_lib_uncaught_exceptions 201411 <exception>
P0007R1 std::as_const __cpp_lib_as_const 201510 <utility>
P0209R2 make_from_tuple: apply for construction __cpp_lib_make_from_tuple 201606 <tuple>
N3915 P0220R1 std::apply __cpp_lib_apply 201603 <tuple>
N3793 P0220R1 P0032R3 P0307R2 std::optional __cpp_lib_optional 201606 <optional>
P0088R3 P0032R3 P0393R3 std::variant: a type-safe union for C++17 __cpp_lib_variant 201606 <variant>
N3804 P0220R1 P0032R3 std::any __cpp_lib_any 201606 <any>
LWG2296 constexpr std::addressof __cpp_lib_addressof_constexpr 201603 <memory>
P0040R3 Extending memory management tools __cpp_lib_raw_memory_algorithms 201606 <memory>
P0074R0 Making std::owner_less more flexible (std::owner_less<void>) __cpp_lib_transparent_operators (value increased) 201510 <memory> <functional>
P0033R1 Re-enabling shared_from_this __cpp_lib_enable_shared_from_this 201603 <memory>
P0163R0 shared_ptr::weak_type __cpp_lib_shared_ptr_weak_type 201606 <memory>
N3920 P0497R0 std::shared_ptr support for arrays __cpp_lib_shared_ptr_arrays 201611 <memory>
N3916 P0220R1 Memory resources __cpp_lib_memory_resource 201603 <memory_resource>
N3905 P0220R1 P0253R1 searchers __cpp_lib_boyer_moore_searcher 201603 <functional>
N4169 std::invoke function template __cpp_lib_invoke 201411 <functional>
P0005R4 Adopt not_fn from Library Fundamentals 2 for C++17 __cpp_lib_not_fn 201603 <functional>
N3911 std::void_t __cpp_lib_void_t 201411 <type_traits>
N4389 std::bool_constant __cpp_lib_bool_constant 201505 <type_traits>
P0006R0 Adopt Type Traits Variable Templates from Library Fundamentals TS for C++17 (std::is_void_v, etc) __cpp_lib_type_trait_variable_templates 201510 <type_traits>
P0013R1 Logical operator type traits __cpp_lib_logical_traits 201510 <type_traits>
P0185R1 [nothrow-]swappable traits __cpp_lib_is_swappable 201603 <type_traits>
P0604R0 Resolving GB 55, US 84, US 85, US 86 (renaming std::is_callable to std::is_invocable; adding std::invoke_result; deprecating std::result_of) __cpp_lib_is_invocable 201703 <type_traits>
P0258R2 std::has_unique_object_representations __cpp_lib_has_unique_object_representations 201606 <type_traits>
LWG2911 std::is_aggregate type trait __cpp_lib_is_aggregate 201703 <type_traits>
P0092R1 P0505R0 rounding functions for std::chrono::duration and std::chrono::time_point; making all the member functions of std::chrono::duration and std::chrono::time_point constexpr __cpp_lib_chrono 201611 <chrono>
P0024R2 P0336R1 Adopt the Parallelism TS for C++17 __cpp_lib_execution 201603 <execution>
__cpp_lib_parallel_algorithm 201603 <algorithm> <numeric>
P0067R5 Elementary string conversions (std::to_chars, std::from_chars) __cpp_lib_to_chars 201611 <charconv>
N3921 P0220R1 P0254R2 std::string_view __cpp_lib_string_view 201606 <string> <string_view>
N4258 Cleaning-up noexcept in the Library __cpp_lib_allocator_traits_is_always_equal 201411 <memory> <scoped_allocator> <string> <deque> <forward_list> <list> <vector> <map> <set> <unordered_map> <unordered_set>
N4510 Minimal incomplete type support for standard containers __cpp_lib_incomplete_container_elements 201505 <forward_list> <list> <vector>
N4279 Improved insertion interface for unique-key maps (std::map::try_emplace, std::map::insert_or_assign and their counterparts in std::unordered_map) __cpp_lib_map_try_emplace 201411 <map>
__cpp_lib_unordered_map_try_emplace 201411 <unordered_map>
P0083R3 Splicing Maps and Sets (std::map::extract, std::map::merge, std::map::insert(node_type), etc) __cpp_lib_node_extract 201606 <map> <set> <unordered_map> <unordered_set>
P0031R0 Adding Constexpr Modifiers to std::reverse_iterator, std::move_iterator, std::array and Range Access __cpp_lib_array_constexpr 201603 <iterator> <array>
N4280 Non-member size() and more (uniform container access) __cpp_lib_nonmember_container_access 201411 <iterator> <array> <deque> <forward_list> <list> <map> <regex> <set> <string> <unordered_map> <unordered_set> <vector>
N3925 P0220R1 std::sample __cpp_lib_sample 201603 <algorithm>
P0025R0 An algorithm to "clamp" a value between a pair of boundary values (std::clamp) __cpp_lib_clamp 201603 <algorithm>
P0295R0 Adopt Selected Library Fundamentals V2 Components for C++17 (std::gcd, std::lcm) __cpp_lib_gcd_lcm 201606 <numeric>
P0030R1 Introduce a 3-Argument Overload to std::hypot __cpp_lib_hypot 201603 <cmath>
P0226R1 Mathematical Special Functions for C++17 __cpp_lib_math_special_functions 201603 <cmath>
P0218R1 P0219R1 P0392R0 P0317R1 File System __cpp_lib_filesystem 201703 <filesystem>
P0152R1 constexpr atomic<T>::is_always_lock_free __cpp_lib_atomic_is_always_lock_free 201603 <atomic>
N4508 std::shared_mutex (untimed) __cpp_lib_shared_mutex 201505 <shared_mutex>
P0156R2 Variadic std::lock_guard (std::scoped_lock) __cpp_lib_scoped_lock 201703 <mutex>

C++14

Paper(s) Feature Macro name Value Header
N3472 Binary literals __cpp_binary_literals 201304 predefined
N3610 N3648 Generalized lambda-capture __cpp_init_captures 201304 predefined
N3649 Generic lambdas __cpp_generic_lambdas 201304 predefined
N3778 Sized deallocation __cpp_sized_deallocation 201309 predefined
N3652 Relaxed constraints on constexpr functions / constexpr member functions and implicit const __cpp_constexpr (value increased) 201304 predefined
N3638 Return type deduction for normal functions __cpp_decltype_auto 201304 predefined
__cpp_return_type_deduction 201304 predefined
N3760 [[deprecated]] attribute __has_cpp_attribute(deprecated) 201309 predefined
N3653 Member initializers and aggregates __cpp_aggregate_nsdmi 201304 predefined
N3651 Variable Templates __cpp_variable_templates 201304 predefined
N3658 Compile-time integer sequences (std::integer_sequence) __cpp_lib_integer_sequence 201304 <utility>
N3668 std::exchange() __cpp_lib_exchange_function 201304 <utility>
N3670 Addressing tuples by type __cpp_lib_tuples_by_type 201304 <utility> <tuple>
N3887 std::tuple_element_t __cpp_lib_tuple_element_t 201402 <tuple>
N3656 std::make_unique __cpp_lib_make_unique 201304 <memory>
N3421 Transparent operator functors (std::greater<>, etc) __cpp_lib_transparent_operators 201210 <functional>
N3545 std::integral_constant::operator() __cpp_lib_integral_constant_callable 201304 <type_traits>
N3655 Type alias versions of standard transformation traits __cpp_lib_transformation_trait_aliases 201304 <type_traits>
N3462 SFINAE-friendly std::result_of __cpp_lib_result_of_sfinae 201210 <functional> <type_traits>
LWG 2112 std::is_final __cpp_lib_is_final 201402 <type_traits>
LWG 2247 std::is_null_pointer __cpp_lib_is_null_pointer 201309 <type_traits>
N3642 User-defined literals for standard library types (std::chrono_literals, std::string_literals) __cpp_lib_chrono_udls 201304 <chrono>
__cpp_lib_string_udls 201304 <string>
N3657 Heterogeneous comparison lookup to associative containers __cpp_lib_generic_associative_lookup 201304 <map> <set>
N3644 Null Forward Iterators __cpp_lib_null_iterators 201304 <iterator>
LWG 2285 std::make_reverse_iterator __cpp_lib_make_reverse_iterator 201402 <iterator>
N3671 Making non-modifying sequence operations more robust (two-range overloads for std::mismatch, std::equal and std::is_permutation) __cpp_lib_robust_nonmodifying_seq_ops 201304 <algorithm>
N3779 User-defined literals for std::complex (std::complex_literals) __cpp_lib_complex_udls 201309 <complex>
N3654 std::quoted __cpp_lib_quoted_string_io 201304 <iomanip>
N3659 Shared locking __has_include(<shared_mutex>) 1 predefined
N3891 Rename shared_mutex to shared_timed_mutex __cpp_lib_shared_timed_mutex 201402 <shared_mutex>

C++11

Paper Feature Macro name Value Header
N2249 New character types (char16_t and char32_t) __cpp_unicode_characters 200704 predefined
N2442 Raw and unicode string literals __cpp_raw_strings 200710 predefined
__cpp_unicode_literals 200710 predefined
N2765 User-defined literals __cpp_user_defined_literals 200809 predefined
N2660 Dynamic Initialization and Destruction with Concurrency __cpp_threadsafe_static_init 200806 predefined
N2927 Lambda expressions __cpp_lambdas 200907 predefined
N2235 constexpr __cpp_constexpr 200704 predefined
N2930 Range-for loop __cpp_range_based_for 200907 predefined
N1720 static_assert __cpp_static_assert 200410 predefined
N2343 decltype __cpp_decltype 200707 predefined
N2761 Attributes __cpp_attributes 200809 predefined
__has_cpp_attribute(noreturn) 200809 predefined
__has_cpp_attribute(carries_dependency) 200809 predefined
N2118 Rvalue reference __cpp_rvalue_references 200610 predefined
N2242 Variadic templates __cpp_variadic_templates 200704 predefined
N2672 Initializer lists __cpp_initializer_lists 200806 predefined
N1986 Delegating constructors __cpp_delegating_constructors 200604 predefined
N2756 Non-static data member initializers __cpp_nsdmi 200809 predefined
N2540 Inheriting constructors __cpp_inheriting_constructors 200802 predefined
N2439 ref-qualifiers __cpp_ref_qualifiers 200710 predefined
N2258 Template aliases __cpp_alias_templates 200704 predefined

C++98

Feature Macro name Value Header
Run-time type identification (dynamic_cast, typeid) __cpp_rtti 199711 predefined
Exception handling __cpp_exceptions 199711 predefined

Technical Specifications

File System

Paper Feature Macro name Value Header
N4100 Filesystem library __cpp_lib_experimental_filesystem 201406 <experimental/filesystem>

Library Fundamentals

v1

Paper(s) Feature Macro Name Value Header
N3915 apply() call a function with arguments from a tuple __cpp_lib_experimental_apply 201402 <experimental/tuple>
N3932 Variable templates for type traits __cpp_lib_experimental_type_trait_variable_templates 201402 <experimental/type_traits>
N3866 Invocation type traits __cpp_lib_experimental_invocation_type 201406 <experimental/type_traits>
N3916 Type-erased allocator for std::function __cpp_lib_experimental_function_erased_allocator 201406 <experimental/functional>
N3905 Searchers __cpp_lib_experimental_boyer_moore_searching 201411 <experimental/functional>
N3672 N3793 optional objects __cpp_lib_experimental_optional 201411 <experimental/optional>
N3804 class any __cpp_lib_experimental_any 201411 <experimental/any>
N3921 string_view: a non-owning reference to a string __cpp_lib_experimental_string_view 201411 <experimental/string_view>
N3920 Extending shared_ptr to support arrays __cpp_lib_experimental_shared_ptr_arrays 201406 <experimental/memory>
N3916 Polymorphic memory resources __cpp_lib_experimental_memory_resources 201402 <experimental/memory_resource>
N3916 Type-erased allocator for std::promise __cpp_lib_experimental_promise_erased_allocator 201406 <experimental/future>
N3916 Type-erased allocator for std::packaged_task __cpp_lib_experimental_packaged_task_erased_allocator 201406 <experimental/future>
N3925 sample __cpp_lib_experimental_sample 201402 <experimental/algorithm>

v2

Library Fundamentals v2 incorporates all the facilities and feature-test macros of v1. In addition, it defines the following macros.

Paper Feature Macro name Value Header
P0013R1 Logical operator type traits (conjunction, disjunction, negation) __cpp_lib_experimental_logical_traits 201511 <experimental/type_traits>
N4502 The C++ detection idiom __cpp_lib_experimental_detect 201505 <experimental/type_traits>
N4388 A const-propagating wrapper (propagate_const) __cpp_lib_experimental_propagate_const 201505 <experimental/propagate_const>
N4076 Generalized callable negator (not_fn) __cpp_lib_experimental_not_fn 201406 <experimental/functional>
N4282 The world's dumbest smart pointer (observer_ptr, a non-owning, observe-only pointer-like class) __cpp_lib_experimental_observer_ptr 201411 <experimental/memory>
N4273 Uniform container erasure __cpp_lib_experimental_erase_if 201411 <experimental/vector>
N4391 make_array, to_array __cpp_lib_experimental_make_array 201505 <experimental/array>
N4257 Delimited iterators __cpp_lib_experimental_ostream_joiner 201411 <experimental/iterator>
N4061 Greatest common divisor and least common multiple (gcd, lcm) __cpp_lib_experimental_gcd_lcm 201411 <experimental/numeric>
N4531 std::rand replacement __cpp_lib_experimental_randint 201511 <experimental/random>
N4417 n4519 Source-code information capture __cpp_lib_experimental_source_location 201505 <experimental/source_location>

Parallelism

v1

Paper Feature Macro name Value Header
N4507 parallelism __cpp_lib_experimental_parallel_algorithm 201505 <experimental/algorithm> <experimental/exception_list> <experimental/execution_policy> <experimental/numeric>

v2

Paper Feature Macro name Value Header
N4793 Task Block __cpp_lib_experimental_parallel_task_block 201711 <experimental/exception_list> <experimental/task_block>
Vector and Wavefront Policies __cpp_lib_experimental_execution_vector_policy 201711 <experimental/algorithm> <experimental/execution>
Template Library for Parallel For Loops __cpp_lib_experimental_parallel_for_loop 201711 <experimental/algorithm>
Data-Parallel Vector Types __cpp_lib_experimental_parallel_simd 201803 <experimental/simd>

Concurrency

Paper Feature Macro name Value Header
N4399 Improvements to std::future<T> and Related APIs __cpp_lib_experimental_future_continuations 201505 <experimental/future>
N4204 Latches and Barriers __cpp_lib_experimental_latch 201505 <experimental/latch>
__cpp_lib_experimental_barrier 201505 <experimental/barrier>
N4162 N4260 Atomic Smart Pointers __cpp_lib_experimental_atomic_smart_pointers 201505 <experimental/atomic>

Transactional Memory

Paper Feature Macro name Value Header
N4514 Transactional Memory __cpp_transactional_memory 201505 predefined
__has_cpp_attribute(optimize_for_synchronized) 201505 predefined

Concepts

Paper Feature Macro name Value Header
N4553 Constraints and concepts __cpp_concepts 201507 predefined

Networking

Paper Feature Macro name Value Header
N4734 Networking library __cpp_lib_experimental_net 201803 <experimental/net> <experimental/netfwd> <experimental/executor> <experimental/io_context> <experimental/timer> <experimental/buffer> <experimental/socket> <experimental/internet>
conditionally-supported features __cpp_lib_experimental_net_extensible 201803

Coroutines

Paper Feature Macro name Value Header
N4723 Coroutines __cpp_coroutines 201707 predefined