Change arbitrary collection element type?

Hello all, Are there any standard means to clone collection class while changing only element type? Like receiving some_collection<int> as a template parameter and creating some_collection<string> without knowing what exactly some_collection is. In case there are none, is anyone interested to see it as a standalone library? With Best Regards, Marat

On Wednesday 11 July 2007 05:55:59 Marat Khalili wrote:
Are there any standard means to clone collection class while changing only element type? Like receiving some_collection<int> as a template parameter and creating some_collection<string> without knowing what exactly some_collection is.
Looks like a case for std::transform(), or?
In case there are none, is anyone interested to see it as a standalone library?
Not really, I'd be much more interested in how it allows a friendlier syntax than std::transform... ;) cheers Uli

Quoting Ulrich Eckhardt <doomster@knuut.de>:
On Wednesday 11 July 2007 05:55:59 Marat Khalili wrote:
Are there any standard means to clone collection class while changing only element type? Like receiving some_collection<int> as a template parameter and creating some_collection<string> without knowing what exactly some_collection is.
Looks like a case for std::transform(), or?
I think he wants to transform only the type (at compile time). A facility like rebind for the stl allocator. Somthing like this but specialised for all the stl container: template<class T,class D> struct rebind; template<class T,class D> struct rebind< std::vector<T>, D > { typedef std::vector<D> type; }; ... typedef rebind< some_collection<int>, string > some_collection_string; I don't know an existing implementation, and I don't have immediat use of this, but it could be useful. -- Cédric Venet

On 7/11/07, Cédric Venet <cedric.venet@student.ecp.fr> wrote:
Quoting Ulrich Eckhardt <doomster@knuut.de>:
On Wednesday 11 July 2007 05:55:59 Marat Khalili wrote:
Are there any standard means to clone collection class while changing only element type? Like receiving some_collection<int> as a template parameter and creating some_collection<string> without knowing what exactly some_collection is.
Looks like a case for std::transform(), or?
I think he wants to transform only the type (at compile time). A facility like rebind for the stl allocator.
Somthing like this but specialised for all the stl container:
template<class T,class D> struct rebind; template<class T,class D> struct rebind< std::vector<T>, D > { typedef std::vector<D> type; }; ... typedef rebind< some_collection<int>, string > some_collection_string;
I don't know an existing implementation, and I don't have immediat use of this, but it could be useful.
You can take a look at Boost.ContainerAdaptor, an internal library of Boost.Bimap. There are no docs yet... I will write them soon. Best regards Matias

Hello, Cédric Venet wrote:
I think he wants to transform only the type (at compile time).
Yep, I did mean this, thank you for translation. Matias Capeletto wrote:
You can take a look at Boost.ContainerAdaptor, an internal library of Boost.Bimap. There are no docs yet... I will write them soon.
I took, but understood nothing, sorry. It looks much more complicated than is necessary for my task. If it can be used to change <CODE>int</CODE> to <CODE>string</CODE> in my example, can you please show how. Or, I can wait for docs. With Best Regards, Marat

On 7/11/07, Marat Khalili <0x8.0p15@rol.ru> wrote:
Matias Capeletto wrote:
You can take a look at Boost.ContainerAdaptor, an internal library of Boost.Bimap. There are no docs yet... I will write them soon.
I took, but understood nothing, sorry. It looks much more complicated than is necessary for my task. If it can be used to change <CODE>int</CODE> to <CODE>string</CODE> in my example, can you please show how. Or, I can wait for docs.
It will be better to wait for the docs, because I may change some things. I will let you know when they are ready. Best regards Matias

On 10/07/07, Marat Khalili <0x8.0p15@rol.ru> wrote:
Are there any standard means to clone collection class while changing only element type? Like receiving some_collection<int> as a template parameter and creating some_collection<string> without knowing what exactly some_collection is.
It seems like a std::transform with a type conversion func and into an insert iterator would do the job, or an iterator range constructor from some kind of transform_iterator that I'm sure is in boost somewhere. std::vector<int> vi; v += 1,2,3,4,5; std::vector<std::string> vs; std::transform( vi.begin(), i.end(), std::back_inserter(vs), &boost::lexical_cast<std::string,int> ); HTH, ~ Scott McMurray P.S. We have containers in C++, not collections.
participants (5)
-
Cédric Venet
-
Marat Khalili
-
Matias Capeletto
-
Scott McMurray
-
Ulrich Eckhardt