
On Fri, Mar 7, 2008 at 4:32 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
AMDG
Giovanni Piero Deretta wrote:
It seems a perfect application for fold:
template<typename Seq> struct or_seq : mpl::apply< mpl::fold<mpl::_1, mpl::false_, mpl::quote2<mpl::or_> > , Seq > {};
template<typename Seq> struct and_seq : mpl::apply< mpl::fold<mpl::_1, mpl::true_, mpl::quote2<mpl::and_> > , Seq > {};
Not quite, because we want it to short circuit.
Hum, I think it actually does short circuit evaulation (haskel-like): struct bad {}; typedef mpl::vector<mpl::false_, mpl::false_, bad> ffb_v; typedef mpl::vector<mpl::false_, mpl::false_, fail> tfb_v; or_seq<ffb_v> gives the expected compile time error (error: no type named 'type' in 'struct fail') , while or_seq<tfb_v> compiles fine (and yelds true).
Not to mention that quote2 will not work on and_ and or_.
I now see that and_ and or_ take n parameters, so the compiler should complain about quote2. (it did work for me because of the gcc extension that allows a template with default parameters to match a template template argument with less parameters.) This should fix the problem: template<typename Seq> struct or_seq : mpl::apply< mpl::fold<mpl::_1, mpl::false_, mpl::lambda<mpl::or_<mpl::_,mpl::_> > > , Seq
{};
Not shorter than your solution, but it is an MPL only solution. Playing with MPL is always fun :). -- gpd
In Christ, Steven Watanabe
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost