Thread View: comp.std.c++
2 messages
2 total messages
Started by Eugene Radchenko
Wed, 17 Jan 1996 20:21
More on the operations on the entire container
Author: Eugene Radchenko
Date: Wed, 17 Jan 1996 20:21
Date: Wed, 17 Jan 1996 20:21
39 lines
2528 bytes
2528 bytes
Hi!
Operations on the whole container are (as the threads flashing here
sometimes show) the most common kind of range operations in a program using
the STL. Hence, it is generally felt that the current idiom for this
Iterator i = find(c.begin(), c.end(), x);
is verbose, cumbersome and error-prone. However, no solution (fitting into
the split container/algorithm paradigm) has been proposed yet.
I think this can do the trick:
template <class Iterator> struct range : public pair<Iterator, Iterator> {
range(Iterator first, Iterator last)
: pair<Iterator, Iterator>(first, last) {}
};
template <...> class vector {
//....
range<iterator> all() { return range(begin(), end()); }
range<const_iterator> all() const { return range(begin(), end()); }
};
Also, the library would provide the 'range' version of all functions, e.g.
template<class Iterator, class T> Iterator find(range<Iterator> r, T x);
simply inlining to find(r.first, r.second, x).
(If the conversions were allowed in the template deduction, it would be
even simpler with
operator range<iterator>()
in vector).
So, what do you think? Genie
--
--------------------------------------------------------------------
Eugene V. Radchenko Research associate, Computer Chemistry
E-mail: eugene@qsar.chem.msu.su Fax: +7-(095)939-0290
Ordinary mail: Chair of Organic Chemistry, Department of Chemistry,
Moscow State University, 119899 Moscow, Russia
***************** Disappearances are deceptive *******************
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Re: More on the operations on the entire container
Author: David Byrden
Date: Thu, 18 Jan 1996 13:23
Date: Thu, 18 Jan 1996 13:23
31 lines
1491 bytes
1491 bytes
Genie;
>> Operations on the whole container are (as the threads flashing here
>> sometimes show) the most common kind of range operations in a program
>> using the STL. Hence, it is generally felt that the current idiom for
>> this Iterator i = find(c.begin(), c.end(), x); is verbose,
>> cumbersome and error-prone.
>> So, what do you think?
I think it's 6 months too late to propose changes to the standard! :)
I keep a little library of template functions;
template< class Container, class Functor >
void for_contents( Container& c, Functor f )
{
for_each( c.begin(), c.end(), f ) ;
}
Problem solved?
David
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads