|
Boost : |
From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2002-08-07 09:58:17
----- Original Message -----
From: "Eric Friedman" <ebf_at_[hidden]>
To: "'Fernando Cacciola'" <fcacciola_at_[hidden]>; "'boost developers'"
<boost_at_[hidden]>
Sent: Wednesday, August 07, 2002 1:01 AM
Subject: RE: [boost] Mini-review request: aligned_storage.hpp
> I'm not sure if the intent of your proposal is to "Keep It Simple,
> Stupid", but I have developed far more full-featured aligned-storage and
> incomplete-type facilities, which may be of interest to the Boost
> community.
>
> They are available in the sandbox:
>
> boost/aligned_storage.hpp
> boost/incomplete.hpp
> boost/incomplete_fwd.hpp
> boost/utility/safe_swap.hpp
> boost/utility/safe_assign.hpp
>
> Note, however, the semantics for my boost::aligned_storage varies some
> from yours (to allow greater genericity of usage):
>
> boost::aligned_storage<size_t Size, size_t Alignment = -1>
>
> ...where an omitted Alignment (i.e. an Alignment of '-1') provides for
> maximally-aligned storage, leveraging boost::detail::max_align (which I
> think BTW should be promoted out of the detail namespace).
>
> [rest stripped]
Hi Eric,
I've carefully looked at your aligned_storage.hpp.
If I understood it correctly, it features these two things:
1) Provides a raw buffer which can allocate an object of type T with the
appropriate alignment.
2) Provides a high-level adaptor interface based on placement new which
allows users to treat the aligned buffer as ordinary objects (through
construct_as,get_as,assign_as, destroy_as,etc...)
AFAICT, (2) is built entirely upon (1), so I think that a factorization
might be more adequate.
That is, I think we should keep aligned_storage<> clean and simple, and
provide the adaptor as another, higher-level class built upon
aligned_storage.
As for the simple aligned_storage<>, I like the idea of being able to select
maximum or best alignment.
I'm not sure if the interface which takes two integers is good, though; It
does have potential for greater flexibility, but it is also significantly
more obscure for the user (IMHO).
In all the examples of this sort of utility that I've seen, 'size_' is
always 'sizeof(T)' and 'alignment_' is always
'boost::alignment_of<T>::value'; so, unless a concrete example pops up, I
prefer to parametrize aligned_storage in terms of T + Count (for arrays) + a
tag struct indicating minimum (default) or maximum alignment.
That is, instead of this interface:
template < std::size_t size_, std::size_t alignment_ = -1> class
aligned_storage ;
I prefer:
struct use_min_alignment ;
struct use_max_alignment ;
template<class T, class align_choice = user_min_alignment, size_t count = 1>
class aligned_storage ;
P.S: I'm looking also at safe_assign()... but I'm not totally convinced.
Once I have boiled down all the details about it, I'll let you know so we
can discuss it.
Fernando Cacciola
Sierra s.r.l.
fcacciola_at_[hidden]
www.gosierra.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk