mirror of
https://github.com/boostorg/range.git
synced 2025-07-31 13:27:31 +02:00
[boost][range] - Make the type_erased adaptor test compatible with more compilers and reduce the time of test compilation/execution to avoid timeouts on the Intel compilers.
[SVN r67601]
This commit is contained in:
@ -21,23 +21,28 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace boost_range_adaptor_type_erased_test
|
namespace boost_range_adaptor_type_erased_test
|
||||||
{
|
|
||||||
namespace
|
|
||||||
{
|
{
|
||||||
class MockType
|
class MockType
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit MockType(int x)
|
MockType()
|
||||||
: m_x(x) {}
|
: m_x(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
MockType(int x)
|
||||||
|
: m_x(x)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
int get() const { return m_x; }
|
int get() const { return m_x; }
|
||||||
|
|
||||||
bool operator==(const MockType& other) const
|
inline bool operator==(const MockType& other) const
|
||||||
{
|
{
|
||||||
return m_x == other.m_x;
|
return m_x == other.m_x;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator!=(const MockType& other) const
|
inline bool operator!=(const MockType& other) const
|
||||||
{
|
{
|
||||||
return m_x != other.m_x;
|
return m_x != other.m_x;
|
||||||
}
|
}
|
||||||
@ -46,7 +51,7 @@ namespace boost_range_adaptor_type_erased_test
|
|||||||
int m_x;
|
int m_x;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& out, const MockType& obj)
|
inline std::ostream& operator<<(std::ostream& out, const MockType& obj)
|
||||||
{
|
{
|
||||||
out << obj.get();
|
out << obj.get();
|
||||||
return out;
|
return out;
|
||||||
@ -183,10 +188,8 @@ namespace boost_range_adaptor_type_erased_test
|
|||||||
, Buffer
|
, Buffer
|
||||||
> type_erased_t;
|
> type_erased_t;
|
||||||
|
|
||||||
type_erased_t type_erased_ex;
|
|
||||||
|
|
||||||
Container source;
|
Container source;
|
||||||
for (int i = 0; i < 100; ++i)
|
for (int i = 0; i < 10; ++i)
|
||||||
source.push_back(value_type(i));
|
source.push_back(value_type(i));
|
||||||
|
|
||||||
mutable_any_range r(source);
|
mutable_any_range r(source);
|
||||||
@ -196,12 +199,12 @@ namespace boost_range_adaptor_type_erased_test
|
|||||||
r = mutable_any_range();
|
r = mutable_any_range();
|
||||||
BOOST_CHECK_EQUAL( r.empty(), true );
|
BOOST_CHECK_EQUAL( r.empty(), true );
|
||||||
|
|
||||||
r = source | type_erased_ex;
|
r = source | type_erased_t();
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS( source.begin(), source.end(),
|
BOOST_CHECK_EQUAL_COLLECTIONS( source.begin(), source.end(),
|
||||||
r.begin(), r.end() );
|
r.begin(), r.end() );
|
||||||
r = mutable_any_range();
|
r = mutable_any_range();
|
||||||
|
|
||||||
r = boost::adaptors::type_erase(source, type_erased_ex);
|
r = boost::adaptors::type_erase(source, type_erased_t());
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS( source.begin(), source.end(),
|
BOOST_CHECK_EQUAL_COLLECTIONS( source.begin(), source.end(),
|
||||||
r.begin(), r.end() );
|
r.begin(), r.end() );
|
||||||
r = mutable_any_range();
|
r = mutable_any_range();
|
||||||
@ -223,21 +226,21 @@ namespace boost_range_adaptor_type_erased_test
|
|||||||
// range to a constant any_range
|
// range to a constant any_range
|
||||||
const Container& const_source = source;
|
const Container& const_source = source;
|
||||||
cr = const_any_range();
|
cr = const_any_range();
|
||||||
cr = const_source | type_erased_ex;
|
cr = const_source | type_erased_t();
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS( const_source.begin(), const_source.end(),
|
BOOST_CHECK_EQUAL_COLLECTIONS( const_source.begin(), const_source.end(),
|
||||||
cr.begin(), cr.end() );
|
cr.begin(), cr.end() );
|
||||||
|
|
||||||
// Test the pipe type erased adaptor from a mutable source
|
// Test the pipe type erased adaptor from a mutable source
|
||||||
// range to a constant any_range
|
// range to a constant any_range
|
||||||
cr = const_any_range();
|
cr = const_any_range();
|
||||||
cr = source | type_erased_ex;
|
cr = source | type_erased_t();
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS( source.begin(), source.end(),
|
BOOST_CHECK_EQUAL_COLLECTIONS( source.begin(), source.end(),
|
||||||
cr.begin(), cr.end() );
|
cr.begin(), cr.end() );
|
||||||
|
|
||||||
// Use the function form of the type_erase adaptor from a constant
|
// Use the function form of the type_erase adaptor from a constant
|
||||||
// source range
|
// source range
|
||||||
cr = const_any_range();
|
cr = const_any_range();
|
||||||
cr = boost::adaptors::type_erase(const_source, type_erased_ex);
|
cr = boost::adaptors::type_erase(const_source, type_erased_t());
|
||||||
BOOST_CHECK_EQUAL_COLLECTIONS( const_source.begin(), const_source.end(),
|
BOOST_CHECK_EQUAL_COLLECTIONS( const_source.begin(), const_source.end(),
|
||||||
cr.begin(), cr.end() );
|
cr.begin(), cr.end() );
|
||||||
|
|
||||||
@ -284,17 +287,10 @@ namespace boost_range_adaptor_type_erased_test
|
|||||||
test_type_erased_impl_fn< Container, Traversal, any_iterator_heap_only_buffer >()();
|
test_type_erased_impl_fn< Container, Traversal, any_iterator_heap_only_buffer >()();
|
||||||
test_type_erased_impl_fn< Container, Traversal, any_iterator_buffer<1> >()();
|
test_type_erased_impl_fn< Container, Traversal, any_iterator_buffer<1> >()();
|
||||||
test_type_erased_impl_fn< Container, Traversal, any_iterator_buffer<2> >()();
|
test_type_erased_impl_fn< Container, Traversal, any_iterator_buffer<2> >()();
|
||||||
test_type_erased_impl_fn< Container, Traversal, any_iterator_buffer<4> >()();
|
|
||||||
test_type_erased_impl_fn< Container, Traversal, any_iterator_buffer<8> >()();
|
|
||||||
test_type_erased_impl_fn< Container, Traversal, any_iterator_buffer<16> >()();
|
|
||||||
test_type_erased_impl_fn< Container, Traversal, any_iterator_buffer<32> >()();
|
test_type_erased_impl_fn< Container, Traversal, any_iterator_buffer<32> >()();
|
||||||
test_type_erased_impl_fn< Container, Traversal, any_iterator_buffer<64> >()();
|
test_type_erased_impl_fn< Container, Traversal, any_iterator_buffer<64> >()();
|
||||||
test_type_erased_impl_fn< Container, Traversal, any_iterator_buffer<128> >()();
|
test_type_erased_impl_fn< Container, Traversal, any_iterator_buffer<128> >()();
|
||||||
test_type_erased_impl_fn< Container, Traversal, any_iterator_buffer<4096> >()();
|
|
||||||
test_type_erased_impl_fn< Container, Traversal, any_iterator_buffer<16384> >()();
|
|
||||||
test_type_erased_impl_fn< Container, Traversal, any_iterator_stack_only_buffer<128> >()();
|
test_type_erased_impl_fn< Container, Traversal, any_iterator_stack_only_buffer<128> >()();
|
||||||
test_type_erased_impl_fn< Container, Traversal, any_iterator_stack_only_buffer<4096> >()();
|
|
||||||
test_type_erased_impl_fn< Container, Traversal, any_iterator_stack_only_buffer<16384> >()();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_type_erased_single_pass()
|
void test_type_erased_single_pass()
|
||||||
@ -419,23 +415,12 @@ namespace boost_range_adaptor_type_erased_test
|
|||||||
t2.begin(), t2.end() );
|
t2.begin(), t2.end() );
|
||||||
}
|
}
|
||||||
|
|
||||||
class MockInt
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
MockInt() : m_value() {}
|
|
||||||
MockInt(int x) : m_value(x) {}
|
|
||||||
operator int() const { return m_value; }
|
|
||||||
private:
|
|
||||||
int m_value;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
template<class Traversal>
|
template<class Traversal>
|
||||||
void test_type_erased_mix_values_driver()
|
void test_type_erased_mix_values_driver()
|
||||||
{
|
{
|
||||||
test_type_erased_mix_values_impl< Traversal, int, char, const int&, short, const int& >();
|
test_type_erased_mix_values_impl< Traversal, int, char, const int&, short, const int& >();
|
||||||
test_type_erased_mix_values_impl< Traversal, int, int*, const int&, char, const int& >();
|
test_type_erased_mix_values_impl< Traversal, int, int*, const int&, char, const int& >();
|
||||||
test_type_erased_mix_values_impl< Traversal, MockInt, char, const MockInt&, short, const MockInt& >();
|
test_type_erased_mix_values_impl< Traversal, MockType, char, const MockType&, short, const MockType& >();
|
||||||
|
|
||||||
// In fact value type should have no effect in the eligibility
|
// In fact value type should have no effect in the eligibility
|
||||||
// for conversion, hence we should be able to convert it
|
// for conversion, hence we should be able to convert it
|
||||||
@ -460,10 +445,19 @@ namespace boost_range_adaptor_type_erased_test
|
|||||||
for (int i = 0; i < 10; ++i)
|
for (int i = 0; i < 10; ++i)
|
||||||
c.push_back(i);
|
c.push_back(i);
|
||||||
|
|
||||||
|
typedef boost::any_range<
|
||||||
|
int
|
||||||
|
, boost::random_access_traversal_tag
|
||||||
|
, int
|
||||||
|
, boost::range_difference< std::vector<int> >::type
|
||||||
|
, boost::use_default
|
||||||
|
> any_range_type;
|
||||||
|
|
||||||
|
any_range_type rng = c | type_erased_t();
|
||||||
|
|
||||||
for (int i = 0; i < 10; ++i)
|
for (int i = 0; i < 10; ++i)
|
||||||
{
|
{
|
||||||
BOOST_CHECK_EQUAL( (c | type_erased_t())[i], i );
|
BOOST_CHECK_EQUAL( rng[i], i );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user