Template methods provide safe access to associative containers.
More...
|
template<class C > |
C::mapped_type | getValue (const C &m, const typename C::key_type &key, std::string calledFrom) |
|
template<class C > |
void | setValueHelper (C &m, const typename C::key_type &key, const typename C::mapped_type &value, std::string calledFrom) |
|
template<class C , class T = typename C::mapped_type> |
void | setValue (C &m, const typename C::key_type &key, const typename std::enable_if< std::is_pointer< T >::value, T >::type &value, std::string calledFrom) |
|
template<class C , class T = typename C::mapped_type> |
void | setValue (C &m, const typename C::key_type &key, const typename std::enable_if<!std::is_pointer< T >::value, T >::type &value, std::string calledFrom) |
|
Template methods provide safe access to associative containers.
Template methods provide safe access to associative containers, i.e. it does not allow to store e.g. null pointers or rewrite already existing values in the map. Errors are handled by using exceptions.
map<uint32_t, double> mymap;
setValue(mymap, 0, 5.0, caller());
setValue(mymap, 1, 7.0, caller());
double x = getValue(mymap, 0, caller());
double y = getValue(mymap, 1, caller());
cout<<"x + y = "<<x+y<<endl;
- Note
- There is a useful macro caller() for filling the string of the caller method.
- Warning
- Due to the construction of the caller string there is a significant overhead, and therefore it is not recommended to use these functions inside the performance critical functions.