C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

static_assert and SFINAE

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
thoth39
Guest





PostPosted: Mon May 15, 2006 7:21 pm    Post subject: static_assert and SFINAE Reply with quote



Should this work?

template <bool condition, typename T>
enable_if
{
static_assert(condition, "overload not enabled");
typedef T type;
};

I don't think I understand SFINAE completely.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Carl Barron
Guest





PostPosted: Tue May 16, 2006 10:21 am    Post subject: Re: static_assert and SFINAE Reply with quote



In article <1147707917.848787.179660 (AT) j33g2000cwa (DOT) googlegroups.com>,
thoth39 <pedro.lamarao (AT) gmail (DOT) com> wrote:

Quote:
Should this work?

template <bool condition, typename T
enable_if
{
static_assert(condition, "overload not enabled");
typedef T type;
};

I don't think I understand SFINAE completely.

no this generates an error if condition is false it SFINAE does not

generate errors but uses an invalid syntax to eliminate candidates
from the compiler.

template <bool B,typename T=void>
struct enable_if{};

template <typename T>
struct enable_if<true,T>
{
typedef T type;
};

template <class C>
void foo(C x, typename enable_if<condition>::type *=0) {/* 1 */}

template <class C>
void foo(C x, typename enable_if<!condition>::type *=0){/* 2 */}

if condition is a compile time constant convertable to bool and the
boolean value is true /* 1 */ is a candidate but /* 2 */ is not since
enable_if<false> has no member type type. That is the gist of
enable_if.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.