Examples of using Constexpr in English and their translations into Chinese
{-}
-
Political
-
Ecclesiastic
-
Programming
Constexpr functions by example.
It can call only other constexpr functions.
Constexpr is part of an object's or function's interface.
When should you use constexpr capability in C++11?
In C++11 constexpr function must compose only from one return statement.
This definition is deprecated for constexpr data members(since C++17).
Every constructor involved in initializing non-static data members andbase class sub-objects shall be a constexpr constructor;
C++14 conformance improvements: constexpr and aggregate initialization.
If a function may have to be evaluated at compile time,declare it constexpr;§1.6;[CG: F.4].
If a static data member is declared constexpr, it is implicitly inline and does not need to be redeclared at namespace scope.
Such conditional operator was commonly used in C++11 constexpr programming prior to C++14.
However, if the declaration uses constexpr or inline(since C++17) specifier, the member must be declared to have complete type.
Such conditional operator was commonly used in C++11 constexpr programming prior to C++14.
InfoWorld: With the addition of constexpr lambdas in C++ 17, does C++ continue to become more of a functional programming language?
Every constructor involved in initializing non-static data members andbase class sub-objects shall be a constexpr constructor;
The above expression states that during the compilation constexpr must be true, but it does not affect static_assert.
Every constructor involved in initializing non-static data members andbase class sub-objects shall be a constexpr constructor;
This constant expression mayonly call other functions defined as constexpr, or it may use other constant expression data variables.
Copying constexpr constructed types should also be defined as a constexpr, in order to allow them to be returned by value from a constexpr function.
Currently, implicitly-defined constructors aren't automatically specified as constexpr even when they would fulfill all the requirements to be so:.
C++0x will introduce the keyword constexpr, which allows the user to guarantee that a function or object constructor is a compile-time constant.
Also, C++11 stated that allnon-static member functions that were declared constexpr were also implicitly declared const, with respect to this.
Copying constexpr constructed types should also be defined as a constexpr, in order to allow them to be returned by value from a constexpr function.
The proposal explicitly states, that the constexpr must be true to be included during compilation, but this has no effect on static_assert.
Copying constexpr constructed types should also be defined as a constexpr, in order to allow them to be returned by value from a constexpr function.
Also interesting: the feature is written if constexpr, but the standard wording still names it constexpr if, but defines it as if constexpr.
The copy constructor for a type with any constexpr constructors should usually also be defined as a constexpr constructor, to allow objects of the type to be returned by value from a constexpr function.
C++0x will introduce the keyword constexpr, which allows the user to guarantee that a function or object constructor is a compile-time constant.
Literal types are the types of constexpr variables and they can be constructed, manipulated, and returned from constexpr functions.