#include #include namespace proto=boost::proto; class value_base { public: virtual ~value_base() { } virtual value_base* clone() const = 0; /* new */ virtual void display() const = 0; }; template class value_type : public value_base { T t; public: value_type(const T& t_) : t(t_) { } value_base* clone() const /* new */ { return new value_type(t); } void display() const { proto::display_expr(t); } }; struct apply_tag {}; class function { value_base* v; public: function() : v(0) { } template function(const value_t& v_) : v(new value_type(v_)) { } /* new */ function(function const & other) : v(other.v ? other.v->clone() : 0) {} /* new */ function& operator=(const function& other) { if(&other != this) { function copy(other); swap(copy); } return *this; } /* new */ void swap(function& other) { std::swap(v, other.v); } ~function() { delete v; } template typename proto::result_of::make_expr< proto::tag::function, apply_tag, const function &, const A0 & >::type const operator()(const A0 &a0) const { return proto::make_expr( apply_tag(), boost::ref(*this), boost::ref(a0) ); } void display() const { v->display(); } };