In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how to use decltype in C++. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
1. Grammar
Decltype (entity) (1) (11 cases)
Decltype (expression) (2) (since 11)
Explanation:
1) if the argument is an identification expression without parentheses or an access expression by a class member without parentheses, decltype produces the type of entity named after that expression. If there is no such entity or the argument specifies a set of overloaded functions, the program is not well constructed.
If the argument refers to an unparenthesized identity expression that names a structured binding, then decltype produces its referenced type (described in the note on the structured binding declaration).
If the argument refers to an unparenthesized identification expression that names a non-type template parameter, decltype generates the type of the template parameter (when the template parameter is declared as a placeholder type, the type does any required type derivation).
2) if the argument is any expression of other type T, and
If the value category of the expression is dead, decltype will generate a token &
If the value category of the expression is a left value, decltype will generate T &
If the value category of the expression is pure right, decltype will generate T.
If the expression is a function call that returns the pure right value of the class type, or the right Operand is a comma expression for such a function call, no temporary quantity is introduced for that pure right value.
If the expression is a pure right value other than (parenthesized) immediate invocation (starting from 20), the temporary object is not materialized from that pure right value: that is, the pure right value has no result object.
The type does not need to be a complete type or have a destructor available, and the type can be abstract. This rule does not apply to its subexpression: in decltype (f (g (), g () must have a full type, but f () does not.
Note:
If the object's name is parenthesized, it is treated as the usual left-value expression, so decltype (x) and decltype ((x)) are usually different types.
Decltype is useful for types that are difficult or impossible to declare in standard writing, such as lambda-related types or types that depend on template parameters.
two。 Keyword decltype
Example:
# include # include struct A {double x;}; const A* a; decltype (a-> x) y; / y is of type double (its declared type) decltype ((a-> x)) z = y The type of / / z is const double& (left-value expression) templateauto add (T t, U)-> decltype (t _ u) / / the return type depends on the template parameter {/ / cantilever 14 to derive the return type return tweeu;} int main () {int I = 33; decltype (I) j = I * 2; std::cout
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.