toUTFz and WinAPI GetTextExtentPoint32W

Jonathan M Davis jmdavisProg at gmx.com
Tue Sep 20 14:56:24 PDT 2011


On Tuesday, September 20, 2011 14:43 Andrej Mitrovic wrote:
> On 9/20/11, Jonathan M Davis <jmdavisProg at gmx.com> wrote:
> > Or std.range.walkLength. I don't know why we really have std.utf.count. I
> > just
> > calls walkLength anyway. I suspect that it's a function that predates
> > walkLength and was made to use walkLength after walkLength was
> > introduced. But
> > it's kind of pointless now.
> > 
> > - Jonathan M Davis
> 
> I don't think having better-named aliases is a bad thing. Although now
> I'm seeing it's not just an alias but a function.

We specifically avoid having aliases in Phobos simply for having alternate 
function names. Aliases need to actually be useful, or they shouldn't be 
there.

> What exactly is the "static if (E.sizeof < 4)" in there for btw? When
> would the element type exceed 4 bytes while still passing the
> isSomeChar contract, and then why not stop compilation at that point
> instead of return "s.length"?

The static if is there to special-case narrow strings. It's unnecessary 
(though it does eliminate a function call when -inline isn't used). It would 
have been necessary prior to count just forwarding to walkLength, but it isn't 
now.

> One other thing, count can only take an array which seems too
> restrictive since walkLength can take any range at all. So maybe count
> should be just an alias to walkLength or it should possibly be removed
> (I'm against fully removing it because I already use it in code and I
> think the name does make sense).

I don't know if we're going to remove std.utf.count or not, but it _is_ the 
kind of thing that we've been removing. It doesn't add any real value. It's 
just another function which does exactly the same thing as walkLength except 
that it's restricted to strings, and we don't generally like having pointless 
aliases around (or pointless function wrappers, which amounts to pretty much 
the same thing). So, it wouldn't surprise me at all if it goes away, but 
if/when it does, it'll go through the proper deprecation cycle rather than 
just being removed, so if/when we do that, it's not like your code would
immediately break.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list