Boost logo

Boost :

From: Ben FrantzDale (benfrantzdale_at_[hidden])
Date: 2007-01-15 10:03:27


I've been using Boost increasingly in my work and am loving it. There are
two utilities I've beens surprised Boost lacks:

First, I would like to see an "insert_const" metafunction that would work
like this:
template <typename T>
struct insert_const<T*> {
  typedef typename add_const<T>::type* type;
};

That is, it would insert a const into the thing pointed to by a pointer
type. (I am interfacing with a C-style interface to C++ code. The interface
passes around "pFoo" and "pBar" – pointers to Foos and Bars. I've used the
above metafunction to create typedefs for const_pFoo and const_pBar, like
so:
  typedef typename<insert_const<pFoo> >::type const_pFoo;
  typedef typename<insert_const<pBar> >::type const_pBar;
Would this be a desirable addition?

Second, I often find myself wanting to iterate over every element in a
nested container. For example, a vector<list<double> >. I've made a
partly-functional nested_iterator class that models ForwardIterator. My
implementation defaults to use ".begin()" and ".end()" to find the inner
range, but can be adapted with a function object.

Has anyone considered adding this sort of iterator to Boost?

—Ben


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