It already works. If you want to detect STL sequence-ness, you'll have to try some nasty hacks. I'm have doubts about whether it's even possible to approximate that metafunction in portable code.
Wouldn't something about these lines work? template<typename T> char test( T const&, long ); template<typename T> int test( std::list<T> const&, int ); template<typename T> struct is_list { static T t; enum { value = sizeof( test( t, 0 ) ) == 4; } }; Gennadiy.
On Tuesday 11 May 2004 19:09, Rozental, Gennadiy wrote:
It already works. If you want to detect STL sequence-ness, you'll have to try some nasty hacks. I'm have doubts about whether it's even possible to approximate that metafunction in portable code.
Wouldn't something about these lines work?
template<typename T> char test( T const&, long );
template<typename T> int test( std::list<T> const&, int );
template<typename T> struct is_list { static T t; enum { value = sizeof( test( t, 0 ) ) == 4; } };
Thanks for the hint, but I think this would only detect lists - not other sequence (vector, deque, possible user defined sequences). In case someone is interested: My original objective was to distinguish OutputIterators and Sequences. So I settled for a solution that checks if the type has a nested type "iterator". Of course, that does not suffice to establish a Sequence, but for my application it is good enough... Wolfgang Meyer
participants (2)
-
Rozental, Gennadiy
-
Wolfgang Meyer