Bug in IwArray

Home / Forums / Marmalade Archive / IwUtil / Bug in IwArray
3 replies [Last post]
by: Woof
Status: Offline
Joined: 2011-04-24
Points: 1220

I've spotted a bug in IwArray (seen in 5.1.3 with no mentions in the changelog for newer versions). The constructor accepting a size doesn't result in a container of that size, e.g.:

{syntaxhighlighter brush:cpp;collapse:false}CIwArray a(10);
cout vector b(10);
cout

As you'll see the vector has 10 entries but the IwArray doesn't. Looking into the array's constructor the entries are created (in push_back_qty()) but clear() is called immediately afterwards (destroying the newly created elements).

by: PetterL
Status: Offline
Joined: 2010-08-30
Points: 280
CIwArray

CIwArray a;
a.push_back_qty(10);
would be what your looking for.

But yes that is confusing, the constructor states that it takes a size
"@param sz If specified initialise the array with sz newly constructed members."
but what it really does is only reserving capacity for at least that many elements..

by: Woof
Status: Offline
Joined: 2011-04-24
Points: 1220
It's clearly a bug. It

It's clearly a bug. It doesn't just reserve, it reserves, performs a placement new, then calls the destructor. If it's not a bug then the implementation neither follows the documentation nor is it an implementation of vector.

by: Victor T.
Status: Offline
Joined: 2011-12-20
Points: 280
I agree with PetterL, it's

I agree with PetterL, it's confusing that the documentation says "...newly constructed members" when the members are actually NOT constructed. I guess "newly destructed" would be correct, but that's also confusing.

I don't agree with CW, though; this is NOT a bug, it's just a difference between CIwArray and std::vector. The purpose of the CIwArray constructor is to allow the user to allocate the appropriate amount of memory in the constructor, but NOT have constructed objects.

I also DO agree with CW: CIwArray isn't an implementation of std::vector. It's an implementation of CIwArray.

Latest Posts

Latest Comments

Top Contributors

  • Chris D : 27,010
  • MonRoyals : 26,970
  • Salman : 26,720
  • Jez Hammond : 20,130
  • pjan : 11,150
  • gjw : 10,350
  • Paolo Oliverio : 9,640
  • Beaker_2 : 8,390
  • Kite : 8,210
  • bluescrn : 7,810