Does it make sense to use std :: forward with the typeid operator?

I was wondering if it makes sense to use std::forward<>

when sending an instance to typeid

?

template <typename T>
void foo(T&& value) {
  std::cout << typeid(std::forward<T>(value)).name() << std::endl;
}

      

Does the call cause typeid(value)

the same result?

+3


source to share


2 answers


From [expr.typeid] / 3:

When typeid

applied to an expression other than the glvalue of the polymorphic class type, the result refers to an object std::type_info

that represents the static type of the expression.



In the C ++ standard, "expression type" is never a reference type; The "referential" (lvalue or rvalue) of an expression is expressed in its value category. Since it std::forward

does not change the type of the expression, only its value category (for example, from lvalue to rvalue), when applied std::forward

, will not affect the result typeid

.

+5


source


No, it is not. The result will be the same either way.



+3


source







All Articles