How to ignore constness in a function template?

Viewed 312

I have the following template function:

template<typename K, typename V>
bool hasKey( const std::map<K, V>& m, K& k ) {
    return m.find(k) != m.end();
}

The keys in the map are not const.

Now, I may have a const K. How can I write a template that would allow me to pass in both K andconst K` to the function?

Is the solution to use a const_cast every time I call the function?

2 Answers
Related