[assign] Default list_of() behavior

None of the examples, for list_of, show the use of the default list_of constructor. When I tried to use list_of() for a vector I expected a blank vector without any elements. What I found was a vector that had one element of the vector type. This element had a default value. Is this the correct behavior? t_ucvector temp( list_of() ); //The temp vector has one element of type unsigned char with a default value of zero. There is a structure with a couple of constant std::vectors that are being initializing in the constructor's preamble. I've included the structure with the working version of the code. I've included the desired creation of the std::vector, but because of list_of() is not working. Thank you for your help. Ryan struct SplitterFixture { public: SplitterFixture(void) : header(list_of(2)(2)) , messageA(list_of('a').repeat(2,'a')) , input(t_boostVector(new t_ucvector(list_of(2)(2).range(messageA)))) //Desired implementation. //: header(list_of().repeat(2,'2')) //, messageA(list_of().repeat(3,'a')) //, input(t_boostVector(new t_ucvector(list_of().range(header).range(messageA)))) {} public: typedef std::vector<unsigned char> t_ucvector; typedef boost::shared_ptr<t_ucvector> t_boostVector; public: t_ucvector const header; t_ucvector const messageA; t_boostVector const input; };

Thorsten Ottosen wrote:
If you look at the definition of list_of(), then you can easily add your own version that does what you want.
namespace assign { //Current implementation template< class T > inline assign_detail::generic_list<T> list_of() { return assign_detail::generic_list<T>()( T() ); } } Just put this version of list_of in my own namespace? Or is there a way to add this to the assign namespace? template< class T > inline assign_detail::generic_list<T> list_of() { return assign_detail::generic_list<T>()(); } Ryan

Ryan McConnehey skrev:
No. Soon hopefully.
create your own header, include the relevant headers from Boost.Assign. Then open the assign namespace: namespace boost { namespace assign { // your code here } } but you have to choose a different name than list_of() if you use the boost::assign namespace. HTH -Thorsten
participants (2)
-
Ryan McConnehey
-
Thorsten Ottosen