assign with my container

Hi, I am inheriting a vector for some reason. Just like template<typename T> class my_vector : public std::vector<T>{ }; I want my_vector to take the advantage of boost::assign library. How to do it? Thanks abir -- Abir Basak, Member IEEE Software Engineer, Read Ink Technologies B. Tech, IIT Kharagpur email: abir@abirbasak.com homepage: www.abirbasak.com

abir basak skrev:
Hi, I am inheriting a vector for some reason. Just like template<typename T> class my_vector : public std::vector<T>{ }; I want my_vector to take the advantage of boost::assign library. How to do it?
From http://www.boost.org/libs/assign/doc/index.html#list_of_ref it says: // // Convert to a 'Container'. 'Container' must have a constructor // which takes two iterators. // template< class Container > operator Container() const; so it should simply work out of the box: my_vector<T> foo; foo += 1,2,3,43; my_vector<T> foo = list_of(1)(2)(3); -Thorsten

Thorsten Ottosen wrote:
abir basak skrev:
Hi, I am inheriting a vector for some reason. Just like template<typename T> class my_vector : public std::vector<T>{ }; I want my_vector to take the advantage of boost::assign library. How to do it?
From
http://www.boost.org/libs/assign/doc/index.html#list_of_ref
it says:
// // Convert to a 'Container'. 'Container' must have a constructor // which takes two iterators. // template< class Container > operator Container() const;
so it should simply work out of the box:
my_vector<T> foo; foo += 1,2,3,43; my_vector<T> foo = list_of(1)(2)(3);
-Thorsten Thanks. I had removed that constructor from my actual implementation (which has a private inheritance ) :( Now it works .
Thanks again. abir -- Abir Basak, Member IEEE Software Engineer, Read Ink Technologies B. Tech, IIT Kharagpur email: abir@abirbasak.com homepage: www.abirbasak.com

Thorsten Ottosen wrote:
abir basak skrev:
Hi, I am inheriting a vector for some reason. Just like template<typename T> class my_vector : public std::vector<T>{ }; I want my_vector to take the advantage of boost::assign library. How to do it?
From
http://www.boost.org/libs/assign/doc/index.html#list_of_ref
it says:
// // Convert to a 'Container'. 'Container' must have a constructor // which takes two iterators. // template< class Container > operator Container() const;
so it should simply work out of the box:
my_vector<T> foo; foo += 1,2,3,43; my_vector<T> foo = list_of(1)(2)(3);
-Thorsten And anyway it can be done for ublas vectors & matrix ? I am missing this feature so much in some non-STL container classes.
Thanks. -- Abir Basak, Member IEEE Software Engineer, Read Ink Technologies B. Tech, IIT Kharagpur email: abir@abirbasak.com homepage: www.abirbasak.com

abir basak skrev:
so it should simply work out of the box:
my_vector<T> foo; foo += 1,2,3,43; my_vector<T> foo = list_of(1)(2)(3);
-Thorsten And anyway it can be done for ublas vectors & matrix ?
Is that a question?
I am missing this feature so much in some non-STL container classes.
I think there is an example of ublas usage. At least it should be very hard to use with those. -Thorsten

abir basak
Hi, I am inheriting a vector for some reason. Just like template<typename T> class my_vector : public std::vector<T>{ }; I want my_vector to take the advantage of boost::assign library. How to do it? Thanks abir
Though it's a little off topic, I want to point out that STL container classes were not designed to be base classes; it would be preferable to make a vector<T> member variable and add to or subtract from the interface explicitly. Had there been a 'final' keyword in 1995, every STL container would have been final. Mark Ruzon

abir basak
writes: Hi, I am inheriting a vector for some reason. Just like template<typename T> class my_vector : public std::vector<T>{ }; I want my_vector to take the advantage of boost::assign library. How to do it? Thanks abir
Though it's a little off topic, I want to point out that STL container classes were not designed to be base classes; it would be preferable to make a vector<T> member variable and add to or subtract from the interface explicitly. Had there been a 'final' keyword in 1995, every STL container would have been final.
Mark Ruzon Thanks for pointing me about that. I am well aware about the fact, and had a long discussion in cpp news group, and finally thought to have a
Mark Ruzon wrote: private inheritance rather than composition :) Here is the link. http://groups.google.com/group/comp.lang.c++/browse_thread/thread/303a560a8e0c040e/103662450d71ef83?lnk=gst&q=abir&rnum=2#103662450d71ef83 Just for information , in this thread someone asked about the status of the boost circular_buffer library. It also has a container called circular_buffer_space_optimized which privately inherit from circular_buffer (a decorator class ) . I really stl container to be final, AND really dislike stl container to be polymorphic (I am not sure anyone uses it in that way, if they do, they are BAD persons ! ). Thus it SAFE to have a non-polymorphic derivation of stl container. and thanks again -- Abir Basak, Member IEEE Software Engineer, Read Ink Technologies B. Tech, IIT Kharagpur email: abir@abirbasak.com homepage: www.abirbasak.com
participants (3)
-
abir basak
-
Mark Ruzon
-
Thorsten Ottosen