When using boost::any_range
, what's the correct way of specifying that the underlying container (if any) shouldn't be modified?
E.g., with the alias
template<typename T>
using Range = boost::any_range<T, boost::forward_traversal_tag>;
to declare a range that isn't capable of modifying the contents of the underlying container or "data source", should it be declared as
const Range<T> myRange;
or as
Range<const T> myRange;
?
I suspect the first version is the correct one. But is it guaranteed to keep the const
ness of the container, if, for example, I apply any of the boost::adaptors
?
Edit
From the documentation, apparently the range_iterator
metafunction "deduces" the const
ness of the underlying container by declaring the range with const T
instead of T
. That is, range_iterator::<const T>::type
is const_iterator
(if the underlying container has such member type), instead of iterator
, so the container can't be modified through this iterator.
Does that mean that Range<const T>
also uses const_iterators
to traverse the range?