From: teamhyer (teamhyer_at_[hidden])
Date: 2002-01-21 03:56:45
--- In boost_at_y..., "Andrei Alexandrescu"
> <andrewalex_at_h...> wrote:
> I think a good solution would be the following.
> The policies might take two template arguments, the last one being
the SmartPtr class itself. In turn, SmartPtr exposes all of its
policies through typedefs. Here's a trimmed-down example.
> template <
> class T,
> template <class, class> class Checking>
> template <class, class> class Storage>
> class SmartPtr
> : public Checking< T, SmartPtr<T, Checking, Storage> >
> : public Storage< T, SmartPtr<T, Checking, Storage> >
> typedef Checking checking_policy;
> typedef Storage storage_policy;
> So now the policies that don't care of each
> other simply ignore
> their second template parameter. Policies that
> do need to
> communicate with neighbouring policies can
> access them by
> using the parent class and their named typedefs.
I'm very suspicious of this proposed solution. It's closely
analogous to (in non-template C++ programming) passing *this
rather than extracting the relevant members "so we won't have to
worry about the details of communication". Like that strategy,
it will have the effect of denying the user the knowledge of which
parameters truly are needed -- it will make complicated things
appear simple on the surface, and make truly simple things
indistinguishable from them. Happily, policies are often truly
I'm perfectly content for non-orthogonal policies to _explicitly_
demand knowledge of each other.
On a more practical level, this would also be a problem if (say)
a checking policy and a storage policy were later
asked to coexist somewhere else besides in SmartPtr.
Am I making a false analogy here?
Perhaps helper (meta)functions could contribute to a solution
(very rough example):
template<template<class> class Storage_, class Ownership>
typedef Storage_<Ownership> Storage;
// ... lots of compile-time assertions of compatibility ...
template<template<class> class Storage_, class Ownership, ...>
public SmartPtrImp<StorageAndOwnership<Storage_, Ownership>, ...>
-- Tom Hyer
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk