|
Boost : |
Subject: Re: [boost] Minimizing Dependencies within Generic Classes for Faster and Smaller Programs
From: Daniel James (dnljms_at_[hidden])
Date: 2010-11-12 11:36:50
On 12 November 2010 12:42, vicente.botet <vicente.botet_at_[hidden]> wrote:
>
> The iterator can depend on the Allocator::pointer but this doesn't forcerly means that it depends on the Allocator. If Allocator::pointer is a typedef to a type idependent of Allocator the independency is ensured.
>
> In addition we could make iterator depend on Allocator::void_pointer and use pointer_traits<>::rebind.
>
> Am I missing something?
If the node contains a pointer to node, then to work out the type of
the pointer, you need to know the type of the node. But you can't know
that until you know the type of the pointer. For example:
template <typename NodePtr>
struct node
{
NodePtr next_;
};
How do you write the node typedef? What's the ??? parameter in:
typedef typename node<
typename Allocator::template rebind<???>::other::pointer
> node_type;
But if you use allocator:
template <typename Allocator>
struct node
{
typedef typename
Allocator::template rebind<node>::other::pointer
node_ptr;
node_ptr next_;
};
typedef node<Allocator> node_type;
IIRC C++0x is going to introduce a trait for this purpose, so we'll be
able to write something like:
template <typename VoidPtr>
struct node
{
typedef typename
convert_pointer<VoidPtr, node> node_ptr;
node_ptr next_;
};
But we can't do that until the trait is available for current custom
pointer types.
Daniel
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk