#####  [ cppreference.com ](/)

[ Log in
](/mwiki/index.php?title=Special:UserLogin&returnto=cpp%2Ffeature+test "You
are encouraged to log in; however, it is not mandatory \[o\]")

#####  Namespaces

  * [ Page ](/w/cpp/feature_test "View the content page \[c\]")
  * [ Discussion ](/w/Talk:cpp/feature_test "Discussion about the content page \[t\]")

#####  Variants

#####  Views

  * [ View ](/w/cpp/feature_test)
  * [ Edit ](/mwiki/index.php?title=cpp/feature_test&action=edit "You can edit this page. Please use the preview button before saving \[e\]")
  * [ History ](/mwiki/index.php?title=cpp/feature_test&action=history "Past revisions of this page \[h\]")

#####  Actions

#  Feature testing  (since C++20)

From cppreference.com

< [ cpp ](/w/cpp "cpp")

[ C++ ](/w/cpp "cpp")

[ Compiler support ](/w/cpp/compiler_support "cpp/compiler support")  
---  
[ Freestanding and hosted ](/w/cpp/freestanding "cpp/freestanding")  
[ Language ](/w/cpp/language "cpp/language")  
[ Standard library ](/w/cpp/standard_library "cpp/standard library")  
[ Standard library headers ](/w/cpp/header "cpp/header")  
[ Named requirements ](/w/cpp/named_req "cpp/named req")  
**Feature test macros** (C++20)  
[ Language support library ](/w/cpp/utility#Language_support "cpp/utility")  
[ Concepts library ](/w/cpp/concepts "cpp/concepts") (C++20)  
[ Metaprogramming library ](/w/cpp/meta "cpp/meta") (C++11)  
[ Diagnostics library ](/w/cpp/error "cpp/error")  
[ General utilities library ](/w/cpp/utility "cpp/utility")  
[ Strings library ](/w/cpp/string "cpp/string")  
[ Containers library ](/w/cpp/container "cpp/container")  
[ Iterators library ](/w/cpp/iterator "cpp/iterator")  
[ Ranges library ](/w/cpp/ranges "cpp/ranges") (C++20)  
[ Algorithms library ](/w/cpp/algorithm "cpp/algorithm")  
[ Numerics library ](/w/cpp/numeric "cpp/numeric")  
[ Localizations library ](/w/cpp/locale "cpp/locale")  
[ Input/output library ](/w/cpp/io "cpp/io")  
[ Filesystem library ](/w/cpp/filesystem "cpp/filesystem") (C++17)  
[ Regular expressions library ](/w/cpp/regex "cpp/regex") (C++11)  
[ Concurrency support library ](/w/cpp/thread "cpp/thread") (C++11)  
[ Technical specifications ](/w/cpp/experimental "cpp/experimental")  
[ Symbols index ](/w/cpp/symbol_index "cpp/symbol index")  
[ External libraries ](/w/cpp/links/libs "cpp/links/libs")  
  
[ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/navbar_content&action=edit)

**Feature testing**

The standard defines a set of [ preprocessor macros
](/w/cpp/preprocessor/replace "cpp/preprocessor/replace") corresponding to C++
language and library features introduced in C++11 or later. They are intended
as a simple and portable way to detect the presence of said features.

##  Contents

  * 1  Attributes 
  * 2  Language features 
  * 3  Library features 
  * 4  Example 
    * 4.1  Normal usage 
    * 4.2  Compiler Features Dump 
  * 5  Defect reports 
  * 6  See also 
  * 7  External links 

  
---  
  
###  [ [ edit ](/mwiki/index.php?title=cpp/feature_test&action=edit&section=1
"Edit section: Attributes") ]  Attributes  
  
---  
` **__has_cpp_attribute(** ` attribute-token  ` **)** ` |  |   
  
Checks for the support of an [ attribute ](/w/cpp/language/attributes
"cpp/language/attributes") named by  attribute-token  (after macro expansion).

For each standard attribute, it is implementation-defined whether `
__has_cpp_attribute ` expands to the value given in the table below (which is
the year and month in which the attribute was added to the working draft) or
​  0  ​  . It will expand to given value in the table if and only if the
standard attribute causes the implementation to behave as recommended (issuing
diagnostic messages, affecting class layout, etc.).

The presence of vendor-specific attributes is determined by a non-zero value.

` __has_cpp_attribute ` can be expanded in the expression of [ ` #if `
](/w/cpp/preprocessor/conditional "cpp/preprocessor/conditional") and [