96d003df457c25035bbca27d377e4c4c563f9b06
[babeltrace.git] / src / cpp-common / bt2s / optional.hpp
1 /*
2 * Copyright (c) 2023 Philippe Proulx <pproulx@efficios.com>
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7 #ifndef BABELTRACE_CPP_COMMON_BT2S_OPTIONAL_HPP
8 #define BABELTRACE_CPP_COMMON_BT2S_OPTIONAL_HPP
9
10 #include "cpp-common/vendor/optional-lite/optional.hpp"
11
12 namespace bt2s {
13
14 template <typename T>
15 using optional = nonstd::optional<T>;
16
17 using nullopt_t = nonstd::nullopt_t;
18 using bad_optional_access = nonstd::bad_optional_access;
19 constexpr nullopt_t nullopt {nonstd::nullopt};
20
21 template <typename T>
22 constexpr optional<typename std::decay<T>::type> make_optional(T&& value)
23 {
24 return nonstd::make_optional(std::forward<T>(value));
25 }
26
27 template <typename T, typename... ArgTs>
28 constexpr optional<T> make_optional(ArgTs&&...args)
29 {
30 return nonstd::make_optional<T>(std::forward<ArgTs>(args)...);
31 }
32
33 using in_place_t = nonstd::in_place_t;
34
35 template <typename T>
36 inline in_place_t in_place()
37 {
38 return nonstd::in_place<T>();
39 }
40
41 template <std::size_t K>
42 inline in_place_t in_place()
43 {
44 return nonstd::in_place<K>();
45 }
46
47 template <typename T>
48 inline in_place_t in_place_type()
49 {
50 return nonstd::in_place_type<T>();
51 }
52
53 template <std::size_t K>
54 inline in_place_t in_place_index()
55 {
56 return nonstd::in_place_index<K>();
57 }
58
59 } /* namespace bt2s */
60
61 #endif /* BABELTRACE_CPP_COMMON_BT2S_OPTIONAL_HPP */
This page took 0.029876 seconds and 3 git commands to generate.