Boost logo

Boost :

From: cedric\.venet (cedric.venet_at_[hidden])
Date: 2005-07-21 06:17:50


> >
> > struct MySingletonCategory;
> >
> > // must provide specializations in singleton namespace
> > namespace boost { namespace singleton {
> >
> > // the following specifies that multi threading will be
used for
> > singletons which use MySingletonCategory
> > template < >
> > struct threading_policy < MySingletonCategory >
> > {
> > typedef multi_threaded type;
> > };
>
> This should be called *trait* not a policy. Policy is type
orthogonal. And
> btw I don't think traits-based solution will work here. I
most definitely
> may want different threading policies for the same singleton
type in
> different circumstances.
>

why not simply pass the category as a template parameter:

struct MyCategory ;

namespace boost { namespace singleton {

template < >
struct threading_policy < MyCategory >
{
typedef multi_threaded type;
};

} } // close namespace

void test ( )
{
singleton_ptr < MySingletonType,MyCategory > ptr;
}

you can have the same category for many type but also
many category for one type.

if you really want no policy in the type declaration, you
can provide a default who would search for a type declared
category as in your code (I am not very understandable I think,
perhaps the following code while be more explicit):

struct defaultcategory;

tempate< class T, class category_param = defaultcategory >
class singleton_ptr {
typedef mpl::if<
   mpl::IsSame<category_param,defaultcategory>,
   category<T>::type,
   category_param>::type the_category;
...
};

the syntaxe is perhaps not correct but it's the principe
who count.

so you can use:

struct another_type;
template<> category<another_type> {
typedef MT_category type;
};

int main() {
  singleton_ptr<MyType> a_defaut_singleton;
  singleton_ptr<another_type> a_MT_singleton;
  singleton_ptr<MyType,MT_category> another_MT_singleton;
}

perhaps it don't work, or it's stupid, but perhaps
it can help you. And sorry for my poor english.

you can also want to read the papers here:
http://www.prakinf.tu-ilmenau.de/~czarn/cpe2000/

--(space [webmail cut my space :( )
Cédric Venet
ECP student

Accédez au courrier électronique de La Poste : www.laposte.net ;
3615 LAPOSTENET (0,34€/mn) ; tél : 08 92 68 13 50 (0,34€/mn)


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk