Boost logo

Boost :

From: Thorsten Ottosen (nesotto_at_[hidden])
Date: 2003-03-02 15:27:54

"Dirk Gerrits" <dirk_at_[hidden]> wrote in message
> Dirk Gerrits wrote:
> > Thorsten Ottosen wrote:
> >
> >> I see your point. Does anyone have a nice idea of how to detect when
> >> template argument is an iterator? It's easy with pairs and arrays and
> >> default case is containers.
> >
> >
> > Perhaps you can use Boost's concept check to see if the template
> > argument models the Input Iterator concept? That's the first thing that
> > came to mind, I haven't tried it out or anything.
> On second thought, that won't work. Concept check causes a compilation
> error when the argument does not conform to the concept.
> Perhaps you can do it the other way around? Check for a T::begin member
> function to see if the type is a container, and assume the type is an
> iterator in the default case? I'm not sure what that check would look
> like though.

I can't come up with any reason that it should be easier to detect a
container. Here's my initial attempt for iterators based on the assumption
all important iterators have derived from std::iterator:

     template< typename C, typename T, typename D,
        typename P, typename R >
      true_t is_iterator( const std::iterator<C,T,D,P,R>& );
     false_t is_iterator( ... );

    template< typename C >
    struct container_traits
 static C& c;
 BOOST_STATIC_CONSTANT( bool, is_iterator =
          sizeof( detail::container::is_iterator( c ) )
          == sizeof( detail::container::true_t ) );

but it doesn't seem to work for eg. an ostream iterator. Does anyone know if
the binding in is_iterator is possible with all these templates involved?



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