[SVN r35144]
This commit is contained in:
Joel de Guzman
2006-09-17 13:19:48 +00:00
parent 3f06921d11
commit 1a6f4f948c

View File

@ -9,7 +9,8 @@
So... you have an input sequence I and a target vector R. You want to
copy I into R. But, I may have less elements than the result vector R.
For those elements not in R, you want them to be default conctructed.
For those elements not in R, you want them to be default constructed.
Here's a case:
I: list<double, std::string>
@ -18,17 +19,19 @@
You want the elements at the right of I not in R (i.e. int, short)
default constructed. Those at the left, found in both I and R, you want
to simply copy from I.
Of course you want to be able to handle any type of I and R.
==============================================================================*/
// We'll use these containers
// We'll use these containers as examples
#include <boost/fusion/sequence/container/list.hpp>
#include <boost/fusion/sequence/container/vector.hpp>
// For doing I/O
#include <boost/fusion/sequence/io.hpp>
// We'll use join and advance
// We'll use join and advance for processing
#include <boost/fusion/algorithm/transformation/join.hpp>
#include <boost/fusion/iterator/advance.hpp>
@ -58,13 +61,15 @@ main()
typedef vector<double, std::string, int, short> R;
// Let's get the sizes of the sequences. Yeah, you already know that.
// But with templates, where you are simply given, say, R and I,
// corresponding to the types of the sequences, you'll have to deal
// with it generically.
// But with templates, you are simply given, say, R and I, corresponding
// to the types of the sequences. You'll have to deal with it generically.
static int const r_size = result_of::size<R>::value;
static int const i_size = result_of::size<I>::value;
// Make sure that I has no more elements than R
// Be nice and catch obvious errors earlier rather than later.
// Without this assert, the mistake will still be caught by Fusion,
// but the error will point to somewhere really obscure.
BOOST_STATIC_ASSERT(i_size <= r_size);
// Let's get the begin and end iterator types of the output sequence
@ -86,9 +91,11 @@ main()
// Use join to join the input sequence and our mpl::iterator_range
// Our mpl::iterator_range is 'tail'. Here, we'll actually instantiate
// 'tail'. Notice that this is a flyweight object, typically just 1 byte
// in size -- it doesn't really hold any data, but it is a fully conforming
// in size -- it doesn't really hold any data, but is a fully conforming
// sequence nonetheless. When asked to return its elements, 'tail' returns
// each element default constructed. Breeds like a rabbit!
// Construct R from the joined sequences:
R r(join(i, tail()));
// Then finally, print the result: