Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r49470 - trunk/libs/fusion/test/compile_time
From: danmarsden_at_[hidden]
Date: 2008-10-27 18:13:21


Author: danmarsden
Date: 2008-10-27 18:13:20 EDT (Mon, 27 Oct 2008)
New Revision: 49470
URL: http://svn.boost.org/trac/boost/changeset/49470

Log:
bugfix to fold test, and new transform test
Added:
   trunk/libs/fusion/test/compile_time/transform.cpp (contents, props changed)
Text files modified:
   trunk/libs/fusion/test/compile_time/Makefile | 3 ++-
   trunk/libs/fusion/test/compile_time/fold.cpp | 13 ++++++++++++-
   2 files changed, 14 insertions(+), 2 deletions(-)

Modified: trunk/libs/fusion/test/compile_time/Makefile
==============================================================================
--- trunk/libs/fusion/test/compile_time/Makefile (original)
+++ trunk/libs/fusion/test/compile_time/Makefile 2008-10-27 18:13:20 EDT (Mon, 27 Oct 2008)
@@ -13,7 +13,8 @@
         vector_construction.cpp\
         vector_iteration.cpp\
         vector_intrinsic.cpp\
- fold.cpp
+ fold.cpp\
+ transform.cpp
 
 TEST_OBJS=$(TEST_SRCS:.cpp=.o)
 

Modified: trunk/libs/fusion/test/compile_time/fold.cpp
==============================================================================
--- trunk/libs/fusion/test/compile_time/fold.cpp (original)
+++ trunk/libs/fusion/test/compile_time/fold.cpp 2008-10-27 18:13:20 EDT (Mon, 27 Oct 2008)
@@ -15,8 +15,17 @@
 {
   template<int n, int batch>
   struct distinct
+ {};
+
+ struct f
   {
- static const int value = n;
+ typedef int result_type;
+
+ template<int n, int batch>
+ int operator()(distinct<n, batch> const& d, int state) const
+ {
+ return state + n;
+ }
   };
 
   template<int batch>
@@ -25,6 +34,8 @@
     fusion::vector<
       distinct<0, batch>, distinct<1, batch>, distinct<2, batch>, distinct<3, batch>, distinct<4, batch>,
       distinct<5, batch>, distinct<6, batch>, distinct<7, batch>, distinct<8, batch>, distinct<9, batch> > v;
+
+ fusion::fold(v, 0, f());
   }
 }
 

Added: trunk/libs/fusion/test/compile_time/transform.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/fusion/test/compile_time/transform.cpp 2008-10-27 18:13:20 EDT (Mon, 27 Oct 2008)
@@ -0,0 +1,55 @@
+/*=============================================================================
+ Copyright (c) 2008 Dan Marsden
+
+ Use modification and distribution are subject to 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/fusion/include/transform.hpp>
+#include <boost/fusion/include/for_each.hpp>
+#include <boost/fusion/include/vector.hpp>
+
+namespace fusion = boost::fusion;
+
+namespace
+{
+ template<int n, int batch>
+ struct distinct
+ {
+ static const int value = n;
+ };
+
+ struct f
+ {
+ typedef int result_type;
+
+ template<typename T>
+ result_type operator()(T const& t) const
+ {
+ return T::value;
+ }
+ };
+
+ struct touch
+ {
+ template<typename T>
+ void operator()(T const&) const
+ {}
+ };
+
+ template<int batch>
+ void test()
+ {
+ fusion::vector<
+ distinct<0, batch>, distinct<1, batch>, distinct<2, batch>, distinct<3, batch>, distinct<4, batch>,
+ distinct<5, batch>, distinct<6, batch>, distinct<7, batch>, distinct<8, batch>, distinct<9, batch> > v;
+
+ // We're testing transform really
+ // for_each call is to force iteration through the lazy
+ // transform, otherwise very little will happen.
+ fusion::for_each(fusion::transform(v, f()), touch());
+ }
+}
+
+#include "./driver.hpp"


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