mirror of
https://github.com/opencv/opencv.git
synced 2025-01-19 06:53:50 +08:00
Merge pull request #16849 from anton-potapov:ap/variant__assignment_operator_compile_error
This commit is contained in:
commit
978666c816
@ -281,13 +281,14 @@ namespace util
|
||||
template<class T> typename detail::are_different<variant<Ts...>, T, variant<Ts...>&>
|
||||
::type variant<Ts...>::operator=(T&& t) noexcept
|
||||
{
|
||||
using decayed_t = typename std::decay<T>::type;
|
||||
// FIXME: No version with implicit type conversion available!
|
||||
static const constexpr std::size_t t_index =
|
||||
util::type_list_index<T, Ts...>::value;
|
||||
util::type_list_index<decayed_t, Ts...>::value;
|
||||
|
||||
if (t_index == m_index)
|
||||
{
|
||||
util::get<T>(*this) = std::move(t);
|
||||
util::get<decayed_t>(*this) = std::move(t);
|
||||
return *this;
|
||||
}
|
||||
else return (*this = variant(std::move(t)));
|
||||
|
@ -115,6 +115,18 @@ TEST(Variant, Assign_Basic)
|
||||
EXPECT_EQ(42, util::get<int>(vis));
|
||||
}
|
||||
|
||||
TEST(Variant, Assign_LValueRef)
|
||||
{
|
||||
TestVar vis;
|
||||
EXPECT_EQ(0u, vis.index());
|
||||
EXPECT_EQ(0, util::get<int>(vis));
|
||||
|
||||
int val = 42;
|
||||
vis = val;
|
||||
EXPECT_EQ(0u, vis.index());
|
||||
EXPECT_EQ(42, util::get<int>(vis));
|
||||
}
|
||||
|
||||
TEST(Variant, Assign_ValueUpdate_SameType)
|
||||
{
|
||||
TestVar vis(42);
|
||||
@ -139,6 +151,19 @@ TEST(Variant, Assign_ValueUpdate_DiffType)
|
||||
EXPECT_EQ("42", util::get<std::string>(vis));
|
||||
}
|
||||
|
||||
TEST(Variant, Assign_LValueRef_DiffType)
|
||||
{
|
||||
TestVar vis(42);
|
||||
|
||||
EXPECT_EQ(0u, vis.index());
|
||||
EXPECT_EQ(42, util::get<int>(vis));
|
||||
|
||||
std::string s("42");
|
||||
vis = s;
|
||||
EXPECT_EQ(1u, vis.index());
|
||||
EXPECT_EQ("42", util::get<std::string>(vis));
|
||||
}
|
||||
|
||||
TEST(Variant, Assign_ValueUpdate_Const)
|
||||
{
|
||||
TestVar va(42);
|
||||
|
Loading…
Reference in New Issue
Block a user