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