Skip to content

Instantly share code, notes, and snippets.

@bradphelan
Created February 26, 2020 12:05
Show Gist options
  • Save bradphelan/0bb9397ea7b49f45122908b1a9da061f to your computer and use it in GitHub Desktop.
Save bradphelan/0bb9397ea7b49f45122908b1a9da061f to your computer and use it in GitHub Desktop.
TEST(RANGE, LVALUE){
auto vector = IRange(3,5) | ToVector();
auto mvector = vector | Map([](int i){return i+1;}) | ToVector();
// Check the vector has not been moved
ASSERT_EQ(2,vector.size());
ASSERT_EQ(3,vector[0]);
ASSERT_EQ(4,vector[1]);
// Check the result has what it needs
ASSERT_EQ(2,mvector.size());
ASSERT_EQ(4,mvector[0]);
ASSERT_EQ(5,mvector[1]);
}
TEST(RANGE, MOVED_LVALUE){
auto vector = IRange(3,5) | ToVector();
auto mvector = std::move(vector) | Map([](int i){return i+1;}) | ToVector();
// Check the vector has not been copied but moved
ASSERT_EQ(0,vector.size());
// Check the result has what it needs
ASSERT_EQ(2,mvector.size());
ASSERT_EQ(4,mvector[0]);
ASSERT_EQ(5,mvector[1]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment