"Dirk Gerrits" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Dirk Gerrits wrote:
> > Thorsten Ottosen wrote:
> >
> >> I see your point. Does anyone have a nice idea of how to detect when
the
> >> template argument is an iterator? It's easy with pairs and arrays and
the
> >> 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
that
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
    {
    private:
 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?

regards

Thorsten



_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to