|
Boost : |
From: Daniel Wallin (dalwan01_at_[hidden])
Date: 2003-01-21 20:41:28
Given the recent discussions on policy based pointers and arbitrary parameter
order I thought I'd see if there is any interest in some policy extraction
template's
I recently wrote.
The idea here is that the user specifies a set of parameters, a set of
rules by which
to extract the policy types and a set of default values. The
extract_policies template
then extracts the matched types and makes them easily accessible through
numbered typedefs.
My implementation currently lacks several important error checking
features, like
checking to see that parameter types cannot be extracted by any of the
rules, or
that several rules match a parameter type. These should be fairly easy to
implement
though.
Note the use of policy<T> as base for policy tags. This is used to simplify the
rule-specification:
storage_policy_tag -> is_base_and_derived<storage_policy_tag, _1>
usage sample:
---------------------------------
struct storage_policy_tag : policy<storage_policy_tag> {};
struct ownership_policy_tag : policy<ownership_policy_tag> {};
struct default_storage : storage_policy_tag {};
struct heap_storage : storage_policy_tag {};
struct default_ownership : ownership_policy_tag {};
struct ref_counted : ownership_policy_tag {};
template<class T, class P1 = unspecified, class P2 = unspecified, class P3
= unspecified>
struct my_policy_based_thing
{
typedef extract_policies<
mpl::vector<P1,P2,P3>
, mpl::vector<
storage_policy_tag
, ownership_policy_tag
, mpl::logical_not<
mpl::logical_or<
boost::is_base_and_derived<storage_policy_tag,
mpl::_1>
,
boost::is_base_and_derived<ownership_policy_tag, mpl::_1>
> >
>
, mpl::vector<default_storage, default_ownership, void*>
> policies;
typedef typename policies::policy0 storage_policy_t;
typedef typename policies::policy1 ownership_policy_t;
typedef typename policies::policy2 any_type_t;
};
Daniel Wallin, dalwan01_at_[hidden]
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk