Boost logo

Boost Users :

Subject: Re: [Boost-users] [mpl] newbie question about if_c et al
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-04-06 12:52:08


AMDG

Jonathan Leonard wrote:
> I'm trying to make a class which is conditionally synchronized. What I have is like the following:
>
> template<bool SYNCH=true>
> class c
> {
> public:
> void f()
> {
> typename boost::mpl::if_c<SYNCH, ScopedCriticalSection<>,
> void*>::type scs(cs); // SCS == RAII wrapper around CS
> // do other stuff
> }
>
> private:
> typename boost::mpl::if_c<SYNCH, CriticalSection<>, void*>::type cs;
> };
>
> This is not entirely optimal though as it requires 3 MOV instructions to create the scs void* copy when SYNCH is false (and I'd rather not lean on compiler optimizations even if they will help in this case).

Why not? Have you actually looked at what compiler optimizations do?
The optimization required is really not very sophisticated.

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