DCCL v4
any.h
1 // Copyright 2023:
2 // GobySoft, LLC (2013-)
3 // Community contributors (see AUTHORS file)
4 // File authors:
5 // Toby Schneider <toby@gobysoft.org>
6 //
7 //
8 // This file is part of the Dynamic Compact Control Language Library
9 // ("DCCL").
10 //
11 // DCCL is free software: you can redistribute it and/or modify
12 // it under the terms of the GNU Lesser General Public License as published by
13 // the Free Software Foundation, either version 2.1 of the License, or
14 // (at your option) any later version.
15 //
16 // DCCL is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU Lesser General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public License
22 // along with DCCL. If not, see <http://www.gnu.org/licenses/>.
23 #ifndef DCCLAny
24 #define DCCLAny
25 
26 #include "dccl/def.h"
27 
28 #ifdef DCCL_HAS_CPP17
29 #include <any>
30 namespace dccl
31 {
32 using any = std::any;
33 template <class T> T any_cast(const any& operand) { return std::any_cast<T>(operand); }
34 template <class T> T any_cast(any& operand) { return std::any_cast<T>(operand); }
35 template <class T> T any_cast(any&& operand) { return std::any_cast<T>(operand); }
36 template <class T> const T* any_cast(const any* operand) noexcept
37 {
38  return std::any_cast<T>(operand);
39 }
40 template <class T> T* any_cast(any* operand) noexcept { return std::any_cast<T>(operand); }
41 using bad_any_cast = std::bad_any_cast;
42 inline bool is_empty(const any& a) { return !a.has_value(); }
43 } // namespace dccl
44 #else
45 #include <boost/any.hpp>
46 namespace dccl
47 {
48 using any = boost::any;
49 template <class T> T any_cast(const any& operand) { return boost::any_cast<T>(operand); }
50 template <class T> T any_cast(any& operand) { return boost::any_cast<T>(operand); }
51 template <class T> T any_cast(any&& operand) { return boost::any_cast<T>(operand); }
52 template <class T> const T* any_cast(const any* operand) noexcept
53 {
54  return boost::any_cast<T>(operand);
55 }
56 template <class T> T* any_cast(any* operand) noexcept { return boost::any_cast<T>(operand); }
57 using bad_any_cast = boost::bad_any_cast;
58 inline bool is_empty(const any& a) { return a.empty(); }
59 } // namespace dccl
60 #endif
61 
62 #endif
dccl
Dynamic Compact Control Language namespace.
Definition: any.h:46