http://stxxl.sourceforge.net
<beckmann@cs.uni-frankfurt.de>
<tb@panthema.net>
http://www.boost.org/LICENSE_1_0.txt
#include <vector>
#include <stxxl/stream>
#include <stxxl/vector>
#include <stxxl/algorithm>
struct forty_two
{
unsigned counter, length;
forty_two(unsigned l) : counter(0), length(l) { }
bool empty() const { return !(counter < length); }
unsigned len() const { return length; }
int operator * ()
{
STXXL_CHECK(!empty());
return counter;
}
forty_two& operator ++ ()
{
STXXL_CHECK(!empty());
++counter;
return *this;
}
forty_two & reset()
{
counter = 0;
return *this;
}
};
int generate_0()
{
return 0;
}
template <typename VectorType>
void check_42_fill(VectorType& v, unsigned length)
{
typename VectorType::const_iterator ci = v.begin();
for (unsigned i = 0; i < length; ++i)
{
STXXL_CHECK(*ci == (int)i);
++ci;
}
for (unsigned i = length; i < v.size(); ++i)
{
STXXL_CHECK(*ci == 0);
++ci;
}
std::fill(v.begin(), v.end(), 0);
}
int main()
{
stxxl::config::get_instance();
{
forty_two _42(42);
std::vector<int> v(1000);
std::generate(v.begin(), v.end(), generate_0);
stxxl::stream::materialize(_42.reset(), v.begin());
check_42_fill(v, _42.len());
stxxl::stream::materialize(_42.reset(), v.begin(), v.end());
check_42_fill(v, _42.len());
}
{
forty_two _42(42);
stxxl::VECTOR_GENERATOR<int>::result v(1000);
stxxl::generate(v.begin(), v.end(), generate_0, 42);
stxxl::stream::materialize(_42.reset(), v.begin());
check_42_fill(v, _42.len());
stxxl::stream::materialize(_42.reset(), v.begin(), 42);
check_42_fill(v, _42.len());
stxxl::stream::materialize(_42.reset(), v.begin(), v.end());
check_42_fill(v, _42.len());
stxxl::stream::materialize(_42.reset(), v.begin(), v.end(), 42);
check_42_fill(v, _42.len());
}
{
forty_two _42mill(42 * 1000000);
stxxl::VECTOR_GENERATOR<int>::result v(60 * 1000000);
stxxl::generate(v.begin(), v.end(), generate_0, 42);
stxxl::stream::materialize(_42mill.reset(), v.begin());
check_42_fill(v, _42mill.len());
stxxl::stream::materialize(_42mill.reset(), v.begin(), 42);
check_42_fill(v, _42mill.len());
stxxl::stream::materialize(_42mill.reset(), v.begin(), v.end());
check_42_fill(v, _42mill.len());
stxxl::stream::materialize(_42mill.reset(), v.begin(), v.end(), 42);
check_42_fill(v, _42mill.len());
}
}