Boost logo

Boost :

Subject: Re: [boost] Dynamic_bitset and access to underlying storage
From: Sylvester-Bradley, Gareth (Gareth.Sylvester-Bradley_at_[hidden])
Date: 2010-06-29 05:50:24


Stefan Strasser wrote:
> all of these problems could be solved if dynamic_bitset was changed
> into a container adapter similar to std::stack and leave the
> underlying container to the user.

That seems like a neat idea.

In the meantime, [1] GotW #76 warns us not to do this...

#include <boost/dynamic_bitset.hpp>

typedef unsigned long block_t;

namespace { struct weasel { block_t* ptr; }; }

namespace boost {
  template <> template <>
  void dynamic_bitset< block_t >::append( weasel* first, weasel* last )
  {
    first->ptr = &m_bits[0];
    last->ptr = &m_bits[0] + m_bits.size();
  }
}

#include <iostream>

int main( int argc, char* const argv[] )
{
  boost::dynamic_bitset< block_t > db;
  db.append( 42 );
  weasel first = {0}, last = {0};
  db.append( &first, &last );
  std::cout << "size: " << last.ptr - first.ptr;
  std::cout << " first element: " << *first.ptr << std::endl;
  return 0;
}

;-)

Gareth

[1] http://www.gotw.ca/gotw/076.htm

************************************************************************
The information contained in this message or any of its attachments may be confidential and is intended for the exclusive use of the addressee(s). Any disclosure, reproduction, distribution or other dissemination or use of this communication is strictly prohibited without the express permission of the sender. The views expressed in this email are those of the individual and not necessarily those of Sony or Sony affiliated companies. Sony email is for business use only.

This email and any response may be monitored by Sony to be in compliance with Sony's global policies and standards


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk