2015-04-20 17:16:18 +10:00
|
|
|
#include "tap.hpp"
|
|
|
|
|
2018-04-05 13:54:42 +10:00
|
|
|
#include "tuple/type.hpp"
|
2016-10-11 23:47:57 +11:00
|
|
|
|
2018-04-05 13:54:42 +10:00
|
|
|
#include <typeindex>
|
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;
|
|
|
|
};
|
|
|
|
|
2018-04-05 13:54:42 +10:00
|
|
|
|
2015-04-20 17:16:18 +10:00
|
|
|
int
|
2018-04-05 13:54:42 +10:00
|
|
|
main (void)
|
2015-04-20 17:16:18 +10:00
|
|
|
{
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::TAP::logger tap;
|
2015-04-20 17:16:18 +10:00
|
|
|
|
|
|
|
{
|
2018-04-05 13:54:42 +10:00
|
|
|
using tuple_t = std::tuple<float,int,void>;
|
2018-08-05 14:42:02 +10:00
|
|
|
tap.expect_eq (cruft::tuple::type::index<tuple_t,int>::value, 1u, "tuple index extraction");
|
2015-04-20 17:16:18 +10:00
|
|
|
}
|
|
|
|
|
2018-11-13 12:56:48 +11:00
|
|
|
{
|
|
|
|
using tuple_t = std::tuple<float,int,void>;
|
|
|
|
tap.expect (
|
|
|
|
std::is_same_v<
|
|
|
|
cruft::tuple::type::nth_t<tuple_t,1>,
|
|
|
|
int
|
|
|
|
>,
|
|
|
|
"tuple type indexing with 'nth'"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-04-20 17:16:18 +10:00
|
|
|
{
|
2018-04-05 13:54:42 +10: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-08-05 14:42:02 +10:00
|
|
|
cruft::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");
|
2018-04-05 13:54:42 +10:00
|
|
|
#else
|
2016-05-12 17:59:08 +10:00
|
|
|
tap.skip ("type iteration because no-rtti");
|
2018-04-05 13:54:42 +10:00
|
|
|
#endif
|
2015-04-20 17:16:18 +10:00
|
|
|
}
|
2015-04-21 14:19:56 +10:00
|
|
|
|
2018-06-06 19:13:17 +10:00
|
|
|
{
|
|
|
|
using pair_t = std::pair<int,float>;
|
|
|
|
using tuple_t = std::tuple<int,float>;
|
|
|
|
|
2018-08-05 14:42:02 +10:00
|
|
|
tap.expect (std::is_same_v<cruft::tuple::type::entuple_t<pair_t>, tuple_t>, "entuple a pair");
|
2018-06-06 19:13:17 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
using a = std::pair<int,float>;
|
|
|
|
using b = std::tuple<char>;
|
|
|
|
using c = std::tuple<int,float,char>;
|
|
|
|
|
|
|
|
tap.expect (std::is_same_v<
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::tuple::type::cat_t<a,b>, c
|
2018-06-06 19:13:17 +10:00
|
|
|
>, "concatenate pair and tuple");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
using original_t = std::tuple<int,char,float,int,double,int>;
|
|
|
|
using removed_t = std::tuple<char,float,double>;
|
|
|
|
|
|
|
|
tap.expect (std::is_same_v<
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::tuple::type::remove_t<int,original_t>,
|
2018-06-06 19:13:17 +10:00
|
|
|
removed_t
|
|
|
|
>, "removed int from tuple");
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
using original_t = std::tuple<int,float,float,char,double,char>;
|
|
|
|
using unique_t = std::tuple<int,float,char,double>;
|
|
|
|
|
|
|
|
tap.expect (std::is_same_v<
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::tuple::type::unique_t<original_t>,
|
2018-06-06 19:13:17 +10:00
|
|
|
unique_t
|
|
|
|
>, "removed duplicates from tuple");
|
|
|
|
}
|
|
|
|
|
2015-04-21 14:19:56 +10:00
|
|
|
{
|
2018-04-05 13:54:42 +10:00
|
|
|
|
2015-05-01 02:43:27 +10:00
|
|
|
using src_t = std::tuple<std::string>;
|
2018-08-05 14:42:02 +10:00
|
|
|
using dst_t = typename cruft::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 ();
|
2018-04-05 13:54:42 +10:00
|
|
|
}
|