Eric Lemings wrote:
-----Original Message-----
From: Eric Lemings
Sent: Wednesday, May 07, 2008 3:50 PM
To: '[email protected]'
Subject: RE: [STDCXX-905] 22.locale.synopsis link error on
Solaris platforms
-----Original Message-----
From: Martin Sebor [mailto:[EMAIL PROTECTED] On Behalf Of
Martin Sebor
Sent: Thursday, May 01, 2008 2:30 PM
To: [email protected]
Subject: Re: [STDCXX-905] 22.locale.synopsis link error on
Solaris platforms
...
What we would need to do if we really wanted to exercise the
template is define a dummy explicit specialization of the
collate facet on a user-defined (non-fundamental) type such
as UserChar from rw_char.h and instantiate the template
operator on it. E.g., something like:
namespace std {
template <>
struct collate<UserChar>: locale::facet {
/* define all members as no-ops */
};
}
// exercise a specialization other than on the default
// char types
typedef StringTypes<UserChar>::string_type UserString;
MEMFUN (bool, operator(), (const UserString&, const
UserString&) const);
Martin
I infer from this that if developers need collate facets for
user-defined character types then they are required to define
their own specializations for these types. That right?
Uh huh. Users are only allowed to specialize standard library
templates on user-defined types (and not on fundamental ones
like int). There's no way for the library to know or guess
how such characters should be compared.
If that's the case, adding collate specializations with no-op
members for a user-defined ctype doesn't really test anything
in the library and is therefore useless in which case I should
just remove the corresponding test cases. Or does it actually
test something?
It tests the template locale::operator(). I.e., that there
actually is a template and not just a few ordinary overloads.
But perhaps a better test, one that we won't need to add
specializations of collate for, would be one on basic_string
specialized on a user-defined Traits or Allocator type. It's
especially easy to create one for Traits:
template <class charT>
struct UserTrats: std::char_traits<charT> { };
We will then be able to instantiate the operator like so:
typedef std::basic_string<char, UserTraits<char> >
UserString;
MEMFUN (bool, operator(),
(const UserString&, const UserString&) const);
Martin