
Thanks Steven, that worked.
Christian
On Fri, Feb 15, 2008 at 1:05 PM, Steven Watanabe
Christian Henning wrote:
Hi there, I'm having a problem with using enable_if. For the sake of simplicity I have created the following test code which compiles fine.
#include <string>
#include
#include using namespace std; using namespace boost;
struct reader {};
template< typename String > struct is_string : public mpl::false_ {}; template<> struct is_stringstd::string : public mpl::true_ {};
template< typename Device > struct is_device : public mpl::false_ {}; template<> struct is_device<reader> : public mpl::true_ {};
template< typename String> struct enable_if_helper { typedef typename enable_if< typename is_string< String >::type >::type type; };
template<typename Device > void foo( typename enable_if< typename is_device<Device>::type >::type* ptr = 0 ) {}
template<typename String> void foo( typename enable_if< typename is_string<String>::type
::type* ptr = 0 )
{ foo<reader>(); }
int main(int argc, _TCHAR* argv[]) { foostd::string(); return 0; }
If I changed the string foo() interface to use the enable_if_helper the code doesn't compile anymore. Why is that?
I've changed the foo ( with the string template parameter ) to the following:
template<typename String> void foo( typename enable_if_helper< String >::type* ptr = 0 ) { foo<reader>(); }
Anyone can help me out here? I'm using Visual Studio 8.
Basically, enable_if_helper is instantiated and fails and SFINAE doesn't protect you. Use the following:
template< typename String> struct enable_if_helper : enable_if< is_string< String > > { };
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users