Boost logo

Boost Users :

Subject: Re: [Boost-users] challange to MPL gurus
From: Jeremiah Willcock (jewillco_at_[hidden])
Date: 2011-12-12 17:39:44


On Mon, 12 Dec 2011, Robert Ramey wrote:

> I am trying to implement concept checking for a couple of MPL concepts as
> part of a large project. I've having a heck of a time with some aspects of
> this.
>
> The example below illustrates one of the problems I'm having.
> The intent is to test the concept. for next<I>, the concept
> check is invoked recurrsively until the end of iteration is
> encountered. (I'm assuming it's a list in this test). But the
> is_end<false_> branch is always invoked leading to failure
> on both MSVC 9.0 and gcc 4.5.3 compilers
>
> I'll be quite impressed with anyone who can figure out
> how to make this work.

Here's my version:

template<typename I>
struct ForwardIterator;

template <typename I, typename B>
struct check_unless_end {};

template <typename I>
struct check_unless_end<I, boost::mpl::false_> {
   typedef typename boost::mpl::deref<I>::type t1;
   typedef typename boost::mpl::next<I>::type t2;
   BOOST_CONCEPT_ASSERT(( ForwardIterator<t2> ));
};

template<typename I>
struct ForwardIterator {
     typedef typename boost::mpl::print<
         I
>::type t1;
     typedef check_unless_end<
         I,
         boost::is_same<
             boost::mpl::l_iter<boost::mpl::l_end>,
             I
>
> t2;
     BOOST_MPL_ASSERT((
             boost::is_convertible<
                 typename I::category,
                 boost::mpl::forward_iterator_tag
>
     ));
};

template<typename S>
struct ForwardSequence {
   typedef typename boost::mpl::end<S>::type t2;
   BOOST_CONCEPT_ASSERT(( ForwardIterator<t2> ));
};

#include <boost/mpl/list.hpp>
void test_list_sequence(){
     BOOST_CONCEPT_ASSERT(( ForwardSequence<
             boost::mpl::list<int, char>
>
     ));
}

-- Jeremiah Willcock


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net