c++c++11language-lawyerc++14constexpr

C++14 constexpr function requirements on cppreference


cppreference says that, until C++14, a constexpr function must satisfy the following requirement:

the function body must be either deleted or defaulted or contain only the following:

  • null statements (plain semicolons)
  • static_assert declarations
  • typedef declarations and alias declarations that do not define classes or enumerations
  • using declarations
  • using directives
  • if the function is not a constructor, exactly one return statement

Yet the example contains many other elements.

Is the requirement misstated or am I misunderstanding something?


Solution

  • On cppreference.com, you'll often find pages, identifiers, declarations, definitions and blocks of text annotated with one of:

    1. (C++XX)
    2. (since C++XX)
    3. (until C++XX)
    4. (since C++XX)
      (until C++YY)

    where XX and YY indicate standard revisions (currently one of 98, 03, 11, 14, 17, 20, 23 or 26).

    The first and second are equivalent and mean that the annotated element is applicable for C++XX and later.

    The third type of annotation, on the other hand, indicates that the annotated element was applicable before C++XX. Starting from C++XX, such element is not applicable anymore.

    Finally, the fourth type of annotation (less common), indicates that the annotated element is applicable for C++XX and later, up to, but not including, C++YY.


    All of these annotations can make some pages harder to read. If you only care about a certain revision, you can select it on the "Standard revision" drop-down menu located in the top-right corner. Doing so will hide everything that's not relevant for the chosen revision.