It seems that the compiler is trying to apply const to int& , making it int& const , which is superfluous, since the link cannot be redone 1) Try to put a constant between decltype and the link: decltype(*ints.begin()) const&
1) Thanks for the comments.
Drop that thanks to @Ben's comment, I noticed a real problem. Try decltype(*ints.cbegin()) . cbegin returns a const_iterator , which is shared by a const-reference. In addition, there is no need for an extra ampersand, since *ints.cbegin() already returns int const& .
To explain what went wrong in the OP code, it just like @Ben Voigt says in the comments: decltype(*std::begin(ints)) resolves int& since std::begin(ints) returns a non-constant iterator for containers without constants and dereferencing, such an iterator returns a reference to non-const.
source share