Skip to content

Commit

Permalink
Create andyli.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
gandyli authored Aug 4, 2023
1 parent 967bb97 commit dc06f68
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/群友提交/第二题/andyli.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <format>
#include <iostream>
#include <string_view>
#include <string>

namespace impl {
struct Helper {
const std::string_view s;
Helper(const char* s, std::size_t len): s(s, len) {}
template <typename... Args>
std::string operator()(Args&&... args) const {
return std::vformat(s, std::make_format_args(std::forward<Args>(args)...));
}
};
} // namespace impl
impl::Helper operator""_f(const char* s, std::size_t len) noexcept {
return {s, len};
}

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);
}

0 comments on commit dc06f68

Please sign in to comment.