-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #264 from puji4810/main
- Loading branch information
Showing
2 changed files
with
48 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
#include <algorithm> | ||
#include <vector> | ||
#include <functional> | ||
#include <iostream> | ||
template<typename T,typename IT> | ||
T& operator |(T&& v,const IT& f) | ||
{ | ||
for(auto&& x:v) | ||
{ | ||
f(x); | ||
} | ||
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; | ||
#include <algorithm> | ||
#include <vector> | ||
#include <functional> | ||
#include <iostream> | ||
template<typename T,typename IT> | ||
T& operator |(T&& v,const IT& f) | ||
{ | ||
for(auto&& x:v) | ||
{ | ||
f(x); | ||
} | ||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include <format> | ||
#include <functional> | ||
#include <iostream> | ||
#include <numbers> | ||
#include <string> | ||
#include <string_view> | ||
using namespace std; | ||
|
||
auto operator""_f(const char *s, size_t size) | ||
{ | ||
return [=](auto &&...Args) | ||
{ | ||
auto t=string_view(s,size); | ||
return vformat(t, make_format_args(Args...)); | ||
}; | ||
} | ||
|
||
int main() | ||
{ | ||
std::cout << "乐 :{} *\n"_f(5); | ||
std::cout << "乐 :{0} {0} *\n"_f(5); | ||
std::cout << "乐 :{:b} *\n"_f(0b01010101); | ||
std::cout << "{:*<10}"_f("卢瑟"); | ||
std::cout << '\n'; | ||
int n{}; | ||
std::cin >> n; | ||
std::cout << "π:{:.{}f}\n"_f(std::numbers::pi_v<double>, n); | ||
} |