By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,409 Members | 938 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,409 IT Pros & Developers. It's quick & easy.

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

P: n/a
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 Tstruct 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.
Mar 18 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 18 Mar, 13:43, Philipp Reh <s...@s-e-f-i.dewrote:
<...>
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 Tstruct traits {
enum { two_params = false };
};

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

template<typename Tstruct traits : boost::false_type{};

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

class foo {
public:
template<typename T>
typename boost::enable_if<
traits<T>
>::type test_fun(int);
template<typename T>
typename boost::enable_if<
traits<T>
>::type test_fun(int,int);
};
}
template<typename T>
typename boost::enable_if<
test::traits<T>
>::type
test::foo::test_fun(int)
{
}
template<typename T>
typename boost::enable_if<
test::traits<T>,
void
>::type test::foo::test_fun(int,int)
{
}
int main()
{
test::foo f;
f.test_fun<int>(1,2);
}

regards
Andy Little

Mar 19 '07 #2

P: n/a
On Mon, 19 Mar 2007 03:31:45 -0700, kwikius wrote:
On 18 Mar, 13:43, Philipp Reh <s...@s-e-f-i.dewrote: <...>
>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
Mar 19 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.