Boost logo

Boost Users :

Subject: Re: [Boost-users] [enable_if] Doesn't work for static member functions ?
From: Jeremiah Willcock (jewillco_at_[hidden])
Date: 2009-09-23 17:00:57


On Wed, 23 Sep 2009, Jean-Louis Leroy wrote:

> Consider :
>
> template<typename U>
> struct Test {
> template<typename T>
> typename enable_if<is_same<T, int>, void>::type test() {
> cout << "int" << endl;
> }
>
> template<typename T>
> typename enable_if<is_same<T, char>, void>::type test() {
> cout << "char" << endl;
> }
> };
>
> template<typename T>
> typename enable_if<is_same<T, int>, void>::type test() {
> cout << "int" << endl;
> }
>
> template<typename T>
> typename enable_if<is_same<T, char>, void>::type test() {
> cout << "char" << endl;
> }
>
> int _tmain(int argc, _TCHAR* argv[])
> {
> test<int>();
> test<char>();
> Test<int>::test<double>(); // error
> return 0;
> }
>
> MSVC9 will give a compilation error (see below) where marked. Am I missing
> something obvious ?

For one thing, your functions are not static. The actual problem is that
SFINAE applies to template argument deduction, and does not work with
explicitly specified template arguments. You would need to have T deduced
in each of the member functions to have SFINAE (and thus enable_if) work.

-- Jeremiah Willcock


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