|
Boost Users : |
Subject: Re: [Boost-users] challange to MPL gurus
From: Larry Evans (cppljevans_at_[hidden])
Date: 2011-12-12 18:04:33
On 12/12/11 16:39, Jeremiah Willcock wrote:
[snip]
> 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
Hi Jeremiah,
After adding the #include's shown in the attached, I got warning:
k/boost/mpl/print.hpp:55:10: warning: comparison between signed and
unsigned integer expressions [-Wsign-compare]
Simply rm'ing the print typedef solved the problem and seems harmless
since the t1 is not used anywhere.
Looking at your code, it seems you solved the problem by removing
the nested specialization of is_end, with a specialization in file
scope of check_unless_end. I've a vague memory of hearing some similar
solution elsewhere. Is there some reason why specializations cannot
occur within the class?
-regards,
Larry
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