Возможный дубликат:
Получение const_iterator с итератора
Я хочу написать metafunction, который возвращает соответствующий const_iterator
из iterator
template <class Iterator>
struct get_const_iterator
{
typedef ??? type;
};
-
get_const_iterator<int*>::type
должен бытьconst int*
-
get_const_iterator<const int*>::type
должен бытьconst int*
-
get_const_iterator<int* const>::type
должен бытьconst int*
илиconst int* const
, мне все равно -
get_const_iterator<std::list<char>::iterator>::type
должен бытьstd::list<char>::const_iterator
и др.
Можно ли это сделать с помощью iterator_traits
или без них?
Изменить: Предположим, что если 2 контейнера имеют одинаковый тип iterator
, то они также имеют одинаковый тип const_iterator
. Я думаю, что это разумное предположение, хотя теоретически не совсем правильно.