Boost logo

Boost Users :

Subject: Re: [Boost-users] [Proto] lazy transform is not working
From: Dave Jenkins (david_at_[hidden])
Date: 2009-04-03 16:40:56


> A bug. It's fixed now on the trunk and release branches. Thanks.

Thank you, Eric. That works, but now proto::lazy isn't working with
proto::fold.

Below is a program you posted to boost.devel on 3/29/2008, updated with
s/bind/lazy/ and s/_arg/_child/. It's giving me the following syntax error.
Any idea what's wrong?

Thanks,
Dave Jenkins

error C2664: 'Accumulator<IsValid,Value>::Accumulator(const
Accumulator<IsValid,Value> &)' : cannot convert parameter 1 from
'Accumulator<IsValid,Value>' to 'const Accumulator<IsValid,Value> &'
c:\boost\boost\proto\transform\call.hpp 156

#include <iostream>
#include <boost/assert.hpp>
#include <boost/mpl/or.hpp>
#include <boost/mpl/and.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/is_void.hpp>
#include <boost/proto/proto.hpp>
#include <boost/proto/transform.hpp>
namespace mpl = boost::mpl;
namespace proto = boost::proto;

template<typename IsValid = mpl::true_, typename Value = void>
struct Accumulator
    : IsValid
{
    template<typename Value2>
    struct validate
        : mpl::and_<
            IsValid
          , mpl::or_<
                boost::is_void<Value>
              , boost::is_same<Value, Value2>
>
>
    {};

    template<typename Sig>
    struct result;

    template<typename This, typename Value2>
    struct result<This(Value2)>
    {
        typedef Accumulator<validate<Value2>, Value2> type;
    };

    template<typename Value2>
    typename result<void(Value2)>::type
        operator ()(Value2 const &) const
    {
        return typename result<void(Value2)>::type();
    }
};

struct SameTerminals
    : proto::or_<
        proto::when<
            proto::terminal<proto::_>
            // treat the current state as a callable
            // object and pass it the value of the terminal.
          , proto::lazy<proto::_state(proto::_child)>
>
      , proto::otherwise<
            proto::fold<proto::_, proto::_state, SameTerminals>
>
>
{};

int main()
{
    int dummy = 0;
    proto::terminal<int>::type i = {0}, j = {1}, k = {2};
    proto::terminal<short>::type s = {42};

    BOOST_ASSERT( SameTerminals()(i+j*k, Accumulator<>(), dummy) );
    BOOST_ASSERT(!SameTerminals()(i+s*k, Accumulator<>(), dummy) );
}


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