Boost logo

Boost Users :

Subject: [Boost-users] [assign] Default list_of() behavior
From: Ryan McConnehey (mccorywork_at_[hidden])
Date: 2010-08-05 11:26:02


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;
};


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net