[mpl] newbie question about if_c et al
Hi,
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
Any ideas on this one?
From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Jonathan Leonard
Sent: Thursday, April 02, 2009 2:13 PM
To: boost-users@lists.boost.org
Subject: [Boost-users] [mpl] newbie question about if_c et al
Hi,
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
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
, void*>::type scs(cs); // SCS == RAII wrapper around CS // do other stuff } private: typename boost::mpl::if_c
, 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
Steven Watanabe wrote:
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.
Mmm. I know that compilers do much more sophisticated optimization than this but I just figured that there was a more elegant way to express my actual intent here. Using a 'void*' when it isn't ever actually used/read seems like a 'hack' [and I don't like writing superfluous code]. However, it seems that there's no better approach in this case, so it will be fine. Thanks, Jonathan
AMDG Jonathan Leonard wrote:
Why not? Have you actually looked at what compiler optimizations do? The optimization required is really not very sophisticated.
Mmm. I know that compilers do much more sophisticated optimization than this but I just figured that there was a more elegant way to express my actual intent here. Using a 'void*' when it isn't ever actually used/read seems like a 'hack' [and I don't like writing superfluous code].
However, it seems that there's no better approach in this case, so it will be fine.
The alternative is to create a dummy class whose constructor ignores its arguments. In Christ, Steven Watanabe
Just a question on your discussion. Why not to let mpl::if choose an
appropriate overload, like:
//... somewher in c
private:
inline void functionality_impl()const/or non const
{
//make impl here
}
inline void f()
{
f
actually, specialization and not overload should be correct. But idea
remains the same.
On Tue, Apr 7, 2009 at 4:13 PM, Ovanes Markarian
Just a question on your discussion. Why not to let mpl::if choose an appropriate overload, like:
//... somewher in c
private: inline void functionality_impl()const/or non const { //make impl here }
inline void f() { f
::type>(); } template<class T> void f();
void f<ScopedCriticalSection>() { scs(cs); functionality_impl(); }
void f
() { functionlity_impl(); } Greetings, Ovanes
Nice idea! I'll do this instead.
Thanks,
Jonathan
From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Ovanes Markarian
Sent: Tuesday, April 07, 2009 7:18 AM
To: boost-users@lists.boost.org
Subject: Re: [Boost-users] [mpl] newbie question about if_c et al
actually, specialization and not overload should be correct. But idea remains the same.
On Tue, Apr 7, 2009 at 4:13 PM, Ovanes Markarian
participants (3)
-
Jonathan Leonard
-
Ovanes Markarian
-
Steven Watanabe