Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2006-08-10 20:38:29


"Michael Marcin" <mmarcin_at_[hidden]> 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

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