Boost logo

Boost :

From: Daniel Frey (daniel.frey_at_[hidden])
Date: 2003-10-02 05:31:10

Neal D. Becker wrote:
> On Wednesday 01 October 2003 09:45 am, Daniel Frey wrote:
>>Neal D. Becker wrote:
>>>A nice addition to type_traits would be: is_complex.
>>Seems like a very special case. How about something more generic:
>>is_template_base< std::complex, T >::value
>>Although the number of template parameters might be a problem. For 1
>>parameter, it might look like this:
> Why do you say "Seems like a very special case"?

Because complex is just one of many classes you might want to detect,
unlike is_integral which only detects a limited set of types which
doesn't change. I played with some ideas and I have a working
implementation for is_template<T>::value and template_traits<T>::arity
now. It's tested on GCC 2.95.3, GCC 3.3 and Intel 7.1.

Currently it lacks certain features, like

- non-type template parameters are not supported yet
- I need a way to extract the n-th parameter type

But I think it's possible now that I can detect the arity.

For the GCC, I can also detect the number of non-default parameters with
template_traits<T>::minimum_arity, although the name "minimum_arity" is
ugly and it relies on what I think is a bug in the GCC, so this might
not be generally possible :)

I think I can also extend it to provide something like
template_traits<T>::template base::is< complex >::value or something,
but I haven't found enough time yet to implement it.

@Neal: You can also use this to detect all complex<F>, vector<F>,
allocator<F> for whatever F without the need to write a new
implementation each time.

Anyway, I think that template_traits might be generally interesting. If
there is interest, I can show the code I have here or - if it is
considered more appropriate - at c.l.c++.m

@John: I think that the template-traits would nicely fit into the
type-traits library, possible even in N1424 if it's not too late. My
main problem in the moment is time, but if you are interested, I will
find a way to work on it. Of course, any help is also appreciated :)

Regards, Daniel

Daniel Frey
aixigo AG - financial training, research and technology
Schloß-Rahe-Straße 15, 52072 Aachen, Germany
fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99
eMail: daniel.frey_at_[hidden], web:

Boost list run by bdawes at, gregod at, cpdaniel at, john at