|
Boost Users : |
Subject: Re: [Boost-users] Scoped_array with constructors?
From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2009-04-21 10:07:36
On Tue, Apr 21, 2009 at 12:05 PM, Space Ship Traveller <
space.ship.traveller_at_[hidden]> wrote:
> Hi,
> I want to use scoped_ptr with std::vector or scoped_array, but the problem
> is that the type I want to allocate has a non-trivial constructor.
>
> What is the standard way to make this work? My current best guess is to use
> std::vector with boost::scoped_ptr in the following way:
>
> TextureUnitsController::TextureUnitsController ()
> {
> GLint textureUnitCount = 1;
> glGetIntegerv(GL_MAX_TEXTURE_UNITS, &textureUnitCount);
>
> m_textureUnits.resize(textureUnitCount);
>
>
> for (unsigned i = 0; i < textureUnitCount; i += 1) {
> m_textureUnits[i].reset(new TextureUnit(GL_TEXTURE0 + i));
> }
>
>
> std::cerr << "Found " << textureUnitCount << " texture units..." << std::
> endl;
> }
>
> But this doesn't work because scoped_ptr also has a non-trivial
> constructor, so resize fails.
>
> Thanks
> Samuel
>
Hi!
Just a question. Why not using std::vector in conjunction with reserve and
std::fill_n or std::generate_n algorithm? Why do you need your object
instances to be heap allocated and not simply constructed in the vector
storage? You might be interested by boost assign library to fill vector on
the fly, instead of using std algorithms.
Regards,
Ovanes
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