|
Boost Users : |
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2008-08-30 16:26:41
AMDG
Hicham Mouline wrote:
> Hello,
>
> i have 2 choices:
>
> 1) runtime
>
> class BaseD
> class D1 .... D200 derived from BaseD (all of them singletons,
> don't really store any data in them, they just provide policy)
>
> and class C1... C100 (also all derived from BaseC)
> for each Cxxx, there is a perferred D to deal with it, but "some" other Ds work also...
> the library user creates instances of Cxxx,
> I could then have a global runtime std::map<BaseC&, BaseD&>, that stores singletons of Cxxx,
> and preferred Dxxx
>
> 2) compiletime
> or i could store this mpl::map<> to associate each type Cxxx with its favorite Dxxx
> i suppose i could construct this by extending in each header file (for each Cxxx),
> the mpl::map with the Cxxx and its associated Dxxx
>
Remember that all mpl sequences are immutable.
> Any comments are appreciated re this choice,
> for e.g. the max number of elts for map<>
>
I doubt that an MPL map would work well. The default
limit is 50 elements.
My personal preference in this case would be to use specialization:
template<class C>
struct preferedD;
template<>
struct preferedD<C1> {
typedef Dx type;
};
//...
In Christ,
Steven Watanabe
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net