Understanding how enable_if works.

Hi, I'm new to boost / generic programming and I'm trying to understand how enable_if works because I don't like using things I don't understand. I made a simple example which I thought would have the same behavior as using enable_if but doesn't. I've attached the test could someone take a look and explain why enable_if works and the other doesn't. Thanks begin 666 main.cpp M(VEN8VQU9&4@/&)O;W-T+W5T:6QI='DO96YA8FQE7VEF+FAP<#X-"B-I;F-L M=61E(#QI;W-T<F5A;3X-"@T*;F%M97-P86-E(%1E<W1"<F]K96X-"GL-"@ET M96UP;&%T93P@8VQA<W,@5" ^#0H)<W1R=6-T(%1E<W14<F%I= T*"7L-"@E] M.PT*#0H)=&5M<&QA=&4\/@T*"7-T<G5C="!497-T5')A:70\:6YT/@T*"7L- M"@D)='EP961E9B!I;G0@96YA8FQE7W1Y<&4[#0H)?3L-"@T*"71E;7!L871E M/"!C;&%S<R!4+"!C;&%S<R!%;F%B;&4@/2!V;VED(#X-"@ES=')U8W0@16YA M8FQE5&5S= T*"7L-"@D)16YA8FQE5&5S="@I#0H)"7L-"@D)"7-T9#HZ8V]U M=" \/" B1V5N97)I8R!%;F%B;&4@5&5S="!C;VYS=')U8W1E9"(@/#P@<W1D M.CIE;F1L.PT*"0E]#0H)?3L-"@T*"71E;7!L871E/"!C;&%S<R!4(#X-"@ES M=')U8W0@16YA8FQE5&5S=#P@5"P@='EP96YA;64@5&5S=%1R86ET/%0^.CIE M;F%B;&5?='EP92 ^#0H)>PT*"0E%;F%B;&5497-T*"D-"@D)>PT*"0D)<W1D M.CIC;W5T(#P\(")3<&5C:6%L:7IE9"!%;F%B;&4@5&5S="!C;VYS=')U8W1E M9"(@/#P@<W1D.CIE;F1L.PT*"0E]#0H)?3L-"GT-"@T*;F%M97-P86-E(%1E M<W17;W)K:6YG#0I[#0H)=&5M<&QA=&4\(&-L87-S(%0@/@T*"7-T<G5C="!I M<U]I;G0-"@E[#0H)"7-T871I8R!C;VYS="!B;V]L('9A;'5E(#T@9F%L<V4[ M#0H)?3L-"@T*"71E;7!L871E/#X-"@ES=')U8W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@(D9L;V%T.B(@/#P@<W1D.CIE;F1L.PT*"7M4 M97-T0G)O:V5N.CI%;F%B;&5497-T/&9L;V%T/B!T96UP.WT-"@T*"7-T9#HZ M8V]U=" \/" B26YT.B(@/#P@<W1D.CIE;F1L.PT*"7M497-T0G)O:V5N.CI% M;F%B;&5497-T/&EN=#X@=&5M<#M]#0H-"@ES=&0Z.F-O=70@/#P@(D)O;VPZ M(B \/"!S=&0Z.F5N9&P[#0H)>U1E<W1"<F]K96XZ.D5N86)L951E<W0\8F]O :;#X@=&5M<#M]#0H-"@ER971U<FX@,#L-"GT` ` end

"Michael Marcin" <mmarcin@method-solutions.com> writes:
Hi,
I'm new to boost / generic programming and I'm trying to understand how enable_if works because I don't like using things I don't understand.
I made a simple example which I thought would have the same behavior as using enable_if but doesn't.
I've attached the test could someone take a look and explain why enable_if works and the other doesn't.
Thanks
#include <boost/utility/enable_if.hpp> #include <iostream>
namespace TestBroken { template< class T > struct TestTrait { };
template<> struct TestTrait<int> { typedef int enable_type; ^^^ };
template< class T, class Enable = void > struct EnableTest { EnableTest() { std::cout << "Generic Enable Test constructed" << std::endl; } };
It doesn't work because your specialization doesn't match the default. Change the indicated int to void and it should work for you. -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (2)
-
David Abrahams
-
Michael Marcin