A
Alf P. Steinbach
I have e.g.
template< typename T >
inline typename T::iterator startOf( T& c )
{
return c.begin();
}
template< typename T >
inline typename T::const_iterator startOf( T const& c )
{
return c.begin();
}
template< typename T, Size N >
inline T* startOf( T (&a)[N] )
{
return a;
}
Types from the standard library use 'iterator' and 'const_iterator', but imagine
some other large set of types TheirOwnWay with e.g. 'Iter' and 'ConstIter', and
that those types are in numeruous different namespaces.
How can the functions above be modified so that it's simple to make them work
also with TheirOwnWay types, e.g. by defining some type trait thing?
I tried the to me "obvious" customization hook, like
template< typename T >
inline typename IterTrait<T>::T startOf( T& c ) ...
keeping the last overload above as-is, but this failed spectacularly when
calling startOf(a) where a is a raw array.
I'd rather avoid using Boost enable_if (or any Boost dependency).
Cheers,
- Alf
template< typename T >
inline typename T::iterator startOf( T& c )
{
return c.begin();
}
template< typename T >
inline typename T::const_iterator startOf( T const& c )
{
return c.begin();
}
template< typename T, Size N >
inline T* startOf( T (&a)[N] )
{
return a;
}
Types from the standard library use 'iterator' and 'const_iterator', but imagine
some other large set of types TheirOwnWay with e.g. 'Iter' and 'ConstIter', and
that those types are in numeruous different namespaces.
How can the functions above be modified so that it's simple to make them work
also with TheirOwnWay types, e.g. by defining some type trait thing?
I tried the to me "obvious" customization hook, like
template< typename T >
inline typename IterTrait<T>::T startOf( T& c ) ...
keeping the last overload above as-is, but this failed spectacularly when
calling startOf(a) where a is a raw array.
I'd rather avoid using Boost enable_if (or any Boost dependency).
Cheers,
- Alf