-
Notifications
You must be signed in to change notification settings - Fork 362
/
Copy pathOptional.hpp
89 lines (73 loc) · 1.97 KB
/
Optional.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#pragma once
// Distributed under the 3-Clause BSD License. See accompanying
// file LICENSE or https://github.com/CLIUtils/CLI11 for details.
#include <istream>
#include "CLI/Macros.hpp"
// [CLI11:verbatim]
#ifdef __has_include
// You can explicitly enable or disable support
// by defining these to 1 or 0.
#if defined(CLI11_CPP17) && __has_include(<optional>) && \
!defined(CLI11_STD_OPTIONAL)
#define CLI11_STD_OPTIONAL 1
#endif
#if defined(CLI11_CPP14) && __has_include(<experimental/optional>) && \
!defined(CLI11_EXPERIMENTAL_OPTIONAL) \
&& (!defined(CLI11_STD_OPTIONAL) || CLI11_STD_OPTIONAL != 0)
#define CLI11_EXPERIMENTAL_OPTIONAL 1
#endif
#if __has_include(<boost/optional.hpp>) && !defined(CLI11_BOOST_OPTIONAL)
#include <boost/version.hpp>
#if BOOST_VERSION >= 105800
#define CLI11_BOOST_OPTIONAL 1
#endif
#endif
#endif
#if CLI11_STD_OPTIONAL
#include <optional>
#endif
#if CLI11_EXPERIMENTAL_OPTIONAL
#include <experimental/optional>
#endif
#if CLI11_BOOST_OPTIONAL
#include <boost/optional.hpp>
#endif
// [CLI11:verbatim]
namespace CLI {
#if CLI11_STD_OPTIONAL
template <typename T> std::istream &operator>>(std::istream &in, std::optional<T> &val) {
T v;
in >> v;
val = v;
return in;
}
#endif
#if CLI11_EXPERIMENTAL_OPTIONAL
template <typename T> std::istream &operator>>(std::istream &in, std::experimental::optional<T> &val) {
T v;
in >> v;
val = v;
return in;
}
#endif
#if CLI11_BOOST_OPTIONAL
template <typename T> std::istream &operator>>(std::istream &in, boost::optional<T> &val) {
T v;
in >> v;
val = v;
return in;
}
#endif
// Export the best optional to the CLI namespace
#if CLI11_STD_OPTIONAL
using std::optional;
#elif CLI11_EXPERIMENTAL_OPTIONAL
using std::experimental::optional;
#elif CLI11_BOOST_OPTIONAL
using boost::optional;
#endif
// This is true if any optional is found
#if CLI11_STD_OPTIONAL || CLI11_EXPERIMENTAL_OPTIONAL || CLI11_BOOST_OPTIONAL
#define CLI11_OPTIONAL 1
#endif
} // namespace CLI