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 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
struct check_unless_end {};
template <typename I>
struct check_unless_end {
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_iterboost::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
void test_list_sequence(){
BOOST_CONCEPT_ASSERT(( ForwardSequence<
boost::mpl::list
>
));
}
-- Jeremiah Willcock