TEST(Visit, MutVarConstType) { mpark::variant<const int> v(42); EXPECT_EQ(42, mpark::get<const int>(v)); // Check qualifier. EXPECT_EQ(ConstLRef, mpark::visit(get_qual(), v)); EXPECT_EQ(ConstRRef, mpark::visit(get_qual(), lib::move(v))); }
TEST(Visit, MutVarMutType) { mpark::variant<int> v(42); // Check `v`. EXPECT_EQ(42, mpark::get<int>(v)); // Check qualifier. EXPECT_EQ(LRef, mpark::visit(get_qual(), v)); EXPECT_EQ(RRef, mpark::visit(get_qual(), lib::move(v))); }
TEST(Access_GetIf, ConstVarConstType) { const std_exp::variant<const int> v(42); EXPECT_EQ(42, *std_exp::get_if<const int>(&v)); // Check qualifier. EXPECT_EQ(ConstPtr, get_qual(std_exp::get_if<const int>(&v))); /* constexpr */ { constexpr std_exp::variant<const int> v(42); static_assert(42 == *std_exp::get_if<const int>(&v), ""); // Check qualifier. static_assert(ConstPtr == get_qual(std_exp::get_if<const int>(&v)), ""); } }
TEST(Visit, ConstVarConstType) { const mpark::variant<const int> v(42); EXPECT_EQ(42, mpark::get<const int>(v)); // Check qualifier. EXPECT_EQ(ConstLRef, mpark::visit(get_qual(), v)); EXPECT_EQ(ConstRRef, mpark::visit(get_qual(), lib::move(v))); #if !defined(__GNUC__) || __GNUC__ >= 5 /* constexpr */ { constexpr mpark::variant<const int> cv(42); static_assert(42 == mpark::get<const int>(cv), ""); // Check qualifier. static_assert(ConstLRef == mpark::visit(get_qual(), cv), ""); static_assert(ConstRRef == mpark::visit(get_qual(), lib::move(cv)), ""); } #endif }
TEST(Access_GetIf, ConstVarConstTypeRef) { int expected = 42; const std_exp::variant<const int &> v(expected); EXPECT_EQ(expected, *std_exp::get_if<const int &>(&v)); EXPECT_EQ(&expected, std_exp::get_if<const int &>(&v)); // Check qualifier. EXPECT_EQ(ConstPtr, get_qual(std_exp::get_if<const int &>(&v))); }
TEST(Access_GetIf, MutVarMutTypeRef) { int expected = 42; std_exp::variant<int &> v(expected); EXPECT_EQ(expected, *std_exp::get_if<int &>(&v)); EXPECT_EQ(&expected, std_exp::get_if<int &>(&v)); // Check qualifier. EXPECT_EQ(Ptr, get_qual(std_exp::get_if<int &>(&v))); }
TEST(Access_GetIf, MutVarConstType) { std_exp::variant<const int> v(42); EXPECT_EQ(42, *std_exp::get_if<const int>(&v)); // Check qualifier. EXPECT_EQ(ConstPtr, get_qual(std_exp::get_if<const int>(&v))); }