Possible Duplicate:
Reference collapsing?
template<
class T = const std::vector<int> &
> void f(const T &);
If T is already const and a reference, what will happen? Why does this code compile then?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That would be the equivalent of
const (const std::vector<int>&)&, and in this case, theconstwould be ignored since you cannot have a const reference to const T, only reference to const T. Since references cannot be reseated, theconstwould be redundant anyway. Also, ignoring theconstyou have(T&) &, and due to reference collapsing rules in C++11, this becomesT&. So the end result isconst T&orconst std::vector<int>&in your case.If you had
const T*, then it would make a difference since that would beconst (const std::vector<int>&)* pwhich would make the pointerconst.