optional.h
Go to the documentation of this file.
1 /*
2 * ECVL - European Computer Vision Library
3 * Version: 0.3.4
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 optional to include yet
15 #ifndef INCLUDE_STD_OPTIONAL_EXPERIMENTAL
16 
17 // Check for feature test macro for <optional>
18 # if defined(__cpp_lib_optional)
19 # define INCLUDE_STD_OPTIONAL_EXPERIMENTAL 0
20 
21 // Check for feature test macro for <experimental/optional>
22 # elif defined(__cpp_lib_experimental_optional)
23 # define INCLUDE_STD_OPTIONAL_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_OPTIONAL_EXPERIMENTAL 1
29 
30 // Check if the header "<optional>" exists
31 # elif __has_include(<optional>)
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_OPTIONAL_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_OPTIONAL_EXPERIMENTAL
49 # define INCLUDE_STD_OPTIONAL_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_OPTIONAL_EXPERIMENTAL 0
55 # endif
56 
57 // Check if the header "<optional>" exists
58 # elif __has_include(<experimental/optional>)
59 # define INCLUDE_STD_OPTIONAL_EXPERIMENTAL 1
60 
61 // Fail if neither header is available with a nice error message
62 # else
63 # error Could not find system header "<optional>" or "<experimental/optional>"
64 # endif
65 
66 // We previously determined that we need the experimental version
67 # if INCLUDE_STD_OPTIONAL_EXPERIMENTAL
68 # include <experimental/optional>
69 namespace ecvl
70 {
71 template<typename T>
72 using optional = std::experimental::optional<T>;
73 
75 static auto& nullopt = std::experimental::nullopt;
76 }
77 # else
78 # include <optional>
79 namespace ecvl
80 {
81 template<typename T>
82 using optional = std::optional<T>;
83 
85 static auto& nullopt = std::nullopt;
86 }
87 # endif
88 
89 #endif // #ifndef INCLUDE_STD_OPTIONAL_EXPERIMENTAL
std::experimental::bad_optional_access bad_optional_access
Definition: optional.h:74
std::experimental::optional< T > optional
Definition: optional.h:72