Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r63001 - in sandbox/SOC/2009/fusion: boost/fusion/algorithm/iteration/detail libs/fusion/test/suite1 libs/fusion/test/suite1/algorithm
From: mr.chr.schmidt_at_[hidden]
Date: 2010-06-15 17:08:28


Author: cschmidt
Date: 2010-06-15 17:08:26 EDT (Tue, 15 Jun 2010)
New Revision: 63001
URL: http://svn.boost.org/trac/boost/changeset/63001

Log:
added (XXX_)fold testcases
Added:
   sandbox/SOC/2009/fusion/libs/fusion/test/suite1/algorithm/fold.hpp (contents, props changed)
   sandbox/SOC/2009/fusion/libs/fusion/test/suite1/algorithm/fold2.cpp (contents, props changed)
   sandbox/SOC/2009/fusion/libs/fusion/test/suite1/algorithm/iter_fold.cpp (contents, props changed)
   sandbox/SOC/2009/fusion/libs/fusion/test/suite1/algorithm/reverse_fold.cpp (contents, props changed)
   sandbox/SOC/2009/fusion/libs/fusion/test/suite1/algorithm/reverse_iter_fold.cpp (contents, props changed)
Text files modified:
   sandbox/SOC/2009/fusion/boost/fusion/algorithm/iteration/detail/fold.hpp | 29 ++++++++++++++++-------------
   sandbox/SOC/2009/fusion/libs/fusion/test/suite1/Jamfile | 6 +++++-
   2 files changed, 21 insertions(+), 14 deletions(-)

Modified: sandbox/SOC/2009/fusion/boost/fusion/algorithm/iteration/detail/fold.hpp
==============================================================================
--- sandbox/SOC/2009/fusion/boost/fusion/algorithm/iteration/detail/fold.hpp (original)
+++ sandbox/SOC/2009/fusion/boost/fusion/algorithm/iteration/detail/fold.hpp 2010-06-15 17:08:26 EDT (Tue, 15 Jun 2010)
@@ -66,7 +66,6 @@
 # define BOOST_FUSION_FOLD_IMPL_INVOKE_IT_TRANSFORM(IT) fusion::deref(IT)
 #endif
 
-
 namespace boost { namespace fusion
 {
     namespace detail
@@ -121,15 +120,16 @@
                             f(
                                 f(
                                     BOOST_FUSION_FORWARD(State,state),
- fusion::deref(it0)
+ BOOST_FUSION_FOLD_IMPL_INVOKE_IT_TRANSFORM(
+ it0)
                                 ),
- fusion::deref(it1)
+ BOOST_FUSION_FOLD_IMPL_INVOKE_IT_TRANSFORM(it1)
                             ),
- fusion::deref(it2)
+ BOOST_FUSION_FOLD_IMPL_INVOKE_IT_TRANSFORM(it2)
                         ),
- fusion::deref(it3)
+ BOOST_FUSION_FOLD_IMPL_INVOKE_IT_TRANSFORM(it3)
                     ),
- fusion::next(it3),
+ fusion::BOOST_FUSION_FOLD_IMPL_NEXT_IT_FUNCTION(it3),
                     BOOST_FUSION_FORWARD(F,f));
             }
         };
@@ -160,11 +160,11 @@
                         f(
                             f(
                                 BOOST_FUSION_FORWARD(State,state),
- fusion::deref(it0)
+ BOOST_FUSION_FOLD_IMPL_INVOKE_IT_TRANSFORM(it0)
                             ),
- fusion::deref(it1)
+ BOOST_FUSION_FOLD_IMPL_INVOKE_IT_TRANSFORM(it1)
                         ),
- fusion::deref(
+ BOOST_FUSION_FOLD_IMPL_INVOKE_IT_TRANSFORM(
                             fusion::BOOST_FUSION_FOLD_IMPL_NEXT_IT_FUNCTION(it1)
                         ));
             }
