cpp-common: add `bt2s::optional`, alias of `nonstd::optional`
[babeltrace.git] / src / cpp-common / bt2s / optional.hpp
CommitLineData
c022776a
SM
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
12namespace bt2s {
13
14template <typename T>
15using optional = nonstd::optional<T>;
16
17using nullopt_t = nonstd::nullopt_t;
18using bad_optional_access = nonstd::bad_optional_access;
19constexpr nullopt_t nullopt {nonstd::nullopt};
20
21template <typename T>
22constexpr optional<typename std::decay<T>::type> make_optional(T&& value)
23{
24 return nonstd::make_optional(std::forward<T>(value));
25}
26
27template <typename T, typename... ArgTs>
28constexpr optional<T> make_optional(ArgTs&&...args)
29{
30 return nonstd::make_optional<T>(std::forward<ArgTs>(args)...);
31}
32
33using in_place_t = nonstd::in_place_t;
34
35template <typename T>
36inline in_place_t in_place()
37{
38 return nonstd::in_place<T>();
39}
40
41template <std::size_t K>
42inline in_place_t in_place()
43{
44 return nonstd::in_place<K>();
45}
46
47template <typename T>
48inline in_place_t in_place_type()
49{
50 return nonstd::in_place_type<T>();
51}
52
53template <std::size_t K>
54inline 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.025133 seconds and 4 git commands to generate.