CBMC
optional.h
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module: typedef for optional class template. To be replaced with
4
std::optional once C++17 support is enabled
5
6
Author: Diffblue Ltd.
7
8
\*******************************************************************/
9
10
#ifndef CPROVER_UTIL_OPTIONAL_H
11
#define CPROVER_UTIL_OPTIONAL_H
12
13
#if defined __clang__
14
#pragma clang diagnostic push ignore "-Wall"
15
#pragma clang diagnostic push ignore "-Wpedantic"
16
#elif defined __GNUC__
17
#pragma GCC diagnostic push ignore "-Wall"
18
#pragma GCC diagnostic push ignore "-Wpedantic"
19
#elif defined _MSC_VER
20
#pragma warning(push)
21
#endif
22
#include <nonstd/optional.hpp>
23
#if defined __clang__
24
#pragma clang diagnostic pop
25
#pragma clang diagnostic pop
26
#elif defined __GNUC__
27
#pragma GCC diagnostic pop
28
#pragma GCC diagnostic pop
29
#elif defined _MSC_VER
30
#pragma warning(pop)
31
#endif
32
33
// Swap for std::optional when switching to C++17
34
template
<
typename
T>
35
using
optionalt
=nonstd::optional<T>;
// NOLINT template typedef
36
37
typedef
nonstd::bad_optional_access
bad_optional_accesst
;
38
39
using
nonstd::nullopt;
40
43
template
<
typename
T>
44
T &
get_value_or_abort
(
optionalt<T>
&opt)
45
{
46
PRECONDITION
(opt.has_value());
47
return
opt.value();
48
}
49
51
template
<
typename
T>
52
const
T &
get_value_or_abort
(
const
optionalt<T>
&opt)
53
{
54
PRECONDITION
(opt.has_value());
55
return
opt.value();
56
}
57
58
#endif // CPROVER_UTIL_OPTIONAL_H
bad_optional_accesst
nonstd::bad_optional_access bad_optional_accesst
Definition:
optional.h:37
PRECONDITION
#define PRECONDITION(CONDITION)
Definition:
invariant.h:463
optionalt
nonstd::optional< T > optionalt
Definition:
optional.h:35
get_value_or_abort
T & get_value_or_abort(optionalt< T > &opt)
Similar to optionalt::value but in case of empty optional, generates an invariant failure instead of ...
Definition:
optional.h:44
src
util
optional.h
Generated by
1.8.17