merged from trunk

[SVN r49607]
This commit is contained in:
Eric Niebler
2008-11-06 00:15:47 +00:00
parent 47b53ea207
commit 45a6115d9b
4 changed files with 133 additions and 8 deletions

23
CMakeLists.txt Normal file
View File

@ -0,0 +1,23 @@
#----------------------------------------------------------------------------
# This file was automatically generated from the original CMakeLists.txt file
# Add a variable to hold the headers for the library
set (lib_headers
fusion
)
# Add a library target to the build system
boost_library_project(
fusion
# SRCDIRS
# TESTDIRS
HEADERS ${lib_headers}
# DOCDIRS
DESCRIPTION "Library for working with tuples, including various containers, algorithms, etc."
MODULARIZED
AUTHORS "Joel de Guzman <joel -at- boost-consulting.com>"
"Dan Marsden <danmarsden -at- yahoo.co.uk>"
"Tobias Schwinger <tschwinger -at- isonews2.com>"
# MAINTAINERS
)

View File

@ -9,16 +9,21 @@
CXX=g++ CXX=g++
CXXFLAGS=-I$(BOOST_ROOT) CXXFLAGS=-I$(BOOST_ROOT)
all: vector_construction vector_iteration vector_intrinsic TEST_SRCS=\
vector_construction.cpp\
vector_iteration.cpp\
vector_intrinsic.cpp\
fold.cpp\
transform.cpp
vector_construction: vector_construction.cpp TEST_OBJS=$(TEST_SRCS:.cpp=.o)
time $(CXX) $(CXXFLAGS) vector_construction.cpp -o vector_construction
vector_iteration: vector_iteration.cpp TEST_TARGETS=$(TEST_SRCS:.cpp=.test)
time $(CXX) $(CXXFLAGS) vector_iteration.cpp -o vector_iteration
vector_intrinsic: vector_intrinsic.cpp all: $(TEST_TARGETS)
time $(CXX) $(CXXFLAGS) vector_intrinsic.cpp -o vector_intrinsic
%.test : %.cpp
time $(CXX) $(CXXFLAGS) $< -o $@
clean: clean:
rm -f vector_construction vector_construction.o vector_iteration vector_iteration.o vector_intrinsic vector_intrinsic.o rm -f $(TEST_TARGETS) $(TEST_OBJS)

View File

@ -0,0 +1,42 @@
/*=============================================================================
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/fold.hpp>
#include <boost/fusion/include/vector.hpp>
namespace fusion = boost::fusion;
namespace
{
template<int n, int batch>
struct distinct
{};
struct f
{
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>
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;
fusion::fold(v, 0, f());
}
}
#include "./driver.hpp"

View File

@ -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"