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

Help: need non-const first_type

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

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Apr 12 '06 #1
Share this Question
Share on Google+
4 Replies


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 use Boost.TypeTraits' remove_const
(http://boost.org/doc/html/boost_type...s.remove_const)
or Loki's TypeTraits' NonConstType (http://loki-lib.sourceforge.net).

Cheers! --M
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Apr 13 '06 #2

P: n/a
JE

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?

<snip>

MAP::key_type?
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Apr 13 '06 #3

P: n/a
In article <e1**********@mailhost.cas.org>, Paul Dubuc <pd****@cas.org>
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?


I would at least leave open the possibility for arg to be a different
type that is convertible to first_type. That would mean a separate
template parameter, you might want to do the same with val as well.
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Apr 13 '06 #4

P: n/a
In article <e1**********@mailhost.cas.org>, Paul Dubuc <pd****@cas.org>
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?

Thanks,

you can use boost or loki stuff or since you want the types T,V
of map<T,V,...> or multimap<T,V,...> they are key_type and mapped_type.

template <class MAP>
int match(const MAP &choices,typename MAP::key_type &arg,
typename MAP::mapped_type &val)
{ /* .... */}

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Apr 14 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.