sparrow 0.6.0
Loading...
Searching...
No Matches
pair.hpp
Go to the documentation of this file.
1// Copyright 2024 Man Group Operations Limited
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <utility>
18
19#if defined(__cpp_lib_format)
20# include <format>
21# include <ostream>
22#endif
23
24#if defined(__cpp_lib_format) && __cplusplus < 202300L
25
26template <typename T, typename U>
27struct std::formatter<std::pair<T, U>>
28{
29 constexpr auto parse(std::format_parse_context& ctx)
30 {
31 return ctx.begin();
32 }
33
34 auto format(const std::pair<T, U>& p, std::format_context& ctx) const
35 {
36 return std::format_to(ctx.out(), "({}, {})", p.first, p.second);
37 }
38};
39
40template <typename T, typename U>
41std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& value)
42{
43 os << std::format("{}", value);
44 return os;
45}
46
47#endif
std::ostream & operator<<(std::ostream &os, const sparrow::nullval_t &)
Definition nullable.hpp:900