1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
// (C) Copyright John Maddock 2005.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifdef TEST_STD_HEADERS
#include <tuple>
#include <functional>
#include <utility>
#else
#include <boost/tr1/tuple.hpp>
#include <boost/tr1/functional.hpp>
#include <boost/tr1/utility.hpp>
#endif
#include <boost/static_assert.hpp>
#include <boost/type_traits/is_same.hpp>
#include "verify_return.hpp"
struct strict_comparison1{};
struct strict_comparison2
{
strict_comparison2();
strict_comparison2(const strict_comparison1&);
strict_comparison2(const strict_comparison2&);
strict_comparison2& operator=(const strict_comparison2&);
strict_comparison2& operator=(const strict_comparison1&);
};
bool operator==(const strict_comparison1&, const strict_comparison1&);
bool operator<(const strict_comparison1&, const strict_comparison1&);
bool operator==(const strict_comparison2&, const strict_comparison2&);
bool operator<(const strict_comparison2&, const strict_comparison2&);
bool operator==(const strict_comparison1&, const strict_comparison2&);
bool operator<(const strict_comparison1&, const strict_comparison2&);
bool operator==(const strict_comparison2&, const strict_comparison1&);
bool operator<(const strict_comparison2&, const strict_comparison1&);
int main()
{
std::tr1::tuple<int> t1a;
std::tr1::tuple<int> t1b(0);
std::tr1::tuple<int> t1c(t1b);
t1a = t1c;
std::tr1::tuple<int> t1d(std::tr1::tuple<short>(0));
t1a = std::tr1::tuple<short>(0);
std::tr1::tuple<int, long> t2a;
std::tr1::tuple<int, long> t2b(0, 0);
std::tr1::tuple<int, long> t2c(t2b);
t2a = t2c;
std::tr1::tuple<int, long> t2d(std::tr1::tuple<short, int>(0, 0));
t2a = std::tr1::tuple<short, int>(0, 0);
std::tr1::tuple<int, long> t2e(std::make_pair(0, 0L));
t2e = std::make_pair(0, 0L);
// check implementation limits:
std::tr1::tuple<int, long, float, int, int, int, int, int, int> t10(0, 0, 0, 0, 0, 0, 0, 0, 0);
// make_tuple:
verify_return_type(std::tr1::make_tuple(0, 0, 0L), std::tr1::tuple<int, int, long>());
int i = 0;
std::tr1::tuple<int&, int, long> t3a(std::tr1::make_tuple(std::tr1::ref(i), 0, 0L));
verify_return_type(std::tr1::make_tuple(std::tr1::ref(i), 0, 0L), t3a);
std::tr1::tuple<const int&, int, long> t3b(std::tr1::make_tuple(std::tr1::cref(i), 0, 0L));
verify_return_type(std::tr1::make_tuple(std::tr1::cref(i), 0, 0L), t3b);
long j = 0;
std::tr1::tuple<int&, long&> tt(std::tr1::tie(i,j));
BOOST_STATIC_ASSERT((::std::tr1::tuple_size<std::tr1::tuple<int, long> >::value == 2));
BOOST_STATIC_ASSERT((::std::tr1::tuple_size<std::tr1::tuple<int, long, float, int, int, int, int, int, int> >::value == 9));
BOOST_STATIC_ASSERT((::boost::is_same< ::std::tr1::tuple_element<0, std::tr1::tuple<int, long> >::type, int>::value));
BOOST_STATIC_ASSERT((::boost::is_same< ::std::tr1::tuple_element<1, std::tr1::tuple<int, long> >::type, long>::value));
BOOST_STATIC_ASSERT((::boost::is_same< ::std::tr1::tuple_element<0, std::tr1::tuple<int&, long> >::type, int&>::value));
BOOST_STATIC_ASSERT((::boost::is_same< ::std::tr1::tuple_element<0, std::tr1::tuple<const int&, long> >::type, const int&>::value));
// get:
verify_return_type(&::std::tr1::get<0>(t1a), static_cast<int*>(0));
verify_return_type(&::std::tr1::get<1>(t2d), static_cast<long*>(0));
verify_return_type(&::std::tr1::get<0>(t3a), static_cast<int*>(0));
verify_return_type(&::std::tr1::get<0>(t3b), static_cast<const int*>(0));
const std::tr1::tuple<int>& cr1 = t1a;
verify_return_type(&::std::tr1::get<0>(cr1), static_cast<const int*>(0));
const std::tr1::tuple<int&, int, long>& cr2 = t3a;
verify_return_type(&::std::tr1::get<0>(cr2), static_cast<int*>(0));
const std::tr1::tuple<const int&, int, long>& cr3 = t3b;
// comparison:
verify_return_type(cr2 == cr3, false);
verify_return_type(cr2 != cr3, false);
verify_return_type(cr2 < cr3, false);
verify_return_type(cr2 > cr3, false);
verify_return_type(cr2 <= cr3, false);
verify_return_type(cr2 >= cr3, false);
// strict comparisons:
const std::tr1::tuple<strict_comparison1, strict_comparison2> comp1, comp2;
verify_return_type(comp1 == comp2, false);
verify_return_type(comp1 != comp2, false);
verify_return_type(comp1 < comp2, false);
verify_return_type(comp1 > comp2, false);
verify_return_type(comp1 <= comp2, false);
verify_return_type(comp1 >= comp2, false);
// test strict mixed comparisons
const std::tr1::tuple<strict_comparison2, strict_comparison1> comp3;
verify_return_type(comp1 == comp3, false);
verify_return_type(comp1 != comp3, false);
verify_return_type(comp1 < comp3, false);
verify_return_type(comp1 > comp3, false);
verify_return_type(comp1 <= comp3, false);
verify_return_type(comp1 >= comp3, false);
verify_return_type(comp3 == comp2, false);
verify_return_type(comp3 != comp2, false);
verify_return_type(comp3 < comp2, false);
verify_return_type(comp3 > comp2, false);
verify_return_type(comp3 <= comp2, false);
verify_return_type(comp3 >= comp2, false);
// test mixed construct and assign:
const std::tr1::tuple<strict_comparison1, double> cons1;
std::tr1::tuple<strict_comparison2, long double> cons2(cons1);
cons2 = cons1;
const std::pair<strict_comparison1, double> p1;
std::tr1::tuple<strict_comparison2, long double> cons3(p1);
cons3 = p1;
// pair interface:
BOOST_STATIC_ASSERT((::std::tr1::tuple_size<std::pair<int, long> >::value == 2));
BOOST_STATIC_ASSERT((::std::tr1::tuple_size<std::pair<int, float> >::value == 2));
BOOST_STATIC_ASSERT((::boost::is_same< ::std::tr1::tuple_element<0, std::pair<int, long> >::type, int>::value));
BOOST_STATIC_ASSERT((::boost::is_same< ::std::tr1::tuple_element<1, std::pair<int, long> >::type, long>::value));
std::pair<int, long> p2;
const std::pair<int, long>& p3 = p2;
verify_return_type(&std::tr1::get<0>(p2), static_cast<int*>(0));
verify_return_type(&std::tr1::get<1>(p2), static_cast<long*>(0));
verify_return_type(&std::tr1::get<0>(p3), static_cast<const int*>(0));
verify_return_type(&std::tr1::get<1>(p3), static_cast<const long*>(0));
return 0;
}
|