// This file is part of Eigen, a lightweight C++ template library // for linear algebra. // // Copyright (C) 2008 Gael Guennebaud // // This Source Code Form is subject to the terms of the Mozilla // Public License v. 2.0. If a copy of the MPL was not distributed // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. // SPDX-License-Identifier: MPL-2.0 #include "main.h" #include #include struct FooReturnType { typedef int ReturnType; }; struct MyInterface { virtual void func() = 0; virtual ~MyInterface() {} }; struct MyImpl : public MyInterface { void func() {} }; using Eigen::internal::apply_op_from_left; using Eigen::internal::apply_op_from_right; using Eigen::internal::arg_prod; using Eigen::internal::arg_sum; using Eigen::internal::array_prod; using Eigen::internal::array_reduce; using Eigen::internal::array_sum; using Eigen::internal::concat; using Eigen::internal::contained_in_list; using Eigen::internal::contained_in_list_gf; // Eigen::internal::get is intentionally left fully-qualified below: test/main.h // does `using namespace Eigen;`, and Eigen/src/Core/StructuredBindings.h defines // free functions `Eigen::get` that would otherwise clash with this metafunction. using Eigen::internal::id_numeric; using Eigen::internal::id_type; using Eigen::internal::is_same_gf; using Eigen::internal::mconcat; using Eigen::internal::skip; using Eigen::internal::slice; using Eigen::internal::take; using Eigen::internal::type_list; struct dummy_a {}; struct dummy_b {}; struct dummy_c {}; struct dummy_d {}; struct dummy_e {}; // dummy operation for testing apply template struct dummy_op; template <> struct dummy_op { typedef dummy_c type; }; template <> struct dummy_op { typedef dummy_d type; }; template <> struct dummy_op { typedef dummy_a type; }; template <> struct dummy_op { typedef dummy_d type; }; template <> struct dummy_op { typedef dummy_b type; }; template <> struct dummy_op { typedef dummy_d type; }; template <> struct dummy_op { typedef dummy_e type; }; template <> struct dummy_op { typedef dummy_e type; }; template <> struct dummy_op { typedef dummy_e type; }; template struct dummy_test { constexpr static bool value = false; constexpr static int global_flags = 0; }; template <> struct dummy_test { constexpr static bool value = true; constexpr static int global_flags = 1; }; template <> struct dummy_test { constexpr static bool value = true; constexpr static int global_flags = 2; }; template <> struct dummy_test { constexpr static bool value = true; constexpr static int global_flags = 4; }; static void test_concat() { VERIFY((std::is_same, type_list<>>::type, type_list>::value)); VERIFY((std::is_same, type_list>::type, type_list>::value)); VERIFY((std::is_same, type_list>::type, type_list>::value)); VERIFY((std::is_same, type_list>::type, type_list>::value)); VERIFY((std::is_same, type_list>::type, type_list>::value)); VERIFY((std::is_same>::type, type_list>::value)); VERIFY((std::is_same, type_list>::type, type_list>::value)); VERIFY((std::is_same, type_list, type_list>::type, type_list>::value)); VERIFY((std::is_same, type_list>::type, type_list>::value)); VERIFY((std::is_same, type_list>::type, type_list>::value)); } static void test_slice() { typedef type_list tl; VERIFY((std::is_same::type, type_list<>>::value)); VERIFY((std::is_same::type, type_list>::value)); VERIFY((std::is_same::type, type_list>::value)); VERIFY((std::is_same::type, type_list>::value)); VERIFY((std::is_same::type, type_list>::value)); VERIFY((std::is_same::type, type_list>::value)); VERIFY((std::is_same::type, type_list>::value)); VERIFY((std::is_same::type, type_list>::value)); VERIFY((std::is_same::type, type_list>::value)); VERIFY((std::is_same::type, type_list>::value)); VERIFY((std::is_same::type, type_list>::value)); VERIFY((std::is_same::type, type_list>::value)); VERIFY((std::is_same::type, type_list>::value)); VERIFY((std::is_same::type, type_list<>>::value)); VERIFY((std::is_same::type, typename take<3, tl>::type>::value)); VERIFY((std::is_same::type, type_list>::value)); } static void test_get() { typedef type_list tl; typedef std::integer_sequence il; VERIFY((std::is_same::type, dummy_a>::value)); VERIFY((std::is_same::type, dummy_a>::value)); VERIFY((std::is_same::type, dummy_b>::value)); VERIFY((std::is_same::type, dummy_b>::value)); VERIFY((std::is_same::type, dummy_c>::value)); VERIFY((std::is_same::type, dummy_c>::value)); VERIFY_IS_EQUAL(((int)Eigen::internal::get<0, il>::value), 4); VERIFY_IS_EQUAL(((int)Eigen::internal::get<1, il>::value), 8); VERIFY_IS_EQUAL(((int)Eigen::internal::get<2, il>::value), 15); VERIFY_IS_EQUAL(((int)Eigen::internal::get<3, il>::value), 16); VERIFY_IS_EQUAL(((int)Eigen::internal::get<4, il>::value), 23); VERIFY_IS_EQUAL(((int)Eigen::internal::get<5, il>::value), 42); } static void test_id_helper(dummy_a a, dummy_a b, dummy_a c) { (void)a; (void)b; (void)c; } template static void test_id_numeric() { test_id_helper(typename id_numeric::type()...); } template static void test_id_type() { test_id_helper(typename id_type::type()...); } static void test_id() { // don't call VERIFY here, just assume it works if it compiles // (otherwise it will complain that it can't find the function) test_id_numeric<1, 4, 6>(); test_id_type(); } static void test_is_same_gf() { VERIFY((!is_same_gf::value)); VERIFY((!!is_same_gf::value)); VERIFY_IS_EQUAL((!!is_same_gf::global_flags), false); VERIFY_IS_EQUAL((!!is_same_gf::global_flags), false); } static void test_apply_op() { typedef type_list tl; VERIFY((!!std::is_same::type, type_list>::value)); VERIFY((!!std::is_same::type, type_list>::value)); } static void test_contained_in_list() { typedef type_list tl; VERIFY((!!contained_in_list::value)); VERIFY((!!contained_in_list::value)); VERIFY((!!contained_in_list::value)); VERIFY((!contained_in_list::value)); VERIFY((!contained_in_list::value)); VERIFY((!!contained_in_list_gf::value)); VERIFY((!!contained_in_list_gf::value)); VERIFY((!!contained_in_list_gf::value)); VERIFY((!contained_in_list_gf::value)); VERIFY((!contained_in_list_gf::value)); VERIFY_IS_EQUAL(((int)contained_in_list_gf::global_flags), 1); VERIFY_IS_EQUAL(((int)contained_in_list_gf::global_flags), 2); VERIFY_IS_EQUAL(((int)contained_in_list_gf::global_flags), 4); VERIFY_IS_EQUAL(((int)contained_in_list_gf::global_flags), 0); VERIFY_IS_EQUAL(((int)contained_in_list_gf::global_flags), 0); } static void test_arg_reductions() { VERIFY_IS_EQUAL(arg_sum(1, 2, 3, 4), 10); VERIFY_IS_EQUAL(arg_prod(1, 2, 3, 4), 24); VERIFY_IS_APPROX(arg_sum(0.5, 2, 5), 7.5); VERIFY_IS_APPROX(arg_prod(0.5, 2, 5), 5.0); } static void test_array_reductions() { array a{{4, 8, 15, 16, 23, 42}}; array b{{42, 23, 16, 15, 8, 4}}; VERIFY_IS_EQUAL((array_sum(a)), 108); VERIFY_IS_EQUAL((array_sum(b)), 108); VERIFY_IS_EQUAL((array_prod(a)), 7418880); VERIFY_IS_EQUAL((array_prod(b)), 7418880); } EIGEN_DECLARE_TEST(meta) { VERIFY((std::is_same::value)); VERIFY((!std::is_same::value)); VERIFY((!std::is_same::value)); VERIFY((!std::is_same::value)); VERIFY((std::is_same>::value)); VERIFY((std::is_same>::value)); VERIFY((std::is_same>::value)); VERIFY((std::is_same>::value)); VERIFY((std::is_same>::value)); VERIFY((std::is_same>::value)); VERIFY((std::is_same>::value)); // test add_const_on_value_type VERIFY((std::is_same, float const&>::value)); VERIFY((std::is_same, float const*>::value)); VERIFY((std::is_same, const float>::value)); VERIFY((std::is_same, const float>::value)); VERIFY((std::is_same, const float* const>::value)); VERIFY((std::is_same, const float* const>::value)); // is_convertible STATIC_CHECK((std::is_convertible::value)); STATIC_CHECK((std::is_convertible::value)); STATIC_CHECK((std::is_convertible::value)); STATIC_CHECK((std::is_convertible::value)); STATIC_CHECK((std::is_convertible::value)); STATIC_CHECK((std::is_convertible>::value)); STATIC_CHECK((!std::is_convertible, double>::value)); STATIC_CHECK((std::is_convertible::value)); STATIC_CHECK((std::is_convertible::value)); STATIC_CHECK((std::is_convertible::value)); STATIC_CHECK((std::is_convertible::value)); STATIC_CHECK((std::is_convertible::value)); STATIC_CHECK((std::is_convertible::value)); STATIC_CHECK((!std::is_convertible::value)); STATIC_CHECK((!std::is_convertible::value)); STATIC_CHECK(!(std::is_convertible::value)); STATIC_CHECK(!(std::is_convertible::value)); STATIC_CHECK((std::is_convertible::value)); // STATIC_CHECK((!std::is_convertible::value )); //does not even compile because the // conversion is prevented by a static assertion STATIC_CHECK((!std::is_convertible::value)); STATIC_CHECK((!std::is_convertible::value)); { MatrixXf A, B; VectorXf a, b; VERIFY((std::is_convertible::value)); VERIFY((std::is_convertible::value)); VERIFY((!std::is_convertible::value)); VERIFY((std::is_convertible::value)); } #if (EIGEN_COMP_GNUC_STRICT && EIGEN_COMP_GNUC <= 990) || (EIGEN_COMP_CLANG_STRICT && EIGEN_COMP_CLANG <= 990) || \ (EIGEN_COMP_MSVC && EIGEN_COMP_MSVC <= 1914) // See http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1752, // a fix in the c++ standard changes std::is_convertible behavior for abstract classes. // So the following tests are expected to fail with recent compilers. STATIC_CHECK((!std::is_convertible::value)); STATIC_CHECK((!std::is_convertible::value)); STATIC_CHECK((std::is_convertible::value)); #endif { VERIFY((std::is_convertible()), int>::value)); VERIFY((!std::is_convertible())>::value)); } VERIFY((internal::has_ReturnType::value)); VERIFY((internal::has_ReturnType>::value)); VERIFY((!internal::has_ReturnType::value)); VERIFY((!internal::has_ReturnType::value)); CALL_SUBTEST(test_concat()); CALL_SUBTEST(test_slice()); CALL_SUBTEST(test_get()); CALL_SUBTEST(test_id()); CALL_SUBTEST(test_is_same_gf()); CALL_SUBTEST(test_apply_op()); CALL_SUBTEST(test_contained_in_list()); CALL_SUBTEST(test_arg_reductions()); CALL_SUBTEST(test_array_reductions()); }