OpenVPN 3 Core Library
Loading...
Searching...
No Matches
to_string.hpp
Go to the documentation of this file.
1// OpenVPN -- An application to securely tunnel IP networks
2// over a single port, with support for SSL/TLS-based
3// session authentication and key exchange,
4// packet encryption, packet authentication, and
5// packet compression.
6//
7// Copyright (C) 2012- OpenVPN Inc.
8//
9// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
10//
11
12#ifndef OPENVPN_COMMON_TO_STRING_H
13#define OPENVPN_COMMON_TO_STRING_H
14
15#include <string>
16#include <sstream>
17#include <type_traits>
18
20
21/* This file provides an openvpn::to_string function that works for all
22 types where either std::to_string is available or the type can be
23 streamed to an std::ostringstream. This is useful for types that don't
24 have a std::to_string overload. Also useful in cases where std::to_string
25 support is not complete.
26*/
27
28namespace openvpn {
29
30// Use std::to_string where we can
31using std::to_string;
32
42template <typename T>
43 requires(!requires(T a) { std::to_string(a); })
44 && requires(std::ostream &os, const T &t) { os << t; }
45inline std::string to_string(const T &t)
46{
47 std::ostringstream os;
48 os << t;
49 return os.str();
50}
51
52} // namespace openvpn
53
54#endif
std::ostringstream os