Skip to content

Commit

Permalink
docs: answer question 1 (#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
YouMu-Lew authored Jul 13, 2024
1 parent 12def0c commit 283249c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/群友提交/第01题/youmu_lew.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <iostream>
#include <vector>
#include <functional>

template<typename T, typename Func>
std::vector<T>& operator|(std::vector<T>& v, Func func) {
for (auto& i : v) {
func(i);
}
return v;
}

int main(){
std::vector v{1, 2, 3};
std::function f {[](const int& i) {std::cout << i << ' '; } };
auto f2 = [](int& i) {i *= i; };
v | f2 | f;
}

// 预期结果: 1 4 9

0 comments on commit 283249c

Please sign in to comment.