MySQL 9.1.0
Source Code Documentation
expected_ostream.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2019, 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef MYSQL_HARNESS_STDX_EXPECTED_OSTREAM_H_
27#define MYSQL_HARNESS_STDX_EXPECTED_OSTREAM_H_
28
30
31#include <ostream>
32#include <type_traits>
33
34// operator<< for std::expected
35//
36// the functions are kept in a separate header as it
37//
38// - isn't part of the std-proposal
39// - includes <ostream> which isn't need for stdx::expected<> itself
40
41namespace stdx {
42namespace impl {
43template <typename S, typename T, typename = void>
44struct is_to_stream_writable : std::false_type {};
45
46template <typename S, typename T>
48 S, T, std::void_t<decltype(std::declval<S &>() << std::declval<T>())>>
49 : std::true_type {};
50
51} // namespace impl
52
53/**
54 * write stdx::expected<T, E> to std::ostream.
55 *
56 * T and E must be non-void.
57 *
58 * only takes part in overload-resolution if T and E support 'os << v'
59 */
60template <class T, class E>
61inline std::ostream &operator<<(std::ostream &os,
62 const stdx::expected<T, E> &res)
63 requires((impl::is_to_stream_writable<std::ostream, T>::value &&
64 impl::is_to_stream_writable<std::ostream, E>::value))
65{
66 if (res)
67 os << res.value();
68 else
69 os << res.error();
70
71 return os;
72}
73
74/**
75 * write stdx::expected<void, E> to std::ostream.
76 *
77 * only takes part in overload-resolution if E supports 'os << v'
78 */
79template <class E>
80inline std::ostream &operator<<(std::ostream &os,
81 const stdx::expected<void, E> &res) //
82 requires(impl::is_to_stream_writable<std::ostream, E>::value)
83{
84 if (!res) os << res.error();
85
86 return os;
87}
88
89/**
90 * write stdx::unexpected<E> to std::ostream.
91 *
92 * only takes part in overload-resolution if E supports 'os << v'
93 */
94template <class E>
95inline std::ostream &operator<<(std::ostream &os,
96 const stdx::unexpected<E> &res) //
97 requires(impl::is_to_stream_writable<std::ostream, E>::value)
98{
99 os << res.error();
100
101 return os;
102}
103} // namespace stdx
104
105#endif
Definition: http_server_component.cc:34
Definition: gcs_xcom_synode.h:64
Definition: bit.h:32
Definition: expected_ostream.h:44