@@ -180,8 +180,9 @@
                     BOOST_FUSION_RREF_ELSE_OBJ(F) f)
             {
                 return f(
- f(BOOST_FUSION_FORWARD(State,state),fusion::deref(it0)),
- fusion::deref(
+ f(BOOST_FUSION_FORWARD(State,state),
+ BOOST_FUSION_FOLD_IMPL_INVOKE_IT_TRANSFORM(it0)),
+ BOOST_FUSION_FOLD_IMPL_INVOKE_IT_TRANSFORM(
                         fusion::BOOST_FUSION_FOLD_IMPL_NEXT_IT_FUNCTION(it0)));
             }
         };
@@ -195,7 +196,8 @@
                 It0 const& it0,
                 BOOST_FUSION_RREF_ELSE_OBJ(F) f)
             {
- return f(BOOST_FUSION_FORWARD(State,state),fusion::deref(it0));
+ return f(BOOST_FUSION_FORWARD(State,state),
+ BOOST_FUSION_FOLD_IMPL_INVOKE_IT_TRANSFORM(it0));
             }
         };
 
@@ -405,7 +407,7 @@
             static StateRef
             call(StateRef state, It0 const&, F)
             {
- return state;
+ return static_cast<StateRef>(state);
             }
         };
     }
@@ -473,4 +475,5 @@
 #undef BOOST_FUSION_FOLD_IMPL_NEXT_IT_FUNCTION
 #undef BOOST_FUSION_FOLD_IMPL_FIRST_IT_META_TRANSFORM
 #undef BOOST_FUSION_FOLD_IMPL_FIRST_IT_TRANSFORM
+#undef BOOST_FUSION_FOLD_IMPL_INVOKE_IT_META_TRANSFORM
 #undef BOOST_FUSION_FOLD_IMPL_INVOKE_IT_TRANSFORM

Modified: sandbox/SOC/2009/fusion/libs/fusion/test/suite1/Jamfile
==============================================================================
--- sandbox/SOC/2009/fusion/libs/fusion/test/suite1/Jamfile (original)
+++ sandbox/SOC/2009/fusion/libs/fusion/test/suite1/Jamfile 2010-06-15 17:08:26 EDT (Tue, 15 Jun 2010)
@@ -24,9 +24,11 @@
     [ run algorithm/find.cpp : : : : ]
     [ run algorithm/find_if.cpp : : : : ]
     [ run algorithm/fold.cpp : : : : ]
+ [ run algorithm/fold2.cpp : : : : ]
     [ run algorithm/for_each.cpp : : : : ]
- [ run algorithm/insert.cpp : : : : ]
     [ run algorithm/insert_range.cpp : : : : ]
+ [ run algorithm/insert.cpp : : : : ]
+ [ run algorithm/iter_fold.cpp : : : : ]
     [ run algorithm/none.cpp : : : : ]
     [ run algorithm/pop_back.cpp : : : : ]
     [ run algorithm/pop_front.cpp : : : : ]
@@ -37,6 +39,8 @@
     [ run algorithm/replace.cpp : : : : ]
     [ run algorithm/replace_if.cpp : : : : ]
     [ run algorithm/reverse.cpp : : : : ]
+ [ run algorithm/reverse_fold.cpp : : : : ]
+ [ run algorithm/reverse_iter_fold.cpp : : : : ]
     [ run algorithm/transform.cpp : : : : ]
     [ run algorithm/join.cpp : : : : ]
     [ run algorithm/zip.cpp : : : : ]

