insert_const, nested_iterator

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

Ben FrantzDale wrote:
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?
Maybe something like 'constant_iterator' adaptor seems to be more generic?
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?
It seems the one known as "segmented-iterator". The "boostified" implementation is not found yet, AFAIK. Adobe implementation is here... http://tinyurl.com/2hmcrw , and my implementation is here :-)... http://tinyurl.com/35xg2m Anyway you can upload yours to Vault. Regards, -- Shunsuke Sogame

On 1/16/07, shunsuke <pstade.mb@gmail.com> wrote:
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
above metafunction to create typedefs for const_pFoo and const_pBar,
Ben FrantzDale wrote: the like
so: typedef typename<insert_const<pFoo> >::type const_pFoo; typedef typename<insert_const<pBar> >::type const_pBar; Would this be a desirable addition?
Maybe something like 'constant_iterator' adaptor seems to be more generic?
I'm not sure I follow. Google gives me some hits for "constant_iterator", but not much information. It definitely would be nice to have a way to go from std::vector<foo>::iterator to and from std::vector<foo>::const_iterator and you make a good point that it's the same operation I'm proposing. —Ben
participants (2)
-
Ben FrantzDale
-
shunsuke