Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2001-02-12 21:20:40


On the new generic programming page at
http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/boost/more/generic_programming
.html?cvsroot=boost I have the following section:

----
Object Generators
An object generator is a function template whose only purpose is to
construct a new object out of its arguments. Think of it as a kind of
generic constructor. An object generator may be more useful than a plain
constructor when the exact type to be generated is difficult or impossible
to express and the result of the generator can be passed directly to a
function rather than stored in a variable. Most object generators are named
with the prefix "make_", after std::make_pair(const T&, const U&).
Here is an example, using another standard object generator,
std::back_inserter():
// Append the items in [start, finish) to c
template <class Container, class Iterator>
void append_sequence(Container& c, Iterator start, Iterator finish)
{
   std::copy(start, finish, std::back_inserter(c));
}
Without using the object generator the example above would look like: write:
// Append the items in [start, finish) to c
template <class Container, class Iterator>
void append_sequence(Container& c, Iterator start, Iterator finish)
{
   std::copy(start, finish, std::back_insert_iterator<Container>(c));
}
-------
Unfortunately, this example isn't very compelling. It would be better if the
input to the object generator was the result of calling a function whose
result type was big or impossible to deduce. Can anyone come up with a
plausible example which is more motivating?
Thanks,
Dave

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk