By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,745 Members | 1,873 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,745 IT Pros & Developers. It's quick & easy.

Help with non-const first_type in std::map

P: n/a
Question: In the following template function signature

template <class MAP>
int matchAbbreviationMap(
const MAP & choices,
typename MAP::value_type::first_type & arg,
typename MAP::value_type::second_type & val)
{
...

MAP is a std::map or std::multi_map so MAP::value_type::first_type is a const
type. I want arg to have the same type but to be non-const. Is there some
way to do this generically without specifying a redundant type in the template
parameters?

Thanks,
--
Paul M. Dubuc
Apr 11 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Paul Dubuc wrote:
Question: In the following template function signature

template <class MAP>
int matchAbbreviationMap(
const MAP & choices,
typename MAP::value_type::first_type & arg,
typename MAP::value_type::second_type & val)
{
...

MAP is a std::map or std::multi_map so MAP::value_type::first_type is
a const type. I want arg to have the same type but to be non-const. Is
there some way to do this generically without specifying a
redundant type in the template parameters?


You could try this:

// auxiliary templates for type extraction
template<class T> struct drop_const { typedef T type; };
template<class T> struct drop_const<T const &> { typedef T type; }

..
template<class MAP>
int match...
typename drop_const<MAP::value_type::first>::type & arg,
...

Or some such.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 11 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.