boost::enable_if related code fails to compile on VC++8.0

P

Philipp Reh

Dear group,

I recently tried to port some of my code to a VC++8.0 environment. I
noticed that some boost::enable_if related code fails to compile there
which works under gcc.
I've made a minimal example to illustrate the matter.


#include <boost/utility/enable_if.hpp>

namespace test
{

template<typename T> struct traits {
enum { two_params = false };
};

template<> struct traits<int> {
enum { two_params = true };
};

class foo {
public:
template<typename T>
typename boost::enable_if_c<traits<T>::two_params == false,
void>::type test_fun(int);

template<typename T>
typename boost::enable_if_c<traits<T>::two_params == true,
void>::type test_fun(int,int);
};

}

template<typename T>
typename boost::enable_if_c<test::traits<T>::two_params == false,
void>::type test::foo::test_fun(int)
{
}

template<typename T>
typename boost::enable_if_c<test::traits<T>::two_params == true,
void>::type test::foo::test_fun(int,int)
{
}

int main()
{
test::foo f;
f.test_fun<int>(1,2);
}

It fails with saying that it can't find a matching definition to and
existing declaration for both of the function definitions.
I would like to know if this code is standard compilant or not.
And please excuse the little use of a boost helper class.
 
K

kwikius

It fails with saying that it can't find a matching definition to and
existing declaration for both of the function definitions.
I would like to know if this code is standard compilant or not.
And please excuse the little use of a boost helper class.

I cant answer whether its compliant but SFINAE is known to be
problematic.

FWIW the following version does seem to compile OK, changing the use
of enable_if_c to enable_if. Possibly this works because the
evaluation is done later when types are used. ( could also try
lazy_enable_if_c)

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

namespace test {

/* template<typename T> struct traits {
enum { two_params = false };
};

template<> struct traits<int> {
enum { two_params = true };
}; */

template<typename T> struct traits : boost::false_type{};

template<> struct traits<int> : boost::true_type{};

class foo {
public:
template<typename T>
typename boost::enable_if<
traits said:
>::type test_fun(int);

template<typename T>
typename boost::enable_if<
traits said:
>::type test_fun(int,int);

};
}


template<typename T>
typename boost::enable_if<
test::traits said:
test::foo::test_fun(int)
{
}


template<typename T>
typename boost::enable_if<
test::traits said:
::type test::foo::test_fun(int,int)
{
}


int main()
{
test::foo f;
f.test_fun<int>(1,2);
}

regards
Andy Little
 
P

Philipp Reh

It fails with saying that it can't find a matching definition to and
existing declaration for both of the function definitions. I would like
to know if this code is standard compilant or not. And please excuse
the little use of a boost helper class.

I cant answer whether its compliant but SFINAE is known to be
problematic.

FWIW the following version does seem to compile OK, changing the use of
enable_if_c to enable_if. Possibly this works because the evaluation is
done later when types are used. ( could also try lazy_enable_if_c)
[snip]
regards
Andy Little

Thank you very much. This seems to be a good workaround.

Greetings,
Philipp
 

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,981
Messages
2,570,188
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top