I was wandering, what are the new requirement for a user defined container to be usable with Range-v3(algorithms...)?
For example, what we need to change in our design(member types, member function...) in the standard sense? How to obey Concepts on Range-v3 algorithms? what member functions do we need to provide? what are the changes for iterators?
what is the replacement for iterators/begin/end?
template<typname T>
struct container
{
//...
using value_type = T;
//...
using iterator = value_type*;
using const_iterator = const value_type*;
//...
iterator begin() { //... }
//...
};
it will be great if some can give a canonical container implementation.
what are the new ideas/notions brought by Range-v3? what is the new C++ coding way?
As far as I can tell a range itself simply needs to have
begin
andend
members that return a valid iterator. The iterator may be a bit harder to get right. As far as I can tell, the weakest iterator (i.e. the one that needs the least members) needs the following members:operator =
operator ++
(in both pre and post forms)operator *
operator ==
operator !=
std::iterator
so it has the right type members available -- not though that this is deprecated in C++17 so you may prefer to add the types by hand instead.You can statically assert for the concepts and that should help you work out what you need: