|
Boost : |
From: Thorsten Ottosen (nesotto_at_[hidden])
Date: 2003-03-02 16:11:21
"David Abrahams" <dave_at_[hidden]> wrote in message
news:uwujhsdy6.fsf_at_boost-consulting.com...
> "Thorsten Ottosen" <nesotto_at_[hidden]> writes:
> > I see your point. Does anyone have a nice idea of how to detect when the
> > template argument is an iterator?
>
> Sadly, there is no reliable way. The closest thing I can imagine is
> to use SFINAE to check that iterator_traits<T> has valid types, and
> that the types are consistent with the iterator requirements.
I imagine that will be rather non-portable (Comeau and ?). This seems to
work for como, gcc3.2, vc7:
template< typename C, typename T, typename D,
typename P, typename R >
true_t is_iterator( const std::iterator<C,T,D,P,R>& );
template< typename C >
true_t is_iterator( const std::back_insert_iterator<C>& );
template< typename C >
true_t is_iterator( const std::front_insert_iterator<C>& );
template< typename C >
true_t is_iterator( const std::insert_iterator<C>& );
template< typename T, typename C, typename Tr >
true_t is_iterator( const std::istream_iterator<T,C,Tr>& );
template< typename T, typename C, typename Tr >
true_t is_iterator( const std::ostream_iterator<T,C,Tr>& );
template< typename C, typename Tr >
true_t is_iterator( const std::istreambuf_iterator<C,Tr>& );
template< typename C, typename Tr >
true_t is_iterator( const std::ostreambuf_iterator<C,Tr>& );
false_t is_iterator( ... );
but I'm wondering if that is enough. Can anybody come up with some cases
which will fail here and which is important?
regards
Thorsten
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk