boost::proto lazy vector example

Since I have problems with using grammars in my examples, I started from the lazy_vector example and see if I could incrementally change it to match my situation. As it is, the code doesn't compile for me. I had to make two changes, one trivial and one that I'd like to check with Eric. The trivial one is: template<typename Expr> result_type operator()( Expr const & expr, lazy_subscript_context & ctx ) const changed to: template<typename E> result_type operator()( E const & expr, lazy_subscript_context & ctx ) const in order not to shadow the outher Expr. This is an error in gcc, might be a warning with other compilers. The one I'd like to know about is this: template< typename T > struct lazy_vector : lazy_vector_expr< typename proto::terminal< std::vector<T> >::type > { typedef typename proto::terminal< std::vector<T> >::type expr_type; lazy_vector( std::size_t size = 0, T const & value = T() ) : lazy_vector_expr( expr_type::make( std::vector<T>( size, value ) ) ) {} .... which I had to change, mirroring the code in my integer-wrapping example, into: typedef lazy_vector_expr<typename proto::terminal< std::vector<T> >::type> expr_type; lazy_vector( std::size_t size = 0, T const & value = T() ) : expr_type( expr_type::type::make( std::vector<T>( size, value ) ) ) {} I have to say that I've no idea about what either really does, only that mine compiles. Even with these changes, the following line: v1 += v2 - v3; gives a ambiguity for the overload of operator +=. Eric, if you have a complete lazy_vector example that does compile, it would be helpful to put it in the test or example directory, so that people can avoid problems with extracting code from the documentation. Best regards, Maurizio

Maurizio Vitale wrote:
Since I have problems with using grammars in my examples, I started from the lazy_vector example and see if I could incrementally change it to match my situation.
As it is, the code doesn't compile for me. I had to make two changes, one trivial and one that I'd like to check with Eric.
That shows what I get when I only test with one compiler. It works fine with MSVC-8.0. :-(
The trivial one is: template<typename Expr> result_type operator()( Expr const & expr, lazy_subscript_context & ctx ) const changed to: template<typename E> result_type operator()( E const & expr, lazy_subscript_context & ctx ) const in order not to shadow the outher Expr. This is an error in gcc, might be a warning with other compilers.
Actually, the better fix to to remove "template<typename Expr>" -- operator() doesn't need to be a template.
The one I'd like to know about is this: template< typename T > struct lazy_vector : lazy_vector_expr< typename proto::terminal< std::vector<T> >::type > { typedef typename proto::terminal< std::vector<T> >::type expr_type;
lazy_vector( std::size_t size = 0, T const & value = T() ) : lazy_vector_expr( expr_type::make( std::vector<T>( size, value ) ) ) ------------------^^^^^^^^^^^^^^^^
Whoops, that needs to be lazy_vector_expr<expr_type>.
Even with these changes, the following line: v1 += v2 - v3; gives a ambiguity for the overload of operator +=.
That may be a gcc bug, I'll need to check. But regardless, it only reinforces the point of the example that you need to disable proto's operator+=. The rest of the example shows you how.
Eric, if you have a complete lazy_vector example that does compile, it would be helpful to put it in the test or example directory, so that people can avoid problems with extracting code from the documentation.
Done. I've also patched up the docs. -- Eric Niebler Boost Consulting www.boost-consulting.com
participants (2)
-
Eric Niebler
-
Maurizio Vitale