 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
thoth39 Guest
|
Posted: Mon May 15, 2006 7:21 pm Post subject: static_assert and SFINAE |
|
|
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
|
Posted: Tue May 16, 2006 10:21 am Post subject: Re: static_assert and SFINAE |
|
|
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 |
|
 |
|
|
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
|
|