solver  1.0
Functions
safe access to associative containers

Template methods provide safe access to associative containers. More...

Functions

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)
 

Detailed Description

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()); // 0 -> 5.0
setValue(mymap, 1, 7.0, caller()); // 1 -> 7.0
double x = getValue(mymap, 0, caller()); // returns 5.0
double y = getValue(mymap, 1, caller()); // returns 7.0
cout<<"x + y = "<<x+y<<endl; // prints "x + y = 12"
// Error, duplicit key, exception thrown.
// setValue(mymap, 1, 9.0, caller());
// Error, non-existing key, exception thrown.
// getValue(mymap, 4, caller());
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.