Topic: More locale questions - const external functions?


Author: ncm@nospam.cantrip.org (Nathan Myers)
Date: 1998/02/04
Raw View
Brad Daniels <brad.daniels@missioncritical.com> wrote:
>The implementation I'm using (which ships with MSVC++ 5.0)
>... defines use_facet as:
>
> [something broken, documented with...]
>
> "you should write _USE(loc, Facet), or _USEFAC(loc, Facet) in place
>  of use_facet(loc, (Facet *)0, make_it), ...   The former is strongly
>  preferred when looking up a facet that should always be present --
>  it generates the requested facet on demand, if necessary. ...
>
>So,  what they're saying is that you should use a nonstandard macro
>because they've implemented use_facet in a nonstandard way.  As it
>turns out, the macro they "strongly prefer" just provides a 0 for
>"fac" and true for make_it.  Why those aren't just the default argument
>values I have no idea.

It's easy to say why they have a macro: the compiler is broken,
so it cannot be implemented according to the standard.

Why the macros implement nonstandard behavior is harder to ascertain.
Speculation and history suggest that they would like to lock you
into their implementation by encouraging you to code dependence on
semantics subtly different from the standard that would be nonetheless
be very expensive to abstract from, later.  But I'm sure the true
explanation is something much less logical.

Nathan Myers
ncm@nospam.cantrip.org
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: "Brad Daniels" <brad.daniels@missioncritical.com>
Date: 1998/02/03
Raw View
I posted a locale question yesterday...  Hopefully, that post will show up
before this one does....

Anyway, CD2 has prototypes for all the is* functions that look like:

template <class charT? bool isspace(charT c, const locale& loc) const;

These functions are at namespace scope.  What the does const mean in this
context?  The implementation I'm using (which ships with MSVC++ 5.0) doesn't
have the keyword there, but that may mean nothing, since it also defines
use_facet as:

template<class Facet>
    const Facet& use_facet(const locale& loc,
        const Facet *fac, bool make_it);

(Note that there aren't even any default values for the nonstandard "fac"
and "make_it" arguments)...  And check this out from the documentation of
use_facet:

In this implementation, make_it instructs the function to generate the
locale facet on demand. But you should write _USE(loc, Facet), or
_USEFAC(loc, Facet) in place of use_facet(loc, (Facet *)0, make_it), because
the second and third parameters are a nonstandard extension. The former is
strongly preferred when looking up a facet that should always be present --
it generates the requested facet on demand, if necessary. The latter will
report that the locale initially constructed by locale() has no facets.

So,  what they're saying is that you should use a nonstandard macro because
theye've implemented use_facet in a nonstandard way.  As it turns out, the
macro they "strongly prefer" just provides a 0 for "fac" and true for
make_it.  Why those aren't just the default argument values I have no idea.
It probably has something to do with the fact that the compiler used to have
trouble with instantiating functions unless it had an argument to infer the
type from.

- Brad

--
----------------------------------------------------------------------------
Brad Daniels                  |  Was mich nicht umbringt macht mich hungrig.
Mission Critical Software     |   - Otto Nietzche
Standard disclaimers apply    |     (Friedrich's corpulent brother)
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]