[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
Ryan McConnehey skrev:
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?
Yes, the upcomming revision will fix this somehow without breaking exisiting code. -Thorsten
Ryan McConnehey skrev:
Thorsten Ottosen wrote:
Yes, the upcomming revision will fix this somehow without breaking exisiting code. Good luck with that. I don't know how your going to get two default constructors that do different behaviors.
Will this fix be in the 1.44 release?
no. If you look at the definition of list_of(), then you can easily add your own version that does what you want. -Thorsten
Thorsten Ottosen wrote:
Ryan McConnehey skrev:
Thorsten Ottosen wrote:
Yes, the upcomming revision will fix this somehow without breaking exisiting code. no. If not 1.44, any idea what release it would appear?
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:
Thorsten Ottosen wrote:
Ryan McConnehey skrev:
Thorsten Ottosen wrote:
Yes, the upcomming revision will fix this somehow without breaking exisiting code. no. If not 1.44, any idea what release it would appear?
No. Soon hopefully.
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>()(); }
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
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. Thanks for the help.
Ryan
participants (2)
-
Ryan McConnehey
-
Thorsten Ottosen