#include #include "test.hpp" #include #include #include #include #include #include template struct ac { T value; constexpr ac(T i) : value(i) {} }; template struct tuple_meta { typedef std::tuple type; }; struct tuple_meta_class { template struct apply { typedef std::tuple type; }; }; struct implicit_default { int mem1; std::string mem2; }; struct user_default { int mem1; std::string mem2; user_default() { } }; struct user_construct { int mem1; std::string mem2; user_construct(int) { } }; template struct template_user_construct { int mem1; std::string mem2; template_user_construct(T) { } }; FIT_TEST_CASE() { auto v = fit::construct>()(5, 5); FIT_TEST_CHECK(v.size() == 5); FIT_TEST_CHECK(v == std::vector{5, 5, 5, 5, 5}); } FIT_TEST_CASE() { auto v = fit::construct_basic>()(5, 5); FIT_TEST_CHECK(v.size() == 5); FIT_TEST_CHECK(v == std::vector{5, 5, 5, 5, 5}); } FIT_TEST_CASE() { auto v = fit::construct_forward>()(5, 5); FIT_TEST_CHECK(v.size() == 5); FIT_TEST_CHECK(v == std::vector{5, 5, 5, 5, 5}); } FIT_TEST_CASE() { auto x = fit::construct()(); FIT_TEST_CHECK(x.mem1 == 0); FIT_TEST_CHECK(x.mem2 == ""); } FIT_TEST_CASE() { auto x = fit::construct()(); FIT_TEST_CHECK(x.mem1 == 0); FIT_TEST_CHECK(x.mem2 == ""); } FIT_TEST_CASE() { auto x = fit::construct()(3); FIT_TEST_CHECK(x.mem1 == 0); FIT_TEST_CHECK(x.mem2 == ""); } FIT_TEST_CASE() { auto x = fit::construct()(3); FIT_TEST_CHECK(x.mem1 == 0); FIT_TEST_CHECK(x.mem2 == ""); } FIT_TEST_CASE() { auto x = fit::construct_forward()(3); FIT_TEST_CHECK(x.mem1 == 0); FIT_TEST_CHECK(x.mem2 == ""); } FIT_TEST_CASE() { auto x = fit::construct_basic()(3); FIT_TEST_CHECK(x.mem1 == 0); FIT_TEST_CHECK(x.mem2 == ""); } FIT_TEST_CASE() { auto v = fit::construct>()({5, 5, 5, 5, 5}); FIT_TEST_CHECK(v.size() == 5); FIT_TEST_CHECK(v == std::vector{5, 5, 5, 5, 5}); } FIT_TEST_CASE() { auto t = fit::construct()(1, 2, 3); static_assert(std::is_same, decltype(t)>::value, ""); FIT_TEST_CHECK(t == std::make_tuple(1, 2, 3)); // GCC 4.7 doesn't have fully constexpr tuple #if defined (__clang__) || !(defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ < 8) FIT_STATIC_TEST_CHECK(std::make_tuple(1, 2, 3) == fit::construct()(1, 2, 3)); #endif } FIT_TEST_CASE() { auto t = fit::construct()(1, 2); static_assert(std::is_same, decltype(t)>::value, ""); FIT_TEST_CHECK(t == std::make_pair(1, 2)); // GCC 4.7 doesn't have fully constexpr pair #if defined (__clang__) || !(defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ < 8) FIT_STATIC_TEST_CHECK(std::make_pair(1, 2) == fit::construct()(1, 2)); #endif } FIT_TEST_CASE() { auto f = fit::conditional(fit::construct(), fit::identity); FIT_TEST_CHECK(f(1, 2) == std::make_pair(1, 2)); FIT_TEST_CHECK(f(1) == 1); } FIT_TEST_CASE() { auto x = fit::construct()(1); static_assert(std::is_same, decltype(x)>::value, ""); FIT_TEST_CHECK(x.value == ac(1).value); FIT_STATIC_TEST_CHECK(ac(1).value == fit::construct()(1).value); } FIT_TEST_CASE() { auto x = fit::construct_basic()(1); static_assert(std::is_same, decltype(x)>::value, ""); FIT_TEST_CHECK(x.value == ac(1).value); FIT_STATIC_TEST_CHECK(ac(1).value == fit::construct()(1).value); } FIT_TEST_CASE() { int i = 1; auto x = fit::construct_forward()(i); static_assert(std::is_same, decltype(x)>::value, ""); FIT_TEST_CHECK(&x.value == &i); } FIT_TEST_CASE() { int i = 1; auto x = fit::construct_basic()(i); static_assert(std::is_same, decltype(x)>::value, ""); FIT_TEST_CHECK(&x.value == &i); } FIT_TEST_CASE() { auto t = fit::construct_meta()(1, 2, 3); static_assert(std::is_same, decltype(t)>::value, ""); FIT_TEST_CHECK(t == std::make_tuple(1, 2, 3)); // GCC 4.7 doesn't have fully constexpr tuple #if defined (__clang__) || !(defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ < 8) FIT_STATIC_TEST_CHECK(std::make_tuple(1, 2, 3) == fit::construct_meta()(1, 2, 3)); #endif } FIT_TEST_CASE() { auto t = fit::construct_meta()(1, 2, 3); static_assert(std::is_same, decltype(t)>::value, ""); FIT_TEST_CHECK(t == std::make_tuple(1, 2, 3)); // GCC 4.7 doesn't have fully constexpr tuple #if defined (__clang__) || !(defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ < 8) FIT_STATIC_TEST_CHECK(std::make_tuple(1, 2, 3) == fit::construct_meta()(1, 2, 3)); #endif }