diff --git a/include/etl/generators/type_traits_generator.h b/include/etl/generators/type_traits_generator.h index 3fad300b..0f2d2970 100644 --- a/include/etl/generators/type_traits_generator.h +++ b/include/etl/generators/type_traits_generator.h @@ -135,6 +135,9 @@ namespace etl /// remove_reference template struct remove_reference { typedef T type; }; template struct remove_reference { typedef T type; }; +#if ETL_CPP11_SUPPORTED + template struct remove_reference { typedef T type; }; +#endif #if ETL_CPP11_SUPPORTED template @@ -504,6 +507,11 @@ namespace etl template struct conditional { typedef T type; }; template struct conditional { typedef F type; }; +#if ETL_CPP11_SUPPORTED + template + using conditional_t = typename conditional::type; +#endif + //*************************************************************************** /// make_signed template struct make_signed { typedef T type; }; @@ -1223,6 +1231,11 @@ namespace etl template struct conditional { typedef T type; }; template struct conditional { typedef F type; }; +#if ETL_CPP11_SUPPORTED + template + using conditional_t = typename conditional::type; +#endif + //*************************************************************************** /// make_signed ///\ingroup type_traits @@ -1618,6 +1631,186 @@ namespace etl #if ETL_CPP17_SUPPORTED template inline constexpr bool are_all_same_v = are_all_same::value; +#endif + + //*************************************************************************** + /// conjunction +#if ETL_CPP11_SUPPORTED + template + struct conjunction : public etl::true_type + { + }; + + template + struct conjunction : public etl::conditional_t, T1> + { + }; + + template + struct conjunction : public T + { + }; +#endif + +#if ETL_CPP17_SUPPORTED + template + inline constexpr bool conjunction_v = conjunction::value; +#endif + + //*************************************************************************** + /// disjunction +#if ETL_CPP11_SUPPORTED + template + struct disjunction : public etl::false_type + { + }; + + template + struct disjunction : public etl::conditional_t> + { + }; + + template struct disjunction : public T1 + { + }; +#endif + +#if ETL_CPP17_SUPPORTED + template + inline constexpr bool disjunction_v = etl::disjunction::value; +#endif + + //*************************************************************************** +#if ETL_CPP11_SUPPORTED && ETL_USING_STL && !defined(ETL_USE_TYPE_TRAITS_BUILTINS) && ((!defined(ARDUINO) && ETL_NOT_USING_STLPORT) || defined(ETL_GCC_V5_TYPE_TRAITS_SUPPORTED)) + + //********************************************* + // Use the STL's definitions. + //********************************************* + template + struct is_assignable : public std::is_assignable + { + }; + + template + struct is_lvalue_assignable : public etl::is_assignable::type, + typename etl::add_lvalue_reference::type>::type> + { + }; + + template + struct is_constructible : public std::is_constructible + { + }; + + template + struct is_copy_constructible : public std::is_copy_constructible + { + }; + + template + struct is_move_constructible : public std::is_move_constructible + { + }; + + //#if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED + // template + // struct is_trivially_constructible : public std::is_trivially_constructible + // { + // }; + //#endif + +#elif defined(ETL_USE_TYPE_TRAITS_BUILTINS) + + //********************************************* + // Use the compiler's builtins. + //********************************************* + template + struct is_assignable : public bool_constant<__is_assignable(T1, T2)> + { + }; + + template + struct is_lvalue_assignable : public etl::is_assignable::type, + typename etl::add_lvalue_reference::type>::type> + { + }; + + template + struct is_constructible : public bool_constant<__is_constructible(T, TArgs...)> + { + }; + + template + struct is_copy_constructible : public etl::is_constructible> + { + }; + + template + struct is_move_constructible : public etl::is_constructible + { + }; + + //template + //struct is_trivially_constructible : public bool_constant::value&& __is_trivially_constructible(T, TArgs...)> + //{ + //}; + +#else + + //********************************************* + // Force the user to provide specialisations. + //********************************************* + template + struct is_assignable : public etl::bool_constant + { + }; + + template + struct is_lvalue_assignable : public etl::bool_constant + { + }; + + template + struct is_constructible : public etl::bool_constant + { + }; + + template + struct is_copy_constructible : public etl::bool_constant::value> + { + }; + + template + struct is_move_constructible : public etl::bool_constant::value> + { + }; + + //template + //struct is_trivially_constructible : public etl::bool_constant::value> + //{ + //}; + +#endif + +#if ETL_CPP17_SUPPORTED + template + inline constexpr size_t is_assignable_v = etl::is_assignable::value; + + template + inline constexpr size_t is_lvalue_assignable_v = etl::is_lvalue_assignable::value; + + template + inline constexpr size_t is_constructible_v = etl::is_constructible::value; + + template + inline constexpr size_t is_copy_constructible_v = etl::is_copy_constructible::value; + + template + inline constexpr size_t is_move_constructible_v = etl::is_move_constructible::value; + + //template + //inline constexpr size_t is_trivially_constructible_v = etl::is_trivially_constructible::value; + #endif } diff --git a/include/etl/private/variant_new.h b/include/etl/private/variant_new.h index 7c8cf7a5..2e4d379f 100644 --- a/include/etl/private/variant_new.h +++ b/include/etl/private/variant_new.h @@ -32,7 +32,6 @@ SOFTWARE. #include "../platform.h" #include "../utility.h" -#include "../array.h" #include "../largest.h" #include "../exception.h" #include "../type_traits.h" @@ -260,7 +259,7 @@ namespace etl default_construct_in_place(data); operation = operation_type::value, etl::is_move_constructible::value>::do_operation; - type_id = 0U; + type_id = 0U; } //*************************************************************************** @@ -269,15 +268,12 @@ namespace etl template , variant>::value, int> = 0> ETL_CONSTEXPR14 variant(T&& value) : data() + , operation(operation_type, etl::is_copy_constructible>::value, etl::is_move_constructible>::value>::do_operation) + , type_id(etl::private_variant::parameter_pack::template index_of_type>::value) { - using type = etl::remove_reference_t; + static_assert(etl::is_one_of, TTypes...>::value, "Unsupported type"); - static_assert(etl::is_one_of::value, "Unsupported type"); - - construct_in_place(data, std::forward(value)); - - operation = operation_type::value, etl::is_move_constructible::value>::do_operation; - type_id = etl::private_variant::parameter_pack::template index_of_type::value; + construct_in_place>(data, std::forward(value)); } //*************************************************************************** @@ -286,13 +282,12 @@ namespace etl template ETL_CONSTEXPR14 explicit variant(etl::in_place_type_t, TArgs&&... args) : data() + , operation(operation_type, etl::is_copy_constructible>::value, etl::is_move_constructible>::value>::do_operation) + , type_id(etl::private_variant::parameter_pack::template index_of_type>::value) { - using type = etl::remove_reference_t; + static_assert(etl::is_one_of>, TTypes...>::value, "Unsupported type"); - construct_in_place_args(data, std::forward(args)...); - - operation = operation_type::value, etl::is_move_constructible::value>::do_operation; - type_id = etl::private_variant::parameter_pack::template index_of_type::value; + construct_in_place_args>(data, std::forward(args)...); } //*************************************************************************** @@ -304,10 +299,11 @@ namespace etl , type_id(Index) { using type = typename private_variant::parameter_pack:: template type_from_index_t; + static_assert(etl::is_one_of, TTypes... > ::value, "Unsupported type"); construct_in_place_args(data, std::forward(args)...); - operation = operation_type::value, etl::is_move_constructible::value>::do_operation; + operation = operation_type::value, etl::is_move_constructible::value>::do_operation; } #if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL @@ -317,13 +313,12 @@ namespace etl template ETL_CONSTEXPR14 explicit variant(etl::in_place_type_t, std::initializer_list init, TArgs&&... args) : data() + , operation(operation_type>, etl::is_copy_constructible>::value, etl::is_move_constructible::etl::remove_reference_t>::do_operation) + , type_id(private_variant::parameter_pack:: template index_of_type>::value) { - using type = etl::remove_reference_t; + static_assert(etl::is_one_of>, TTypes... > ::value, "Unsupported type"); - construct_in_place_args(data, std::forward(args)...); - - operation = operation_type::value, etl::is_move_constructible::value>::do_operation; - type_id = private_variant::parameter_pack:: template index_of_type::value; + construct_in_place_args>(data, std::forward(args)...); } //*************************************************************************** @@ -335,10 +330,11 @@ namespace etl , type_id(Index) { using type = typename private_variant::parameter_pack:: template type_from_index_t; + static_assert(etl::is_one_of, TTypes... > ::value, "Unsupported type"); construct_in_place_args(data, std::forward(args)...); - operation = operation_type::value, etl::is_move_constructible::value>::do_operation; + operation = operation_type::value, etl::is_move_constructible::value>::do_operation; } #endif @@ -418,7 +414,7 @@ namespace etl construct_in_place_args(data, std::forward(args)...); - operation = operation_type::value, etl::is_move_constructible::value>::do_operation; + operation = operation_type::value, etl::is_move_constructible::value>::do_operation; type_id = etl::private_variant::parameter_pack::template index_of_type::value; @@ -440,7 +436,7 @@ namespace etl construct_in_place(data, etl::forward(value)); - operation = operation_type::value, etl::is_move_constructible::value>::do_operation; + operation = operation_type::value, etl::is_move_constructible::value>::do_operation; type_id = etl::private_variant::parameter_pack::template index_of_type::value; return *this; @@ -520,9 +516,9 @@ namespace etl //*************************************************************************** void swap(variant& rhs) noexcept { - variant temp(*this); - *this = rhs; - rhs = temp; + variant temp(etl::move(*this)); + *this = etl::move(rhs); + rhs = etl::move(temp); } //*************************************************************************** @@ -585,9 +581,7 @@ namespace etl { using type = etl::remove_reference_t; - type t; - - ::new (pstorage) type(etl::forward(args)...); + ::new (pstorage) type(etl::forward(args)...); } //*************************************************************************** @@ -596,7 +590,9 @@ namespace etl template static void default_construct_in_place(char* pstorage) { - ::new (pstorage) T(); + using type = etl::remove_reference_t; + + ::new (pstorage) type(); } //******************************************* @@ -612,31 +608,33 @@ namespace etl static void do_operation(variant::command operation, char* pstorage, const char* pvalue) { // This should never occur. +#if defined(ETL_IN_UNIT_TEST) assert(false); +#endif } }; //******************************************* - // Specialisation for no-copyable & non-moveable + // Specialisation for no-copyable & non-moveable types. template struct operation_type { static void do_operation(variant::command operation, char* pstorage, const char* pvalue) { - using type = etl::remove_reference_t; - switch (operation) { case variant::command::Destroy: { - reinterpret_cast(pstorage)->~type(); + reinterpret_cast(pstorage)->~T(); break; } default: { // This should never occur. +#if defined(ETL_IN_UNIT_TEST) assert(false); +#endif break; } } @@ -644,32 +642,32 @@ namespace etl }; //******************************************* - // Specialisation for no-copyable & moveable + // Specialisation for no-copyable & moveable types. template struct operation_type { static void do_operation(variant::command operation, char* pstorage, const char* pvalue) { - using type = etl::remove_reference_t; - switch (operation) { case variant::command::Move: { - ::new (pstorage) type(etl::move(*reinterpret_cast(const_cast(pvalue)))); + ::new (pstorage) T(etl::move(*reinterpret_cast(const_cast(pvalue)))); break; } case variant::command::Destroy: { - reinterpret_cast(pstorage)->~type(); + reinterpret_cast(pstorage)->~T(); break; } default: { // This should never occur. +#if defined(ETL_IN_UNIT_TEST) assert(false); +#endif break; } } @@ -677,32 +675,32 @@ namespace etl }; //******************************************* - // Specialisation for copyable & non-moveable + // Specialisation for copyable & non-moveable types. template struct operation_type { static void do_operation(variant::command operation, char* pstorage, const char* pvalue) { - using type = etl::remove_reference_t; - switch (operation) { case variant::command::Copy: { - ::new (pstorage) type(*reinterpret_cast(pvalue)); + ::new (pstorage) T(*reinterpret_cast(pvalue)); break; } case variant::command::Destroy: { - reinterpret_cast(pstorage)->~type(); + reinterpret_cast(pstorage)->~T(); break; } default: { // This should never occur. +#if defined(ETL_IN_UNIT_TEST) assert(false); +#endif break; } } @@ -710,31 +708,29 @@ namespace etl }; //******************************************* - // Specialisation for copyable & moveable + // Specialisation for copyable & moveable types. template struct operation_type { static void do_operation(variant::command command, char* pstorage, const char* pvalue) { - using type = etl::remove_reference_t; - switch (command) { case variant::command::Copy: { - ::new (pstorage) type(*reinterpret_cast(pvalue)); + ::new (pstorage) T(*reinterpret_cast(pvalue)); break; } case variant::command::Move: { - ::new (pstorage) type(etl::move(*reinterpret_cast(const_cast(pvalue)))); + ::new (pstorage) T(etl::move(*reinterpret_cast(const_cast(pvalue)))); break; } case variant::command::Destroy: { - reinterpret_cast(pstorage)->~type(); + reinterpret_cast(pstorage)->~T(); break; } @@ -938,6 +934,24 @@ namespace etl return (Index == variant_npos) ? false : (v.index() == Index); } + //*************************************************************************** + /// Checks if the variant v holds the alternative Index. + //*************************************************************************** + template + ETL_CONSTEXPR14 bool holds_alternative(const etl::variant& v) noexcept + { + return (Index == v.index()); + } + + //*************************************************************************** + /// Checks if the variant v holds the alternative Index. (Runtime) + //*************************************************************************** + template + ETL_CONSTEXPR14 bool holds_alternative(size_t index, const etl::variant& v) noexcept + { + return (index == v.index()); + } + //*************************************************************************** /// variant_alternative //*************************************************************************** diff --git a/include/etl/type_traits.h b/include/etl/type_traits.h index a213149c..35cc59bd 100644 --- a/include/etl/type_traits.h +++ b/include/etl/type_traits.h @@ -123,6 +123,9 @@ namespace etl /// remove_reference template struct remove_reference { typedef T type; }; template struct remove_reference { typedef T type; }; +#if ETL_CPP11_SUPPORTED + template struct remove_reference { typedef T type; }; +#endif #if ETL_CPP11_SUPPORTED template @@ -1669,6 +1672,140 @@ namespace etl #if ETL_CPP17_SUPPORTED template inline constexpr bool disjunction_v = etl::disjunction::value; +#endif + + //*************************************************************************** +#if ETL_CPP11_SUPPORTED && ETL_USING_STL && !defined(ETL_USE_TYPE_TRAITS_BUILTINS) && ((!defined(ARDUINO) && ETL_NOT_USING_STLPORT) || defined(ETL_GCC_V5_TYPE_TRAITS_SUPPORTED)) + + //********************************************* + // Use the STL's definitions. + //********************************************* + template + struct is_assignable : public std::is_assignable + { + }; + + template + struct is_lvalue_assignable : public etl::is_assignable::type, + typename etl::add_lvalue_reference::type>::type> + { + }; + + template + struct is_constructible : public std::is_constructible + { + }; + + template + struct is_copy_constructible : public std::is_copy_constructible + { + }; + + template + struct is_move_constructible : public std::is_move_constructible + { + }; + +//#if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED +// template +// struct is_trivially_constructible : public std::is_trivially_constructible +// { +// }; +//#endif + +#elif defined(ETL_USE_TYPE_TRAITS_BUILTINS) + + //********************************************* + // Use the compiler's builtins. + //********************************************* + template + struct is_assignable : public bool_constant<__is_assignable(T1, T2)> + { + }; + + template + struct is_lvalue_assignable : public etl::is_assignable::type, + typename etl::add_lvalue_reference::type>::type> + { + }; + + template + struct is_constructible : public bool_constant<__is_constructible(T, TArgs...)> + { + }; + + template + struct is_copy_constructible : public etl::is_constructible> + { + }; + + template + struct is_move_constructible : public etl::is_constructible + { + }; + + //template + //struct is_trivially_constructible : public bool_constant::value&& __is_trivially_constructible(T, TArgs...)> + //{ + //}; + +#else + + //********************************************* + // Force the user to provide specialisations. + //********************************************* + template + struct is_assignable : public etl::bool_constant + { + }; + + template + struct is_lvalue_assignable : public etl::bool_constant + { + }; + + template + struct is_constructible : public etl::bool_constant + { + }; + + template + struct is_copy_constructible : public etl::bool_constant::value> + { + }; + + template + struct is_move_constructible : public etl::bool_constant::value> + { + }; + + //template + //struct is_trivially_constructible : public etl::bool_constant::value> + //{ + //}; + +#endif + +#if ETL_CPP17_SUPPORTED + + template + inline constexpr size_t is_assignable_v = etl::is_assignable::value; + + template + inline constexpr size_t is_lvalue_assignable_v = etl::is_lvalue_assignable::value; + + template + inline constexpr size_t is_constructible_v = etl::is_constructible::value; + + template + inline constexpr size_t is_copy_constructible_v = etl::is_copy_constructible::value; + + template + inline constexpr size_t is_move_constructible_v = etl::is_move_constructible::value; + +//template +//inline constexpr size_t is_trivially_constructible_v = etl::is_trivially_constructible::value; + #endif } diff --git a/test/etl_profile.h b/test/etl_profile.h index b3b01bf7..ec26e76c 100644 --- a/test/etl_profile.h +++ b/test/etl_profile.h @@ -80,6 +80,8 @@ SOFTWARE. //#define ETL_NO_STL +#define ETL_USE_TYPE_TRAITS_BUILTINS + #if defined(ETL_FORCE_TEST_CPP03) #define ETL_FUNCTION_FORCE_CPP03 #define ETL_PRIORITY_QUEUE_FORCE_CPP03 diff --git a/test/test_variant_new.cpp b/test/test_variant_new.cpp index f4dd0895..ae0cfc81 100644 --- a/test/test_variant_new.cpp +++ b/test/test_variant_new.cpp @@ -289,501 +289,516 @@ namespace }; } -//namespace etl -//{ -// template <> -// struct is_copy_constructible : public etl::bool_constant -// { -// }; -// -// template <> -// struct is_copy_constructible : public etl::bool_constant -// { -// }; -// -// template <> -// struct is_copy_constructible : public etl::bool_constant -// { -// }; -//} +// Definitions for when the STL and compiler built-ins are not avalable. +#if ETL_NOT_USING_STL && !defined(ETL_USE_TYPE_TRAITS_BUILTINS) +namespace etl +{ + template <> + struct is_copy_constructible : public etl::bool_constant + { + }; + + template <> + struct is_copy_constructible : public etl::bool_constant + { + }; + + template <> + struct is_copy_constructible : public etl::bool_constant + { + }; + + template <> + struct is_move_constructible : public etl::bool_constant + { + }; + + template <> + struct is_move_constructible : public etl::bool_constant + { + }; + + template <> + struct is_move_constructible : public etl::bool_constant + { + }; +} +#endif namespace { SUITE(test_variant) { - //TEST(test_alignment) - //{ - // typedef etl::variant test_variant_a; - // typedef etl::variant test_variant_b; - // typedef etl::variant test_variant_c; - // typedef etl::variant test_variant_d; - - // static test_variant_a a(char('1')); - // static test_variant_b b(short(2)); - // static test_variant_c c(3); - // static test_variant_d d(4.5); - - // CHECK((uintptr_t(&etl::get(a)) % uintptr_t(etl::alignment_of::value)) == 0); - // CHECK((uintptr_t(&etl::get(b)) % uintptr_t(etl::alignment_of::value)) == 0); - // CHECK((uintptr_t(&etl::get(c)) % uintptr_t(etl::alignment_of::value)) == 0); - // CHECK((uintptr_t(&etl::get(d)) % uintptr_t(etl::alignment_of::value)) == 0); - //} - - ////************************************************************************* - //TEST(test_constructor_default) - //{ - // CHECK_NO_THROW(test_variant_etl_3 variant_etl); - - // test_variant_etl_3 variant_etl; - - // CHECK(etl::holds_alternative(variant_etl)); - //} - - ////************************************************************************* - //TEST(test_constructor_value) - //{ - // // Char. - // char c = 'a'; - // test_variant_etl_3 variant_char_etl(c); - // CHECK(c == 'a'); - // CHECK(etl::holds_alternative(variant_char_etl)); - // CHECK_EQUAL(c, etl::get(variant_char_etl)); - - // // Int. - // int i = 1; - // test_variant_etl_3 variant_int_etl(i); - // CHECK(i == 1); - // CHECK(etl::holds_alternative(variant_int_etl)); - // CHECK_EQUAL(i, etl::get(variant_int_etl)); - - // // String. - // std::string text("Some Text"); - // test_variant_etl_3 variant_text_etl(text); - // CHECK(text == "Some Text"); - // CHECK(etl::holds_alternative(variant_text_etl)); - // CHECK_EQUAL(text, etl::get(variant_text_etl)); - //} - - ////************************************************************************* - //TEST(test_constructor_move_value) - //{ - // // Char. - // char c = 'a'; - // test_variant_etl_3 variant_char_etl(etl::move(c)); - // CHECK(etl::holds_alternative(variant_char_etl)); - // CHECK_EQUAL(c, etl::get(variant_char_etl)); - - // // Int. - // int i = 1; - // test_variant_etl_3 variant_int_etl(etl::move(i)); - // CHECK(etl::holds_alternative(variant_int_etl)); - // CHECK_EQUAL(i, etl::get(variant_int_etl)); - - // // String. - // std::string text("Some Text"); - // test_variant_etl_3 variant_text_etl(etl::move(text)); - // CHECK(etl::holds_alternative(variant_text_etl)); - // CHECK_EQUAL(std::string("Some Text"), etl::get(variant_text_etl)); - //} - - ////************************************************************************* - //TEST(test_emplace_value) - //{ - // // Char. - // char c = 'a'; - // test_variant_etl_3 variant_char_etl; - // - // variant_char_etl.emplace(c); - // CHECK(c == 'a'); - // CHECK(etl::holds_alternative(variant_char_etl)); - // CHECK_EQUAL(c, etl::get(variant_char_etl)); - - // // Int. - // int i = 1; - // test_variant_etl_3 variant_int_etl; - - // variant_int_etl.emplace(i); - // CHECK(i == 1); - // CHECK(etl::holds_alternative(variant_int_etl)); - // CHECK_EQUAL(i, etl::get(variant_int_etl)); - - // // String. - // std::string text("Some Text"); - // test_variant_etl_3 variant_text_etl; - - // variant_text_etl.emplace(text); - // CHECK(text == "Some Text"); - // CHECK(etl::holds_alternative(variant_text_etl)); - // CHECK_EQUAL(text, etl::get(variant_text_etl)); - //} - - ////************************************************************************* - //TEST(test_copy_constructor) - //{ - // std::string text("Some Text"); - // test_variant_etl_3 variant_1_etl(text); - - // test_variant_etl_3 variant_2_etl(variant_1_etl); - - // CHECK_EQUAL(variant_1_etl.index(), variant_2_etl.index()); - // CHECK_EQUAL(etl::get(variant_1_etl), etl::get(variant_2_etl)); - //} - - ////************************************************************************* - //TEST(test_copy_constructor_from_empty) - //{ - // std::string text("Some Text"); - // test_variant_etl_3 variant_1_etl; - - // test_variant_etl_3 variant_2_etl(variant_1_etl); - - // CHECK_EQUAL(variant_1_etl.index(), variant_2_etl.index()); - //} - - ////************************************************************************* - //TEST(test_move_constructor) - //{ - // std::string text("Some Text"); - // test_variant_etl_3 variant_1_etl(text); - - // test_variant_etl_3 variant_2_etl(etl::move(variant_1_etl)); - - // CHECK_EQUAL(variant_1_etl.index(), variant_2_etl.index()); - // CHECK_EQUAL(etl::get(variant_1_etl), etl::get(variant_2_etl)); - //} - - ////************************************************************************* - //TEST(test_move_constructor_from_empty) - //{ - // std::string text("Some Text"); - // test_variant_etl_3 variant_1_etl; - - // test_variant_etl_3 variant_2_etl(etl::move(variant_1_etl)); - - // CHECK_EQUAL(variant_1_etl.index(), variant_2_etl.index()); - //} - - ////************************************************************************* - //TEST(test_assign_from_value) - //{ - // std::string text("Some Text"); - // test_variant_etl_3 variant_etl; - - // variant_etl = text; - - // CHECK_EQUAL(text, etl::get(variant_etl)); - //} - - ////************************************************************************* - //TEST(test_assign_from_variant) - //{ - // std::string text("Some Text"); - // test_variant_etl_3 variant_1_etl; - // test_variant_etl_3 variant_2_etl; - - // variant_1_etl = text; - // variant_2_etl = variant_1_etl; - - // CHECK_EQUAL(text, etl::get(variant_2_etl)); - //} - - ////************************************************************************* - //TEST(test_assign_from_variant2) - //{ - // std::string text("Some Text"); - // int integer(99); - // test_variant_etl_3 variant_1_etl; - // test_variant_etl_3 variant_2_etl; - - // variant_1_etl = text; - // variant_2_etl = integer; - // variant_2_etl = variant_1_etl; - - // CHECK_EQUAL(text, etl::get(variant_2_etl)); - //} - - ////************************************************************************* - //TEST(test_assignment_incorrect_type_exception) - //{ - // std::string text("Some Text"); - // test_variant_etl_3 variant_etl(text); - - // int i; - // CHECK_THROW(etl::get(variant_etl), etl::variant_incorrect_type_exception); - // (void)i; - //} - - ////************************************************************************* - //TEST(test_self_assignment) - //{ - // test_variant_etl_3 variant_etl; - - // variant_etl = 1; - // variant_etl = variant_etl; - - // CHECK_EQUAL(1, etl::get(variant_etl)); - //} - - ////************************************************************************* - //TEST(test_member_swap_variants) - //{ - // std::string text("Some Text"); - // int integer(99); - // test_variant_etl_3 variant_1_etl(text); - // test_variant_etl_3 variant_2_etl(integer); - - // variant_1_etl.swap(variant_2_etl); - - // CHECK(etl::holds_alternative(variant_1_etl)); - // CHECK_EQUAL(integer, etl::get(variant_1_etl)); - - // CHECK(etl::holds_alternative(variant_2_etl)); - // CHECK_EQUAL(text, etl::get(variant_2_etl)); - //} - - ////************************************************************************* - //TEST(test_global_swap_variants) - //{ - // std::string text("Some Text"); - // int integer(99); - // test_variant_etl_3 variant_1_etl(text); - // test_variant_etl_3 variant_2_etl(integer); - - // etl::swap(variant_1_etl, variant_2_etl); - - // CHECK(etl::holds_alternative(variant_1_etl)); - // CHECK_EQUAL(integer, etl::get(variant_1_etl)); - - // CHECK(etl::holds_alternative(variant_2_etl)); - // CHECK_EQUAL(text, etl::get(variant_2_etl)); - //} - - ////************************************************************************* - //TEST(test_emplace) - //{ - // test_variant_emplace variant_etl; - - // variant_etl.emplace("1"); - // CHECK(etl::holds_alternative(variant_etl)); - // CHECK_EQUAL(D1("1"), etl::get(variant_etl)); - - // variant_etl.emplace("1", "2"); - // CHECK(etl::holds_alternative(variant_etl)); - // CHECK_EQUAL(D2("1", "2"), etl::get(variant_etl)); - - // variant_etl.emplace("1", "2", "3"); - // CHECK(etl::holds_alternative(variant_etl)); - // CHECK_EQUAL(D3("1", "2", "3"), etl::get(variant_etl)); - - // variant_etl.emplace("1", "2", "3", "4"); - // CHECK(etl::holds_alternative(variant_etl)); - // CHECK_EQUAL(D4("1", "2", "3", "4"), etl::get(variant_etl)); - //} - - ////************************************************************************* - //D1 getD1() - //{ - // return D1("1"); - //} - - //TEST(test_move) - //{ - // D1 da("1"); - // - // test_variant_emplace variant_etl(etl::move(getD1())); - - // D1 db = etl::move(etl::get(variant_etl)); - //} - - ////************************************************************************* - //TEST(test_variant_visitor) - //{ - // struct Visitor : public etl::visitor - // { - // Visitor() - // : result_c(0) - // , result_i(0) - // , result_s("") - // { - // } - - // void visit(char& c) - // { - // result_c = c; - // } - - // void visit(int& i) - // { - // result_i = i; - // } - - // void visit(std::string& s) - // { - // result_s = s; - // } - - // char result_c; - // int result_i; - // std::string result_s; - // }; - - // Visitor visitor; - - // test_variant_etl_3 variant_etl; - - // variant_etl = char(1); - // variant_etl.accept_visitor(visitor); - // CHECK_EQUAL(1, visitor.result_c); - // - // variant_etl = int(2); - // variant_etl.accept_visitor(visitor); - // CHECK_EQUAL(2, visitor.result_i); - - // variant_etl = std::string("3"); - // variant_etl.accept_visitor(visitor); - // CHECK_EQUAL("3", visitor.result_s); - //} - - ////************************************************************************* - //TEST(test_variant_operator_visit) - //{ - // struct Visitor - // { - // Visitor() - // : result_c(0) - // , result_i(0) - // , result_s("") - // { - // } - - // void operator()(char& c) - // { - // result_c = c; - // } - - // void operator()(int& i) - // { - // result_i = i; - // } - - // void operator()(std::string& s) - // { - // result_s = s; - // } - - // char result_c; - // int result_i; - // std::string result_s; - // }; - - // Visitor visitor; - - // test_variant_etl_3 variant_etl; - - // variant_etl = char(1); - // variant_etl.accept_functor(visitor); - // CHECK_EQUAL(1, visitor.result_c); - // - // variant_etl = int(2); - // variant_etl.accept_functor(visitor); - // CHECK_EQUAL(2, visitor.result_i); - - // variant_etl = std::string("3"); - // variant_etl.accept_functor(visitor); - // CHECK_EQUAL("3", visitor.result_s); - //} - - ////************************************************************************* - //TEST(test_get_if_index) - //{ - // test_variant_etl_3 variant_etl; - - // variant_etl = char(1); - // CHECK(etl::get_if<0>(&variant_etl) != nullptr); - // CHECK(etl::get_if<0>(variant_etl) != nullptr); - // CHECK(etl::get_if<1>(&variant_etl) == nullptr); - // CHECK(etl::get_if<1>(variant_etl) == nullptr); - // CHECK(etl::get_if<2>(&variant_etl) == nullptr); - // CHECK(etl::get_if<2>(variant_etl) == nullptr); - - // variant_etl = int(2); - // CHECK(etl::get_if<0>(&variant_etl) == nullptr); - // CHECK(etl::get_if<0>(variant_etl) == nullptr); - // CHECK(etl::get_if<1>(&variant_etl) != nullptr); - // CHECK(etl::get_if<1>(variant_etl) != nullptr); - // CHECK(etl::get_if<2>(&variant_etl) == nullptr); - // CHECK(etl::get_if<2>(variant_etl) == nullptr); - - // variant_etl = std::string("3"); - // CHECK(etl::get_if<0>(&variant_etl) == nullptr); - // CHECK(etl::get_if<0>(variant_etl) == nullptr); - // CHECK(etl::get_if<1>(&variant_etl) == nullptr); - // CHECK(etl::get_if<1>(variant_etl) == nullptr); - // CHECK(etl::get_if<2>(&variant_etl) != nullptr); - // CHECK(etl::get_if<2>(variant_etl) != nullptr); - //} - - ////************************************************************************* - //TEST(test_get_if_type) - //{ - // test_variant_etl_3 variant_etl; - - // variant_etl = char(1); - // CHECK(etl::get_if(&variant_etl) != nullptr); - // CHECK(etl::get_if(variant_etl) != nullptr); - // CHECK(etl::get_if(&variant_etl) == nullptr); - // CHECK(etl::get_if(variant_etl) == nullptr); - // CHECK(etl::get_if(&variant_etl) == nullptr); - // CHECK(etl::get_if(variant_etl) == nullptr); - - // variant_etl = int(2); - // CHECK(etl::get_if(&variant_etl) == nullptr); - // CHECK(etl::get_if(variant_etl) == nullptr); - // CHECK(etl::get_if(&variant_etl) != nullptr); - // CHECK(etl::get_if(variant_etl) != nullptr); - // CHECK(etl::get_if(&variant_etl) == nullptr); - // CHECK(etl::get_if(variant_etl) == nullptr); - - // variant_etl = std::string("3"); - // CHECK(etl::get_if(&variant_etl) == nullptr); - // CHECK(etl::get_if(variant_etl) == nullptr); - // CHECK(etl::get_if(&variant_etl) == nullptr); - // CHECK(etl::get_if(variant_etl) == nullptr); - // CHECK(etl::get_if(&variant_etl) != nullptr); - // CHECK(etl::get_if(variant_etl) != nullptr); - //} - - ////************************************************************************* - //TEST(test_variant_size) - //{ - // test_variant_etl_3 variant_etl; - - // CHECK_EQUAL(3U, etl::variant_size_v); - //} + TEST(test_alignment) + { + typedef etl::variant test_variant_a; + typedef etl::variant test_variant_b; + typedef etl::variant test_variant_c; + typedef etl::variant test_variant_d; + + static test_variant_a a(char('1')); + static test_variant_b b(short(2)); + static test_variant_c c(3); + static test_variant_d d(4.5); + + CHECK((uintptr_t(&etl::get(a)) % uintptr_t(etl::alignment_of::value)) == 0); + CHECK((uintptr_t(&etl::get(b)) % uintptr_t(etl::alignment_of::value)) == 0); + CHECK((uintptr_t(&etl::get(c)) % uintptr_t(etl::alignment_of::value)) == 0); + CHECK((uintptr_t(&etl::get(d)) % uintptr_t(etl::alignment_of::value)) == 0); + } + + //************************************************************************* + TEST(test_constructor_default) + { + CHECK_NO_THROW(test_variant_etl_3 variant_etl); + + test_variant_etl_3 variant_etl; + + CHECK(etl::holds_alternative(variant_etl)); + CHECK(!etl::holds_alternative(variant_etl)); + CHECK(!etl::holds_alternative(variant_etl)); + + CHECK(etl::holds_alternative<0U>(variant_etl)); + CHECK(!etl::holds_alternative<1U>(variant_etl)); + CHECK(!etl::holds_alternative<2U>(variant_etl)); + + CHECK(etl::holds_alternative(0U, variant_etl)); + CHECK(!etl::holds_alternative(1U, variant_etl)); + CHECK(!etl::holds_alternative(2U, variant_etl)); + CHECK(!etl::holds_alternative(99U, variant_etl)); + } + + //************************************************************************* + TEST(test_constructor_value) + { + // Char. + char c = 'a'; + test_variant_etl_3 variant_char_etl(c); + CHECK(c == 'a'); + CHECK(etl::holds_alternative(variant_char_etl)); + CHECK_EQUAL(c, etl::get(variant_char_etl)); + + // Int. + int i = 1; + test_variant_etl_3 variant_int_etl(i); + CHECK(i == 1); + CHECK(etl::holds_alternative(variant_int_etl)); + CHECK_EQUAL(i, etl::get(variant_int_etl)); + + // String. + std::string text("Some Text"); + test_variant_etl_3 variant_text_etl(text); + CHECK(text == "Some Text"); + CHECK(etl::holds_alternative(variant_text_etl)); + CHECK_EQUAL(text, etl::get(variant_text_etl)); + } + + //************************************************************************* + TEST(test_constructor_move_value) + { + // Char. + char c = 'a'; + test_variant_etl_3 variant_char_etl(etl::move(c)); + CHECK(etl::holds_alternative(variant_char_etl)); + CHECK_EQUAL(c, etl::get(variant_char_etl)); + + // Int. + int i = 1; + test_variant_etl_3 variant_int_etl(etl::move(i)); + CHECK(etl::holds_alternative(variant_int_etl)); + CHECK_EQUAL(i, etl::get(variant_int_etl)); + + // String. + std::string text("Some Text"); + test_variant_etl_3 variant_text_etl(etl::move(text)); + CHECK(etl::holds_alternative(variant_text_etl)); + CHECK_EQUAL(std::string("Some Text"), etl::get(variant_text_etl)); + } + + //************************************************************************* + TEST(test_emplace_value) + { + // Char. + char c = 'a'; + test_variant_etl_3 variant_char_etl; + + variant_char_etl.emplace(c); + CHECK(c == 'a'); + CHECK(etl::holds_alternative(variant_char_etl)); + CHECK_EQUAL(c, etl::get(variant_char_etl)); + + // Int. + int i = 1; + test_variant_etl_3 variant_int_etl; + + variant_int_etl.emplace(i); + CHECK(i == 1); + CHECK(etl::holds_alternative(variant_int_etl)); + CHECK_EQUAL(i, etl::get(variant_int_etl)); + + // String. + std::string text("Some Text"); + test_variant_etl_3 variant_text_etl; + + variant_text_etl.emplace(text); + CHECK(text == "Some Text"); + CHECK(etl::holds_alternative(variant_text_etl)); + CHECK_EQUAL(text, etl::get(variant_text_etl)); + } + + //************************************************************************* + TEST(test_copy_constructor) + { + std::string text("Some Text"); + test_variant_etl_3 variant_1_etl(text); + + test_variant_etl_3 variant_2_etl(variant_1_etl); + + CHECK_EQUAL(variant_1_etl.index(), variant_2_etl.index()); + CHECK_EQUAL(etl::get(variant_1_etl), etl::get(variant_2_etl)); + } + + //************************************************************************* + TEST(test_copy_constructor_from_empty) + { + test_variant_etl_3 variant_1_etl; + + test_variant_etl_3 variant_2_etl(variant_1_etl); + + CHECK_EQUAL(variant_1_etl.index(), variant_2_etl.index()); + } + + //************************************************************************* + TEST(test_move_constructor) + { + std::string text("Some Text"); + test_variant_etl_3 variant_1_etl(text); + + test_variant_etl_3 variant_2_etl(etl::move(variant_1_etl)); + + CHECK_EQUAL(variant_1_etl.index(), variant_2_etl.index()); + CHECK(etl::get(variant_1_etl) != etl::get(variant_2_etl)); + } + + //************************************************************************* + TEST(test_move_constructor_from_empty) + { + std::string text("Some Text"); + test_variant_etl_3 variant_1_etl; + + test_variant_etl_3 variant_2_etl(etl::move(variant_1_etl)); + + CHECK_EQUAL(variant_1_etl.index(), variant_2_etl.index()); + } + + //************************************************************************* + TEST(test_assign_from_value) + { + std::string text("Some Text"); + test_variant_etl_3 variant_etl; + + variant_etl = text; + + CHECK_EQUAL(text, etl::get(variant_etl)); + } + + //************************************************************************* + TEST(test_assign_from_variant) + { + std::string text("Some Text"); + test_variant_etl_3 variant_1_etl; + test_variant_etl_3 variant_2_etl; + + variant_1_etl = text; + variant_2_etl = variant_1_etl; + + CHECK_EQUAL(text, etl::get(variant_2_etl)); + } + + //************************************************************************* + TEST(test_assign_from_variant2) + { + std::string text("Some Text"); + int integer(99); + test_variant_etl_3 variant_1_etl; + test_variant_etl_3 variant_2_etl; + + variant_1_etl = text; + variant_2_etl = integer; + variant_2_etl = variant_1_etl; + + CHECK_EQUAL(text, etl::get(variant_2_etl)); + } + + //************************************************************************* + TEST(test_assignment_incorrect_type_exception) + { + std::string text("Some Text"); + test_variant_etl_3 variant_etl(text); + + int i; + CHECK_THROW(etl::get(variant_etl), etl::variant_incorrect_type_exception); + (void)i; + } + + //************************************************************************* + TEST(test_self_assignment) + { + test_variant_etl_3 variant_etl; + + variant_etl = 1; + variant_etl = variant_etl; + + CHECK_EQUAL(1, etl::get(variant_etl)); + } + + //************************************************************************* + TEST(test_member_swap_variants) + { + std::string text("Some Text"); + int integer(99); + test_variant_etl_3 variant_1_etl(text); + test_variant_etl_3 variant_2_etl(integer); + + variant_1_etl.swap(variant_2_etl); + + CHECK(etl::holds_alternative(variant_1_etl)); + CHECK_EQUAL(integer, etl::get(variant_1_etl)); + + CHECK(etl::holds_alternative(variant_2_etl)); + CHECK_EQUAL(text, etl::get(variant_2_etl)); + } + + //************************************************************************* + TEST(test_global_swap_variants) + { + std::string text("Some Text"); + int integer(99); + test_variant_etl_3 variant_1_etl(text); + test_variant_etl_3 variant_2_etl(integer); + + etl::swap(variant_1_etl, variant_2_etl); + + CHECK(etl::holds_alternative(variant_1_etl)); + CHECK_EQUAL(integer, etl::get(variant_1_etl)); + + CHECK(etl::holds_alternative(variant_2_etl)); + CHECK_EQUAL(text, etl::get(variant_2_etl)); + } + + //************************************************************************* + TEST(test_emplace_multiple_parameters) + { + test_variant_emplace variant_etl; + + variant_etl.emplace("1"); + CHECK(etl::holds_alternative(variant_etl)); + CHECK_EQUAL(D1("1"), etl::get(variant_etl)); + + variant_etl.emplace("1", "2"); + CHECK(etl::holds_alternative(variant_etl)); + CHECK_EQUAL(D2("1", "2"), etl::get(variant_etl)); + + variant_etl.emplace("1", "2", "3"); + CHECK(etl::holds_alternative(variant_etl)); + CHECK_EQUAL(D3("1", "2", "3"), etl::get(variant_etl)); + + variant_etl.emplace("1", "2", "3", "4"); + CHECK(etl::holds_alternative(variant_etl)); + CHECK_EQUAL(D4("1", "2", "3", "4"), etl::get(variant_etl)); + } + + //************************************************************************* + TEST(test_variant_visitor) + { + struct Visitor : public etl::visitor + { + Visitor() + : result_c(0) + , result_i(0) + , result_s("") + { + } + + void visit(char& c) + { + result_c = c; + } + + void visit(int& i) + { + result_i = i; + } + + void visit(std::string& s) + { + result_s = s; + } + + char result_c; + int result_i; + std::string result_s; + }; + + Visitor visitor; + + test_variant_etl_3 variant_etl; + + variant_etl = char(1); + variant_etl.accept_visitor(visitor); + CHECK_EQUAL(1, visitor.result_c); + + variant_etl = int(2); + variant_etl.accept_visitor(visitor); + CHECK_EQUAL(2, visitor.result_i); + + variant_etl = std::string("3"); + variant_etl.accept_visitor(visitor); + CHECK_EQUAL("3", visitor.result_s); + } + + //************************************************************************* + TEST(test_variant_operator_visit) + { + struct Visitor + { + Visitor() + : result_c(0) + , result_i(0) + , result_s("") + { + } + + void operator()(char& c) + { + result_c = c; + } + + void operator()(int& i) + { + result_i = i; + } + + void operator()(std::string& s) + { + result_s = s; + } + + char result_c; + int result_i; + std::string result_s; + }; + + Visitor visitor; + + test_variant_etl_3 variant_etl; + + variant_etl = char(1); + variant_etl.accept_functor(visitor); + CHECK_EQUAL(1, visitor.result_c); + + variant_etl = int(2); + variant_etl.accept_functor(visitor); + CHECK_EQUAL(2, visitor.result_i); + + variant_etl = std::string("3"); + variant_etl.accept_functor(visitor); + CHECK_EQUAL("3", visitor.result_s); + } + + //************************************************************************* + TEST(test_get_if_index) + { + test_variant_etl_3 variant_etl; + + variant_etl = char(1); + CHECK(etl::get_if<0>(&variant_etl) != nullptr); + CHECK(etl::get_if<0>(variant_etl) != nullptr); + CHECK(etl::get_if<1>(&variant_etl) == nullptr); + CHECK(etl::get_if<1>(variant_etl) == nullptr); + CHECK(etl::get_if<2>(&variant_etl) == nullptr); + CHECK(etl::get_if<2>(variant_etl) == nullptr); + + variant_etl = int(2); + CHECK(etl::get_if<0>(&variant_etl) == nullptr); + CHECK(etl::get_if<0>(variant_etl) == nullptr); + CHECK(etl::get_if<1>(&variant_etl) != nullptr); + CHECK(etl::get_if<1>(variant_etl) != nullptr); + CHECK(etl::get_if<2>(&variant_etl) == nullptr); + CHECK(etl::get_if<2>(variant_etl) == nullptr); + + variant_etl = std::string("3"); + CHECK(etl::get_if<0>(&variant_etl) == nullptr); + CHECK(etl::get_if<0>(variant_etl) == nullptr); + CHECK(etl::get_if<1>(&variant_etl) == nullptr); + CHECK(etl::get_if<1>(variant_etl) == nullptr); + CHECK(etl::get_if<2>(&variant_etl) != nullptr); + CHECK(etl::get_if<2>(variant_etl) != nullptr); + } + + //************************************************************************* + TEST(test_get_if_type) + { + test_variant_etl_3 variant_etl; + + variant_etl = char(1); + CHECK(etl::get_if(&variant_etl) != nullptr); + CHECK(etl::get_if(variant_etl) != nullptr); + CHECK(etl::get_if(&variant_etl) == nullptr); + CHECK(etl::get_if(variant_etl) == nullptr); + CHECK(etl::get_if(&variant_etl) == nullptr); + CHECK(etl::get_if(variant_etl) == nullptr); + + variant_etl = int(2); + CHECK(etl::get_if(&variant_etl) == nullptr); + CHECK(etl::get_if(variant_etl) == nullptr); + CHECK(etl::get_if(&variant_etl) != nullptr); + CHECK(etl::get_if(variant_etl) != nullptr); + CHECK(etl::get_if(&variant_etl) == nullptr); + CHECK(etl::get_if(variant_etl) == nullptr); + + variant_etl = std::string("3"); + CHECK(etl::get_if(&variant_etl) == nullptr); + CHECK(etl::get_if(variant_etl) == nullptr); + CHECK(etl::get_if(&variant_etl) == nullptr); + CHECK(etl::get_if(variant_etl) == nullptr); + CHECK(etl::get_if(&variant_etl) != nullptr); + CHECK(etl::get_if(variant_etl) != nullptr); + } + + //************************************************************************* + TEST(test_variant_size) + { + test_variant_etl_3 variant_etl; + + CHECK_EQUAL(3U, etl::variant_size_v); + } //************************************************************************* TEST(test_compare_etl_and_stl_variant_with_moveable_type) { - //Moveable from_etl; - ////Moveable to_etl; + Moveable from_etl; + Moveable to_etl; - //Moveable from_std; - ////Moveable to_std; + Moveable from_std; + Moveable to_std; - //etl::variant variant_etl(etl::move(from_etl)); - //std::variant variant_std(etl::move(from_std)); + etl::variant variant_etl(etl::move(from_etl)); + std::variant variant_std(etl::move(from_std)); - //variant_etl = etl::move(from_etl); - //variant_std = etl::move(from_std); + variant_etl = etl::move(from_etl); + variant_std = etl::move(from_std); - //CHECK_EQUAL(from_std.moved_from, from_etl.moved_from); - //CHECK_EQUAL(from_std.moved_to, from_etl.moved_to); + CHECK_EQUAL(from_std.moved_from, from_etl.moved_from); + CHECK_EQUAL(from_std.moved_to, from_etl.moved_to); + CHECK_EQUAL(from_std.copied_to, from_etl.copied_to); - //to_etl = etl::move(etl::get<0>(variant_etl)); - //to_std = etl::move(std::get<0>(variant_std)); + to_etl = etl::move(etl::get<0>(variant_etl)); + to_std = etl::move(std::get<0>(variant_std)); - //CHECK_EQUAL(to_std.moved_from, to_etl.moved_from); - //CHECK_EQUAL(to_std.moved_to, to_etl.moved_to); + CHECK_EQUAL(to_std.moved_from, to_etl.moved_from); + CHECK_EQUAL(to_std.moved_to, to_etl.moved_to); + CHECK_EQUAL(to_std.copied_to, to_etl.copied_to); } //************************************************************************* @@ -801,82 +816,127 @@ namespace variant_etl = from_etl; variant_std = from_std; - CHECK_EQUAL(from_std.copied_to, from_etl.copied_to); + CHECK_EQUAL(from_std.moved_from, from_etl.moved_from); + CHECK_EQUAL(from_std.moved_to, from_etl.moved_to); + CHECK_EQUAL(from_std.copied_to, from_etl.copied_to); to_etl = etl::get<0>(variant_etl); to_std = std::get<0>(variant_std); - CHECK_EQUAL(to_std.copied_to, to_etl.copied_to); + CHECK_EQUAL(to_std.moved_from, to_etl.moved_from); + CHECK_EQUAL(to_std.moved_to, to_etl.moved_to); + CHECK_EQUAL(to_std.copied_to, to_etl.copied_to); } //************************************************************************* - TEST(test_copyable_vs_moveable_types_etl) + TEST(test_compare_etl_and_stl_variant_with_moveable_copyable_type) { - Copyable copyable_from; - Copyable copyable_to; + MoveableCopyable from_etl; + MoveableCopyable to_etl; - Moveable moveable_from; - Moveable moveable_to; + MoveableCopyable from_std; + MoveableCopyable to_std; - MoveableCopyable movecopyable_from1; - MoveableCopyable movecopyable_from2; - MoveableCopyable movecopyable_to1; - MoveableCopyable movecopyable_to2; + etl::variant variant_etl; + std::variant variant_std; - etl::variant variant_c(copyable_from); - copyable_to = etl::get<0>(variant_c); + variant_etl = from_etl; + variant_std = from_std; - etl::variant variant_m(etl::move(moveable_from)); - moveable_to = etl::move(etl::get<0>(variant_m)); + CHECK_EQUAL(from_std.moved_from, from_etl.moved_from); + CHECK_EQUAL(from_std.moved_to, from_etl.moved_to); + CHECK_EQUAL(from_std.copied_to, from_etl.copied_to); - etl::variant variant_mc1(movecopyable_from1); - movecopyable_to1 = etl::get<0>(variant_mc1); + variant_etl = etl::move(from_etl); + variant_std = etl::move(from_std); - etl::variant variant_mc2(etl::move(movecopyable_from2)); - movecopyable_to2 = etl::move(etl::get<0>(variant_mc2)); + CHECK_EQUAL(from_std.moved_from, from_etl.moved_from); + CHECK_EQUAL(from_std.moved_to, from_etl.moved_to); + CHECK_EQUAL(from_std.copied_to, from_etl.copied_to); - etl::variant variant_mc3(variant_mc1); + to_etl = etl::get<0>(variant_etl); + to_std = std::get<0>(variant_std); - etl::variant variant_mc4(etl::move(variant_mc1)); + CHECK_EQUAL(to_std.moved_from, to_etl.moved_from); + CHECK_EQUAL(to_std.moved_to, to_etl.moved_to); + CHECK_EQUAL(to_std.copied_to, to_etl.copied_to); - etl::variant variant_mc5(variant_mc2); + to_etl = etl::move(etl::get<0>(variant_etl)); + to_std = etl::move(std::get<0>(variant_std)); - etl::variant variant_mc6(etl::move(variant_mc2)); + CHECK_EQUAL(to_std.moved_from, to_etl.moved_from); + CHECK_EQUAL(to_std.moved_to, to_etl.moved_to); + CHECK_EQUAL(to_std.copied_to, to_etl.copied_to); } //************************************************************************* - TEST(test_copyable_vs_moveable_types_std) - { - Copyable copyable_from; - Copyable copyable_to; + //TEST(test_copyable_vs_moveable_types_etl) + //{ + // Copyable copyable_from; + // Copyable copyable_to; - Moveable moveable_from; - Moveable moveable_to; + // Moveable moveable_from; + // Moveable moveable_to; - MoveableCopyable movecopyable_from1; - MoveableCopyable movecopyable_from2; - MoveableCopyable movecopyable_to1; - MoveableCopyable movecopyable_to2; + // MoveableCopyable movecopyable_from1; + // MoveableCopyable movecopyable_from2; + // MoveableCopyable movecopyable_to1; + // MoveableCopyable movecopyable_to2; - std::variant variant_c(copyable_from); - copyable_to = std::get<0>(variant_c); + // etl::variant variant_c(copyable_from); + // copyable_to = etl::get<0>(variant_c); - //std::variant variant_m(etl::move(moveable_from)); - //moveable_to = std::move(std::get<0>(variant_m)); + // etl::variant variant_m(etl::move(moveable_from)); + // moveable_to = etl::move(etl::get<0>(variant_m)); - std::variant variant_mc1(movecopyable_from1); - movecopyable_to1 = std::get<0>(variant_mc1); + // etl::variant variant_mc1(movecopyable_from1); + // movecopyable_to1 = etl::get<0>(variant_mc1); -// std::variant variant_mc2(std::move(movecopyable_from2)); -// movecopyable_to2 = std::move(std::get<0>(variant_mc2)); + // etl::variant variant_mc2(etl::move(movecopyable_from2)); + // movecopyable_to2 = etl::move(etl::get<0>(variant_mc2)); -// std::variant variant_mc3(variant_mc1); + // etl::variant variant_mc3(variant_mc1); -// std::variant variant_mc4(std::move(variant_mc1)); + // etl::variant variant_mc4(etl::move(variant_mc1)); -// std::variant variant_mc5(variant_mc2); + // etl::variant variant_mc5(variant_mc2); -// std::variant variant_mc6(std::move(variant_mc2)); - } + // etl::variant variant_mc6(etl::move(variant_mc2)); + //} + + //************************************************************************* +// TEST(test_copyable_vs_moveable_types_std) +// { +// Copyable copyable_from; +// Copyable copyable_to; +// +// Moveable moveable_from; +// Moveable moveable_to; +// +// MoveableCopyable movecopyable_from1; +// MoveableCopyable movecopyable_from2; +// MoveableCopyable movecopyable_to1; +// MoveableCopyable movecopyable_to2; +// +// std::variant variant_c(copyable_from); +// copyable_to = std::get<0>(variant_c); +// +// //std::variant variant_m(etl::move(moveable_from)); +// //moveable_to = std::move(std::get<0>(variant_m)); +// +// std::variant variant_mc1(movecopyable_from1); +// movecopyable_to1 = std::get<0>(variant_mc1); +// +//// std::variant variant_mc2(std::move(movecopyable_from2)); +//// movecopyable_to2 = std::move(std::get<0>(variant_mc2)); +// +//// std::variant variant_mc3(variant_mc1); +// +//// std::variant variant_mc4(std::move(variant_mc1)); +// +//// std::variant variant_mc5(variant_mc2); +// +//// std::variant variant_mc6(std::move(variant_mc2)); +// } }; }