Added: sandbox/SOC/2009/fusion/libs/fusion/test/suite1/algorithm/fold.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2009/fusion/libs/fusion/test/suite1/algorithm/fold.hpp 2010-06-15 17:08:26 EDT (Tue, 15 Jun 2010)
@@ -0,0 +1,207 @@
+/*=============================================================================
+ Copyright (c) 2010 Christopher Schmidt
+
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+==============================================================================*/
+
+#include <boost/config.hpp>
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/fusion/sequence.hpp>
+#include <boost/fusion/iterator.hpp>
+#include <boost/fusion/algorithm/transformation/reverse.hpp>
+#include <boost/fusion/algorithm/iteration/fold.hpp>
+#include <boost/fusion/algorithm/iteration/reverse_fold.hpp>
+#include <boost/fusion/algorithm/iteration/iter_fold.hpp>
+#include <boost/fusion/algorithm/iteration/reverse_iter_fold.hpp>
+#include <boost/fusion/container/vector/convert.hpp>
+#include <boost/fusion/container/vector/vector.hpp>
+#include <boost/fusion/adapted/mpl.hpp>
+#include <boost/fusion/support/pair.hpp>
+#include <boost/fusion/mpl.hpp>
+#include <boost/mpl/front.hpp>
+#include <boost/mpl/back.hpp>
+#include <boost/mpl/int.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/for_each.hpp>
+#include <boost/mpl/range_c.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/if.hpp>
+#include <boost/mpl/back_inserter.hpp>
+#include <boost/mpl/always.hpp>
+#include <boost/mpl/copy.hpp>
+#include <boost/type_traits/is_same.hpp>
+#include <iostream>
+
+namespace mpl=boost::mpl;
+namespace fusion=boost::fusion;
+
+#ifdef BOOST_FUSION_TEST_REVERSE_FOLD
+# ifdef BOOST_FUSION_TEST_ITER_FOLD
+# define BOOST_FUSION_TEST_FOLD_NAME reverse_iter_fold
+# else
+# define BOOST_FUSION_TEST_FOLD_NAME reverse_fold
+# endif
+#else
+# ifdef BOOST_FUSION_TEST_ITER_FOLD
+# define BOOST_FUSION_TEST_FOLD_NAME iter_fold
+# else
+# define BOOST_FUSION_TEST_FOLD_NAME fold
+# endif
+#endif
+
+struct sum
+{
+ template<typename Sig>
+ struct result;
+
+ template<typename Self, typename State, typename T>
+ struct result<Self(State,T)>
+ : fusion::result_of::make_pair<
+ mpl::int_<
+ fusion::detail::remove_reference<
+ State
+ >::type::first_type::value+1
+ >
+ , int
+ >
+ {};
+
+#ifdef BOOST_FUSION_TEST_ITER_FOLD
+ template<typename State, typename It>
+ typename result<sum const&(State,It)>::type
+ operator()(State state, It const& it)const
+ {
+ static const int n=State::first_type::value;
+ return fusion::make_pair<mpl::int_<n+1> >(
+ state.second+fusion::deref(it)*n);
+ }
+#else
+ template<typename State>
+ typename result<sum const&(State, int)>::type
+ operator()(State state, int e)const
+ {
+ static const int n=State::first_type::value;
+ return fusion::make_pair<mpl::int_<n+1> >(state.second+e*n);
+ }
+#endif
+};
+
+struct meta_sum
+{
+ template<typename Sig>
+ struct result;
+
+ template<typename Self, typename State, typename T>
+ struct result<Self(State,T)>
+ {
+ typedef typename fusion::detail::remove_reference<State>::type state;
+ static const int n=mpl::front<state>::type::value;
+
+ typedef
+ mpl::vector<
+ mpl::int_<n+1>
+ , mpl::int_<
+ mpl::back<state>::type::value+
+#ifdef BOOST_FUSION_TEST_ITER_FOLD
+ fusion::result_of::value_of<
+#else
+ fusion::detail::remove_reference<
+#endif
+ T
+ >::type
+ ::value*n
+ >
+ >
+ type;
+ };
+
+ template<typename State, typename T>
+ typename result<meta_sum const&(State,T)>::type
+ operator()(State, T)const;
+};
+
+struct fold_test_n
+{
+ template<typename I>
+ void
+ operator()(I)const
+ {
+ static const int n=I::value;
+ typedef mpl::range_c<int, 0, n> range;
+
+ static const int squares_sum=n*(n+1)*(2*n+1)/6;
+
+ {
+ mpl::range_c<int, 1, n+1> init_range;
+ typename fusion::result_of::as_vector<
+ typename mpl::transform<
+ range
+ , mpl::always<int>
+ , mpl::back_inserter<mpl::vector<> >
+ >::type
+ >::type vec(
+#ifdef BOOST_FUSION_TEST_REVERSE_FOLD
+ fusion::reverse(init_range)
+#else
+ init_range
+#endif
+ );
+
+ int result=BOOST_FUSION_TEST_FOLD_NAME(
+ vec,
+ fusion::make_pair<mpl::int_<1> >(0),
+ sum()).second;
+ std::cout << n << ": " << result << std::endl;
+ BOOST_TEST(result==squares_sum);
+ }
+
+ {
+ typedef typename
+#ifdef BOOST_FUSION_TEST_REVERSE_FOLD
+ fusion::result_of::as_vector<
+ typename mpl::copy<
+ mpl::range_c<int, 1, n+1>
+ , mpl::front_inserter<fusion::vector<> >
+ >::type
+ >::type
+#else
+ fusion::result_of::as_vector<mpl::range_c<int, 1, n+1> >::type
+#endif
+ vec;
+
+ typedef
+#ifdef BOOST_NO_RVALUE_REFERENCES
+ mpl::vector<mpl::int_<1>, mpl::int_<0> > const&
+#else
+ mpl::vector<mpl::int_<1>, mpl::int_<0> >&
+#endif
+ result_type;
+
+ BOOST_MPL_ASSERT((
+ boost::is_same<
+ typename fusion::result_of::BOOST_FUSION_TEST_FOLD_NAME<
+ vec
+ , mpl::vector<mpl::int_<1>, mpl::int_<0> >
+ , meta_sum
+ >::type
+ , typename mpl::if_c<
+ !n
+ , result_type
+ , mpl::vector<mpl::int_<n+1>, mpl::int_<squares_sum> >
+ >::type
+ >));
+ }
+ }
+};
+
+int
+main()
+{
+ mpl::for_each<mpl::range_c<int, 0, 10> >(fold_test_n());
+
+ return boost::report_errors();
+}
+
+#undef BOOST_FUSION_TEST_FOLD_NAME
+

