With reference to
template<typename T>
void fun(ParamType param); // ParamType is some form of T, e.g. T, T&, T const, ...
fun(expr); // expr is an expression
I know that && "somewhere" in ParamType is not enough for ParamType to be a universal reference, for instance ParamType = std::vector<T>&& is an rvalue reference. && needs to be just beside the template parameter T for it (T&&) to possibly be a universal reference.
But I also know that T&& "somewhere" in ParamType is still not enough, for instance ParamType = std::remove_reference_t<T&&> is not a universal reference.
Therefore, I was almost asking are there/what are the requirements on the "form" of ParamType for it to be a forwarding reference?.
However, by doing a bit of research, I kind of feel I need to ask a more "binary" question:
Assuming for simplicity that T is the only template parameter and, consequently, that ParamType is only function (in the math sense) of T, is it correct to say that if both of these are true
Tappears inParamTypethe form ofT&&fundeducesTandPramType(i.e. theTdoesn't need to be passed viafun<T>)
then ParamType is a universal reference?
In other words, is ParamType always a universal reference if it has a T&& in it with T deduced?
Aucun commentaire:
Enregistrer un commentaire