2018-03-15 23:48:21 +11:00
|
|
|
#include "tuple/type.hpp"
|
|
|
|
#include "tuple/value.hpp"
|
2015-04-20 17:16:18 +10:00
|
|
|
|
|
|
|
#include "tap.hpp"
|
|
|
|
|
|
|
|
#include <typeindex>
|
2016-10-11 23:47:57 +11:00
|
|
|
#include <vector>
|
|
|
|
|
2015-04-20 17:16:18 +10:00
|
|
|
|
2015-04-21 14:19:56 +10:00
|
|
|
template <typename T>
|
|
|
|
struct int_mapper
|
|
|
|
{
|
|
|
|
typedef int type;
|
|
|
|
};
|
|
|
|
|
2015-04-20 17:16:18 +10:00
|
|
|
int
|
|
|
|
main ()
|
|
|
|
{
|
|
|
|
util::TAP::logger tap;
|
|
|
|
|
2018-03-15 23:48:21 +11:00
|
|
|
static_assert (
|
|
|
|
util::tuple::type::index<
|
|
|
|
std::tuple<float,int,void>,
|
|
|
|
int
|
|
|
|
>::value == 1
|
|
|
|
);
|
|
|
|
|
2015-04-20 17:16:18 +10:00
|
|
|
{
|
|
|
|
auto tuple = std::make_tuple (1,2,3,4);
|
|
|
|
std::vector<int> expected {{ 1, 2, 3, 4 }};
|
|
|
|
|
|
|
|
std::vector<int> actual;
|
2018-03-15 23:48:21 +11:00
|
|
|
util::tuple::value::each ([&actual] (auto i) { actual.push_back (i); }, tuple);
|
2015-04-20 17:16:18 +10:00
|
|
|
|
|
|
|
tap.expect_eq (actual, expected, "value iteration");
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2015-10-08 12:20:56 +11:00
|
|
|
#if !defined(NO_RTTI)
|
2015-04-20 17:16:18 +10:00
|
|
|
auto tuple = std::make_tuple (1u, 1, 1.f, 1.);
|
|
|
|
std::vector<std::type_index> expected {
|
|
|
|
std::type_index (typeid (1u)),
|
|
|
|
std::type_index (typeid (1)),
|
|
|
|
std::type_index (typeid (1.f)),
|
|
|
|
std::type_index (typeid (1.))
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<std::type_index> actual;
|
2018-03-15 23:48:21 +11:00
|
|
|
util::tuple::type::each<decltype(tuple)> ([&actual] (auto i) {
|
2015-04-20 17:16:18 +10:00
|
|
|
actual.push_back (typeid (typename decltype(i)::type));
|
|
|
|
});
|
|
|
|
|
|
|
|
tap.expect_eq (actual, expected, "type iteration");
|
2015-10-08 12:20:56 +11:00
|
|
|
#else
|
2016-05-12 17:59:08 +10:00
|
|
|
tap.skip ("type iteration because no-rtti");
|
2015-10-08 12:20:56 +11:00
|
|
|
#endif
|
2015-04-20 17:16:18 +10:00
|
|
|
}
|
2015-04-21 14:19:56 +10:00
|
|
|
|
2015-10-08 12:20:56 +11:00
|
|
|
|
2015-04-21 14:19:56 +10:00
|
|
|
{
|
2015-05-01 02:43:27 +10:00
|
|
|
using src_t = std::tuple<std::string>;
|
2018-03-15 23:48:21 +11:00
|
|
|
using dst_t = typename util::tuple::type::map<src_t, int_mapper>::type;
|
2015-04-21 14:19:56 +10:00
|
|
|
|
2015-05-01 02:43:27 +10:00
|
|
|
tap.expect (std::is_same<dst_t, std::tuple<int>>::value, "tuple type mapping");
|
2015-04-21 14:19:56 +10:00
|
|
|
}
|
2017-05-22 13:55:21 +10:00
|
|
|
|
|
|
|
return tap.status ();
|
2015-04-20 17:16:18 +10:00
|
|
|
}
|