473,396 Members | 2,014 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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
2 1787
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Richard Latter | last post by:
Hello All, I am a newbie to the Boost library and I have a question about a simple function. All I would like to do is to create a simple function that can test strings using regular...
0
by: ufnuceda | last post by:
Hello everyone, I was wondering if any of you have some experience with the boost library. I am having trouble compiling code with it. Since boost is being used a lot these days I thought some...
7
by: Bo Yang | last post by:
Hi , I am reading some boost code now , and I got confused by the following code in the add_reference type trait . template <class TT&(* is_reference_helper1(wrap<T>) )(wrap<T>); char...
3
by: Christoph Bartoschek | last post by:
Hi, I try to use boost::enable_if inside of a constructor but the following code fails. How can I correct it? #include <boost/utility/enable_if.hpp> #include...
1
by: Noah Roberts | last post by:
Trying to use boost::function in a C++/CLI program. Here is code: pragma once #include <boost/function.hpp> #include <boost/shared_ptr.hpp> #include <vector> using namespace System;
5
by: mackenzie | last post by:
Hello, I am looking for a little bit of help. I am trying to create a dynamically allocated object which contains one or more objects of type boost::pool<>. I get a compiler error when an object...
1
by: werasm | last post by:
Hi, This is not boost related per sé, therefore I'm posing the question here. I need to do many small object allocations, and I'm considering using boost::pool for this. I've contemplated...
7
by: BubbaT | last post by:
What is the best way to pick up Boost? Thanks BubbaT
3
by: greek_bill | last post by:
With regards to using Boost enable_if and similar SFINAE constructs, is it right that you can only put an enable_if on the return type or as an additional parameter? Why is that? The following...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.