0

即,两者之间有什么区别

subrange(V, 0, 3);

project(V, range(0,3));

?

我问是因为我正在研究一些似乎同时使用两种形式的代码(一种与另一种没有明显的押韵/原因),但我看不出两者之间有任何区别......只是想检查一下确保我没有遗漏任何东西。

4

1 回答 1

1

Looked into it, and I've confirmed there is no difference - subrange is simply an easy wrapper for a common-case of project, and in these cases:

subrange(V, 0, 3);
project(V, range(0,3));

...they end up identical. So using either should be fine, as long as you're consistent!

For the more curious... subrange does:

template<class V>
vector_range<V> subrange (V &data, typename V::size_type start, typename V::size_type stop) {
        typedef basic_range<typename V::size_type, typename V::difference_type> range_type;
        return vector_range<V> (data, range_type (start, stop));
    }

while project does:

template<class V>
vector_range<V> project (V &data, typename vector_range<V>::range_type const &r) {
    return vector_range<V> (data, r);
}

..and since vector_range::range_type is defined to be

typedef basic_range<size_type, difference_type> range_type;

...ie, exactly what is used in subrange, the two forms are identical.

于 2012-08-22T17:35:42.693 回答