Scarab  v3.4.4
Project 8 C++ Utility Library
map_at_default.hh
Go to the documentation of this file.
1 /*
2  * map_at_default.hh
3  *
4  * Created on: Jan 8, 2019
5  * Author: N.S. Oblath
6  */
7 
8 #ifndef SCARAB_UTILITY_MAPATDEFAULT
9 #define SCARAB_UTILITY_MAPATDEFAULT
10 
11 #include <map>
12 
13 namespace scarab
14 {
15  template< typename x_key, typename x_value >
16  const x_value& at( const std::map< x_key, x_value >& a_map, const x_key& a_key, const x_value& a_default )
17  {
18  try
19  {
20  return a_map.at( a_key );
21  }
22  catch(...)
23  {
24  return a_default;
25  }
26  }
27 
28 } /* end namespace scarab */
29 
30 #endif /* SCARAB_UTILITY_MAPATDEFAULT */
const x_value & at(const std::map< x_key, x_value > &a_map, const x_key &a_key, const x_value &a_default)