
Boost : 
Subject: Re: [boost] [range] [general] making member functions SFINAEfriendly
From: Nathan Ridge (zeratul976_at_[hidden])
Date: 20130218 05:19:52
> Could you share a use case that requires to depend on size()
> specifically rather than the iterator category?
Given an arbitrary range r, determine its size by the fasest
means possible.
If we use std::distance, we can do it in O(1) for std::vector,
O(n) for std::map, and O(n) for std::forward_list.
If we can detect whether "r.size()" is a valid expression,
and use that if available, and std::distance otherwise, then
we have O(1) for std::vector, O(1) for std::map, and O(n) for
std::forward_list. Notice how that's an improvement for
std::map.
However, if detecting whether "r.size()" is a valid expression
cannot be done reliably (for example, if we determine that for
iterator_range<I> where I is not randomaccess it is a valid
expression, but then that staticasserts on us), then we
can't use this approach.
Regards,
Nate
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk