[range] iterator_range::size() requires a random access iterator?
Why does boost::iterator_range::size() require a random access iterator? The implementation is 'return m_End - m_Begin;' -- if this were changed to 'return std::distance(m_Begin, m_End);' then size() would work with any iterator type. This strikes me as an arbitrary limitation, or at the least a leaky abstraction. Is there a rationale here?
AMDG Adam Merz wrote:
Why does boost::iterator_range::size() require a random access iterator? The implementation is 'return m_End - m_Begin;' -- if this were changed to 'return std::distance(m_Begin, m_End);' then size() would work with any iterator type.
This strikes me as an arbitrary limitation, or at the least a leaky abstraction. Is there a rationale here?
This is intentional. size is always constant time. If you want distance, call boost::distance. In Christ, Steven Watanabe
participants (2)
-
Adam Merz
-
Steven Watanabe