What is the status of ranges in C++?

大兔子大兔子 提交于 2019-11-30 14:40:26

问题


Sometimes I get tired of all this my_vector.begin(), my_vector.end() noise. Last year at boostcon, Andrei Alexandrescu's keynote speech was titled Iterators Must Go (video)

Is there any progress on introducing ranges into C++, so I can finally say std::sort(my_vector)?


回答1:


Range in C++ still has an insufficient experience.
As current experimental implementation, there are Boost.Range 2.0 and Oven Range Library.




回答2:


As far as I know, no progress has been made toward that end.




回答3:


#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>

template< class Container >
void sort( Container& c ) { sort( c.begin(), c.end() ); }

int main()
{
    using namespace std;

    int const           data[]  = {3, 1, 4, 1, 5, 9, 2, 6, 5, 4};
    vector<int>         v( data, data + sizeof( data )/sizeof( *data ) );

    sort( v );
    copy( v.begin(), v.end(), ostream_iterator<int>( cout, " " ) );
}

Of course, replace member function calls begin and end with calls of startOf and endOf (your versions), at least until C++0x...



来源:https://stackoverflow.com/questions/4220247/what-is-the-status-of-ranges-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!