Merged the tuples_subnamespace branch to main trunk.

[SVN r11120]
This commit is contained in:
Jaakko Järvi
2001-09-14 07:55:25 +00:00
parent 2764718489
commit 531fb617eb
4 changed files with 428 additions and 289 deletions

View File

@ -22,12 +22,13 @@
#include "boost/tuple/tuple_io.hpp" #include "boost/tuple/tuple_io.hpp"
namespace boost { namespace boost {
namespace detail {
namespace tuples { namespace tuples {
namespace detail {
const int const int
format_info::stream_index[number_of_manipulators] format_info::stream_index[number_of_manipulators]
= { std::ios::xalloc(), std::ios::xalloc(), std::ios::xalloc() }; = { std::ios::xalloc(), std::ios::xalloc(), std::ios::xalloc() };
} // namespace tuples
} // namespace detail } // namespace detail
} // namespace tuples
} // namespace boost } // namespace boost

View File

@ -1,5 +1,8 @@
// tuple_test_bench.cpp -------------------------------- // another_test_bench.cpp --------------------------------
//
// This file has various tests to see that things that shouldn't
// compile, don't compile.
// Defining any of E1 to E5 or E7 to E11 opens some illegal code that // Defining any of E1 to E5 or E7 to E11 opens some illegal code that
// should cause the compliation to fail. // should cause the compliation to fail.
@ -8,156 +11,148 @@
#include "boost/tuple/tuple.hpp" #include "boost/tuple/tuple.hpp"
#include "boost/tuple/tuple_comparison.hpp" #include <string>
#include <utility>
using namespace std; using namespace std;
using namespace boost; using namespace boost;
using namespace boost::tuples;
class foo
{ template<class T> void dummy(const T&) {}
class A {}; class B {}; class C {};
// A non-copyable class
class no_copy {
no_copy(const no_copy&) {}
public: public:
explicit foo(int v) : val(v) {} no_copy() {};
bool operator==(const foo& other) const
{
return val == other.val;
}
private:
foo() {}
int val;
}; };
void no_copy y;
construction_test()
{
tuple<int> t1;
BOOST_TEST(get<0>(t1) == int());
tuple<float> t2(5.5f);
BOOST_TEST(get<0>(t2) == 5.5f);
tuple<foo> t3(foo(12)); #ifdef E1
BOOST_TEST(get<0>(t3) == foo(12)); tuple<no_copy> v1; // should faild
#endif
tuple<double> t4(t2);
BOOST_TEST(get<0>(t4) == 5.5);
tuple<int, float> t5; #ifdef E2
BOOST_TEST(get<0>(t5) == int()); char cs[10];
BOOST_TEST(get<1>(t5) == float()); tuple<char[10]> v3; // should fail, arrays must be stored as references
#endif
tuple<int, float> t6(12, 5.5f); // a class without a public default constructor
BOOST_TEST(get<0>(t6) == 12); class no_def_constructor {
BOOST_TEST(get<1>(t6) == 5.5f); no_def_constructor() {}
public:
no_def_constructor(std::string) {} // can be constructed with a string
};
tuple<long, double> t7(t6); void foo1() {
BOOST_TEST(get<0>(t7) == 12);
BOOST_TEST(get<1>(t7) == 5.5f); #ifdef E3
dummy(tuple<no_def_constructor, no_def_constructor, no_def_constructor>());
// should fail
#endif
} }
void void foo2() {
copy_test() // testing default values
{ #ifdef E4
tuple<int, float> t1(4, 12.5f); dummy(tuple<double&>()); // should fail, not defaults for references
tuple<int, float> t2(5, 2.2f); dummy(tuple<const double&>()); // likewise
t2 = t1; #endif
BOOST_TEST(get<0>(t1) == get<0>(t2));
BOOST_TEST(get<1>(t1) == get<1>(t2));
tuple<long, double> t3(2, 3.3); double dd = 5;
t3 = t1;
BOOST_TEST((double)get<0>(t1) == get<0>(t3));
BOOST_TEST((double)get<1>(t1) == get<1>(t3));
}
void
mutate_test()
{
tuple<int, float, bool, foo> t1(5, 12.2f, true, foo(4));
get<0>(t1) = 6;
get<1>(t1) = 2.2f;
get<2>(t1) = false;
get<3>(t1) = foo(5);
BOOST_TEST(get<0>(t1) == 6);
BOOST_TEST(get<1>(t1) == 2.2f);
BOOST_TEST(get<2>(t1) == false);
BOOST_TEST(get<3>(t1) == foo(5));
}
void
make_tuple_test()
{
tuple<int, float> t1 = make_tuple(5, 2.25f);
BOOST_TEST(get<0>(t1) == 5);
BOOST_TEST(get<1>(t1) == 2.25f);
tuple<int, double> t2;
t2 = make_tuple((short int)2, 2.25);
BOOST_TEST(get<0>(t2) == 2);
BOOST_TEST(get<1>(t2) == 2.25);
}
void
tie_test()
{
int a;
float b;
foo c(5);
tie(a, b, c) = make_tuple(2, 5.5f, foo(3));
BOOST_TEST(a == 2);
BOOST_TEST(b == 5.5f);
BOOST_TEST(c == foo(3));
tie(a, ignore, c) = make_tuple((short int)5, false, foo(5));
BOOST_TEST(a == 5);
BOOST_TEST(b == 5.5f);
BOOST_TEST(c == foo(5));
}
void
equality_test()
{
tuple<int, float> t1(5, 3.3f);
tuple<int, float> t2(5, 3.3f);
BOOST_TEST(t1 == t2);
tuple<int, float> t3(5, 2.2f);
tuple<int, float> t4(2, 3.3f);
BOOST_TEST(t1 != t3);
BOOST_TEST(t1 != t4);
}
void
ordering_test()
{
tuple<int, float> t1(4, 3.3f);
tuple<short, float> t2(5, 3.3f);
tuple<long, double> t3(5, 4.4);
BOOST_TEST(t1 < t2);
BOOST_TEST(t1 <= t2);
BOOST_TEST(t2 > t1);
BOOST_TEST(t2 >= t1);
BOOST_TEST(t2 < t3);
BOOST_TEST(t2 <= t3);
BOOST_TEST(t3 > t2);
BOOST_TEST(t3 >= t2);
#ifdef E5
dummy(tuple<double&>(dd+3.14)); // should fail, temporary to non-const reference
#endif
} }
int
test_main(int, char *[]) // make_tuple ------------------------------------------
void foo3() {
#ifdef E7
std::make_pair("Doesn't","Work"); // fails
#endif
// make_tuple("Does", "Work"); // this should work
}
// - testing element access
void foo4()
{ {
construction_test(); #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
copy_test(); double d = 2.7;
mutate_test(); A a;
make_tuple_test(); tuple<int, double&, const A&> t(1, d, a);
tie_test(); const tuple<int, double&, const A> ct = t;
equality_test();
ordering_test(); #ifdef E8
get<0>(ct) = 5; // can't assign to const
#endif
#ifdef E9
get<4>(t) = A(); // can't assign to const
#endif
#ifdef E10
dummy(get<5>(ct)); // illegal index
#endif
#endif
}
// testing copy and assignment with implicit conversions between elements
// testing tie
class AA {};
class BB : public AA {};
struct CC { CC() {} CC(const BB& b) {} };
struct DD { operator CC() const { return CC(); }; };
void foo5() {
tuple<char, BB*, BB, DD> t;
tuple<char, char> aaa;
tuple<int, int> bbb(aaa);
// tuple<int, AA*, CC, CC> a = t;
// a = t;
}
// testing tie
// testing assignment from std::pair
void foo7() {
tuple<int, int, float> a;
#ifdef E11
a = std::make_pair(1, 2); // should fail, tuple is of length 3, not 2
#endif
dummy(a);
}
// --------------------------------
// ----------------------------
int test_main(int, char *[]) {
foo1();
foo2();
foo3();
foo4();
foo5();
foo7();
return 0; return 0;
} }

View File

@ -34,6 +34,10 @@ typedef istringstream useThisIStringStream;
int test_main(int argc, char * argv[] ) { int test_main(int argc, char * argv[] ) {
using boost::tuples::set_close;
using boost::tuples::set_open;
using boost::tuples::set_delimiter;
useThisOStringStream os1; useThisOStringStream os1;
// Set format [a, b, c] for os1 // Set format [a, b, c] for os1

View File

@ -1,8 +1,5 @@
// tuple_test_bench.cpp -------------------------------- // tuple_test_bench.cpp --------------------------------
// Defining any of E1 to E5 or E7 to E11 opens some illegal code that
// should cause the compliation to fail.
#define BOOST_INCLUDE_MAIN // for testing, include rather than link #define BOOST_INCLUDE_MAIN // for testing, include rather than link
#include <boost/test/test_tools.hpp> // see "Header Implementation Option" #include <boost/test/test_tools.hpp> // see "Header Implementation Option"
@ -12,24 +9,63 @@
#include <string> #include <string>
#include <utility> #include <utility>
#include <vector>
#include <algorithm>
#include <functional>
#include <iostream>
using namespace std; using namespace std;
using namespace boost; using namespace boost;
// ----------------------------------------------------------------------------
// helpers
// ----------------------------------------------------------------------------
class A {};
class B {};
class C {};
// classes with different kinds of conversions
class AA {};
class BB : public AA {};
struct CC { CC() {} CC(const BB& b) {} };
struct DD { operator CC() const { return CC(); }; };
// something to prevent warnings for unused variables
template<class T> void dummy(const T&) {} template<class T> void dummy(const T&) {}
class A {}; class B {}; class C {}; // no public default constructor
class foo {
public:
explicit foo(int v) : val(v) {}
bool operator==(const foo& other) const {
return val == other.val;
}
private:
foo() {}
int val;
};
// another class without a public default constructor
class no_def_constructor {
no_def_constructor() {}
public:
no_def_constructor(std::string) {}
};
// A non-copyable class
class no_copy {
no_copy(const no_copy&) {}
public:
no_copy() {};
};
// ----------------------------------------------------------------------------
// Testing different element types --------------------------------------------
// ----------------------------------------------------------------------------
typedef int(t)(float);
// some arbitrary tuple definitions
typedef tuple<int> t1; typedef tuple<int> t1;
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
typedef tuple<double&, const double&, const double, double*, const double*> t2; typedef tuple<double&, const double&, const double, double*, const double*> t2;
typedef tuple<A, int(*)(char, int), C> t3; typedef tuple<A, int(*)(char, int), C> t3;
@ -43,84 +79,192 @@ typedef tuple<B(A::*)(C&), A&> t7;
#endif #endif
// A non-copyable class // -----------------------------------------------------------------------
class no_copy { // -tuple construction tests ---------------------------------------------
no_copy(const no_copy&) {} // -----------------------------------------------------------------------
public:
no_copy() {};
};
no_copy y;
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
no_copy y;
tuple<no_copy&> x = tuple<no_copy&>(y); // ok tuple<no_copy&> x = tuple<no_copy&>(y); // ok
#endif #endif
#ifdef E1
tuple<no_copy> v1; // should faild
#endif
char cs[10];
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
char cs[10];
tuple<char(&)[10]> v2(cs); // ok tuple<char(&)[10]> v2(cs); // ok
#endif #endif
#ifdef E2
tuple<char[10]> v3; // should fail, arrays must be stored as references
#endif
void
construction_test()
{
// Note, the get function can be called without the tuples:: qualifier,
// as it is lifted to namespace boost with a "using tuples::get" but
// MSVC 6.0 just cannot find get without the namespace qualifier
// -tuple construction tests ------------------------------------ tuple<int> t1;
BOOST_TEST(tuples::get<0>(t1) == int());
tuple<float> t2(5.5f);
BOOST_TEST(tuples::get<0>(t2) > 5.4f && tuples::get<0>(t2) < 5.6f);
// a class without a public default constructor tuple<foo> t3(foo(12));
class no_def_constructor { BOOST_TEST(tuples::get<0>(t3) == foo(12));
no_def_constructor() {}
public:
no_def_constructor(std::string) {} // can be constructed with a string
};
tuple<double> t4(t2);
BOOST_TEST(tuples::get<0>(t4) > 5.4 && tuples::get<0>(t4) < 5.6);
void foo1() { tuple<int, float> t5;
BOOST_TEST(tuples::get<0>(t5) == int());
BOOST_TEST(tuples::get<1>(t5) == float());
#ifdef E3 tuple<int, float> t6(12, 5.5f);
dummy(tuple<no_def_constructor, no_def_constructor, no_def_constructor>()); BOOST_TEST(tuples::get<0>(t6) == 12);
// should fail BOOST_TEST(tuples::get<1>(t6) > 5.4f && tuples::get<1>(t6) < 5.6f);
#endif tuple<int, float> t7(t6);
dummy( tuple<no_def_constructor, no_def_constructor, no_def_constructor>( BOOST_TEST(tuples::get<0>(t7) == 12);
std::string("Jaba"), // ok, since the default BOOST_TEST(tuples::get<1>(t7) > 5.4f && tuples::get<1>(t7) < 5.6f);
std::string("Daba"), // constructor is not used
std::string("Doo"))); tuple<long, double> t8(t6);
} BOOST_TEST(tuples::get<0>(t8) == 12);
BOOST_TEST(tuples::get<1>(t8) > 5.4f && tuples::get<1>(t8) < 5.6f);
dummy(
tuple<no_def_constructor, no_def_constructor, no_def_constructor>(
std::string("Jaba"), // ok, since the default
std::string("Daba"), // constructor is not used
std::string("Doo")
)
);
void foo2() {
// testing default values // testing default values
dummy(tuple<int, double>()); dummy(tuple<int, double>());
dummy(tuple<int, double>(1)); dummy(tuple<int, double>(1));
dummy(tuple<int, double>(1,3.14)); dummy(tuple<int, double>(1,3.14));
#ifdef E4
dummy(tuple<double&>()); // should fail, not defaults for references
dummy(tuple<const double&>()); // likewise
#endif
// dummy(tuple<double&>()); // should fail, not defaults for references
// dummy(tuple<const double&>()); // likewise
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
double dd = 5; double dd = 5;
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
dummy(tuple<double&>(dd)); // ok dummy(tuple<double&>(dd)); // ok
dummy(tuple<const double&>(dd+3.14)); // ok, but dangerous
#endif #endif
#ifdef E5 // dummy(tuple<double&>(dd+3.14)); // should fail,
dummy(tuple<double&>(dd+3.14)); // should fail, temporary to non-const reference // // temporary to non-const reference
#endif
}
// ----------------------------------------------------------------------------
// - testing element access ---------------------------------------------------
// ----------------------------------------------------------------------------
void element_access_test()
{
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
dummy(tuple<const double&>(dd+3.14)); // ok, but potentially dangerous double d = 2.7;
A a;
tuple<int, double&, const A&> t(1, d, a);
const tuple<int, double&, const A> ct = t;
int i = tuples::get<0>(t);
int j = tuples::get<0>(ct);
BOOST_TEST(i == 1 && j == 1);
tuples::get<0>(t) = 5;
BOOST_TEST(t.head == 5);
// tuples::get<0>(ct) = 5; // can't assign to const
double e = tuples::get<1>(t);
BOOST_TEST(e > 2.69 && e < 2.71);
tuples::get<1>(t) = 3.14+i;
BOOST_TEST(tuples::get<1>(t) > 4.13 && tuples::get<1>(t) < 4.15);
// tuples::get<4>(t) = A(); // can't assign to const
// dummy(tuples::get<5>(ct)); // illegal index
++tuples::get<0>(t);
BOOST_TEST(tuples::get<0>(t) == 6);
dummy(i); dummy(j); dummy(e); // avoid warns for unused variables
#endif #endif
} }
// ----------------------------------------------------------------------------
// make_tuple ------------------------------------------ // - copying tuples -----------------------------------------------------------
// ----------------------------------------------------------------------------
void
copy_test()
{
tuple<int, char> t1(4, 'a');
tuple<int, char> t2(5, 'b');
t2 = t1;
BOOST_TEST(tuples::get<0>(t1) == tuples::get<0>(t2));
BOOST_TEST(tuples::get<1>(t1) == tuples::get<1>(t2));
tuple<long, std::string> t3(2, "a");
t3 = t1;
BOOST_TEST((double)tuples::get<0>(t1) == tuples::get<0>(t3));
BOOST_TEST(tuples::get<1>(t1) == tuples::get<1>(t3)[0]);
// testing copy and assignment with implicit conversions between elements
// testing tie
tuple<char, BB*, BB, DD> t;
tuple<int, AA*, CC, CC> a(t);
a = t;
int i; char c; double d;
tie(i, c, d) = make_tuple(1, 'a', 5.5);
BOOST_TEST(i==1);
BOOST_TEST(c=='a');
BOOST_TEST(d>5.4 && d<5.6);
}
void
mutate_test()
{
tuple<int, float, bool, foo> t1(5, 12.2f, true, foo(4));
tuples::get<0>(t1) = 6;
tuples::get<1>(t1) = 2.2f;
tuples::get<2>(t1) = false;
tuples::get<3>(t1) = foo(5);
BOOST_TEST(tuples::get<0>(t1) == 6);
BOOST_TEST(tuples::get<1>(t1) > 2.1f && tuples::get<1>(t1) < 2.3f);
BOOST_TEST(tuples::get<2>(t1) == false);
BOOST_TEST(tuples::get<3>(t1) == foo(5));
}
// ----------------------------------------------------------------------------
// make_tuple tests -----------------------------------------------------------
// ----------------------------------------------------------------------------
void
make_tuple_test()
{
tuple<int, char> t1 = make_tuple(5, 'a');
BOOST_TEST(tuples::get<0>(t1) == 5);
BOOST_TEST(tuples::get<1>(t1) == 'a');
tuple<int, std::string> t2;
t2 = make_tuple((short int)2, std::string("Hi"));
BOOST_TEST(tuples::get<0>(t2) == 2);
BOOST_TEST(tuples::get<1>(t2) == "Hi");
void foo3() {
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
A a; B b; A a; B b;
const A ca = a; const A ca = a;
@ -131,16 +275,18 @@ void foo2() {
make_tuple(ref(ca)); make_tuple(ref(ca));
#endif #endif
// the result of make_tuple is assignable:
BOOST_TEST(make_tuple(2, 4, 6) ==
(make_tuple(1, 2, 3) = make_tuple(2, 4, 6)));
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
make_tuple("Donald", "Daisy"); // should work; make_tuple("Donald", "Daisy"); // should work;
#endif #endif
#ifdef E7 // std::make_pair("Doesn't","Work"); // fails
std::make_pair("Doesn't","Work"); // fails
#endif
// You can store a reference to a function in a tuple // You can store a reference to a function in a tuple
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
tuple<void(&)()> adf(foo3); tuple<void(&)()> adf(make_tuple_test);
dummy(adf); // avoid warning for unused variable dummy(adf); // avoid warning for unused variable
#endif #endif
@ -148,17 +294,14 @@ void foo2() {
// But make_tuple doesn't work // But make_tuple doesn't work
// with function references, since it creates a const qualified function type // with function references, since it creates a const qualified function type
// make_tuple(foo3); // make_tuple(make_tuple_test);
// With function pointers, make_tuple works just fine // With function pointers, make_tuple works just fine
#if !defined(__BORLANDC__) || __BORLAND__ > 0x0551 #if !defined(__BORLANDC__) || __BORLAND__ > 0x0551
make_tuple(&foo3); make_tuple(&make_tuple_test);
#endif #endif
// NOTE: // NOTE:
// //
// wrapping it the function reference with ref helps on gcc 2.95.2. // wrapping it the function reference with ref helps on gcc 2.95.2.
@ -167,103 +310,94 @@ void foo2() {
// make_tuple(ref(foo3)); // make_tuple(ref(foo3));
// It seems that edg can't use implicitly the ref's conversion operator, e.g.: // It seems that edg can't use implicitly the ref's conversion operator, e.g.:
// typedef void (&foo3type) (void); // typedef void (&func_t) (void);
// foo3type foo3ref = static_cast<foo3type>(ref(foo3)); // works fine // func_t fref = static_cast<func_t>(ref(make_tuple_test)); // works fine
// foo3type foo3ref = ref(foo3); // error // func_t fref = ref(make_tuple_test); // error
// This is probably not a very common situation, so currently // This is probably not a very common situation, so currently
// I don't know how which compiler is right (JJ) // I don't know how which compiler is right (JJ)
} }
void
tie_test()
// - testing element access
void foo4()
{ {
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) int a;
double d = 2.7; char b;
A a; foo c(5);
tuple<int, double&, const A&> t(1, d, a);
const tuple<int, double&, const A> ct = t;
int i = get<0>(t); tie(a, b, c) = make_tuple(2, 'a', foo(3));
int j = get<0>(ct); BOOST_TEST(a == 2);
BOOST_TEST(i == 1 && j == 1); BOOST_TEST(b == 'a');
BOOST_TEST(c == foo(3));
get<0>(t) = 5;
BOOST_TEST(t.head == 5);
#ifdef E8
get<0>(ct) = 5; // can't assign to const
#endif
double e = get<1>(t); tie(a, tuples::ignore, c) = make_tuple((short int)5, false, foo(5));
BOOST_TEST(e > 2.69 && e < 2.71); BOOST_TEST(a == 5);
BOOST_TEST(b == 'a');
get<1>(t) = 3.14+i; BOOST_TEST(c == foo(5));
BOOST_TEST(get<1>(t) > 4.13 && get<1>(t) < 4.15);
#ifdef E9
get<4>(t) = A(); // can't assign to const
#endif
#ifdef E10
dummy(get<5>(ct)); // illegal index
#endif
++get<0>(t);
BOOST_TEST(get<0>(t) == 6);
dummy(i); dummy(j); dummy(e); // avoid warns for unused variables
#endif
}
// testing copy and assignment with implicit conversions between elements
// testing tie
class AA {};
class BB : public AA {};
struct CC { CC() {} CC(const BB& b) {} };
struct DD { operator CC() const { return CC(); }; };
void foo5() {
tuple<char, BB*, BB, DD> t;
tuple<int, AA*, CC, CC> a(t);
a = t;
}
void foo6() {
int i; char c; double d;
tie(i, c, d) = make_tuple(1, 'a', 5.5);
BOOST_TEST(i==1);
BOOST_TEST(c=='a');
BOOST_TEST(d==5.5);
}
// testing tie
// testing assignment from std::pair // testing assignment from std::pair
void foo7() {
int i, j; int i, j;
tie (i, j) = std::make_pair(1, 2); tie (i, j) = std::make_pair(1, 2);
BOOST_TEST(i == 1 && j == 2); BOOST_TEST(i == 1 && j == 2);
tuple<int, int, float> a; tuple<int, int, float> ta;
#ifdef E11 #ifdef E11
a = std::make_pair(1, 2); // should fail, tuple is of length 3, not 2 ta = std::make_pair(1, 2); // should fail, tuple is of length 3, not 2
#endif #endif
// the result of make_tuple is assignable: dummy(ta);
BOOST_TEST(make_tuple(2, 4, 6) ==
(make_tuple(1, 2, 3) = make_tuple(2, 4, 6)));
dummy(a);
} }
// Testing cons lists
void foo8() // ----------------------------------------------------------------------------
// - testing tuple equality -------------------------------------------------
// ----------------------------------------------------------------------------
void
equality_test()
{
tuple<int, char> t1(5, 'a');
tuple<int, char> t2(5, 'a');
BOOST_TEST(t1 == t2);
tuple<int, char> t3(5, 'b');
tuple<int, char> t4(2, 'a');
BOOST_TEST(t1 != t3);
BOOST_TEST(t1 != t4);
}
// ----------------------------------------------------------------------------
// - testing tuple comparisons -----------------------------------------------
// ----------------------------------------------------------------------------
void
ordering_test()
{
tuple<int, float> t1(4, 3.3f);
tuple<short, float> t2(5, 3.3f);
tuple<long, double> t3(5, 4.4);
BOOST_TEST(t1 < t2);
BOOST_TEST(t1 <= t2);
BOOST_TEST(t2 > t1);
BOOST_TEST(t2 >= t1);
BOOST_TEST(t2 < t3);
BOOST_TEST(t2 <= t3);
BOOST_TEST(t3 > t2);
BOOST_TEST(t3 >= t2);
}
// ----------------------------------------------------------------------------
// - testing cons lists -------------------------------------------------------
// ----------------------------------------------------------------------------
void cons_test()
{ {
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
using tuples::cons;
using tuples::null_type;
cons<volatile float, null_type> a(1, null_type()); cons<volatile float, null_type> a(1, null_type());
cons<const int, cons<volatile float, null_type> > b(2,a); cons<const int, cons<volatile float, null_type> > b(2,a);
int i = 3; int i = 3;
@ -275,27 +409,32 @@ void foo8()
#endif #endif
} }
// Testing const tuples // ----------------------------------------------------------------------------
void foo9() // - testing const tuples -----------------------------------------------------
// ----------------------------------------------------------------------------
void const_tuple_test()
{ {
const tuple<int, float> t1(5, 3.3f); const tuple<int, float> t1(5, 3.3f);
BOOST_TEST(get<0>(t1) == 5); BOOST_TEST(tuples::get<0>(t1) == 5);
BOOST_TEST(get<1>(t1) == 3.3f); BOOST_TEST(tuples::get<1>(t1) == 3.3f);
} }
// --------------------------------
// ---------------------------- // ----------------------------------------------------------------------------
// - main ---------------------------------------------------------------------
// ----------------------------------------------------------------------------
int test_main(int, char *[]) { int test_main(int, char *[]) {
foo1(); construction_test();
foo2(); element_access_test();
foo3(); copy_test();
foo4(); mutate_test();
foo5(); make_tuple_test();
foo6(); tie_test();
foo7(); equality_test();
foo8(); ordering_test();
foo9(); cons_test();
const_tuple_test();
return 0; return 0;
} }