[Boost-bugs] [Boost C++ Libraries] #5408: transform(fold(.... )) gives erroneous result: dangling reference?

Subject: [Boost-bugs] [Boost C++ Libraries] #5408: transform(fold(.... )) gives erroneous result: dangling reference?
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-04-01 12:09:55


#5408: transform(fold(.... )) gives erroneous result: dangling reference?
------------------------------+---------------------------------------------
 Reporter: joe@… | Owner: djowel
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: fusion
  Version: Boost 1.47.0 | Severity: Problem
 Keywords: |
------------------------------+---------------------------------------------
 The code below demonstrates a problem using fusion's transform on a fold
 view in conjunction with a phoenix functional. It produces the output:

    Should be the same: 1 =? 4.59177e-41

 it should produce

    Should be the same: 1 =? 1

 Thanks,
 Joe


 {{{
 #include <iostream>
 #include <cmath>
 #include <boost/detail/lightweight_test.hpp>
 #include <boost/spirit/include/phoenix_core.hpp>
 #include <boost/spirit/include/phoenix_operator.hpp>
 #include <boost/spirit/include/phoenix_function.hpp>
 #include <boost/fusion/container.hpp>
 #include <boost/fusion/functional.hpp>
 #include <boost/fusion/include/io.hpp>
 #include <boost/fusion/include/fold.hpp>
 #include <boost/fusion/include/transform.hpp>
 #include <boost/type_traits.hpp>
 #include <boost/mpl/assert.hpp>

 using namespace boost::fusion;
 using namespace boost::phoenix;

 typedef float OutputType;

 // A general error function, measuring the difference between two output
 patterns.
 struct error_function3 {
         template <typename Outputs1, typename Outputs2>
         struct result
         {
                 typedef OutputType type;
         };

         template <typename Outputs1, typename Outputs2>
         OutputType operator()(Outputs1& outputs1, Outputs2& outputs2)
 const
         {
                 using boost::phoenix::arg_names::_1;
                 using boost::phoenix::arg_names::_2;
                 using boost::fusion::fold;
                 using boost::fusion::transform;

                 float bad_result = fold(transform(outputs1, outputs2, (_1
 - _2) * (_1 - _2)), 0, _1 + _2);
                 float good_result = fold(as_vector(transform(outputs1,
 outputs2, (_1 - _2) * (_1 - _2))), 0, _1 + _2);

                 std::cout << "Should be the same: " << good_result << " =?
 " << bad_result << std::endl;
                 return good_result;
         }
 };

 int main() {
         using boost::phoenix::arg_names::_1;
         using boost::phoenix::arg_names::_2;
         vector<OutputType, OutputType> o1 = make_vector(1., 2.);
         vector<OutputType, OutputType> o2 = make_vector(2., 3.);

         boost::phoenix::function<error_function3> const error;
         std::cout << error(_1, _2)(o1, o2) << std::endl;
 }
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/5408>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:06 UTC