.all() ?

T

Thomas J. Gritzan

DerekBaker said:
At
http://www.boostcon.com/site-media/var/sphene/sphwiki/attachment/2009/05/08/iterators-must-go.pdf
saw (p. 44):

auto r = find(v.all(), value);

Is there any implementation of '.all()'?

You can't do it as member function, so here's a quick version as free
function. It might be better to rename it to something more meaningful:

template <typename Iterator>
struct range {
range(Iterator b, Iterator e) : begin(b), end(e) {}
bool empty() const { return begin == end; }
void popFront() { assert(!empty()); ++begin; }
typename Iterator::reference front()
{ assert(!empty()); return *begin; }
private:
Iterator begin;
Iterator end;
};

template <typename Container>
range<typename Container::const_iterator> all(Container const& c) {
typedef typename Container::const_iterator iterator;
return range<iterator>(c.begin(), c.end());
}

template <typename Container>
range<typename Container::iterator> all(Container& c) {
typedef typename Container::iterator iterator;
return range<iterator>(c.begin(), c.end());
}

PS: I hope it's not homework ;-)
 
D

DerekBaker

Thomas said:
You can't do it as member function, so here's a quick version as free
function. It might be better to rename it to something more meaningful:

template <typename Iterator>
struct range {
range(Iterator b, Iterator e) : begin(b), end(e) {}
bool empty() const { return begin == end; }
void popFront() { assert(!empty()); ++begin; }
typename Iterator::reference front()
{ assert(!empty()); return *begin; }
private:
Iterator begin;
Iterator end;
};

template <typename Container>
range<typename Container::const_iterator> all(Container const& c) {
typedef typename Container::const_iterator iterator;
return range<iterator>(c.begin(), c.end());
}

template <typename Container>
range<typename Container::iterator> all(Container& c) {
typedef typename Container::iterator iterator;
return range<iterator>(c.begin(), c.end());
}

PS: I hope it's not homework ;-)

Thanks for the reply.

No, it's not homework. Happened across the pdf while surfing the web, and wondered if had been done.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,158
Messages
2,570,881
Members
47,414
Latest member
djangoframe

Latest Threads

Top