Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2008-05-01 12:22:41

on Wed Mar 26 2008, "Michael Fawcett" <> wrote:

> I recently had the need to code up an AllocatorConcept, and it
> occurred to me that it might fit well within the BCCL. I noticed that
> Intrusive also had an allocator concept and wondered if other
> libraries did too (perhaps under a different name).
> Would this be of interest as an extension to BCCL? A quick Google
> search of shows that dynamic_bitset, multi_index, function,
> regex, shared_ptr (and I'm sure more) all have Allocator template
> parameters where it might make sense.
> For very generic concepts such as Allocator, do they belong in BCCL
> rather than coded in each library?
> I've pasted the code below.

Not a bad idea, but I think you also need an archetype class template.

According to the new usage, void constraints() should be
invocations should be replaced by BOOST_CONCEPT_ASSERT. Please see

> -- code --
> namespace boost {
> template <typename T>
> struct AllocatorConcept {
> typedef typename T::const_pointer const_pointer;
> typedef typename T::const_reference const_reference;
> typedef typename T::difference_type difference_type;
> typedef typename T::pointer pointer;
> typedef typename T::reference reference;
> typedef typename T::size_type size_type;
> typedef typename T::value_type value_type;
> // TODO: Do we need to do more here, e.g.
> char_allocator_type::rebind<value_type>::other == T?
> typedef typename T::template rebind<char>::other char_allocator_type;
> BOOST_CLASS_REQUIRE(T, boost, DefaultConstructibleConcept);
> BOOST_CLASS_REQUIRE(T, boost, CopyConstructibleConcept);
> BOOST_CLASS_REQUIRE(T, boost, EqualityComparableConcept);
> void constraints() {
> pointer p = 0;
> reference ref = *p;


Dave Abrahams
Boost Consulting

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