DEV: meta reshape
This commit is contained in:
@@ -0,0 +1,218 @@
|
||||
/*!
|
||||
* \file TmetaBasic.cpp
|
||||
*
|
||||
* Copyright (C) 2018 Christos Choutouridis
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#include <utl/meta/meta.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <type_traits>
|
||||
|
||||
namespace TmetaBasic {
|
||||
using namespace utl;
|
||||
using namespace meta;
|
||||
|
||||
/*
|
||||
* Types to behave like Fixtures
|
||||
*/
|
||||
// Test type_of fixture
|
||||
template<class T> struct Identity {
|
||||
using type = T;
|
||||
};
|
||||
|
||||
/*
|
||||
* Test integral constant
|
||||
*/
|
||||
TEST(TmetaBasic, IntegrealType) {
|
||||
EXPECT_EQ(true, (std::is_same<int, eval<Identity<int>>>::value));
|
||||
EXPECT_EQ(true, (std::is_same<nil_, eval<nil_>>::value));
|
||||
EXPECT_EQ(true, (std::is_same<nil_, eval<eval<nil_>>>::value));
|
||||
EXPECT_EQ(true, (std::is_same<nil_, eval<eval<eval<nil_>>>>::value));
|
||||
}
|
||||
TEST(TmetaBasic, IntegrealConstant) {
|
||||
EXPECT_EQ(true, (std::is_same<int, integral_<int, 42>::value_type>::value));
|
||||
EXPECT_EQ(true, (std::is_same<int, integral_<int, 42>::type::value_type>::value));
|
||||
EXPECT_EQ(42, (integral_<int, 0>::value_type(42)));
|
||||
EXPECT_EQ(42, (integral_<int, 42>()));
|
||||
}
|
||||
TEST(TmetaBasic, BasicTypes) {
|
||||
EXPECT_EQ(true, (std::is_same<bool, bool_<false>::value_type>::value));
|
||||
EXPECT_EQ(true, bool_<true>::value);
|
||||
EXPECT_EQ(true, (std::is_same<bool, false_::value_type>::value));
|
||||
EXPECT_EQ(false, false_::value);
|
||||
EXPECT_EQ(true, (std::is_same<bool, true_::value_type>::value));
|
||||
EXPECT_EQ(true, true_::value);
|
||||
|
||||
EXPECT_EQ(true, (std::is_same<int8_t, int8_<0>::value_type>::value));
|
||||
EXPECT_EQ(42, int8_<42>::value);
|
||||
EXPECT_EQ(true, (std::is_same<uint8_t, uint8_<0>::value_type>::value));
|
||||
EXPECT_EQ(42u, uint8_<42u>::value);
|
||||
EXPECT_EQ(true, (std::is_same<int16_t, int16_<0>::value_type>::value));
|
||||
EXPECT_EQ(42, int16_<42>::value);
|
||||
EXPECT_EQ(true, (std::is_same<uint16_t, uint16_<0>::value_type>::value));
|
||||
EXPECT_EQ(42u, uint16_<42u>::value);
|
||||
EXPECT_EQ(true, (std::is_same<int32_t, int32_<0>::value_type>::value));
|
||||
EXPECT_EQ(42, int32_<42>::value);
|
||||
EXPECT_EQ(true, (std::is_same<uint32_t, uint32_<0>::value_type>::value));
|
||||
EXPECT_EQ(42u, uint32_<42u>::value);
|
||||
|
||||
EXPECT_EQ(true, (std::is_same<char, char_<0>::value_type>::value));
|
||||
EXPECT_EQ(42, char_<42>::value);
|
||||
EXPECT_EQ(true, (std::is_same<int, int_<0>::value_type>::value));
|
||||
EXPECT_EQ(42, int_<42>::value);
|
||||
EXPECT_EQ(true, (std::is_same<long, long_<0>::value_type>::value));
|
||||
EXPECT_EQ(42, long_<42>::value);
|
||||
|
||||
EXPECT_EQ(true, (std::is_same<index_t, index_<0>::value_type>::value));
|
||||
EXPECT_EQ(42U, index_<42U>::value);
|
||||
EXPECT_EQ(true, (std::is_same<size_t, size_<0>::value_type>::value));
|
||||
EXPECT_EQ(42U, size_<42U>::value);
|
||||
|
||||
EXPECT_EQ(sizeof(int), sizeof_<int>::value);
|
||||
EXPECT_EQ(alignof(int), alignof_<int>::value);
|
||||
EXPECT_EQ(static_cast<index_t>(-1), Npos::value);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test integral constant selection operations
|
||||
*/
|
||||
TEST(TmetaBasic, Selection) {
|
||||
struct Foo {};
|
||||
struct Bar {};
|
||||
|
||||
EXPECT_EQ (true, (std::is_same<int_<42>, if_c<true, int_<42>, false_>>()));
|
||||
EXPECT_EQ (true, (std::is_same<Foo, if_c<false, int_<42>, Foo>>()));
|
||||
EXPECT_EQ (true, (std::is_same<Foo, if_c<42, Foo, Bar>>()));
|
||||
|
||||
EXPECT_EQ (true, (std::is_same<int_<42>, if_<true_, int_<42>, Bar>>()));
|
||||
EXPECT_EQ (true, (std::is_same<Bar, if_<false_, int_<42>, Bar>>()));
|
||||
EXPECT_EQ (true, (std::is_same<int_<42>, if_<int_<1>, int_<42>, Bar>>()));
|
||||
EXPECT_EQ (true, (std::is_same<Foo, if_<int_<0>, int_<42>, Foo>>()));
|
||||
|
||||
EXPECT_EQ (true, (std::is_same<true_, first_of<true_, false_>>()));
|
||||
EXPECT_EQ (false,(std::is_same<true_, first_of<false_, true_>>()));
|
||||
EXPECT_EQ (false,(std::is_same<true_, second_of<true_, false_>>()));
|
||||
EXPECT_EQ (true, (std::is_same<true_, second_of<false_, true_>>()));
|
||||
|
||||
}
|
||||
|
||||
TEST(TmetaBasic, LogicalOperations) {
|
||||
struct Foo {};
|
||||
struct Bar {};
|
||||
|
||||
EXPECT_EQ (true, (std::is_same<true_, not_c<false>>::value));
|
||||
EXPECT_EQ (true, (std::is_same<false_, not_c<true>>::value));
|
||||
EXPECT_EQ (true, (std::is_same<false_, not_c<1>>::value));
|
||||
EXPECT_EQ (true, (std::is_same<true_, not_c<0>>::value));
|
||||
|
||||
EXPECT_EQ (true, (std::is_same<true_, not_<false_>>()));
|
||||
EXPECT_EQ (true, (std::is_same<false_, not_<true_>>()));
|
||||
EXPECT_EQ (true, (std::is_same<true_, not_<int_<0>>>()));
|
||||
EXPECT_EQ (true, (std::is_same<false_, not_<int_<1>>>()));
|
||||
|
||||
EXPECT_EQ (true, (std::is_same<false_, or_<false_, false_, not_c<true>, int_<0>, not_<true_>>>()));
|
||||
EXPECT_EQ (true, (std::is_same<false_, or_<>>()));
|
||||
EXPECT_EQ (true, (std::is_same<int_<1>,or_<int_<1>>>()));
|
||||
EXPECT_EQ (true, (std::is_same<true_, or_<true_>>()));
|
||||
EXPECT_EQ (true, (std::is_same<true_, or_<false_, true_>>()));
|
||||
EXPECT_EQ (true, (std::is_same<true_, or_<false_, false_, true_>>()));
|
||||
EXPECT_EQ (true, (std::is_same<int_<1>,or_<int_<0>, false_, not_<true_>, not_c<true>, int_<1>>>()));
|
||||
|
||||
EXPECT_EQ (true, (std::is_same<true_, and_<true_, true_, int_<1>, not_<false_>, not_c<false>>>()));
|
||||
EXPECT_EQ (true, (std::is_same<true_, and_<>>()));
|
||||
EXPECT_EQ (true, (std::is_same<true_, and_<true_>>()));
|
||||
EXPECT_EQ (true, (std::is_same<false_, and_<false_>>()));
|
||||
EXPECT_EQ (true, (std::is_same<true_, and_<true_, true_>>()));
|
||||
EXPECT_EQ (true, (std::is_same<false_, and_<true_, false_>>()));
|
||||
EXPECT_EQ (true, (std::is_same<true_, and_<true_, true_, true_>>()));
|
||||
EXPECT_EQ (true, (std::is_same<false_, and_<true_, true_, false_>>()));
|
||||
|
||||
EXPECT_EQ (true, (same_<Foo, Foo>()));
|
||||
EXPECT_EQ (false, (same_<Foo, Bar>()));
|
||||
EXPECT_EQ (true, (not_same_<Foo, Bar>()));
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Test integral constant arithmetic operations
|
||||
*/
|
||||
TEST(TmetaBasic, ArithmeticOperations) {
|
||||
EXPECT_EQ (int_<42>(), inc<int_<41>>());
|
||||
EXPECT_EQ (int_<42>(), dec<int_<43>>());
|
||||
EXPECT_EQ (int_<42>(), (add<int_<23>, add<int_<17>, int_<2>>>()));
|
||||
EXPECT_EQ (int_<42>(), (sub<int_<108>, int_<66>>()));
|
||||
EXPECT_EQ (int_<42>(), (mult<int_<7>, mult<int_<3>, int_<2>>>()));
|
||||
EXPECT_EQ (int_<42>(), (divide<int_<210>, int_<5>>()));
|
||||
EXPECT_EQ (int_<42>(), negate<int_<-42>>());
|
||||
EXPECT_EQ (int_< 1>(), (modulo<int_<43>, int_<42>>()));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test integral constant comparison operations
|
||||
*/
|
||||
TEST(TmetaBasic, ComparisonOperations) {
|
||||
EXPECT_EQ (true, (comp_eq<int_<7>, int_<7>>()));
|
||||
EXPECT_EQ (false, (comp_eq<int_<42>, int_<7>>()));
|
||||
|
||||
EXPECT_EQ (true, (comp_ne<int_<42>, int_<7>>()));
|
||||
EXPECT_EQ (false, (comp_ne<int_<42>, int_<42>>()));
|
||||
|
||||
EXPECT_EQ (true, (comp_lt<int_<42>, int_<43>>()));
|
||||
EXPECT_EQ (false, (comp_lt<int_<43>, int_<42>>()));
|
||||
|
||||
EXPECT_EQ (true, (comp_gt<int_<43>, int_<42>>()));
|
||||
EXPECT_EQ (false, (comp_gt<int_<42>, int_<43>>()));
|
||||
|
||||
EXPECT_EQ (true, (comp_le<int_<42>, int_<43>>()));
|
||||
EXPECT_EQ (true, (comp_le<int_<42>, int_<42>>()));
|
||||
EXPECT_EQ (false, (comp_le<int_<43>, int_<42>>()));
|
||||
|
||||
EXPECT_EQ (true, (comp_ge<int_<43>, int_<42>>()));
|
||||
EXPECT_EQ (true, (comp_ge<int_<42>, int_<42>>()));
|
||||
EXPECT_EQ (false, (comp_ge<int_<42>, int_<43>>()));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test integral constant bit operations
|
||||
*/
|
||||
TEST(TmetaBasic, BitOperations) {
|
||||
EXPECT_EQ (0x00, (bitand_<uint8_<0x55>, uint8_<0xAA>>()));
|
||||
EXPECT_EQ (0xFF, (bitor_ <uint8_<0x55>, uint8_<0xAA>>()));
|
||||
EXPECT_EQ (0xFA, (bitxor_<uint8_<0x55>, uint8_<0xAF>>()));
|
||||
EXPECT_EQ (0x00, (bitnot_<uint8_<-1>>()));
|
||||
|
||||
EXPECT_EQ (0x04, (shift_left<uint8_<0x01>, uint8_<2>>()));
|
||||
EXPECT_EQ (0x00, (shift_left<uint8_<0x80>, uint8_<1>>()));
|
||||
EXPECT_EQ (0x02, (shift_right<uint8_<0x08>, uint8_<2>>()));
|
||||
EXPECT_EQ (0x00, (shift_right<uint8_<0x01>, uint8_<1>>()));
|
||||
}
|
||||
|
||||
/*
|
||||
* SFINAE
|
||||
*/
|
||||
template <typename T, typename =when<same_<T, int>::type::value>>
|
||||
int check (T x) { return x; }
|
||||
int check (...) { return 0; }
|
||||
|
||||
TEST(TmetaBasic, Sfinae) {
|
||||
EXPECT_EQ (42, check(42));
|
||||
EXPECT_EQ (0, check(42.0));
|
||||
EXPECT_EQ (0, check());
|
||||
|
||||
// enable_if is imported so we trust stl and skip testing it
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
/*!
|
||||
* \file TmetaDetection.cpp
|
||||
*
|
||||
* Copyright (C) 2018 Christos Choutouridis
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation, either version 3
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#include <utl/meta/meta.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <type_traits>
|
||||
|
||||
namespace TmetaDetection {
|
||||
using namespace utl;
|
||||
using namespace meta;
|
||||
|
||||
/*
|
||||
* Types to behave like Fixtures
|
||||
*/
|
||||
struct Foo {};
|
||||
struct Bar {};
|
||||
|
||||
template <typename T> struct A {
|
||||
using type = T; // nested type
|
||||
A(int i, double d) : i_(i), d_(d) {} // declare a non-trivial constructor
|
||||
A& operator++() { ++i_; return *this; } // declare an operator
|
||||
|
||||
// A sfinae function
|
||||
template <typename TT = T, typename = when<std::is_integral<TT>::type::value>>
|
||||
TT sfun () { return TT{}; }
|
||||
private:
|
||||
int i_; double d_;
|
||||
};
|
||||
|
||||
// A binary metafunction
|
||||
template <typename T1, typename T2>
|
||||
struct mFun {
|
||||
using type = std::is_same <T1, T2>;
|
||||
};
|
||||
|
||||
// detectors
|
||||
template <typename T> using try_type = typename T::type;
|
||||
template <typename T> using try_none = typename T::none;
|
||||
template <typename T> using try_ctor1= decltype (T(std::declval<int>(), std::declval<double>()));
|
||||
template <typename T> using try_ctor2= decltype (T(std::declval<int>()));
|
||||
template <typename T> using try_ppT = decltype (++(std::declval<T>()));
|
||||
template <typename T> using try_Tpp = decltype (std::declval<T>()++);
|
||||
template <typename T> using try_sfun = decltype (std::declval<T>().sfun());
|
||||
|
||||
/*
|
||||
* void_t
|
||||
*/
|
||||
TEST(TmetaDetection, VoidType) {
|
||||
EXPECT_EQ(true, (std::is_same<void, void_t<int, long, void*, void, Foo, Bar>>()));
|
||||
EXPECT_EQ(true, (std::is_same<void, void_t<>>()));
|
||||
}
|
||||
|
||||
/*
|
||||
* not a type
|
||||
*/
|
||||
TEST(TmetaDetection, NotAType) {
|
||||
EXPECT_EQ(false, (std::is_default_constructible<nat_>()));
|
||||
EXPECT_EQ(false, (std::is_destructible<nat_>()));
|
||||
EXPECT_EQ(false, (std::is_copy_constructible<nat_>()));
|
||||
EXPECT_EQ(false, (std::is_copy_assignable<nat_>()));
|
||||
}
|
||||
|
||||
/*
|
||||
* Idiom
|
||||
*/
|
||||
TEST(TmetaDetection, IsDetected) {
|
||||
|
||||
EXPECT_EQ (true, (std::is_same< true_, is_detected<try_type, A<int>> >()));
|
||||
EXPECT_EQ (true, (std::is_same< false_, is_detected<try_none, A<int>> >()));
|
||||
EXPECT_EQ (true, (std::is_same< true_, is_detected<try_ctor1, A<int>> >()));
|
||||
EXPECT_EQ (true, (std::is_same< false_, is_detected<try_ctor2, A<int>> >()));
|
||||
EXPECT_EQ (true, (std::is_same< true_, is_detected<try_ppT, A<int>> >()));
|
||||
EXPECT_EQ (true, (std::is_same< false_, is_detected<try_Tpp, A<int>> >()));
|
||||
EXPECT_EQ (true, (std::is_same< true_, is_detected<try_sfun, A<int>> >()));
|
||||
EXPECT_EQ (true, (std::is_same< false_, is_detected<try_sfun, A<double>> >()));
|
||||
|
||||
EXPECT_EQ (true, (std::is_same< true_, is_detected<mFun, int, void> >()));
|
||||
EXPECT_EQ (true, (std::is_same< false_, is_detected<mFun, char> >()));
|
||||
EXPECT_EQ (true, (std::is_same< false_, is_detected<mFun, char, void, void> >()));
|
||||
|
||||
EXPECT_EQ (true, (is_detected_v<try_type, A<int>>));
|
||||
EXPECT_EQ (false,(is_detected_v<try_none, A<int>>));
|
||||
EXPECT_EQ (true, (is_detected_v<mFun, int, void>));
|
||||
|
||||
// typePrinter (detected_t<try_none, A>{});
|
||||
}
|
||||
|
||||
/*
|
||||
* Idiom
|
||||
*/
|
||||
TEST(TmetaDetection, Toolkit) {
|
||||
|
||||
// detected_t
|
||||
EXPECT_EQ (true, (std::is_same< int, detected_t<try_type, A<int>> >()));
|
||||
EXPECT_EQ (true, (std::is_same< nat_, detected_t< try_none, A<int>> >()));
|
||||
EXPECT_EQ (true, (std::is_same< A<int>, detected_t< try_ctor1, A<int>> >()));
|
||||
EXPECT_EQ (true, (std::is_same< nat_, detected_t< try_ctor2, A<int>> >()));
|
||||
EXPECT_EQ (true, (std::is_same< A<int>&,detected_t< try_ppT, A<int>> >()));
|
||||
EXPECT_EQ (true, (std::is_same< nat_, detected_t< try_Tpp, A<int>> >()));
|
||||
EXPECT_EQ (true, (std::is_same< int, detected_t< try_sfun, A<int>> >()));
|
||||
EXPECT_EQ (true, (std::is_same< nat_, detected_t< try_sfun, A<double>> >()));
|
||||
|
||||
EXPECT_EQ (true, (std::is_same< nat_, detected_t<mFun, void> >()));
|
||||
EXPECT_EQ (true, (std::is_same< mFun<int, int>,
|
||||
detected_t<mFun, int, int> >()));
|
||||
|
||||
// detected_or_t
|
||||
EXPECT_EQ (true, (std::is_same< int, detected_or_t<Foo, try_type, A<int>> >()));
|
||||
EXPECT_EQ (true, (std::is_same< Foo, detected_or_t<Foo, try_none, A<int>> >()));
|
||||
EXPECT_EQ (true, (std::is_same< A<int>, detected_or_t<void, try_ctor1, A<int>> >()));
|
||||
EXPECT_EQ (true, (std::is_same< void, detected_or_t<void, try_ctor2, A<int>> >()));
|
||||
EXPECT_EQ (true, (std::is_same< A<int>&,detected_or_t<nil_, try_ppT, A<int>> >()));
|
||||
EXPECT_EQ (true, (std::is_same< nil_, detected_or_t<nil_, try_Tpp, A<int>> >()));
|
||||
EXPECT_EQ (true, (std::is_same< int, detected_or_t<void*, try_sfun, A<int>> >()));
|
||||
EXPECT_EQ (true, (std::is_same< void*, detected_or_t<void*, try_sfun, A<double>> >()));
|
||||
|
||||
EXPECT_EQ (true, (std::is_same< nil_, detected_or_t<nil_, mFun, int> >()));
|
||||
EXPECT_EQ (true, (std::is_same< mFun<char, int>,
|
||||
detected_or_t<void, mFun, char, int> >()));
|
||||
|
||||
// is_detected_exact
|
||||
EXPECT_EQ (true, (std::is_same<true_, is_detected_exact< int, try_type, A<int>> >()));
|
||||
EXPECT_EQ (true, (std::is_same<false_, is_detected_exact< int, try_none, A<int>> >()));
|
||||
EXPECT_EQ (true, (std::is_same<true_, is_detected_exact< A<int>, try_ctor1, A<int>> >()));
|
||||
EXPECT_EQ (true, (std::is_same<false_, is_detected_exact< A<int>, try_ctor2, A<int>> >()));
|
||||
EXPECT_EQ (true, (std::is_same<true_, is_detected_exact< A<int>&,try_ppT, A<int>> >()));
|
||||
EXPECT_EQ (true, (std::is_same<false_, is_detected_exact< A<int>&,try_Tpp, A<int>> >()));
|
||||
EXPECT_EQ (true, (std::is_same<true_, is_detected_exact< int, try_sfun, A<int>> >()));
|
||||
EXPECT_EQ (true, (std::is_same<false_, is_detected_exact< int, try_sfun, A<double>> >()));
|
||||
|
||||
EXPECT_EQ (true, (std::is_same<true_, is_detected_exact<mFun<char, int>, mFun, char, int> >()));
|
||||
EXPECT_EQ (true, (std::is_same<false_, is_detected_exact<mFun<int, int>, mFun, int> >())); // it would be better to check against mFun<int>
|
||||
|
||||
EXPECT_EQ (true, (is_detected_exact_v< int, try_type, A<int>> ));
|
||||
EXPECT_EQ (false,(is_detected_exact_v< int, try_none, A<int>> ));
|
||||
|
||||
// is_detected_convertible
|
||||
EXPECT_EQ (true, (std::is_same<true_, is_detected_convertible< int, try_type, A<char>> >()));
|
||||
EXPECT_EQ (true, (std::is_same<false_, is_detected_convertible< int, try_none, A<int>> >()));
|
||||
EXPECT_EQ (true, (std::is_same<false_, is_detected_convertible< mFun<int, int>, mFun, char, int> >()));
|
||||
|
||||
EXPECT_EQ (true, (is_detected_convertible_v< int, try_type, A<char>> ));
|
||||
EXPECT_EQ (false,(is_detected_convertible_v< int, try_none, A<int>> ));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*!
|
||||
* \file Tmeta.cpp
|
||||
* \file TmetaTypelist.cpp
|
||||
*
|
||||
* Copyright (C) 2018 Christos Choutouridis
|
||||
*
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <type_traits>
|
||||
|
||||
namespace test_meta {
|
||||
namespace TmetaTypelist {
|
||||
using namespace utl;
|
||||
using namespace meta;
|
||||
|
||||
@@ -53,168 +53,91 @@ namespace test_meta {
|
||||
using type = std::is_void<T>;
|
||||
};
|
||||
|
||||
/*
|
||||
* Test integral constant
|
||||
*/
|
||||
TEST(Tmeta, IntegrealType) {
|
||||
EXPECT_EQ(true, (std::is_same<int, eval<Identity<int>>>::value));
|
||||
}
|
||||
TEST(Tmeta, IntegrealConstant) {
|
||||
EXPECT_EQ(true, (std::is_same<int, integral_<int, 42>::value_type>::value));
|
||||
EXPECT_EQ(true, (std::is_same<int, integral_<int, 42>::type::value_type>::value));
|
||||
EXPECT_EQ(42, (integral_<int, 0>::value_type(42)));
|
||||
EXPECT_EQ(42, (integral_<int, 42>()));
|
||||
}
|
||||
TEST(Tmeta, BasicTypes) {
|
||||
EXPECT_EQ(true, (std::is_same<bool, bool_<false>::value_type>::value));
|
||||
EXPECT_EQ(true, bool_<true>::value);
|
||||
EXPECT_EQ(true, (std::is_same<bool, false_::value_type>::value));
|
||||
EXPECT_EQ(false, false_::value);
|
||||
EXPECT_EQ(true, (std::is_same<bool, true_::value_type>::value));
|
||||
EXPECT_EQ(true, true_::value);
|
||||
|
||||
EXPECT_EQ(true, (std::is_same<int8_t, int8_<0>::value_type>::value));
|
||||
EXPECT_EQ(42, int8_<42>::value);
|
||||
EXPECT_EQ(true, (std::is_same<uint8_t, uint8_<0>::value_type>::value));
|
||||
EXPECT_EQ(42u, uint8_<42u>::value);
|
||||
EXPECT_EQ(true, (std::is_same<int16_t, int16_<0>::value_type>::value));
|
||||
EXPECT_EQ(42, int16_<42>::value);
|
||||
EXPECT_EQ(true, (std::is_same<uint16_t, uint16_<0>::value_type>::value));
|
||||
EXPECT_EQ(42u, uint16_<42u>::value);
|
||||
EXPECT_EQ(true, (std::is_same<int32_t, int32_<0>::value_type>::value));
|
||||
EXPECT_EQ(42, int32_<42>::value);
|
||||
EXPECT_EQ(true, (std::is_same<uint32_t, uint32_<0>::value_type>::value));
|
||||
EXPECT_EQ(42u, uint32_<42u>::value);
|
||||
|
||||
EXPECT_EQ(true, (std::is_same<char, char_<0>::value_type>::value));
|
||||
EXPECT_EQ(42, char_<42>::value);
|
||||
EXPECT_EQ(true, (std::is_same<int, int_<0>::value_type>::value));
|
||||
EXPECT_EQ(42, int_<42>::value);
|
||||
EXPECT_EQ(true, (std::is_same<long, long_<0>::value_type>::value));
|
||||
EXPECT_EQ(42, long_<42>::value);
|
||||
|
||||
EXPECT_EQ(true, (std::is_same<index_t, index_<0>::value_type>::value));
|
||||
EXPECT_EQ(42U, index_<42U>::value);
|
||||
EXPECT_EQ(true, (std::is_same<size_t, size_<0>::value_type>::value));
|
||||
EXPECT_EQ(42U, size_<42U>::value);
|
||||
|
||||
EXPECT_EQ(sizeof(int), sizeof_<int>::value);
|
||||
EXPECT_EQ(alignof(int), alignof_<int>::value);
|
||||
EXPECT_EQ(static_cast<index_t>(-1), Npos::value);
|
||||
}
|
||||
/*
|
||||
* Test integral constant arithmetic operations
|
||||
*/
|
||||
TEST(Tmeta, ArithmeticOperations) {
|
||||
EXPECT_EQ (int_<42>(), inc<int_<41>>());
|
||||
EXPECT_EQ (int_<42>(), dec<int_<43>>());
|
||||
EXPECT_EQ (int_<42>(), (add<int_<23>, add<int_<17>, int_<2>>>()));
|
||||
EXPECT_EQ (int_<42>(), (sub<int_<108>, int_<66>>()));
|
||||
EXPECT_EQ (int_<42>(), (mult<int_<7>, mult<int_<3>, int_<2>>>()));
|
||||
EXPECT_EQ (int_<42>(), (divide<int_<210>, int_<5>>()));
|
||||
EXPECT_EQ (int_<42>(), negate<int_<-42>>());
|
||||
EXPECT_EQ (int_< 1>(), (modulo<int_<43>, int_<42>>()));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test logical
|
||||
* Test high order metaFun tools
|
||||
*/
|
||||
TEST(Tmeta, ComparisonOperations) {
|
||||
EXPECT_EQ (true, (std::is_same<bool_<true>, not_c<false>>::value));
|
||||
EXPECT_EQ (true, (comp_eq<int_<7>, int_<7>>()));
|
||||
EXPECT_EQ (true, (comp_ne<int_<42>, int_<7>>()));
|
||||
EXPECT_EQ (true, (comp_lt<int_<42>, int_<43>>()));
|
||||
EXPECT_EQ (true, (comp_gt<int_<43>, int_<42>>()));
|
||||
EXPECT_EQ (true, (comp_le<int_<42>, int_<42>>()));
|
||||
EXPECT_EQ (true, (comp_ge<int_<42>, int_<42>>()));
|
||||
}
|
||||
|
||||
TEST(Tmeta, BitOperations) {
|
||||
EXPECT_EQ (0x00, (bitand_<uint8_<0x55>, uint8_<0xAA>>()));
|
||||
EXPECT_EQ (0xFF, (bitor_ <uint8_<0x55>, uint8_<0xAA>>()));
|
||||
EXPECT_EQ (0xFA, (bitxor_<uint8_<0x55>, uint8_<0xAF>>()));
|
||||
EXPECT_EQ (0x00, (bitnot_<uint8_<-1>>()));
|
||||
|
||||
EXPECT_EQ (0x04, (shift_left<uint8_<0x01>, uint8_<2>>()));
|
||||
EXPECT_EQ (0x00, (shift_left<uint8_<0x80>, uint8_<1>>()));
|
||||
EXPECT_EQ (0x02, (shift_right<uint8_<0x08>, uint8_<2>>()));
|
||||
EXPECT_EQ (0x00, (shift_right<uint8_<0x01>, uint8_<1>>()));
|
||||
}
|
||||
|
||||
TEST(Tmeta, TypeOperations) {
|
||||
struct Foo {};
|
||||
struct Bar {};
|
||||
|
||||
EXPECT_EQ (true, (std::is_same<bool_<true>, not_<bool_<false>>>()));
|
||||
EXPECT_EQ (true, (std::is_same<int_<42>, if_c<true, int_<42>, bool_<false>>>()));
|
||||
EXPECT_EQ (true, (std::is_same<int_<42>, if_<bool_<true>, int_<42>, bool_<false>>>()));
|
||||
|
||||
EXPECT_EQ (true, (std::is_same<true_, or_<true_, false_>>()));
|
||||
EXPECT_EQ (true, (std::is_same<false_, or_<false_, false_>>()));
|
||||
EXPECT_EQ (true, (std::is_same<false_, and_<true_, false_>>()));
|
||||
EXPECT_EQ (true, (std::is_same<true_, and_<true_, true_>>()));
|
||||
|
||||
EXPECT_EQ (true, (same_<Foo, Foo>()));
|
||||
EXPECT_EQ (false, (same_<Foo, Bar>()));
|
||||
EXPECT_EQ (true, (not_same_<Foo, Bar>()));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test void_t
|
||||
*/
|
||||
TEST(Tmeta, VoidType) {
|
||||
struct Foo {};
|
||||
struct Bar {};
|
||||
EXPECT_EQ(true, (std::is_same<void, void_t<int, long, Foo, Bar>>()));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test invoke
|
||||
*/
|
||||
TEST(Tmeta, Invoke) {
|
||||
TEST(TmetaTypelist, Invoke) {
|
||||
using W = wrap <MfunBin>;
|
||||
using Wi = wrap_i<int, MfunBin_i>;
|
||||
using W1 = wrap<MfunUn1>;
|
||||
using W2 = wrap<MfunUn2>;
|
||||
using Q = quote<MfunBin>;
|
||||
using Qi = quote_i<int, MfunBin_i>;
|
||||
using Q1 = quote<MfunUn1>;
|
||||
using Q2 = quote<MfunUn2>;
|
||||
|
||||
// identity
|
||||
EXPECT_EQ (true, (std::is_same<int, eval<identity<int>>>()));
|
||||
EXPECT_EQ (true, (std::is_same<int, identity_t<int>>()));
|
||||
EXPECT_EQ (true, (std::is_same<void*, identity_t<void*>>()));
|
||||
|
||||
// invoke, check that invoke un-wraps and un-quotes staff
|
||||
EXPECT_EQ (true, (std::is_same< invoke<wrap<MfunBin>, int, char>, MfunBin<int, char> >()));
|
||||
EXPECT_EQ (true, (std::is_same< invoke<quote<MfunBin>, int, char>, MfunBin<int, char> >()));
|
||||
EXPECT_EQ (true, (std::is_same< invoke<wrap_i<int, MfunBin_i>, int_<7>, int_<42>>, MfunBin_i<7, 42> >()));
|
||||
EXPECT_EQ (true, (std::is_same< invoke<quote_i<int, MfunBin_i>, int_<7>, int_<42>>, MfunBin_i<7, 42> >()));
|
||||
|
||||
// Wrap
|
||||
EXPECT_EQ (true, (std::is_same< wrap<MfunBin>::template apply<int, char>, MfunBin<int, char> >()));
|
||||
EXPECT_EQ (false, (std::is_same< wrap<MfunBin>::template apply<int, char>, MfunBin<int, int> >()));
|
||||
EXPECT_EQ (true, (std::is_same< wrap_i<int, MfunBin_i>::template apply<int_<7>, int_<42>>, MfunBin_i<7, 42> >()));
|
||||
EXPECT_EQ (false, (std::is_same< wrap_i<int, MfunBin_i>::template apply<int_<7>, int_<42>>, MfunBin_i<42, 7> >()));
|
||||
|
||||
// applicable trait
|
||||
EXPECT_EQ (true, (is_applicable_t<MfunBin, int, long>()));
|
||||
EXPECT_EQ (false, (is_applicable_t<MfunBin, int>()));
|
||||
|
||||
EXPECT_EQ (true, (is_applicable_qt<Q, int, long>()));
|
||||
EXPECT_EQ (false, (is_applicable_qt<Q, int>()));
|
||||
EXPECT_EQ (true, (is_applicable_qt<W, int, long>()));
|
||||
EXPECT_EQ (false, (is_applicable_qt<W, int>()));
|
||||
|
||||
EXPECT_EQ (true, (is_applicable_it<int, MfunBin_i, 7, 42>()));
|
||||
EXPECT_EQ (false, (is_applicable_it<int, MfunBin_i, 42>()));
|
||||
|
||||
// defer
|
||||
EXPECT_EQ (true, (std::is_same<defer<MfunBin, int, void>::type, MfunBin<int, void>>()));
|
||||
EXPECT_EQ (true, (std::is_same<defer<MfunBin, void>::type, nil_>()));
|
||||
EXPECT_EQ (true, (std::is_same<defer_i<int, MfunBin_i, 7, 42>::type, MfunBin_i<7, 42>>()));
|
||||
EXPECT_EQ (true, (std::is_same<defer_i<int, MfunBin_i, 7>::type, nil_>()));
|
||||
|
||||
EXPECT_EQ (true, (std::is_same<invoke<Q, int>, nil_>()));
|
||||
EXPECT_EQ (true, (std::is_same<invoke<Q, int, void*>, MfunBin<int, void*>>()));
|
||||
EXPECT_EQ (true, (std::is_same<invoke<Qi, int_<7>, int_<42>>, MfunBin_i<7, 42>>()));
|
||||
EXPECT_EQ (true, (std::is_same<invoke<Qi, int_<42>>, nil_>()));
|
||||
// quote
|
||||
EXPECT_EQ (true, (std::is_same< quote<MfunBin>::template apply<int, void*>, MfunBin<int, void*> >()));
|
||||
EXPECT_EQ (false,(std::is_same< quote<MfunBin>::template apply<int, void*>, MfunBin<int, int> >()));
|
||||
EXPECT_EQ (true, (std::is_same< quote_i<int, MfunBin_i>::template apply< int_<7>, int_<42>>, MfunBin_i<7, 42> >()));
|
||||
EXPECT_EQ (false,(std::is_same< quote_i<int, MfunBin_i>::template apply< int_<7>, int_<42>>, MfunBin_i<42, 7> >()));
|
||||
|
||||
// compose
|
||||
EXPECT_EQ (true, (std::is_same<invoke<compose_f<MfunUn1>, int>, MfunUn1<int>>()));
|
||||
EXPECT_EQ (true, (std::is_same<invoke<compose_f<MfunUn1, MfunUn2>, int>, MfunUn1<MfunUn2<int>>>()));
|
||||
|
||||
EXPECT_EQ (true, (std::is_same<invoke<compose<W1>, int>, MfunUn1<int>>()));
|
||||
EXPECT_EQ (true, (std::is_same<invoke<compose<W1, W2>, int>, MfunUn1<MfunUn2<int>>>()));
|
||||
EXPECT_EQ (true, (std::is_same<
|
||||
invoke<compose<W1, W2, Wi>, int_<7>, int_<42>>, MfunUn1<MfunUn2<MfunBin_i<7, 42>>>
|
||||
>()));
|
||||
|
||||
EXPECT_EQ (true, (std::is_same<invoke<compose<Q1>, int>, MfunUn1<int>>()));
|
||||
EXPECT_EQ (true, (std::is_same<invoke<compose<Q1, Q2>, int>, MfunUn1<MfunUn2<int>>>()));
|
||||
EXPECT_EQ (true, (std::is_same<
|
||||
invoke<compose<Q1, Q2, Qi>, int_<7>, int_<42>>,
|
||||
MfunUn1<MfunUn2<MfunBin_i<7, 42>>>
|
||||
>()));
|
||||
EXPECT_EQ (true, (std::is_same<
|
||||
invoke<compose<Q1, Q2, Qi>, int_<42>>,
|
||||
MfunUn1<MfunUn2<nil_>>
|
||||
>()));
|
||||
invoke<compose<Q1, Q2, Qi>, int_<7>, int_<42>>, MfunUn1<MfunUn2<MfunBin_i<7, 42>>>
|
||||
>()));
|
||||
|
||||
// bind
|
||||
EXPECT_EQ (true, (std::is_same<invoke<bind_front<Q, int>, long>, MfunBin<int, long>>()));
|
||||
EXPECT_EQ (true, (std::is_same<invoke<bind_back<Q, int>, long>, MfunBin<long, int>>()));
|
||||
|
||||
// Check the case of ill formed parameter composition. Quote must save us
|
||||
EXPECT_EQ (true, (std::is_same< nil_, invoke<Q, int> >()));
|
||||
EXPECT_EQ (true, (std::is_same< nil_, invoke<Qi, int_<42>> >()));
|
||||
EXPECT_EQ (true, (std::is_same< MfunUn1<MfunUn2<nil_>>, invoke<compose<Q1, Q2, Qi>, int_<42>> >()));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test typelist
|
||||
*/
|
||||
TEST(Tmeta_typelist, Basics) {
|
||||
TEST(TmetaTypelist, Basics) {
|
||||
using l1 = typelist<int, int, int>;
|
||||
using l2 = typelist<int, void*, int, void*>;
|
||||
using l3 = typelist<>;
|
||||
@@ -223,6 +146,7 @@ namespace test_meta {
|
||||
EXPECT_EQ (true, (std::is_same<l2, typelist<int, void*>::times<2>>()));
|
||||
EXPECT_EQ (true, (std::is_same<l3, typelist<>::times<3>>()));
|
||||
EXPECT_EQ (true, (std::is_same<l3, typelist<int>::times<0>>()));
|
||||
EXPECT_EQ (true, (std::is_same<l3, typelist<int, void>::times<0>>()));
|
||||
EXPECT_EQ (true, (std::is_same<typelist<short, double>, pair<short, double>>()));
|
||||
|
||||
EXPECT_EQ (true, (std::is_same<l1, repeat <int_<3>, int>>()));
|
||||
@@ -230,29 +154,30 @@ namespace test_meta {
|
||||
|
||||
|
||||
EXPECT_EQ (3, size<l1>());
|
||||
EXPECT_EQ (0, size<l3>());
|
||||
EXPECT_EQ (true, empty<l3>());
|
||||
|
||||
// pass typelist to an invocable
|
||||
EXPECT_EQ (true, (std::is_same<eval<
|
||||
apply<quote<MfunBin>, typelist<int, long>>
|
||||
>,
|
||||
MfunBin<int, long>
|
||||
>()));
|
||||
EXPECT_EQ (true, (std::is_same< apply_t<quote<MfunUn1>, typelist<int>>, MfunUn1<int> >()));
|
||||
EXPECT_EQ (true, (std::is_same< apply_t<quote<MfunBin>, typelist<int, long>>, MfunBin<int, long> >()));
|
||||
}
|
||||
|
||||
TEST(Tmeta_typelist, Element_access) {
|
||||
using l = typelist<char, void, long, double, short>;
|
||||
TEST(TmetaTypelist, ElementAccess) {
|
||||
using l = typelist<char*, void, void*, long, double, short>;
|
||||
|
||||
EXPECT_EQ (true, (std::is_same<char*, at_c<l, 0>>()));
|
||||
EXPECT_EQ (true, (std::is_same<void*, at_c<l, 2>>()));
|
||||
EXPECT_EQ (true, (std::is_same<short, at_c<l, 5>>()));
|
||||
EXPECT_EQ (true, (std::is_same<nil_, at_c<l, 6>>()));
|
||||
|
||||
EXPECT_EQ (true, (std::is_same<char, at_c<l, 0>>()));
|
||||
EXPECT_EQ (true, (std::is_same<long, at_c<l, 2>>()));
|
||||
EXPECT_EQ (true, (std::is_same<nil_, at_c<l, 5>>()));
|
||||
EXPECT_EQ (true, (std::is_same<void, at<l, int_<1>>>()));
|
||||
EXPECT_EQ (true, (std::is_same<long, at<l, int_<3>>>()));
|
||||
|
||||
EXPECT_EQ (true, (std::is_same<char, front<l>>()));
|
||||
EXPECT_EQ (true, (std::is_same<char*, front<l>>()));
|
||||
EXPECT_EQ (true, (std::is_same<short, back<l>>()));
|
||||
}
|
||||
|
||||
TEST(Tmeta_typelist, Concat) {
|
||||
TEST(TmetaTypelist, Concat) {
|
||||
using l1 = typelist<int, long, void>;
|
||||
using l2 = typelist<void*, int*>;
|
||||
using l3 = typelist<double, long double, short>;
|
||||
@@ -266,7 +191,7 @@ namespace test_meta {
|
||||
}
|
||||
|
||||
template<class T1, class T2> struct F {}; // binary invocable
|
||||
TEST(Tmeta_typelist, Fold) {
|
||||
TEST(TmetaTypelist, Fold) {
|
||||
struct X1 {};
|
||||
struct X2 {};
|
||||
struct X3 {};
|
||||
@@ -286,7 +211,7 @@ namespace test_meta {
|
||||
EXPECT_EQ(true, (std::is_same<rev_fold<typelist<X1, X2, X3, X4>, void, Q>, F<X1, F<X2, F<X3, F<X4, void>>>>>()));
|
||||
}
|
||||
|
||||
TEST(Tmeta_typelist, PushPopReverse) {
|
||||
TEST(TmetaTypelist, PushPopReverse) {
|
||||
using list = typelist <int, long, void>;
|
||||
using l_char = typelist <int, long, void, char>;
|
||||
using l_cc = typelist <int, long, void, char, char>;
|
||||
@@ -294,19 +219,19 @@ namespace test_meta {
|
||||
using cc_l = typelist<char, char, int, long, void>;
|
||||
using rev = typelist<void, long, int>;
|
||||
|
||||
EXPECT_EQ (true, (std::is_same<char_l, push_front<list, char>>()));
|
||||
EXPECT_EQ (true, (std::is_same<cc_l, push_front<list, char, char>>()));
|
||||
EXPECT_EQ (true, (std::is_same<list, pop_front <char_l>>()));
|
||||
EXPECT_EQ (true, (std::is_same<l_char, push_back <list, char>>()));
|
||||
EXPECT_EQ (true, (std::is_same<l_cc, push_back <list, char, char>>()));
|
||||
EXPECT_EQ (true, (std::is_same<list, pop_back <l_char>>()));
|
||||
EXPECT_EQ (true, (std::is_same< char_l, push_front<list, char> >()));
|
||||
EXPECT_EQ (true, (std::is_same< cc_l, push_front<list, char, char> >()));
|
||||
EXPECT_EQ (true, (std::is_same< list, pop_front <char_l> >()));
|
||||
EXPECT_EQ (true, (std::is_same< l_char, push_back <list, char> >()));
|
||||
EXPECT_EQ (true, (std::is_same< l_cc, push_back <list, char, char> >()));
|
||||
EXPECT_EQ (true, (std::is_same< list, pop_back <l_char> >()));
|
||||
|
||||
EXPECT_EQ (true, (std::is_same<rev, reverse <list>>()));
|
||||
EXPECT_EQ (true, (std::is_same< rev, reverse <list> >()));
|
||||
}
|
||||
|
||||
TEST(Tmeta_typelist, Transform) {
|
||||
using QBin = quote<MfunBin>;
|
||||
using QUn = quote<MfunUn1>;
|
||||
TEST(TmetaTypelist, Transform) {
|
||||
using QBin = quote<MfunBin>; // both metafuctions return int
|
||||
using QUn = quote<MfunUn1>;
|
||||
|
||||
using l1 = typelist<char, int, float>;
|
||||
using l2 = typelist<void, void, void>;
|
||||
@@ -322,7 +247,7 @@ namespace test_meta {
|
||||
}
|
||||
|
||||
|
||||
TEST(Tmeta_typelist, Find) {
|
||||
TEST(TmetaTypelist, Find) {
|
||||
using l1 = typelist <int, char, long, float>;
|
||||
using l2 = typelist <char, long, float>;
|
||||
using l3 = typelist <long, float>;
|
||||
@@ -341,7 +266,7 @@ namespace test_meta {
|
||||
EXPECT_EQ(true, (std::is_same<l3, seek<l1, long>>()));
|
||||
}
|
||||
|
||||
TEST(Tmeta_typelist, Count) {
|
||||
TEST(TmetaTypelist, Count) {
|
||||
using list = typelist<int, void*, char, int, long*, char, int, short>;
|
||||
using empty = typelist<>;
|
||||
|
||||
@@ -353,7 +278,7 @@ namespace test_meta {
|
||||
EXPECT_EQ (true, (std::is_same<size_<1>, count<list, void*>>()));
|
||||
}
|
||||
|
||||
TEST(Tmeta_typelist, Filter) {
|
||||
TEST(TmetaTypelist, Filter) {
|
||||
using Q1 = quote<Pred_isInt>;
|
||||
using Q2 = quote<Pred_isVoid>;
|
||||
using list = typelist<int, float, char, long*, short, double, void*>;
|
||||
@@ -362,9 +287,10 @@ namespace test_meta {
|
||||
EXPECT_EQ (true, (std::is_same<filtered, filter<list, Q1>>()));
|
||||
EXPECT_EQ (true, (std::is_same<typelist<>, filter<typelist<>, Q1>>()));
|
||||
EXPECT_EQ (true, (std::is_same<typelist<>, filter<list, Q2>>()));
|
||||
EXPECT_EQ (true, (std::is_same<typelist<>, filter<typelist<>, Q1>>()));
|
||||
}
|
||||
|
||||
TEST(Tmeta_typelist, Replace) {
|
||||
TEST(TmetaTypelist, Replace) {
|
||||
using Q = quote<Pred_isInt>;
|
||||
using list = typelist<int, float, char, long*, short, double, void*>;
|
||||
using res = typelist<void,float, void, long*, void, double, void*>;
|
||||
@@ -373,22 +299,44 @@ namespace test_meta {
|
||||
EXPECT_EQ (true, (std::is_same<res, replace_if<list, Q, void>>()));
|
||||
EXPECT_EQ (true, (std::is_same<typelist<>, replace_if<typelist<>, Q, void>>()));
|
||||
EXPECT_EQ (true, (std::is_same<res, replace_if<res, Q, void>>()));
|
||||
EXPECT_EQ (true, (std::is_same<typelist<>, replace_if<typelist<>, Q, void>>()));
|
||||
|
||||
EXPECT_EQ (true, (std::is_same<repl, replace<list, char, void>>()));
|
||||
EXPECT_EQ (true, (std::is_same<typelist<>, replace<typelist<>, char, void>>()));
|
||||
}
|
||||
|
||||
TEST (Tmeta_typelist, AllAnyNone) {
|
||||
TEST (TmetaTypelist, AllAnyNone) {
|
||||
using l1 = typelist<int, float, char, long*, short, double, void*>;
|
||||
using l2 = typelist<int, char, long, short>;
|
||||
using l3 = typelist<>;
|
||||
|
||||
EXPECT_EQ (true, (std::is_same<false_, all_of<l1, quote<Pred_isInt>>>()));
|
||||
EXPECT_EQ (true, (std::is_same<true_, all_of<l2, quote<Pred_isInt>>>()));
|
||||
EXPECT_EQ (true, (std::is_same<false_, all_of<l3, quote<Pred_isVoid>>>()));
|
||||
|
||||
EXPECT_EQ (true, (std::is_same<true_, any_of<l1, quote<Pred_isInt>>>()));
|
||||
EXPECT_EQ (true, (std::is_same<false_, any_of<l2, quote<Pred_isVoid>>>()));
|
||||
EXPECT_EQ (true, (std::is_same<false_, any_of<l3, quote<Pred_isVoid>>>()));
|
||||
|
||||
EXPECT_EQ (true, (std::is_same<true_, none_of<l1, quote<Pred_isVoid>>>()));
|
||||
EXPECT_EQ (true, (std::is_same<false_, none_of<l1, quote<Pred_isInt>>>()));
|
||||
EXPECT_EQ (true, (std::is_same<true_, none_of<l3, quote<Pred_isInt>>>()));
|
||||
}
|
||||
|
||||
/*
|
||||
* Detection idiom
|
||||
*/
|
||||
TEST(Tmeta, DetectionVoidType) {
|
||||
struct Foo {};
|
||||
struct Bar {};
|
||||
EXPECT_EQ(true, (std::is_same<void, void_t<int, long, void*, void, Foo, Bar>>()));
|
||||
EXPECT_EQ(true, (std::is_same<void, void_t<>>()));
|
||||
}
|
||||
|
||||
TEST(Tmeta, DetectionNotAType) {
|
||||
EXPECT_EQ(false, (std::is_default_constructible<nat_>()));
|
||||
EXPECT_EQ(false, (std::is_destructible<nat_>()));
|
||||
EXPECT_EQ(false, (std::is_copy_constructible<nat_>()));
|
||||
EXPECT_EQ(false, (std::is_copy_assignable<nat_>()));
|
||||
}
|
||||
}
|
||||
@@ -68,7 +68,7 @@ namespace test_i2c {
|
||||
uint8_t b = 42;
|
||||
|
||||
i2c.clock(200000UL);
|
||||
EXPECT_EQ(i2c.clock(), 200000UL);
|
||||
//EXPECT_EQ(i2c.clock(), 200000UL);
|
||||
|
||||
EXPECT_EQ(i2c.tx_data(b), true);
|
||||
EXPECT_EQ(i2c.rx_data(true), 0x00);
|
||||
|
||||
Reference in New Issue
Block a user