To get the “easier to remember” interface, the index-generating function std :: distance (a, b), I came up with the idea of better delimiting its arguments (when using against the vector base: vec.begin ()) calling a template function with a vector and its iterator, for example:
std::vector<MyType> vect;
std::vector<MyType>::const_iterator iter;
...
...
size_t id = vectorindex_of(iter, vect);
with justification, never confuse the order of arguments; -)
Explicit formulation of the above idea read the article. as
template <typename T>
inline
size_t vectorindex_of(
typename std::vector<T>::const_iterator iter,
const std::vector<T>& vect ) {
return std::distance( vect.begin(), iter );
}
... which works but looks uncomfortable.
I would like the template engine to implicitly infer types (pseudocode):
template <typename T>
inline
size_t vectorindex_of(T::const_iterator iter, const T& vect) {
return std::distance( vect.begin(), iter );
}
... which does not work. But why?
source
share