CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
optional_utils.h
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: functions that are useful with std::optional
4
5Author: Diffblue Ltd.
6
7\*******************************************************************/
8
9#ifndef CPROVER_UTIL_OPTIONAL_UTILS_H
10#define CPROVER_UTIL_OPTIONAL_UTILS_H
11
12#include <optional>
13
16template <typename map_like_collectiont, typename keyt>
17auto optional_lookup(const map_like_collectiont &map, const keyt &key)
18 -> std::optional<decltype(map.find(key)->second)>
19{
20 auto const it = map.find(key);
21 if(it != map.end())
22 {
23 return it->second;
24 }
25 return {};
26}
27
28#endif // CPROVER_UTIL_OPTIONAL_UTILS_H
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
auto optional_lookup(const map_like_collectiont &map, const keyt &key) -> std::optional< decltype(map.find(key) ->second)>
Lookup a key in a map, if found return the associated value, nullopt otherwise.