diff --git a/src/cpp-utils/either.h b/src/cpp-utils/either.h index bca422a2..d701c6f8 100644 --- a/src/cpp-utils/either.h +++ b/src/cpp-utils/either.h @@ -27,18 +27,18 @@ namespace cpputils { either(const either &rhs) noexcept(noexcept(std::declval>()._construct_left(rhs._left)) && noexcept(std::declval>()._construct_right(rhs._right))) : _side(rhs._side) { if(_side == Side::left) { - _construct_left(rhs._left); + _construct_left(rhs._left); // NOLINT(cppcoreguidelines-pro-type-union-access) } else { - _construct_right(rhs._right); + _construct_right(rhs._right); // NOLINT(cppcoreguidelines-pro-type-union-access) } } either(either &&rhs) noexcept(noexcept(_construct_left(std::move(rhs._left))) && noexcept(_construct_right(std::move(rhs._right)))) : _side(rhs._side) { if(_side == Side::left) { - _construct_left(std::move(rhs._left)); + _construct_left(std::move(rhs._left)); // NOLINT(cppcoreguidelines-pro-type-union-access) } else { - _construct_right(std::move(rhs._right)); + _construct_right(std::move(rhs._right)); // NOLINT(cppcoreguidelines-pro-type-union-access) } } @@ -51,9 +51,9 @@ namespace cpputils { _destruct(); _side = rhs._side; if (_side == Side::left) { - _construct_left(rhs._left); + _construct_left(rhs._left); // NOLINT(cppcoreguidelines-pro-type-union-access) } else { - _construct_right(rhs._right); + _construct_right(rhs._right); // NOLINT(cppcoreguidelines-pro-type-union-access) } return *this; } @@ -62,9 +62,9 @@ namespace cpputils { _destruct(); _side = rhs._side; if (_side == Side::left) { - _construct_left(std::move(rhs._left)); + _construct_left(std::move(rhs._left)); // NOLINT(cppcoreguidelines-pro-type-union-access) } else { - _construct_right(std::move(rhs._right)); + _construct_right(std::move(rhs._right)); // NOLINT(cppcoreguidelines-pro-type-union-access) } return *this; } @@ -83,7 +83,7 @@ namespace cpputils { if (!is_left()) { throw std::logic_error("Tried to get left side of an either which is right."); } - return _left; + return _left; // NOLINT(cppcoreguidelines-pro-type-union-access) } Left &left() & { return const_cast(const_cast*>(this)->left()); @@ -96,7 +96,7 @@ namespace cpputils { if (!is_right()) { throw std::logic_error("Tried to get right side of an either which is left."); } - return _right; + return _right; // NOLINT(cppcoreguidelines-pro-type-union-access) } Right &right() & { return const_cast(const_cast*>(this)->right()); @@ -107,14 +107,14 @@ namespace cpputils { boost::optional left_opt() const& noexcept { if (_side == Side::left) { - return _left; + return _left; // NOLINT(cppcoreguidelines-pro-type-union-access) } else { return boost::none; } } boost::optional left_opt() & noexcept { if (_side == Side::left) { - return _left; + return _left; // NOLINT(cppcoreguidelines-pro-type-union-access) } else { return boost::none; } @@ -131,14 +131,14 @@ namespace cpputils { boost::optional right_opt() const& noexcept { if (_side == Side::right) { - return _right; + return _right; // NOLINT(cppcoreguidelines-pro-type-union-access) } else { return boost::none; } } boost::optional right_opt() & noexcept { if (_side == Side::right) { - return _right; + return _right; // NOLINT(cppcoreguidelines-pro-type-union-access) } else { return boost::none; } @@ -165,17 +165,17 @@ namespace cpputils { template void _construct_left(Args&&... args) noexcept(noexcept(new Left(std::forward(args)...))) { - new(&_left)Left(std::forward(args)...); + new(&_left)Left(std::forward(args)...); // NOLINT(cppcoreguidelines-pro-type-union-access) } template void _construct_right(Args&&... args) noexcept(noexcept(new Right(std::forward(args)...))) { - new(&_right)Right(std::forward(args)...); + new(&_right)Right(std::forward(args)...); // NOLINT(cppcoreguidelines-pro-type-union-access) } void _destruct() noexcept { if (_side == Side::left) { - _left.~Left(); + _left.~Left(); // NOLINT(cppcoreguidelines-pro-type-union-access) } else { - _right.~Right(); + _right.~Right(); // NOLINT(cppcoreguidelines-pro-type-union-access) } } diff --git a/test/cpp-utils/either_test.cpp b/test/cpp-utils/either_test.cpp index b5c0a8ce..af5de759 100644 --- a/test/cpp-utils/either_test.cpp +++ b/test/cpp-utils/either_test.cpp @@ -341,7 +341,7 @@ TEST(EitherTest, givenLeftMoveConstructedFromValue_thenOldIsCorrect) { [] (const auto& test) { MovableOnly a(3); either b(std::move(a)); - test(a); + test(a); // NOLINT(bugprone-use-after-move) } }, EXPECT_IS(MovableOnly(0)) // 0 is moved-from value @@ -365,7 +365,7 @@ TEST(EitherTest, givenRightMoveConstructedFromValue_thenOldIsCorrect) { [] (const auto& test) { MovableOnly a(3); either b(std::move(a)); - test(a); + test(a); // NOLINT(bugprone-use-after-move) } }, EXPECT_IS(MovableOnly(0)) // 0 is moved-from value @@ -468,12 +468,12 @@ TEST(EitherTest, givenLeftMoveAssignedFromValue_thenOldIsCorrect) { MovableOnly a(3); either b("2"); b = std::move(a); - test(a); + test(a); // NOLINT(bugprone-use-after-move) }, [] (const auto& test) { MovableOnly a(3); either b(MovableOnly(0)); b = std::move(a); - test(a); + test(a); // NOLINT(bugprone-use-after-move) } }, EXPECT_IS(MovableOnly(0)) @@ -504,12 +504,12 @@ TEST(EitherTest, givenRightMoveAssignedFromValue_thenOldIsCorrect) { MovableOnly a(3); either b("2"); b = std::move(a); - test(a); + test(a); // NOLINT(bugprone-use-after-move) }, [] (const auto& test) { MovableOnly a(3); either b(MovableOnly(2)); b = std::move(a); - test(a); + test(a); // NOLINT(bugprone-use-after-move) } }, EXPECT_IS(MovableOnly(0)) // 0 is moved-from value @@ -631,7 +631,7 @@ TEST(EitherTest, givenLeftMoveConstructed_thenOldIsCorrect) { [] (const auto& test) { either a(MovableOnly(3)); either b(std::move(a)); - test(a); + test(a); // NOLINT(bugprone-use-after-move) } }, EXPECT_IS_LEFT(MovableOnly(0)) // 0 is moved-from value @@ -655,7 +655,7 @@ TEST(EitherTest, givenLeftMoveConstructed_withSameType_thenOldIsCorrect) { [] (const auto& test) { either a = make_left(MovableOnly(3)); either b(std::move(a)); - test(a); + test(a); // NOLINT(bugprone-use-after-move) } }, EXPECT_IS_LEFT(MovableOnly(0)) // 0 is moved-from value @@ -679,7 +679,7 @@ TEST(EitherTest, givenRightMoveConstructed_thenOldIsCorrect) { [] (const auto& test) { either a(MovableOnly(3)); either b(std::move(a)); - test(a); + test(a); // NOLINT(bugprone-use-after-move) } }, EXPECT_IS_RIGHT(MovableOnly(0)) // 0 is moved-from value @@ -703,7 +703,7 @@ TEST(EitherTest, givenRightMoveConstructed_withSameType_thenOldIsCorrect) { [] (const auto& test) { either a = make_right(MovableOnly(3)); either b(std::move(a)); - test(a); + test(a); // NOLINT(bugprone-use-after-move) } }, EXPECT_IS_RIGHT(MovableOnly(0)) // 0 is moved-from value @@ -878,12 +878,12 @@ TEST(EitherTest, givenLeftMoveAssigned_thenOldIsCorrect) { either a(MovableOnly(3)); either b(2); b = std::move(a); - test(a); + test(a); // NOLINT(bugprone-use-after-move) }, [] (const auto& test) { either a(MovableOnly(3)); either b(MovableOnly(2)); b = std::move(a); - test(a); + test(a); // NOLINT(bugprone-use-after-move) } }, EXPECT_IS_LEFT(MovableOnly(0)) // 0 is moved-from value @@ -914,12 +914,12 @@ TEST(EitherTest, givenLeftMoveAssigned_withSameType_thenOldIsCorrect) { either a = make_left(3); either b = make_right(2); b = std::move(a); - test(a); + test(a); // NOLINT(bugprone-use-after-move) }, [] (const auto& test) { either a = make_left(3); either b = make_left(2); b = std::move(a); - test(a); + test(a); // NOLINT(bugprone-use-after-move) } }, EXPECT_IS_LEFT(MovableOnly(0)) // 0 is moved-from value @@ -950,12 +950,12 @@ TEST(EitherTest, givenRightMoveAssigned_thenOldIsCorrect) { either a(MovableOnly(3)); either b("2"); b = std::move(a); - test(a); + test(a); // NOLINT(bugprone-use-after-move) }, [] (const auto& test) { either a(MovableOnly(3)); either b(MovableOnly(2)); b = std::move(a); - test(a); + test(a); // NOLINT(bugprone-use-after-move) } }, EXPECT_IS_RIGHT(MovableOnly(0)) // 0 is moved-from value @@ -986,12 +986,12 @@ TEST(EitherTest, givenRightMoveAssigned_withSameType_thenOldIsCorrect) { either a = make_right(3); either b = make_left(2); b = std::move(a); - test(a); + test(a); // NOLINT(bugprone-use-after-move) }, [] (const auto& test) { either a = make_right(3); either b = make_right(2); b = std::move(a); - test(a); + test(a); // NOLINT(bugprone-use-after-move) } }, EXPECT_IS_RIGHT(MovableOnly(0)) // 0 is moved-from value @@ -1033,22 +1033,22 @@ TEST(EitherTest, givenRight_whenModified_thenValueIsChanged) { TEST(EitherTest, canEmplaceConstructLeft) { test_with_matrix({ [] (const auto& test) { - either, tuple> a(2, 3); + either, tuple> a(2, 3); test(a); } }, - EXPECT_IS_LEFT, tuple>(tuple(2, 3)) + EXPECT_IS_LEFT, tuple>(tuple(2, 3)) ); } TEST(EitherTest, canEmplaceConstructRight) { test_with_matrix({ [] (const auto& test) { - either, tuple> a(2, 3, 4); + either, tuple> a(2, "3", 4); test(a); } }, - EXPECT_IS_RIGHT, tuple>(tuple(2, 3, 4)) + EXPECT_IS_RIGHT, tuple>(tuple(2, "3", 4)) ); }