Skip to content

Instantly share code, notes, and snippets.

@Shaun289
Created January 17, 2023 03:13
Show Gist options
  • Save Shaun289/bb6b5c0a13fa24a8d47c9d8963f621e6 to your computer and use it in GitHub Desktop.
Save Shaun289/bb6b5c0a13fa24a8d47c9d8963f621e6 to your computer and use it in GitHub Desktop.
C++ Functional : filter copy_if
#include <iostream>
#include <vector>
#include <numeric>
#include <gtest/gtest.h>
TEST(test_copy_if, TestOdd)
{
std::vector<int> v1(10);
std::vector<int> v2(5);
std::iota(v1.begin(), v1.end(), 0);
std::copy_if(v1.begin(), v1.end(), v2.begin(), [] (int x) {
return x % 2 != 0;
});
std::vector<int> result{1,3,5,7,9};
EXPECT_EQ(v2, result);
}
int main(int argc, char* argv[])
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment