From 31d624f9a80d91dab9453ad92c40ecf4e176d905 Mon Sep 17 00:00:00 2001 From: Anton Potapov Date: Fri, 6 Mar 2020 11:18:30 +0300 Subject: [PATCH] G-API utils - fix compilation error in variant::operator= --- .../include/opencv2/gapi/util/variant.hpp | 5 ++-- modules/gapi/test/util/variant_tests.cpp | 25 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/modules/gapi/include/opencv2/gapi/util/variant.hpp b/modules/gapi/include/opencv2/gapi/util/variant.hpp index 134ba66234..ee0590bf7f 100644 --- a/modules/gapi/include/opencv2/gapi/util/variant.hpp +++ b/modules/gapi/include/opencv2/gapi/util/variant.hpp @@ -281,13 +281,14 @@ namespace util template typename detail::are_different, T, variant&> ::type variant::operator=(T&& t) noexcept { + using decayed_t = typename std::decay::type; // FIXME: No version with implicit type conversion available! static const constexpr std::size_t t_index = - util::type_list_index::value; + util::type_list_index::value; if (t_index == m_index) { - util::get(*this) = std::move(t); + util::get(*this) = std::move(t); return *this; } else return (*this = variant(std::move(t))); diff --git a/modules/gapi/test/util/variant_tests.cpp b/modules/gapi/test/util/variant_tests.cpp index bdeea9445f..f85b1fbf72 100644 --- a/modules/gapi/test/util/variant_tests.cpp +++ b/modules/gapi/test/util/variant_tests.cpp @@ -115,6 +115,18 @@ TEST(Variant, Assign_Basic) EXPECT_EQ(42, util::get(vis)); } +TEST(Variant, Assign_LValueRef) +{ + TestVar vis; + EXPECT_EQ(0u, vis.index()); + EXPECT_EQ(0, util::get(vis)); + + int val = 42; + vis = val; + EXPECT_EQ(0u, vis.index()); + EXPECT_EQ(42, util::get(vis)); +} + TEST(Variant, Assign_ValueUpdate_SameType) { TestVar vis(42); @@ -139,6 +151,19 @@ TEST(Variant, Assign_ValueUpdate_DiffType) EXPECT_EQ("42", util::get(vis)); } +TEST(Variant, Assign_LValueRef_DiffType) +{ + TestVar vis(42); + + EXPECT_EQ(0u, vis.index()); + EXPECT_EQ(42, util::get(vis)); + + std::string s("42"); + vis = s; + EXPECT_EQ(1u, vis.index()); + EXPECT_EQ("42", util::get(vis)); +} + TEST(Variant, Assign_ValueUpdate_Const) { TestVar va(42);