Added: sandbox/SOC/2009/fusion/libs/fusion/test/suite1/algorithm/fold2.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2009/fusion/libs/fusion/test/suite1/algorithm/fold2.cpp 2010-06-15 17:08:26 EDT (Tue, 15 Jun 2010)
@@ -0,0 +1,8 @@
+/*=============================================================================
+ Copyright (c) 2010 Christopher Schmidt
+
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+==============================================================================*/
+
+#include "fold.hpp"

Added: sandbox/SOC/2009/fusion/libs/fusion/test/suite1/algorithm/iter_fold.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2009/fusion/libs/fusion/test/suite1/algorithm/iter_fold.cpp 2010-06-15 17:08:26 EDT (Tue, 15 Jun 2010)
@@ -0,0 +1,10 @@
+/*=============================================================================
+ Copyright (c) 2010 Christopher Schmidt
+
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+==============================================================================*/
+
+#define BOOST_FUSION_TEST_ITER_FOLD
+#include "fold.hpp"
+#undef BOOST_FUSION_TEST_ITER_FOLD

Added: sandbox/SOC/2009/fusion/libs/fusion/test/suite1/algorithm/reverse_fold.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2009/fusion/libs/fusion/test/suite1/algorithm/reverse_fold.cpp 2010-06-15 17:08:26 EDT (Tue, 15 Jun 2010)
@@ -0,0 +1,10 @@
+/*=============================================================================
+ Copyright (c) 2010 Christopher Schmidt
+
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+==============================================================================*/
+
+#define BOOST_FUSION_TEST_REVERSE_FOLD
+#include "fold.hpp"
+#undef BOOST_FUSION_TEST_REVERSE_FOLD

Added: sandbox/SOC/2009/fusion/libs/fusion/test/suite1/algorithm/reverse_iter_fold.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2009/fusion/libs/fusion/test/suite1/algorithm/reverse_iter_fold.cpp 2010-06-15 17:08:26 EDT (Tue, 15 Jun 2010)
@@ -0,0 +1,12 @@
+/*=============================================================================
+ Copyright (c) 2010 Christopher Schmidt
+
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+==============================================================================*/
+
+#define BOOST_FUSION_TEST_REVERSE_FOLD
+#define BOOST_FUSION_TEST_ITER_FOLD
+#include "fold.hpp"
+#undef BOOST_FUSION_TEST_ITER_FOLD
+#undef BOOST_FUSION_TEST_REVERSE_FOLD


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk