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)
?
Using range in switch case in C/C++ You all are familiar with switch case in C/C++, but did you know you can use range of numbers instead of a single number or character in case statement.
If x is in range, then it must be greater than or equal to low, i.e., (x-low) >= 0. And must be smaller than or equal to high i.e., (high – x) <= 0. So if result of the multiplication is less than or equal to 0, then x is in range.
Range in C++ still has an insufficient experience.
As current experimental implementation, there are Boost.Range 2.0 and Oven Range Library.
As far as I know, no progress has been made toward that end.
#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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With