consumer.test.h
Go to the documentation of this file.
// -*- C++ -*- (c) 2006 Petr Rockai <me@mornfall.net>
#include <wibble/consumer.h>
#include <wibble/operators.h>
#include <list>
namespace {
using namespace wibble::operators;
using namespace wibble;
struct TestConsumer {
Test stlInserterConsumer() {
std::list<int> a;
a.push_back( 10 );
a.push_back( 20 );
Range< int > r = range( a.begin(), a.end() );
std::list<int> b;
assert( a != b );
Consumer< int > c = consumer( back_inserter( b ) );
std::copy( r.begin(), r.end(), c );
assert( a == b );
}
Test stlSetConsumer() {
std::set< int > s;
Consumer< int > c = consumer( s );
c.consume( 1 );
assert( *s.begin() == 1 );
assert( s.begin() + 1 == s.end() );
}
Test stlVectorConsumer() {
std::vector< int > v;
Consumer< int > c = consumer( v );
c.consume( 2 );
c.consume( 1 );
assert( *v.begin() == 2 );
assert( *(v.begin() + 1) == 1 );
assert( (v.begin() + 2) == v.end() );
}
};
}
consumer.h
-*- C++ -*-
wibble::operators
Definition: operators.h:12
wibble
Definition: amorph.h:17
wibble::range
Range< typename In::value_type > range(In b, In e)
Definition: range.h:264
wibble::consumer
Consumer< typename Out::container_type::value_type > consumer(Out out)
Definition: consumer.h:108
operators.h
wibble::Consumer
Definition: consumer.h:67
wibble::Consumer::consume
void consume(const T &a)
Definition: consumer.h:78
wibble::RangeMixin::begin
iterator begin() const
Definition: range.h:70
wibble::RangeMixin::end
iterator end() const
Definition: range.h:71
wibble::Range
Definition: range.h:155
Test
void Test
Definition: test.h:178
assert
#define assert(x)
Definition: test.h:30