OpenVPN 3 Core Library
Loading...
Searching...
No Matches
stringtempl2.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
13#pragma once
14
15#include <string>
16#include <type_traits>
17
19
20namespace openvpn::StringTempl {
21
22// empty
23
24// for objects that define an empty method
25template <typename T>
26inline auto empty(const T &t) -> decltype(t.empty())
27{
28 return t.empty();
29}
30
31// for numerical values
32template <typename T,
33 typename std::enable_if<std::is_arithmetic<T>::value, int>::type = 0>
34inline bool empty(T value)
35{
36 return false;
37}
38
39// to_string
40
41// for objects that define a to_string() method
42template <typename T>
43inline auto to_string(const T &t) -> decltype(t.to_string())
44{
45 return t.to_string();
46}
47
48// for numerical values
49template <typename T,
50 typename std::enable_if<std::is_arithmetic<T>::value, int>::type = 0>
51inline std::string to_string(T value)
52{
53 return std::to_string(value);
54}
55
56} // namespace openvpn::StringTempl
bool empty(std::nullptr_t)