Boost logo

Boost :

From: christopher diggins (cdiggins_at_[hidden])
Date: 2005-08-10 11:35:52

----- Original Message -----
From: "Larry Evans" <cppljevans_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Wednesday, August 10, 2005 12:10 PM
Subject: Re: [boost] alignment problem in proposed any alternative

> On 08/10/2005 09:27 AM, christopher diggins wrote:
> [snip]
>> Anyway it turns out we can guarantee alignment by simply using a char
>> buffer. According to 3.9/2 the following automatically has no alignment
>> problems:
>> template<int buffer_size>
>> struct any {
>> char buffer[buffer_size];
>> ...
>> template<typename T>
>> any(const T& x) {
>> if (boost::is_pod<T>::value && (sizeof(T) <= buffer_size)) {
>> memcpy(buffer, &T, N);
> Wouldn't this fail to update the refcount if T was shared_ptr or
> weak_ptr?

You are correct, but they aren't POD types so we would be safe.

I can't help but wonder if this doesn't somehow imply placement new will
work just as well.

  if ((sizeof(T) <= buffer_size)) {
    new(buffer) T(x);

By the way, I made a small mistake originally it should have been
memcpy(buffer, &x, N);

Christopher Diggins

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