mirror of
https://github.com/ETLCPP/etl.git
synced 2026-06-16 00:46:03 +08:00
Added tests
This commit is contained in:
parent
03c97b64fe
commit
c6e31f381f
@ -1304,6 +1304,7 @@ namespace etl
|
||||
{
|
||||
using type = decltype(declval<TCallable>()(declval<Ts>()...));
|
||||
};
|
||||
|
||||
template <typename TCallable, typename... Ts>
|
||||
using single_visit_result_type_t = typename single_visit_result_type<TCallable, Ts...>::type;
|
||||
|
||||
@ -1324,6 +1325,7 @@ namespace etl
|
||||
//***************************************************************************
|
||||
template <template <typename...> typename, typename...>
|
||||
struct visit_result_helper;
|
||||
|
||||
template <template <typename...> typename TToInject, size_t... tAltIndices, typename TCur>
|
||||
struct visit_result_helper<TToInject, index_sequence<tAltIndices...>, TCur>
|
||||
{
|
||||
@ -1333,6 +1335,7 @@ namespace etl
|
||||
|
||||
using type = common_type_t<TToInject<var_type<tAltIndices> >...>;
|
||||
};
|
||||
|
||||
template <template <typename...> typename TToInject, size_t... tAltIndices, typename TCur, typename TNext, typename... TVs>
|
||||
struct visit_result_helper<TToInject, index_sequence<tAltIndices...>, TCur, TNext, TVs...>
|
||||
{
|
||||
@ -1346,6 +1349,7 @@ namespace etl
|
||||
using next_inject = TToInject<var_type<tIndex>, TNextInj...>;
|
||||
using recursive_result = typename visit_result_helper<next_inject, make_index_sequence<variant_size<remove_reference_t<TNext> >::value>, TNext, TVs...>::type;
|
||||
};
|
||||
|
||||
using type = common_type_t<typename next_inject_wrap<tAltIndices>::recursive_result...>;
|
||||
};
|
||||
|
||||
@ -1391,6 +1395,7 @@ namespace etl
|
||||
struct do_visit_helper
|
||||
{
|
||||
using function_pointer = add_pointer_t<TRet(TCallable&&, TCurVariant&&, TVarRest&&...)>;
|
||||
|
||||
template <size_t tIndex>
|
||||
static constexpr function_pointer fptr() noexcept
|
||||
{
|
||||
@ -1405,10 +1410,15 @@ namespace etl
|
||||
ETL_CONSTEXPR14 static TRet do_visit(TCallable&& f, TVariant&& v, index_sequence<tIndices...>, TVarRest&&... variants)
|
||||
{
|
||||
ETL_ASSERT(!v.valueless_by_exception(), ETL_ERROR(bad_variant_access));
|
||||
|
||||
using helper_t = do_visit_helper<TRet, TCallable, TVariant, TVarRest...>;
|
||||
using func_ptr = typename helper_t::function_pointer;
|
||||
constexpr func_ptr jmp_table[]{
|
||||
helper_t::template fptr<tIndices>()...};
|
||||
|
||||
constexpr func_ptr jmp_table[]
|
||||
{
|
||||
helper_t::template fptr<tIndices>()...
|
||||
};
|
||||
|
||||
return jmp_table[v.index()](static_cast<TCallable&&>(f), static_cast<TVariant&&>(v), static_cast<TVarRest&&>(variants)...);
|
||||
}
|
||||
|
||||
@ -1463,6 +1473,5 @@ namespace etl
|
||||
{
|
||||
return private_variant::visit<TDeducedReturn>(static_cast<TCallable&&>(f), static_cast<TVariants&&>(vs)...);
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1328,6 +1328,7 @@ namespace
|
||||
res = etl::visit(f, variant1, variant2);
|
||||
CHECK_EQUAL(3 * 2, res);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_variant_visit_void)
|
||||
{
|
||||
@ -1346,5 +1347,76 @@ namespace
|
||||
etl::visit<void>(f, variant1);
|
||||
CHECK_EQUAL(false, variant_was_signed);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_variant_visit_with_overload)
|
||||
{
|
||||
struct TypeA { };
|
||||
struct TypeB { };
|
||||
struct TypeC { };
|
||||
struct TypeD { };
|
||||
|
||||
std::string result = "?";
|
||||
|
||||
etl::variant<TypeA, TypeB, TypeC, TypeD> package;
|
||||
|
||||
etl::visit(etl::overload
|
||||
{
|
||||
[&result](TypeA&) { result = "TypeA"; },
|
||||
[&result](TypeB&) { result = "TypeB"; },
|
||||
[&result](TypeC&) { result = "TypeC"; },
|
||||
[&result](TypeD&) { result = "TypeD"; }
|
||||
}, package);
|
||||
|
||||
CHECK_EQUAL(std::string("TypeA"), result);
|
||||
|
||||
package = TypeA{};
|
||||
|
||||
etl::visit(etl::overload
|
||||
{
|
||||
[&result](TypeA&) { result = "TypeA"; },
|
||||
[&result](TypeB&) { result = "TypeB"; },
|
||||
[&result](TypeC&) { result = "TypeC"; },
|
||||
[&result](TypeD&) { result = "TypeD"; }
|
||||
}, package);
|
||||
|
||||
CHECK_EQUAL(std::string("TypeA"), result);
|
||||
|
||||
package = TypeB{};
|
||||
|
||||
etl::visit(etl::overload
|
||||
{
|
||||
[&result](TypeA&) { result = "TypeA"; },
|
||||
[&result](TypeB&) { result = "TypeB"; },
|
||||
[&result](TypeC&) { result = "TypeC"; },
|
||||
[&result](TypeD&) { result = "TypeD"; }
|
||||
}, package);
|
||||
|
||||
CHECK_EQUAL(std::string("TypeB"), result);
|
||||
|
||||
package = TypeC{};
|
||||
|
||||
etl::visit(etl::overload
|
||||
{
|
||||
[&result](TypeA&) { result = "TypeA"; },
|
||||
[&result](TypeB&) { result = "TypeB"; },
|
||||
[&result](TypeC&) { result = "TypeC"; },
|
||||
[&result](TypeD&) { result = "TypeD"; }
|
||||
}, package);
|
||||
|
||||
CHECK_EQUAL(std::string("TypeC"), result);
|
||||
|
||||
package = TypeD{};
|
||||
|
||||
etl::visit(etl::overload
|
||||
{
|
||||
[&result](TypeA&) { result = "TypeA"; },
|
||||
[&result](TypeB&) { result = "TypeB"; },
|
||||
[&result](TypeC&) { result = "TypeC"; },
|
||||
[&result](TypeD&) { result = "TypeD"; }
|
||||
}, package);
|
||||
|
||||
CHECK_EQUAL(std::string("TypeD"), result);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -775,48 +775,48 @@
|
||||
<IntDir>$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Intel|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<PostBuildEventUseInBuild>true</PostBuildEventUseInBuild>
|
||||
<IntDir>$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Intel - No STL|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<PostBuildEventUseInBuild>true</PostBuildEventUseInBuild>
|
||||
<IntDir>$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MSVC - No Tests|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<PostBuildEventUseInBuild>false</PostBuildEventUseInBuild>
|
||||
<IntDir>$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<PostBuildEventUseInBuild>true</PostBuildEventUseInBuild>
|
||||
<IntDir>$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20 - No STL|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<PostBuildEventUseInBuild>true</PostBuildEventUseInBuild>
|
||||
<IntDir>$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MSVC - Force C++03|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<PostBuildEventUseInBuild>true</PostBuildEventUseInBuild>
|
||||
<IntDir>$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MSVC - Force cpp03|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<PostBuildEventUseInBuild>true</PostBuildEventUseInBuild>
|
||||
<IntDir>$(Configuration)\</IntDir>
|
||||
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MSVC - Small Strings|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<PostBuildEventUseInBuild>true</PostBuildEventUseInBuild>
|
||||
<IntDir>$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='MSVC Debug - Appveyor|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<PostBuildEventUseInBuild>true</PostBuildEventUseInBuild>
|
||||
<IntDir>$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
@ -826,17 +826,17 @@
|
||||
<IntDir>\$(IntDir)</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MSVC - No Checks|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<PostBuildEventUseInBuild>false</PostBuildEventUseInBuild>
|
||||
<IntDir>$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug - String Truncation Is Error|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<PostBuildEventUseInBuild>true</PostBuildEventUseInBuild>
|
||||
<IntDir>$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug - No STL|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<PostBuildEventUseInBuild>true</PostBuildEventUseInBuild>
|
||||
<IntDir>$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
@ -846,27 +846,27 @@
|
||||
<IntDir>\$(IntDir)</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MSVC - No STL - Built-ins|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<PostBuildEventUseInBuild>true</PostBuildEventUseInBuild>
|
||||
<IntDir>$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MSVC - No STL - Force Built-ins|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<PostBuildEventUseInBuild>true</PostBuildEventUseInBuild>
|
||||
<IntDir>$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug MSVC - No STL - Force Constexpr Algorithms|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<PostBuildEventUseInBuild>true</PostBuildEventUseInBuild>
|
||||
<IntDir>$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='MSVC Debug - No STL - Appveyor|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<PostBuildEventUseInBuild>true</PostBuildEventUseInBuild>
|
||||
<IntDir>$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug - No STL - Force No Advanced|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<PostBuildEventUseInBuild>true</PostBuildEventUseInBuild>
|
||||
<IntDir>$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
@ -1014,7 +1014,7 @@
|
||||
<PostBuildEventUseInBuild>true</PostBuildEventUseInBuild>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug64|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<PostBuildEventUseInBuild>true</PostBuildEventUseInBuild>
|
||||
<IntDir>$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
@ -1023,7 +1023,7 @@
|
||||
<PostBuildEventUseInBuild>true</PostBuildEventUseInBuild>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug - No Unit Tests|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<PostBuildEventUseInBuild>true</PostBuildEventUseInBuild>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug - No Unit Tests|x64'">
|
||||
|
||||
@ -1832,9 +1832,6 @@
|
||||
<ClCompile Include="..\test_variance.cpp">
|
||||
<Filter>Tests\Algorithms</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test_variant_legacy.cpp">
|
||||
<Filter>Tests\Algorithms</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test_binary.cpp">
|
||||
<Filter>Tests\Binary</Filter>
|
||||
</ClCompile>
|
||||
@ -3254,6 +3251,9 @@
|
||||
<ClCompile Include="..\sanity-check\delegate_cpp03.h.t.cpp">
|
||||
<Filter>Tests\Sanity Checks\Source</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test_variant_legacy.cpp">
|
||||
<Filter>Tests\Containers</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\library.properties">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user