olp-cpp-sdk 1.24.0
Loading...
Searching...
No Matches
any.h
1/*
2 * Copyright (C) 2025 HERE Europe B.V.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * SPDX-License-Identifier: Apache-2.0
17 * License-Filename: LICENSE
18 */
19
20#pragma once
21
22#if (__cplusplus >= 201703L) && defined(OLP_SDK_USE_STD_ANY)
23#include <any>
24
25namespace olp {
26namespace porting {
27
28using any = std::any;
29
30template <typename T>
31inline T any_cast(const any& operand) {
32 return std::any_cast<T>(operand);
33}
34
35template <typename T>
36inline T any_cast(any& operand) {
37 return std::any_cast<T>(operand);
38}
39
40template <typename T>
41inline T any_cast(any&& operand) {
42 return std::any_cast<T>(std::move(operand));
43}
44
45template <typename T>
46inline const T* any_cast(const any* operand) noexcept {
47 return std::any_cast<T>(operand);
48}
49
50template <typename T>
51inline T* any_cast(any* operand) noexcept {
52 return std::any_cast<T>(operand);
53}
54
55inline bool has_value(const any& operand) noexcept {
56 return operand.has_value();
57}
58
59inline void reset(any& operand) noexcept { operand.reset(); }
60
61template <typename T, typename... Args>
62inline any make_any(Args&&... args) {
63 return std::make_any<T>(std::forward<Args>(args)...);
64}
65
66template <typename T, typename U, typename... Args>
67inline any make_any(std::initializer_list<U> il, Args&&... args) {
68 return std::make_any<T>(il, std::forward<Args>(args)...);
69}
70
71} // namespace porting
72} // namespace olp
73
74#else
75#include <boost/any.hpp>
76
77namespace olp {
78namespace porting {
79
80using any = boost::any;
81
82template <typename T>
83inline T any_cast(const any& operand) {
84 return boost::any_cast<T>(operand);
85}
86
87template <typename T>
88inline T any_cast(any& operand) {
89 return boost::any_cast<T>(operand);
90}
91
92template <typename T>
93inline T any_cast(any&& operand) {
94 return boost::any_cast<T>(operand);
95}
96
97template <typename T>
98inline const T* any_cast(const any* operand) noexcept {
99 return boost::any_cast<T>(operand);
100}
101
102template <typename T>
103inline T* any_cast(any* operand) noexcept {
104 return boost::any_cast<T>(operand);
105}
106
107inline bool has_value(const any& operand) noexcept { return !operand.empty(); }
108
109inline void reset(any& operand) noexcept { operand = boost::any(); }
110
111template <typename T, typename... Args>
112inline any make_any(Args&&... args) {
113 return any(T(std::forward<Args>(args)...));
114}
115
116template <typename T, typename U, typename... Args>
117inline any make_any(std::initializer_list<U> il, Args&&... args) {
118 return any(T(il, std::forward<Args>(args)...));
119}
120
121} // namespace porting
122} // namespace olp
123
124#endif
Rules all the other namespaces.
Definition AppleSignInProperties.h:24