what happened to my sfinae?

B

Belebele

in t.cpp:

#include <boost/type_traits.hpp>
#include <boost/utility.hpp>

template <typename T>
struct Foo {
typename boost::enable_if<boost::is_pointer<T>, void>::type
bar(T ) const {
}

typename boost::disable_if<boost::is_pointer<T>, void>::type
bar(T ) const {
}
};


void call_bar()
{
Foo<int>().bar(5);
}

// end

$ g++ -c -I/my/path/to/boost t.cpp
t.cpp: In instantiation of 'Foo<int>':
t.cpp:18: instantiated from here
t.cpp:7: error: no type named 'type' in 'struct
boost::enable_if<boost::is_pointer ....

$ g++ --v
gcc version 4.1.2

What happen to my sfinae?

Thanks
 
A

Alf P. Steinbach /Usenet

* Belebele, on 14.02.2011 23:25:
in t.cpp:

#include<boost/type_traits.hpp>
#include<boost/utility.hpp>

template<typename T>
struct Foo {
typename boost::enable_if<boost::is_pointer<T>, void>::type
bar(T ) const {
}

typename boost::disable_if<boost::is_pointer<T>, void>::type
bar(T ) const {
}
};


void call_bar()
{
Foo<int>().bar(5);
}

// end

$ g++ -c -I/my/path/to/boost t.cpp
t.cpp: In instantiation of 'Foo<int>':
t.cpp:18: instantiated from here
t.cpp:7: error: no type named 'type' in 'struct
boost::enable_if<boost::is_pointer ....

$ g++ --v
gcc version 4.1.2

What happen to my sfinae?

It wasn't there in the first place.

Try


#include <boost/type_traits.hpp>
#include <boost/utility.hpp>

struct Foo {
template <typename T>
typename boost::enable_if<boost::is_pointer<T>, void>::type
bar(T ) const {
}

template <typename T>
typename boost::disable_if<boost::is_pointer<T>, void>::type
bar(T ) const {
}
};


void call_bar()
{
Foo().bar<int>(5);
}

// end



Cheers & hth.,

- Alf
 
M

Marc

Alf P. Steinbach /Usenet" said:
* Belebele, on 14.02.2011 23:25:

It wasn't there in the first place.

However, I regularly wish it was. There are a number of things that
are doable but painful with templates. Applying sfinae more widely
would help some. static_if (somewhere between #if and if) would also
be very convenient. Assuming they can be given sensible semantics of
course.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,962
Messages
2,570,134
Members
46,692
Latest member
JenniferTi

Latest Threads

Top