c++ - Why decltype isn't implicit? -
Why type of expression is expected, why decltype can not be added to expression?
template & lt; Class X, Square Y, Class Z & gt; Auto Foo (X X, Y, Z Z) {std :: vector & lt; Decltype (x + y * z) & gt; Values; // valid in c ++ 11 / c ++ 14 // std :: vector & lt; X + y * z & gt; Values; // Invalid values. Push_back (x + y * z); Return value; Type Type Type - OK}
typed with Expression
C ++ 14 compilers will reduce the function return type based on return expressions. Why can not it be extended in any expression -> type 'conversion?
The same applies, why do I have to write:
std :: vector & lt; Decltype (declval () + declval> () * declval & lt; z & gt; ()) & gt; Values; Instead of
:
std :: vector & lt; X + Y * Z & gt; Values;
If the underlying permissions of decltype
Some,
consider the following example:
struct tp {template Output: value parameter
type parameter
type Parameter
If decltype
is passed to t1.foo & lt; X * y + z & gt; ();
, the wrong version of this is called foo ()
.
- C ++ policy to express what you are doing, and IMHO is a very good thing by the compiler when possible.
- After this,
decltype
is only 8 characters
.
Comments
Post a Comment