How to test if a type is of some form?

Hi, I want to test if template argument is of some form like in the following code. I could define some helper class to do such test. But I'm wondering if there is any easy to do it with boost? The type_traits's is_same does not work in this case. I'm wondering if there could be some generalization of it. template <T> void f() { //For example, I want to test if T is of the // form of std::complex<S> } Thanks, Peng

2008/9/24 Peng Yu <pengyu.ut@gmail.com>
Hi,
I want to test if template argument is of some form like in the following code. I could define some helper class to do such test. But I'm wondering if there is any easy to do it with boost? The type_traits's is_same does not work in this case. I'm wondering if there could be some generalization of it.
template <T> void f() { //For example, I want to test if T is of the // form of std::complex<S>
}
Thanks, Peng
Take a look at boost::lambda::is_instance_of (boost/lambda/detail/is_instance_of.hpp). template <class T> void f() { if (boost::lambda::is_instance_of<T, std::complex>::value) std::cout << "T is an instance of std::complex" << std::endl; else std::cout << "T is not an instance of std::complex" << std::endl; } Note: code resides in the detail directory meaning that it's not part of the public interface. Roman Perepelitsa.

Peng Yu wrote:
Hi,
I want to test if template argument is of some form like in the following code. I could define some helper class to do such test. But I'm wondering if there is any easy to do it with boost? The type_traits's is_same does not work in this case. I'm wondering if there could be some generalization of it.
template <T> void f() { //For example, I want to test if T is of the // form of std::complex<S> }
Have you looked at the Type Traits library, is_same, remove_cv, ... Jeff

Peng Yu wrote:
Hi,
I want to test if template argument is of some form like in the following code. I could define some helper class to do such test. But I'm wondering if there is any easy to do it with boost? The type_traits's is_same does not work in this case. I'm wondering if there could be some generalization of it.
template <T> void f() { //For example, I want to test if T is of the // form of std::complex<S>
}
Thanks, Peng
http://www.boost.org/doc/libs/1_36_0/libs/type_traits/doc/html/boost_typetra... --Johan
participants (4)
-
Jeff Flinn
-
Johan Råde
-
Peng Yu
-
Roman Perepelitsa