February 28, 2013 Re: D as a prototyping language (for C/C++ projects) | ||||
---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | On Wednesday, 27 February 2013 at 20:18:29 UTC, H. S. Teoh wrote:
> I wonder if we should do a survey of
> people's "standard.me" libraries to see what are the functionalities
> most commonly missing from Phobos? That might give us some interesting
> insights into what would be most profitable to add to Phobos.
Once we get ability to add user comments to Phobos documentation, then maybe that will help determine what is working and what is not, and also what is missing that perhaps should be there.
--rt
|
February 28, 2013 Re: D as a prototyping language (for C/C++ projects) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Rob T | On 2013-02-28 04:35, Rob T wrote: > I had a look at your isBlank function. Why not check if length exists > and run it as follows? > > @property bool isBlank (T) (T t) > { > > static if (__traits(compiles, t.length)) > { > if (t.length == 0) > return true; > } > > ... > > That would be more generic I think. Sure, I could do that. But I thought checking for "empty" would be more generic. I would expect every type having "length" would/should also have "empty" but perhaps that's a wrong assumption. -- /Jacob Carlborg |
February 28, 2013 Re: D as a prototyping language (for C/C++ projects) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On Thursday, 28 February 2013 at 08:05:20 UTC, Jacob Carlborg wrote:
> On 2013-02-28 04:35, Rob T wrote:
>
>> I had a look at your isBlank function. Why not check if length exists
>> and run it as follows?
>>
>> @property bool isBlank (T) (T t)
>> {
>>
>> static if (__traits(compiles, t.length))
>> {
>> if (t.length == 0)
>> return true;
>> }
>>
>> ...
>>
>> That would be more generic I think.
>
> Sure, I could do that. But I thought checking for "empty" would be more generic. I would expect every type having "length" would/should also have "empty" but perhaps that's a wrong assumption.
It is easy to ensure via UFCS.
|
February 28, 2013 Re: D as a prototyping language (for C/C++ projects) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On Thursday, February 28, 2013 09:05:19 Jacob Carlborg wrote:
> On 2013-02-28 04:35, Rob T wrote:
> > I had a look at your isBlank function. Why not check if length exists and run it as follows?
> >
> > @property bool isBlank (T) (T t)
> > {
> >
> > static if (__traits(compiles, t.length))
> > {
> >
> > if (t.length == 0)
> >
> > return true;
> >
> > }
> >
> > ...
> >
> > That would be more generic I think.
>
> Sure, I could do that. But I thought checking for "empty" would be more generic. I would expect every type having "length" would/should also have "empty" but perhaps that's a wrong assumption.
All ranges are guaranteed to have empty, so any range with length will obviously have empty. Regardless, in general, it's better to check for empty than length, since it's possible for empty to be more efficient, and it's unlikely the empty will ever be less efficient than checking that length == 0. If you're not talking about ranges, then all bets are off as to what it does and doesn't have, because that would depend on what APIs it adheres to and what they're like.
- Jonathan M Davis
|
Copyright © 1999-2021 by the D Language Foundation