[Concept Check] - Extending the BCCL with AllocatorConcept

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 boost.org 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. --Michael Fawcett -- 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; const_reference cref = *p; p = value.address(ref); const_pointer cp = value.address(cref); p = value.allocate(1); p = value.allocate(1, 0); value.construct(p, *p); value.deallocate(p, 1); value.destroy(p); size_type s = value.max_size(); } private: T value; }; }

on Wed Mar 26 2008, "Michael Fawcett" <michael.fawcett-AT-gmail.com> 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 boost.org 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 BOOST_CONCEPT_USAGE(AllocatorConcept) and BOOST_CLASS_REQUIRE invocations should be replaced by BOOST_CONCEPT_ASSERT. Please see http://www.boost.org/doc/libs/1_35_0/libs/concept_check/creating_concepts.ht... and http://www.boost.org/doc/libs/1_35_0/libs/concept_check/using_concept_check....
-- 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;
<schnipp> -- Dave Abrahams Boost Consulting http://boost-consulting.com

On Thu, May 1, 2008 at 12:22 PM, David Abrahams <dave@boost-consulting.com> wrote:
Not a bad idea, but I think you also need an archetype class template.
According to the new usage, void constraints() should be BOOST_CONCEPT_USAGE(AllocatorConcept) and BOOST_CLASS_REQUIRE invocations should be replaced by BOOST_CONCEPT_ASSERT. Please see http://www.boost.org/doc/libs/1_35_0/libs/concept_check/creating_concepts.ht... and http://www.boost.org/doc/libs/1_35_0/libs/concept_check/using_concept_check....
I will do so. I coded the original using boost 1.33.1. BTW, you are truly diligent in catching up on mailing list activity! I thought that post was going to go unnoticed forever :-P --Michael Fawcett

on Thu May 01 2008, "Michael Fawcett" <michael.fawcett-AT-gmail.com> wrote:
On Thu, May 1, 2008 at 12:22 PM, David Abrahams <dave@boost-consulting.com> wrote:
Not a bad idea, but I think you also need an archetype class template.
According to the new usage, void constraints() should be BOOST_CONCEPT_USAGE(AllocatorConcept) and BOOST_CLASS_REQUIRE invocations should be replaced by BOOST_CONCEPT_ASSERT. Please see http://www.boost.org/doc/libs/1_35_0/libs/concept_check/creating_concepts.ht... and http://www.boost.org/doc/libs/1_35_0/libs/concept_check/using_concept_check....
I will do so. I coded the original using boost 1.33.1.
BTW, you are truly diligent in catching up on mailing list activity! I thought that post was going to go unnoticed forever :-P
I'm trying, but I'm not sure I'm going to win the battle ;-) -- Dave Abrahams Boost Consulting http://boost-consulting.com
participants (2)
-
David Abrahams
-
Michael Fawcett