|
| 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 | + |
| 25 | +namespace olp { |
| 26 | +namespace porting { |
| 27 | + |
| 28 | +using any = std::any; |
| 29 | + |
| 30 | +template <typename T> |
| 31 | +inline T any_cast(const any& operand) { |
| 32 | + return std::any_cast<T>(operand); |
| 33 | +} |
| 34 | + |
| 35 | +template <typename T> |
| 36 | +inline T any_cast(any& operand) { |
| 37 | + return std::any_cast<T>(operand); |
| 38 | +} |
| 39 | + |
| 40 | +template <typename T> |
| 41 | +inline T any_cast(any&& operand) { |
| 42 | + return std::any_cast<T>(std::move(operand)); |
| 43 | +} |
| 44 | + |
| 45 | +template <typename T> |
| 46 | +inline const T* any_cast(const any* operand) noexcept { |
| 47 | + return std::any_cast<T>(operand); |
| 48 | +} |
| 49 | + |
| 50 | +template <typename T> |
| 51 | +inline T* any_cast(any* operand) noexcept { |
| 52 | + return std::any_cast<T>(operand); |
| 53 | +} |
| 54 | + |
| 55 | +inline bool has_value(const any& operand) noexcept { |
| 56 | + return operand.has_value(); |
| 57 | +} |
| 58 | + |
| 59 | +inline void reset(any& operand) noexcept { operand.reset(); } |
| 60 | + |
| 61 | +template <typename T, typename... Args> |
| 62 | +inline any make_any(Args&&... args) { |
| 63 | + return std::make_any<T>(std::forward<Args>(args)...); |
| 64 | +} |
| 65 | + |
| 66 | +template <typename T, typename U, typename... Args> |
| 67 | +inline 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 | + |
| 77 | +namespace olp { |
| 78 | +namespace porting { |
| 79 | + |
| 80 | +using any = boost::any; |
| 81 | + |
| 82 | +template <typename T> |
| 83 | +inline T any_cast(const any& operand) { |
| 84 | + return boost::any_cast<T>(operand); |
| 85 | +} |
| 86 | + |
| 87 | +template <typename T> |
| 88 | +inline T any_cast(any& operand) { |
| 89 | + return boost::any_cast<T>(operand); |
| 90 | +} |
| 91 | + |
| 92 | +template <typename T> |
| 93 | +inline T any_cast(any&& operand) { |
| 94 | + return boost::any_cast<T>(operand); |
| 95 | +} |
| 96 | + |
| 97 | +template <typename T> |
| 98 | +inline const T* any_cast(const any* operand) noexcept { |
| 99 | + return boost::any_cast<T>(operand); |
| 100 | +} |
| 101 | + |
| 102 | +template <typename T> |
| 103 | +inline T* any_cast(any* operand) noexcept { |
| 104 | + return boost::any_cast<T>(operand); |
| 105 | +} |
| 106 | + |
| 107 | +inline bool has_value(const any& operand) noexcept { return !operand.empty(); } |
| 108 | + |
| 109 | +inline void reset(any& operand) noexcept { operand = boost::any(); } |
| 110 | + |
| 111 | +template <typename T, typename... Args> |
| 112 | +inline any make_any(Args&&... args) { |
| 113 | + return any(T(std::forward<Args>(args)...)); |
| 114 | +} |
| 115 | + |
| 116 | +template <typename T, typename U, typename... Args> |
| 117 | +inline 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 |
0 commit comments