|
2 | 2 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
3 | 3 |
|
4 | 4 | #include <__msvc_all_public_headers.hpp>
|
| 5 | + |
| 6 | +using namespace std; |
| 7 | + |
| 8 | +void instantiate_regex_machinery() { |
| 9 | + const regex r{R"(.+meow.+)"}; |
| 10 | + assert(regex_match("homeowner", r)); |
| 11 | +} |
| 12 | + |
| 13 | +#if _HAS_CXX20 |
| 14 | +void instantiate_chrono_parse_machinery() { |
| 15 | + istringstream iss{"10:02:07"}; |
| 16 | + chrono::seconds s{}; |
| 17 | + iss >> chrono::parse("%H:%M:%S", s); |
| 18 | + assert(s == 36127s); |
| 19 | +} |
| 20 | +#endif // ^^^ _HAS_CXX20 ^^^ |
| 21 | + |
| 22 | +#if _HAS_CXX23 |
| 23 | +template <class T> |
| 24 | +struct WrappedVector : vector<T> { |
| 25 | + using vector<T>::vector; |
| 26 | +}; |
| 27 | + |
| 28 | +template <class T> |
| 29 | +struct std::formatter<WrappedVector<T>, char> { |
| 30 | +public: |
| 31 | + template <class ParseContext> |
| 32 | + constexpr auto parse(ParseContext& ctx) { |
| 33 | + return underlying.parse(ctx); |
| 34 | + } |
| 35 | + |
| 36 | + template <class FormatContext> |
| 37 | + auto format(const WrappedVector<T>& rng, FormatContext& ctx) const { |
| 38 | + return underlying.format(rng, ctx); |
| 39 | + } |
| 40 | + |
| 41 | +private: |
| 42 | + range_formatter<T, char> underlying; |
| 43 | +}; |
| 44 | + |
| 45 | +void instantiate_range_formatter_machinery() { |
| 46 | + const WrappedVector<int> v{11, 22, 33, 44}; |
| 47 | + assert(format("{}", v) == "[11, 22, 33, 44]"); |
| 48 | + assert(format("{:}", v) == "[11, 22, 33, 44]"); |
| 49 | + assert(format("{:n}", v) == "11, 22, 33, 44"); |
| 50 | +} |
| 51 | +#endif // ^^^ _HAS_CXX23 ^^^ |
0 commit comments