I have the following code which Xcode
says it doesn't recognised the signature for std::advance
:
template<typename Container> const typename Container::value_type&
getNthElement(const Container& container, size_t n) {
auto nElem = advance(container.begin(), n);
return *nElem;
}
The compiler doesn't support C++14
so I can't use cbegin(container)
. Why is this solution wrong ?
std::advance
doesn't return anything (see here: http://www.cplusplus.com/reference/iterator/advance/, its return type is void
) so auto nElem = advance(container.begin(), n);
isn't valid.
As said in comments, you can use next. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With