This is the mail archive of the libstdc++@sourceware.cygnus.com mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

default allocator templ arg for map and multimap



hi -

I noticed recently that one of the default template arguments for the
map and multimap classes in libstdc++ do not agree with the standard.
(Actually, a collegue pointed out this problem in a commercial library,
but when i went to look, i saw that libstdc++ had the same problem.)

The template signature we have for map (and multimap) is

  template <class _Key, class _Tp, class _Compare = less<_Key>,
            class _Alloc = allocator<_Tp> >
  class map;

whereas according to the standard it should be:

  template <class _Key, class _Tp, class _Compare = less<_Key>,
            class _Alloc = allocator<pair<const _Key, _Tp> > >
  class map;


(It looks like this was a change made between CD2 and the final version.)


I'm not sending a patch for this at this time because i ran into a bit
of a technical problem trying to fix this.  What's actually in the code
is not the above, but instead:

#ifndef __STL_LIMITED_DEFAULT_TEMPLATES
template <class _Key, class _Tp, class _Compare = less<_Key>,
          class _Alloc = __STL_DEFAULT_ALLOCATOR(_Tp) >
#else
template <class _Key, class _Tp, class _Compare,
          class _Alloc = __STL_DEFAULT_ALLOCATOR(_Tp) >
#endif
class map {


where __STL_DEFAULT_ALLOCATOR(T) is a macro which expands to allocator<T>.

Not thinking very far ahead, i tried to replace the above with
`__STL_DEFAULT_ALLOCATOR(pair<const _Key, _Tp>)'.  However, this
does not work, since the comma in the middle of the template means
that the preprocessor now sees two arguments to the macro.  And the
typical hack of wrapping the whole macro argument inside parens doesn't
work here since the parens get substrituted into the expansion, giving
a syntax error.

So i'm not sure how to fix this short of introducing a new macro,
or dropping this configuration option and junking the macro entirely.

I guess one could also do something like

#ifdef __STL_USE_STD_ALLOCATORS
template <class _Key, class _Tp, class _Compare = less<_Key>,
          class _Alloc = allocator<const _Key, _Tp> >
#else
template <class _Key, class _Tp, class _Compare = less<_Key>,
          class _Alloc = alloc>
#endif

but (essentially) repeating the definition of the macro here
is not very attractive either...

thanks,
sss

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]