any.h
Go to the documentation of this file.
1 /*
2 * ECVL - European Computer Vision Library
3 * Version: 1.0.0
4 * copyright (c) 2021, Università degli Studi di Modena e Reggio Emilia (UNIMORE), AImageLab
5 * Authors:
6 * Costantino Grana (costantino.grana@unimore.it)
7 * Federico Bolelli (federico.bolelli@unimore.it)
8 * Michele Cancilla (michele.cancilla@unimore.it)
9 * Laura Canalini (laura.canalini@unimore.it)
10 * Stefano Allegretti (stefano.allegretti@unimore.it)
11 * All rights reserved.
12 */
13 
14 // We haven't checked which any to include yet
15 #ifndef INCLUDE_STD_ANY_EXPERIMENTAL
16 
17 // Check for feature test macro for <any>
18 # if defined(__cpp_lib_any)
19 # define INCLUDE_STD_ANY_EXPERIMENTAL 0
20 
21 // Check for feature test macro for <experimental/any>
22 # elif defined(__cpp_lib_experimental_any)
23 # define INCLUDE_STD_ANY_EXPERIMENTAL 1
24 
25 // We can't check if headers exist...
26 // Let's assume experimental to be safe
27 # elif !defined(__has_include)
28 # define INCLUDE_STD_ANY_EXPERIMENTAL 1
29 
30 // Check if the header "<any>" exists
31 # elif __has_include(<any>)
32 
33 // If we're compiling on Visual Studio and are not compiling with C++17, we need to use experimental
34 # ifdef _MSC_VER
35 
36 // Check and include header that defines "_HAS_CXX17"
37 # if __has_include(<yvals_core.h>)
38 # include <yvals_core.h>
39 
40 // Check for enabled C++17 support
41 # if defined(_HAS_CXX17) && _HAS_CXX17
42 // We're using C++17, so let's use the normal version
43 # define INCLUDE_STD_ANY_EXPERIMENTAL 0
44 # endif
45 # endif
46 
47 // If the macro isn't defined yet, that means any of the other VS specific checks failed, so we need to use experimental
48 # ifndef INCLUDE_STD_ANY_EXPERIMENTAL
49 # define INCLUDE_STD_ANY_EXPERIMENTAL 1
50 # endif
51 
52 // Not on Visual Studio. Let's use the normal version
53 # else // #ifdef _MSC_VER
54 # define INCLUDE_STD_ANY_EXPERIMENTAL 0
55 # endif
56 
57 // Check if the header "<any>" exists
58 # elif __has_include(<experimental/any>)
59 # define INCLUDE_STD_ANY_EXPERIMENTAL 1
60 
61 // Fail if neither header is available with a nice error message
62 # else
63 # error Could not find system header "<any>" or "<experimental/any>"
64 # endif
65 
66 // We previously determined that we need the experimental version
67 # if INCLUDE_STD_ANY_EXPERIMENTAL
68 # include <experimental/any>
69 namespace ecvl
70 {
72 
73 template <typename T>
74 auto any_cast(const T& t)
75 {
76  return std::experimental::any_cast<T>(t);
77 }
78 }
79 # else
80 # include <any>
81 namespace ecvl
82 {
83 using any = std::any;
84 
85 template <typename T>
86 auto any_cast(const T& t)
87 {
88  return std::any_cast<T>(t);
89 }
90 }
91 # endif
92 
93 #endif // #ifndef INCLUDE_STD_ANY_EXPERIMENTAL
auto any_cast(const T &t)
Definition: any.h:74
Definition: any.h:69
std::experimental::any any
Definition: any.h:71