Renamed Either to either
This commit is contained in:
parent
cce24dd64b
commit
50503d9ce0
44
either.h
44
either.h
@ -7,30 +7,30 @@
|
||||
namespace cpputils {
|
||||
|
||||
template<class Left, class Right>
|
||||
class Either final {
|
||||
class either final {
|
||||
public:
|
||||
//TODO Try allowing construction with any type that std::is_convertible to Left or Right.
|
||||
Either(const Left &left): _side(Side::left) {
|
||||
either(const Left &left): _side(Side::left) {
|
||||
_construct_left(left);
|
||||
}
|
||||
Either(Left &&left): _side(Side::left) {
|
||||
either(Left &&left): _side(Side::left) {
|
||||
_construct_left(std::move(left));
|
||||
}
|
||||
Either(const Right &right): _side(Side::right) {
|
||||
either(const Right &right): _side(Side::right) {
|
||||
_construct_right(right);
|
||||
}
|
||||
Either(Right &&right): _side(Side::right) {
|
||||
either(Right &&right): _side(Side::right) {
|
||||
_construct_right(std::move(right));
|
||||
}
|
||||
//TODO Try allowing copy-construction when Left/Right types are std::is_convertible
|
||||
Either(const Either<Left, Right> &rhs): _side(rhs._side) {
|
||||
either(const either<Left, Right> &rhs): _side(rhs._side) {
|
||||
if(_side == Side::left) {
|
||||
_construct_left(rhs._left);
|
||||
} else {
|
||||
_construct_right(rhs._right);
|
||||
}
|
||||
}
|
||||
Either(Either<Left, Right> &&rhs): _side(rhs._side) {
|
||||
either(either<Left, Right> &&rhs): _side(rhs._side) {
|
||||
if(_side == Side::left) {
|
||||
_construct_left(std::move(rhs._left));
|
||||
} else {
|
||||
@ -38,12 +38,12 @@ namespace cpputils {
|
||||
}
|
||||
}
|
||||
|
||||
~Either() {
|
||||
~either() {
|
||||
_destruct();
|
||||
}
|
||||
|
||||
//TODO Try allowing copy-assignment when Left/Right types are std::is_convertible
|
||||
Either<Left, Right> &operator=(const Either<Left, Right> &rhs) {
|
||||
either<Left, Right> &operator=(const either<Left, Right> &rhs) {
|
||||
_destruct();
|
||||
_side = rhs._side;
|
||||
if (_side == Side::left) {
|
||||
@ -54,7 +54,7 @@ namespace cpputils {
|
||||
return *this;
|
||||
}
|
||||
|
||||
Either<Left, Right> &operator=(Either<Left, Right> &&rhs) {
|
||||
either<Left, Right> &operator=(either<Left, Right> &&rhs) {
|
||||
_destruct();
|
||||
_side = rhs._side;
|
||||
if (_side == Side::left) {
|
||||
@ -79,7 +79,7 @@ namespace cpputils {
|
||||
return _left;
|
||||
}
|
||||
Left &left() & {
|
||||
return const_cast<Left&>(const_cast<const Either<Left, Right>*>(this)->left());
|
||||
return const_cast<Left&>(const_cast<const either<Left, Right>*>(this)->left());
|
||||
}
|
||||
Left &&left() && {
|
||||
return std::move(left());
|
||||
@ -89,7 +89,7 @@ namespace cpputils {
|
||||
return _right;
|
||||
}
|
||||
Right &right() & {
|
||||
return const_cast<Right&>(const_cast<const Either<Left, Right>*>(this)->right());
|
||||
return const_cast<Right&>(const_cast<const either<Left, Right>*>(this)->right());
|
||||
}
|
||||
Right &&right() && {
|
||||
return std::move(right());
|
||||
@ -146,7 +146,7 @@ namespace cpputils {
|
||||
};
|
||||
enum class Side : unsigned char {left, right} _side;
|
||||
|
||||
Either(Side side): _side(side) {}
|
||||
either(Side side): _side(side) {}
|
||||
|
||||
template<typename... Args>
|
||||
void _construct_left(Args&&... args) {
|
||||
@ -165,14 +165,14 @@ namespace cpputils {
|
||||
}
|
||||
|
||||
template<typename Left_, typename Right_, typename... Args>
|
||||
friend Either<Left_, Right_> make_left(Args&&... args);
|
||||
friend either<Left_, Right_> make_left(Args&&... args);
|
||||
|
||||
template<typename Left_, typename Right_, typename... Args>
|
||||
friend Either<Left_, Right_> make_right(Args&&... args);
|
||||
friend either<Left_, Right_> make_right(Args&&... args);
|
||||
};
|
||||
|
||||
template<class Left, class Right>
|
||||
bool operator==(const Either<Left, Right> &lhs, const Either<Left, Right> &rhs) {
|
||||
bool operator==(const either<Left, Right> &lhs, const either<Left, Right> &rhs) {
|
||||
if (lhs.is_left() != rhs.is_left()) {
|
||||
return false;
|
||||
}
|
||||
@ -184,12 +184,12 @@ namespace cpputils {
|
||||
}
|
||||
|
||||
template<class Left, class Right>
|
||||
bool operator!=(const Either<Left, Right> &lhs, const Either<Left, Right> &rhs) {
|
||||
bool operator!=(const either<Left, Right> &lhs, const either<Left, Right> &rhs) {
|
||||
return !operator==(lhs, rhs);
|
||||
}
|
||||
|
||||
template<class Left, class Right>
|
||||
std::ostream &operator<<(std::ostream &stream, const Either<Left, Right> &value) {
|
||||
std::ostream &operator<<(std::ostream &stream, const either<Left, Right> &value) {
|
||||
if (value.is_left()) {
|
||||
stream << "Left(" << value.left() << ")";
|
||||
} else {
|
||||
@ -199,15 +199,15 @@ namespace cpputils {
|
||||
}
|
||||
|
||||
template<typename Left, typename Right, typename... Args>
|
||||
Either<Left, Right> make_left(Args&&... args) {
|
||||
Either<Left, Right> result(Either<Left, Right>::Side::left);
|
||||
either<Left, Right> make_left(Args&&... args) {
|
||||
either<Left, Right> result(either<Left, Right>::Side::left);
|
||||
result._construct_left(std::forward<Args>(args)...);
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename Left, typename Right, typename... Args>
|
||||
Either<Left, Right> make_right(Args&&... args) {
|
||||
Either<Left, Right> result(Either<Left, Right>::Side::right);
|
||||
either<Left, Right> make_right(Args&&... args) {
|
||||
either<Left, Right> result(either<Left, Right>::Side::right);
|
||||
result._construct_right(std::forward<Args>(args)...);
|
||||
return result;
|
||||
}
|
||||
|
@ -36,33 +36,33 @@ struct StoreWith1ByteFlag {
|
||||
class EitherTest: public Test {
|
||||
public:
|
||||
template<class Left, class Right>
|
||||
void EXPECT_IS_LEFT(const Either<Left,Right> &val) {
|
||||
void EXPECT_IS_LEFT(const either<Left,Right> &val) {
|
||||
EXPECT_TRUE(val.is_left());
|
||||
EXPECT_FALSE(val.is_right());
|
||||
}
|
||||
template<class Left, class Right>
|
||||
void EXPECT_IS_RIGHT(const Either<Left,Right> &val) {
|
||||
void EXPECT_IS_RIGHT(const either<Left,Right> &val) {
|
||||
EXPECT_FALSE(val.is_left());
|
||||
EXPECT_TRUE(val.is_right());
|
||||
}
|
||||
template<class Left, class Right, class Expected>
|
||||
void EXPECT_LEFT_IS(const Expected &expected, Either<Left, Right> &value) {
|
||||
void EXPECT_LEFT_IS(const Expected &expected, either<Left, Right> &value) {
|
||||
EXPECT_IS_LEFT(value);
|
||||
EXPECT_EQ(expected, value.left());
|
||||
EXPECT_EQ(expected, value.left_opt().get());
|
||||
EXPECT_EQ(boost::none, value.right_opt());
|
||||
const Either<Left, Right> &const_value = value;
|
||||
const either<Left, Right> &const_value = value;
|
||||
EXPECT_EQ(expected, const_value.left());
|
||||
EXPECT_EQ(expected, const_value.left_opt().get());
|
||||
EXPECT_EQ(boost::none, const_value.right_opt());
|
||||
}
|
||||
template<class Left, class Right, class Expected>
|
||||
void EXPECT_RIGHT_IS(const Expected &expected, Either<Left, Right> &value) {
|
||||
void EXPECT_RIGHT_IS(const Expected &expected, either<Left, Right> &value) {
|
||||
EXPECT_IS_RIGHT(value);
|
||||
EXPECT_EQ(expected, value.right());
|
||||
EXPECT_EQ(expected, value.right_opt().get());
|
||||
EXPECT_EQ(boost::none, value.left_opt());
|
||||
const Either<Left, Right> &const_value = value;
|
||||
const either<Left, Right> &const_value = value;
|
||||
EXPECT_EQ(expected, const_value.right());
|
||||
EXPECT_EQ(expected, const_value.right_opt().get());
|
||||
EXPECT_EQ(boost::none, const_value.left_opt());
|
||||
@ -71,7 +71,7 @@ public:
|
||||
|
||||
template<typename Left, typename Right>
|
||||
void TestSpaceUsage() {
|
||||
EXPECT_EQ(std::max(sizeof(StoreWith1ByteFlag<Left>), sizeof(StoreWith1ByteFlag<Right>)), sizeof(Either<Left, Right>));
|
||||
EXPECT_EQ(std::max(sizeof(StoreWith1ByteFlag<Left>), sizeof(StoreWith1ByteFlag<Right>)), sizeof(either<Left, Right>));
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, SpaceUsage) {
|
||||
@ -83,180 +83,180 @@ TEST_F(EitherTest, SpaceUsage) {
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, LeftCanBeConstructed) {
|
||||
Either<int, string> val = 3;
|
||||
either<int, string> val = 3;
|
||||
UNUSED(val);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, RightCanBeConstructed) {
|
||||
Either<int, string> val = string("string");
|
||||
either<int, string> val = string("string");
|
||||
UNUSED(val);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, IsLeft) {
|
||||
Either<int, string> val = 3;
|
||||
either<int, string> val = 3;
|
||||
EXPECT_IS_LEFT(val);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, IsRight) {
|
||||
Either<int, string> val = string("string");
|
||||
either<int, string> val = string("string");
|
||||
EXPECT_IS_RIGHT(val);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, LeftIsStored) {
|
||||
Either<int, string> val = 3;
|
||||
either<int, string> val = 3;
|
||||
EXPECT_LEFT_IS(3, val);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, RightIsStored) {
|
||||
Either<int, string> val = string("string");
|
||||
either<int, string> val = string("string");
|
||||
EXPECT_RIGHT_IS("string", val);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, LeftCanBeMoveContructed) {
|
||||
Either<OnlyMoveable, string> val = OnlyMoveable(1);
|
||||
either<OnlyMoveable, string> val = OnlyMoveable(1);
|
||||
UNUSED(val);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, RightCanBeMoveContructed) {
|
||||
Either<string, OnlyMoveable> val = OnlyMoveable(1);
|
||||
either<string, OnlyMoveable> val = OnlyMoveable(1);
|
||||
UNUSED(val);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, IsLeftWhenMoveContructed) {
|
||||
Either<OnlyMoveable, string> val = OnlyMoveable(1);
|
||||
either<OnlyMoveable, string> val = OnlyMoveable(1);
|
||||
EXPECT_IS_LEFT(val);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, IsRightWhenMoveContructed) {
|
||||
Either<string, OnlyMoveable> val = OnlyMoveable(1);
|
||||
either<string, OnlyMoveable> val = OnlyMoveable(1);
|
||||
EXPECT_IS_RIGHT(val);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, LeftIsStoredWhenMoveContructed) {
|
||||
Either<OnlyMoveable, string> val = OnlyMoveable(2);
|
||||
either<OnlyMoveable, string> val = OnlyMoveable(2);
|
||||
EXPECT_LEFT_IS(OnlyMoveable(2), val);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, RightIsStoredWhenMoveContructed) {
|
||||
Either<string, OnlyMoveable> val = OnlyMoveable(3);
|
||||
either<string, OnlyMoveable> val = OnlyMoveable(3);
|
||||
EXPECT_RIGHT_IS(OnlyMoveable(3), val);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, LeftCanBeCopied) {
|
||||
Either<string, int> val = string("string");
|
||||
Either<string, int> val2 = val;
|
||||
either<string, int> val = string("string");
|
||||
either<string, int> val2 = val;
|
||||
EXPECT_LEFT_IS("string", val2);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, CopyingLeftDoesntChangeSource) {
|
||||
Either<string, int> val = string("string");
|
||||
Either<string, int> val2 = val;
|
||||
either<string, int> val = string("string");
|
||||
either<string, int> val2 = val;
|
||||
EXPECT_LEFT_IS("string", val);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, RightCanBeCopied) {
|
||||
Either<int, string> val = string("string");
|
||||
Either<int, string> val2 = val;
|
||||
either<int, string> val = string("string");
|
||||
either<int, string> val2 = val;
|
||||
EXPECT_RIGHT_IS("string", val2);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, CopyingRightDoesntChangeSource) {
|
||||
Either<int, string> val = string("string");
|
||||
Either<int, string> val2 = val;
|
||||
either<int, string> val = string("string");
|
||||
either<int, string> val2 = val;
|
||||
EXPECT_RIGHT_IS("string", val);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, LeftCanBeMoved) {
|
||||
Either<OnlyMoveable, int> val = OnlyMoveable(5);
|
||||
Either<OnlyMoveable, int> val2 = std::move(val);
|
||||
either<OnlyMoveable, int> val = OnlyMoveable(5);
|
||||
either<OnlyMoveable, int> val2 = std::move(val);
|
||||
EXPECT_LEFT_IS(OnlyMoveable(5), val2);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, RightCanBeMoved) {
|
||||
Either<int, OnlyMoveable> val = OnlyMoveable(5);
|
||||
Either<int, OnlyMoveable> val2 = std::move(val);
|
||||
either<int, OnlyMoveable> val = OnlyMoveable(5);
|
||||
either<int, OnlyMoveable> val2 = std::move(val);
|
||||
EXPECT_RIGHT_IS(OnlyMoveable(5), val2);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, LeftCanBeAssigned) {
|
||||
Either<string, int> val = string("string");
|
||||
Either<string, int> val2 = string("otherstring");
|
||||
either<string, int> val = string("string");
|
||||
either<string, int> val2 = string("otherstring");
|
||||
val2 = val;
|
||||
EXPECT_LEFT_IS("string", val2);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, RightCanBeAssigned) {
|
||||
Either<int, string> val = string("string");
|
||||
Either<int, string> val2 = string("otherstring");
|
||||
either<int, string> val = string("string");
|
||||
either<int, string> val2 = string("otherstring");
|
||||
val2 = val;
|
||||
EXPECT_RIGHT_IS("string", val2);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, LeftCanBeMoveAssigned) {
|
||||
Either<OnlyMoveable, int> val = OnlyMoveable(3);
|
||||
Either<OnlyMoveable, int> val2 = OnlyMoveable(4);
|
||||
either<OnlyMoveable, int> val = OnlyMoveable(3);
|
||||
either<OnlyMoveable, int> val2 = OnlyMoveable(4);
|
||||
val2 = std::move(val);
|
||||
EXPECT_LEFT_IS(OnlyMoveable(3), val2);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, RightCanBeMoveAssigned) {
|
||||
Either<int, OnlyMoveable> val = OnlyMoveable(3);
|
||||
Either<int, OnlyMoveable> val2 = OnlyMoveable(4);
|
||||
either<int, OnlyMoveable> val = OnlyMoveable(3);
|
||||
either<int, OnlyMoveable> val2 = OnlyMoveable(4);
|
||||
val2 = std::move(val);
|
||||
EXPECT_RIGHT_IS(OnlyMoveable(3), val2);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, LeftCanBeDirectlyAssigned) {
|
||||
Either<string, int> val = string("string");
|
||||
either<string, int> val = string("string");
|
||||
val = string("otherstring");
|
||||
EXPECT_LEFT_IS("otherstring", val);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, RightCanBeDirectlyAssigned) {
|
||||
Either<int, string> val = string("string");
|
||||
either<int, string> val = string("string");
|
||||
val = string("otherstring");
|
||||
EXPECT_RIGHT_IS("otherstring", val);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, LeftCanBeDirectlyMoveAssigned) {
|
||||
Either<OnlyMoveable, int> val = OnlyMoveable(3);
|
||||
either<OnlyMoveable, int> val = OnlyMoveable(3);
|
||||
val = OnlyMoveable(5);
|
||||
EXPECT_LEFT_IS(OnlyMoveable(5), val);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, RightCanBeDirectlyMoveAssigned) {
|
||||
Either<int, OnlyMoveable> val = OnlyMoveable(3);
|
||||
either<int, OnlyMoveable> val = OnlyMoveable(3);
|
||||
val = OnlyMoveable(5);
|
||||
EXPECT_RIGHT_IS(OnlyMoveable(5), val);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, ModifyLeft) {
|
||||
Either<string, int> val = string("mystring1");
|
||||
either<string, int> val = string("mystring1");
|
||||
val.left() = "mystring2";
|
||||
EXPECT_LEFT_IS("mystring2", val);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, ModifyRight) {
|
||||
Either<int, string> val = string("mystring1");
|
||||
either<int, string> val = string("mystring1");
|
||||
val.right() = "mystring2";
|
||||
EXPECT_RIGHT_IS("mystring2", val);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, ModifyLeftOpt) {
|
||||
Either<string, int> val = string("mystring1");
|
||||
either<string, int> val = string("mystring1");
|
||||
val.left_opt().get() = "mystring2";
|
||||
EXPECT_LEFT_IS("mystring2", val);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, ModifyRightOpt) {
|
||||
Either<int, string> val = string("mystring1");
|
||||
either<int, string> val = string("mystring1");
|
||||
val.right_opt().get() = "mystring2";
|
||||
EXPECT_RIGHT_IS("mystring2", val);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, LeftEquals) {
|
||||
Either<string, int> val1 = string("mystring");
|
||||
Either<string, int> val2 = string("mystring");
|
||||
either<string, int> val1 = string("mystring");
|
||||
either<string, int> val2 = string("mystring");
|
||||
EXPECT_TRUE(val1 == val2);
|
||||
EXPECT_TRUE(val2 == val1);
|
||||
EXPECT_FALSE(val1 != val2);
|
||||
@ -264,8 +264,8 @@ TEST_F(EitherTest, LeftEquals) {
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, LeftNotEquals) {
|
||||
Either<string, int> val1 = string("mystring");
|
||||
Either<string, int> val2 = string("mystring2");
|
||||
either<string, int> val1 = string("mystring");
|
||||
either<string, int> val2 = string("mystring2");
|
||||
EXPECT_TRUE(val1 != val2);
|
||||
EXPECT_TRUE(val2 != val1);
|
||||
EXPECT_FALSE(val1 == val2);
|
||||
@ -273,8 +273,8 @@ TEST_F(EitherTest, LeftNotEquals) {
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, RightEquals) {
|
||||
Either<int, string> val1 = string("mystring");
|
||||
Either<int, string> val2 = string("mystring");
|
||||
either<int, string> val1 = string("mystring");
|
||||
either<int, string> val2 = string("mystring");
|
||||
EXPECT_TRUE(val1 == val2);
|
||||
EXPECT_TRUE(val2 == val1);
|
||||
EXPECT_FALSE(val1 != val2);
|
||||
@ -282,8 +282,8 @@ TEST_F(EitherTest, RightEquals) {
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, RightNotEquals) {
|
||||
Either<int, string> val1 = string("mystring");
|
||||
Either<int, string> val2 = string("mystring2");
|
||||
either<int, string> val1 = string("mystring");
|
||||
either<int, string> val2 = string("mystring2");
|
||||
EXPECT_TRUE(val1 != val2);
|
||||
EXPECT_TRUE(val2 != val1);
|
||||
EXPECT_FALSE(val1 == val2);
|
||||
@ -291,8 +291,8 @@ TEST_F(EitherTest, RightNotEquals) {
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, LeftNotEqualsRight) {
|
||||
Either<string, int> val1 = string("mystring");
|
||||
Either<string, int> val2 = 3;
|
||||
either<string, int> val1 = string("mystring");
|
||||
either<string, int> val2 = 3;
|
||||
EXPECT_TRUE(val1 != val2);
|
||||
EXPECT_TRUE(val2 != val1);
|
||||
EXPECT_FALSE(val1 == val2);
|
||||
@ -312,32 +312,32 @@ TEST_F(EitherTest, OutputRight) {
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, MakeLeft) {
|
||||
Either<string, int> var = make_left<string, int>("mystring");
|
||||
either<string, int> var = make_left<string, int>("mystring");
|
||||
EXPECT_LEFT_IS("mystring", var);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, MakeLeft_OnlyMoveable) {
|
||||
Either<OnlyMoveable, int> var = make_left<OnlyMoveable, int>(4);
|
||||
either<OnlyMoveable, int> var = make_left<OnlyMoveable, int>(4);
|
||||
EXPECT_LEFT_IS(OnlyMoveable(4), var);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, MakeLeft_MultiParam) {
|
||||
Either<pair<int, int>, int> var = make_left<pair<int, int>, int>(4, 5);
|
||||
either<pair<int, int>, int> var = make_left<pair<int, int>, int>(4, 5);
|
||||
EXPECT_LEFT_IS(make_pair(4,5), var);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, MakeRight) {
|
||||
Either<int, string> var = make_right<int, string>("mystring");
|
||||
either<int, string> var = make_right<int, string>("mystring");
|
||||
EXPECT_RIGHT_IS("mystring", var);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, MakeRight_OnlyMoveable) {
|
||||
Either<int, OnlyMoveable> var = make_right<int, OnlyMoveable>(4);
|
||||
either<int, OnlyMoveable> var = make_right<int, OnlyMoveable>(4);
|
||||
EXPECT_RIGHT_IS(OnlyMoveable(4), var);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest, MakeRight_MultiParam) {
|
||||
Either<int, pair<int, int>> var = make_right<int, pair<int, int>>(4, 5);
|
||||
either<int, pair<int, int>> var = make_right<int, pair<int, int>>(4, 5);
|
||||
EXPECT_RIGHT_IS(make_pair(4,5), var);
|
||||
}
|
||||
|
||||
@ -403,7 +403,7 @@ TEST_F(EitherTest_Destructor, LeftDestructorIsCalled) {
|
||||
destructorCallback.EXPECT_CALLED(2); //Once for the temp object, once when the either class destructs
|
||||
|
||||
ClassWithDestructorCallback temp(&destructorCallback);
|
||||
Either<ClassWithDestructorCallback, string> var = temp;
|
||||
either<ClassWithDestructorCallback, string> var = temp;
|
||||
}
|
||||
|
||||
TEST_F(EitherTest_Destructor, RightDestructorIsCalled) {
|
||||
@ -411,7 +411,7 @@ TEST_F(EitherTest_Destructor, RightDestructorIsCalled) {
|
||||
destructorCallback.EXPECT_CALLED(2); //Once for the temp object, once when the either class destructs
|
||||
|
||||
ClassWithDestructorCallback temp(&destructorCallback);
|
||||
Either<string, ClassWithDestructorCallback> var = temp;
|
||||
either<string, ClassWithDestructorCallback> var = temp;
|
||||
}
|
||||
|
||||
TEST_F(EitherTest_Destructor, LeftDestructorIsCalledAfterCopying) {
|
||||
@ -419,8 +419,8 @@ TEST_F(EitherTest_Destructor, LeftDestructorIsCalledAfterCopying) {
|
||||
destructorCallback.EXPECT_CALLED(3); //Once for the temp object, once for var1 and once for var2
|
||||
|
||||
ClassWithDestructorCallback temp(&destructorCallback);
|
||||
Either<ClassWithDestructorCallback, string> var1 = temp;
|
||||
Either<ClassWithDestructorCallback, string> var2 = var1;
|
||||
either<ClassWithDestructorCallback, string> var1 = temp;
|
||||
either<ClassWithDestructorCallback, string> var2 = var1;
|
||||
}
|
||||
|
||||
TEST_F(EitherTest_Destructor, RightDestructorIsCalledAfterCopying) {
|
||||
@ -428,8 +428,8 @@ TEST_F(EitherTest_Destructor, RightDestructorIsCalledAfterCopying) {
|
||||
destructorCallback.EXPECT_CALLED(3); //Once for the temp object, once for var1 and once for var2
|
||||
|
||||
ClassWithDestructorCallback temp(&destructorCallback);
|
||||
Either<string, ClassWithDestructorCallback> var1 = temp;
|
||||
Either<string, ClassWithDestructorCallback> var2 = var1;
|
||||
either<string, ClassWithDestructorCallback> var1 = temp;
|
||||
either<string, ClassWithDestructorCallback> var2 = var1;
|
||||
}
|
||||
|
||||
TEST_F(EitherTest_Destructor, LeftDestructorIsCalledAfterMoving) {
|
||||
@ -437,8 +437,8 @@ TEST_F(EitherTest_Destructor, LeftDestructorIsCalledAfterMoving) {
|
||||
destructorCallback.EXPECT_CALLED(3); //Once for the temp object, once for var1 and once for var2
|
||||
|
||||
OnlyMoveableClassWithDestructorCallback temp(&destructorCallback);
|
||||
Either<OnlyMoveableClassWithDestructorCallback, string> var1 = std::move(temp);
|
||||
Either<OnlyMoveableClassWithDestructorCallback, string> var2 = std::move(var1);
|
||||
either<OnlyMoveableClassWithDestructorCallback, string> var1 = std::move(temp);
|
||||
either<OnlyMoveableClassWithDestructorCallback, string> var2 = std::move(var1);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest_Destructor, RightDestructorIsCalledAfterMoving) {
|
||||
@ -446,8 +446,8 @@ TEST_F(EitherTest_Destructor, RightDestructorIsCalledAfterMoving) {
|
||||
destructorCallback.EXPECT_CALLED(3); //Once for the temp object, once for var1 and once for var2
|
||||
|
||||
OnlyMoveableClassWithDestructorCallback temp(&destructorCallback);
|
||||
Either<string, OnlyMoveableClassWithDestructorCallback> var1 = std::move(temp);
|
||||
Either<string, OnlyMoveableClassWithDestructorCallback> var2 = std::move(var1);
|
||||
either<string, OnlyMoveableClassWithDestructorCallback> var1 = std::move(temp);
|
||||
either<string, OnlyMoveableClassWithDestructorCallback> var2 = std::move(var1);
|
||||
}
|
||||
|
||||
TEST_F(EitherTest_Destructor, LeftDestructorIsCalledAfterAssignment) {
|
||||
@ -457,9 +457,9 @@ TEST_F(EitherTest_Destructor, LeftDestructorIsCalledAfterAssignment) {
|
||||
destructorCallback2.EXPECT_CALLED(3); //Once for the temp2 object, once in destructor of var2, once in destructor of var1
|
||||
|
||||
ClassWithDestructorCallback temp1(&destructorCallback1);
|
||||
Either<ClassWithDestructorCallback, string> var1 = temp1;
|
||||
either<ClassWithDestructorCallback, string> var1 = temp1;
|
||||
ClassWithDestructorCallback temp2(&destructorCallback2);
|
||||
Either<ClassWithDestructorCallback, string> var2 = temp2;
|
||||
either<ClassWithDestructorCallback, string> var2 = temp2;
|
||||
var1 = var2;
|
||||
}
|
||||
|
||||
@ -470,9 +470,9 @@ TEST_F(EitherTest_Destructor, RightDestructorIsCalledAfterAssignment) {
|
||||
destructorCallback2.EXPECT_CALLED(3); //Once for the temp2 object, once in destructor of var2, once in destructor of var1
|
||||
|
||||
ClassWithDestructorCallback temp1(&destructorCallback1);
|
||||
Either<string, ClassWithDestructorCallback> var1 = temp1;
|
||||
either<string, ClassWithDestructorCallback> var1 = temp1;
|
||||
ClassWithDestructorCallback temp2(&destructorCallback2);
|
||||
Either<string, ClassWithDestructorCallback> var2 = temp2;
|
||||
either<string, ClassWithDestructorCallback> var2 = temp2;
|
||||
var1 = var2;
|
||||
}
|
||||
|
||||
@ -483,9 +483,9 @@ TEST_F(EitherTest_Destructor, LeftDestructorIsCalledAfterMoveAssignment) {
|
||||
destructorCallback2.EXPECT_CALLED(3); //Once for the temp2 object, once in destructor of var2, once in destructor of var1
|
||||
|
||||
OnlyMoveableClassWithDestructorCallback temp1(&destructorCallback1);
|
||||
Either<OnlyMoveableClassWithDestructorCallback, string> var1 = std::move(temp1);
|
||||
either<OnlyMoveableClassWithDestructorCallback, string> var1 = std::move(temp1);
|
||||
OnlyMoveableClassWithDestructorCallback temp2(&destructorCallback2);
|
||||
Either<OnlyMoveableClassWithDestructorCallback, string> var2 = std::move(temp2);
|
||||
either<OnlyMoveableClassWithDestructorCallback, string> var2 = std::move(temp2);
|
||||
var1 = std::move(var2);
|
||||
}
|
||||
|
||||
@ -496,8 +496,8 @@ TEST_F(EitherTest_Destructor, RightDestructorIsCalledAfterMoveAssignment) {
|
||||
destructorCallback2.EXPECT_CALLED(3); //Once for the temp2 object, once in destructor of var2, once in destructor of var1
|
||||
|
||||
OnlyMoveableClassWithDestructorCallback temp1(&destructorCallback1);
|
||||
Either<string, OnlyMoveableClassWithDestructorCallback> var1 = std::move(temp1);
|
||||
either<string, OnlyMoveableClassWithDestructorCallback> var1 = std::move(temp1);
|
||||
OnlyMoveableClassWithDestructorCallback temp2(&destructorCallback2);
|
||||
Either<string, OnlyMoveableClassWithDestructorCallback> var2 = std::move(temp2);
|
||||
either<string, OnlyMoveableClassWithDestructorCallback> var2 = std::move(temp2);
|
||||
var1 = std::move(var2);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user