Boost logo

Boost :

From: Rene Rivera (grafik.list_at_[hidden])
Date: 2006-06-01 22:51:29

Maarten Kronenburg wrote:
> "Rene Rivera" wrote in message
>> I don't care that much what the form of access looks like. The important
>> aspect is having a *defined representation* that users can convert to
>> and from. For example other access methods might be:
>> // Iterators, like std::string::data:
>> std::pair<word_type const *, word_type const *> integer::data() const;
>> // Inserter, like std::string::copy:
>> template <typename OutputIterator>
>> void integer::copy(OutputIterator) const;
>> // Stream like:
>> template <typename Container>
>> operator << (Container &, integer const &);
>> Of course there would need to be a corresponding constructor to have the
>> data round trip.
> But what should the iterator iterate over?
> Bits? Bytes?

A "word_type" you define, which at minimum would be bytes. And by you I
mean the TR2 document you are proposing.

> In my opinion get_sub of a bit or byte or whatever,
> with a converter like to_unsigned_int, gives you the
> O(1) access you require.

Sure, but it doesn't follow existing STL practices and norms.

> Perhaps the user can define an iterator
> based on get_sub.

Of course, it's as simple as:

   boost::function< uint8_t (std::size_t) >,
   boost::counting_iterator<std::size_t> > I;

integer n = 5;

uint8_t get_uint8_n(integer * i, std::size_t n)
   return i->get_sub(n*8,8);

I begin_i(I::base_type(0),boost::bind(&get_uint8_n,&n,_1));
I end_i(I::base_type(n.size(),boost::bind(&get_uint8_n,&n,_1,8));

std::vector<uint8_t> m(begin_i,end_i);

But first there's no integer::size(), and second it seems like a rather
complex thing to push onto users (even given how simple the above is
with the use of the Boost.Iterators and Boost.Bind libraries).

-- Grafik - Don't Assume Anything
-- Redshift Software, Inc. -
-- rrivera/ - grafik/
-- 102708583/icq - grafikrobot/aim - grafikrobot/yahoo

Boost list run by bdawes at, gregod at, cpdaniel at, john at