Portable alternative for VS.NET __if_exists

Im looking for a portable version of __if_exists (VS.NET keyword) and unfortunately google turned up nothing good. I use boost fairly regular and checked boost::type_traits but found nothing that seemed to similar. Has anyone heard of something that can accomplish this? As a side note, I got inspired by the technique used when to enable/disable template class specializations using boost::enable_if and succeeded in creating something that managed this: struct x { typedef std::string aggregated_type; }; struct y { }; int main(int, char*) { std::cout << is_aggregated_type_available<x>::value << std::endl; std::cout << is_aggregated_type_available<y>::value << std::endl; } Prints: 1 0 Which means that x has an aggregated type named aggregated_type. Unfortunately I failed miserably when trying to test for member variables and member functions. So I thought I take my chance and post my question here. Regards, Mårten Rånge PS. I want to give a big thank-you to the boost community for putting 1.32.0 together. It was worth waiting for. PS. I attached is_aggregated_type_available in case anyone is interested. Unfortunately only tested on VS.NET 2003 and VS.NET 2005 Beta 1 but it feels like it should work on more compilers due to the similarities with the examples in boost::enable_if documentation.

Mårten Rånge wrote:
I’m looking for a portable version of __if_exists (VS.NET keyword) and unfortunately google turned up nothing good.
I use boost fairly regular and checked boost::type_traits but found nothing that seemed to similar.
Has anyone heard of something that can accomplish this?
It might help if you described what it does. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com


Mårten Rånge wrote:
As a side note, I got inspired by the technique used when to enable/disable template class specializations using boost::enable_if and succeeded in creating something that managed this:
struct x { typedef std::string aggregated_type; };
struct y { };
int main(int, char*) { std::cout << is_aggregated_type_available<x>::value << std::endl; std::cout << is_aggregated_type_available<y>::value << std::endl; }
Prints: 1 0
See <boost/mpl/has_xxx.hpp> Jonathan

Jonathan Turkanis writes:
See <boost/mpl/has_xxx.hpp>
... and the docs here: http://www.boost.org/libs/mpl/doc/refmanual/has-xxx-trait-def.html -- Aleksey Gurtovoy MetaCommunications Engineering

Mårten Rånge writes:
I'm looking for a portable version of __if_exists (VS.NET keyword) and unfortunately google turned up nothing good.
I use boost fairly regular and checked boost::type_traits but found nothing that seemed to similar.
Has anyone heard of something that can accomplish this?
Besides <boost/mpl/has_xxx.hpp> facilities, see these two discussions: http://lists.boost.org/MailArchives/boost/msg76679.php http://lists.boost.org/MailArchives/boost/msg55484.php HTH, -- Aleksey Gurtovoy MetaCommunications Engineering
participants (5)
-
Aleksey Gurtovoy
-
David Abrahams
-
Jan Bares
-
Jonathan Turkanis
-
Mårten Rånge