phoenix function problem

Hi, in the example attached, the 1st test case fails on runtime: test_phoenix_fcn.cpp(105): test 'at_c<0>( rlc ) && at_c<1>( rlc ) && at_c<2>( rlc )' failed in function 'int main(int, char**)' test_phoenix_fcn: /home/olaf/Projects/programming/cpp/boost/trunk/boost/optional/optional.hpp:591: typename boost::optional_detail::optional_base<T>::reference_type boost::optional<T>::get() [with T = double]: Assertion `this->is_initialized()' failed. Aborted the 2nd (with defined WANT_TO_HAVE) doesn't compile. This is the goal. Where is my misunderstanding here? To to get it working correctly? Thanks, Olaf

On 4/23/2010 1:49 AM, Olaf Peter wrote:
Hi,
in the example attached, the 1st test case fails on runtime:
test_phoenix_fcn.cpp(105): test 'at_c<0>( rlc )&& at_c<1>( rlc )&& at_c<2>( rlc )' failed in function 'int main(int, char**)' test_phoenix_fcn: /home/olaf/Projects/programming/cpp/boost/trunk/boost/optional/optional.hpp:591: typename boost::optional_detail::optional_base<T>::reference_type boost::optional<T>::get() [with T = double]: Assertion `this->is_initialized()' failed. Aborted
the 2nd (with defined WANT_TO_HAVE) doesn't compile. This is the goal.
Where is my misunderstanding here? To to get it working correctly?
Your operator()s are wrong (C++ error, unrelated to phoenix). Try this: #if WANT_TO_HAVE template <typename T, typename ID> struct result { typedef vector_type type; }; vector_type operator()( const vector_type& v, rlc ) const { return fusion::as_nview<0, 1, 2>( v ); } vector_type operator()( const vector_type& v, lcr ) const { return fusion::as_nview<2, 0, 1>( v ); } #else Regards, -- Joel de Guzman http://www.boostpro.com http://spirit.sf.net http://www.facebook.com/djowel Meet me at BoostCon http://www.boostcon.com/home http://www.facebook.com/boostcon

Joel de Guzman schrieb:
On 4/23/2010 1:49 AM, Olaf Peter wrote:
Hi,
in the example attached, the 1st test case fails on runtime:
test_phoenix_fcn.cpp(105): test 'at_c<0>( rlc )&& at_c<1>( rlc )&& at_c<2>( rlc )' failed in function 'int main(int, char**)' test_phoenix_fcn: /home/olaf/Projects/programming/cpp/boost/trunk/boost/optional/optional.hpp:591:
typename boost::optional_detail::optional_base<T>::reference_type boost::optional<T>::get() [with T = double]: Assertion `this->is_initialized()' failed. Aborted
the 2nd (with defined WANT_TO_HAVE) doesn't compile. This is the goal.
Where is my misunderstanding here? To to get it working correctly?
Your operator()s are wrong (C++ error, unrelated to phoenix). Try this:
#if WANT_TO_HAVE template <typename T, typename ID> struct result { typedef vector_type type; };
vector_type operator()( const vector_type& v, rlc ) const { return fusion::as_nview<0, 1, 2>( v ); }
vector_type operator()( const vector_type& v, lcr ) const { return fusion::as_nview<2, 0, 1>( v ); }
#else
This fails to compile as well: g++ -DWANT_TO_HAVE -I /home/olaf/Projects/programming/cpp/boost/trunk test_phoenix_fcn.cpp -o test_phoenix_fcn && ./test_phoenix_fcn test_phoenix_fcn.cpp: In function ‘int main(int, char**)’: test_phoenix_fcn.cpp:98: error: no match for call to ‘(boost::phoenix::actor<boost::phoenix::composite<boost::phoenix::detail::function_eval<2>, boost::fusion::vector<boost::phoenix::value<rlc_reorder>, boost::phoenix::argument<0>, boost::phoenix::argument<1>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> > >) (main(int, char**)::rlc_type&, rlc_reorder::lcr)’ /home/olaf/Projects/programming/cpp/boost/trunk/boost/spirit/home/phoenix/core/actor.hpp:90: note: candidates are: typename boost::mpl::eval_if<typename Eval::no_nullary, boost::mpl::identity<boost::phoenix::detail::error_expecting_arguments>, boost::phoenix::eval_result<Eval, boost::phoenix::basic_environment<boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> >
::type boost::phoenix::actor<Eval>::operator()() const [with Eval = boost::phoenix::composite<boost::phoenix::detail::function_eval<2>, boost::fusion::vector<boost::phoenix::value<rlc_reorder>, boost::phoenix::argument<0>, boost::phoenix::argument<1>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> >] /home/olaf/Projects/programming/cpp/boost/trunk/boost/spirit/home/phoenix/core/actor.hpp:125: note: typename boost::phoenix::actor<Eval>::result<boost::phoenix::actor<Eval>(T0&, T1&)>::type boost::phoenix::actor<Eval>::operator()(T0&, T1&) const [with T0 = main(int, char**)::rlc_type, T1 = rlc_reorder::lcr, Eval = boost::phoenix::composite<boost::phoenix::detail::function_eval<2>, boost::fusion::vector<boost::phoenix::value<rlc_reorder>, boost::phoenix::argument<0>, boost::phoenix::argument<1>, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_, boost::fusion::void_> >]

On 4/23/2010 2:58 PM, Olaf Peter wrote:
Your operator()s are wrong (C++ error, unrelated to phoenix). Try this:
#if WANT_TO_HAVE template<typename T, typename ID> struct result { typedef vector_type type; };
vector_type operator()( const vector_type& v, rlc ) const { return fusion::as_nview<0, 1, 2>( v ); }
vector_type operator()( const vector_type& v, lcr ) const { return fusion::as_nview<2, 0, 1>( v ); }
#else
This fails to compile as well:
Olaf, I recommended writing the code above (see the operator() is *not* a template. Why do you still insist on writing it as a template? Here is your problem: template <typename T> vector_type operator()( const vector_type& v, rlc ) const { return fusion::as_nview<0, 1, 2>( v ); } template <typename T> vector_type operator()( const vector_type& v, lcr ) const { return fusion::as_nview<2, 0, 1>( v ); } because you don't have any arguments with T. Regards -- Joel de Guzman http://www.boostpro.com http://spirit.sf.net http://www.facebook.com/djowel Meet me at BoostCon http://www.boostcon.com/home http://www.facebook.com/boostcon

Olaf, I recommended writing the code above (see the operator() is *not* a template. Why do you still insist on writing it as a template? Here is your problem:
template <typename T> vector_type operator()( const vector_type& v, rlc ) const { return fusion::as_nview<0, 1, 2>( v ); }
template <typename T> vector_type operator()( const vector_type& v, lcr ) const { return fusion::as_nview<2, 0, 1>( v ); }
because you don't have any arguments with T.
Damn, you are in right. It was to late in the evening. Sorry for noise and thanks, Olaf
participants (2)
-
Joel de Guzman
-
Olaf Peter