Is there a more idiomatic/elegant way to achieve the following, while
remaining as efficient as possible?
Same question in the simpler case n==0?
using retro seems inefficient because of all the decodings
// returns the largest suffix of a that contains no more than n times c
string
Say I wanna split a string that contains hyphens. If I use
std.algorithm.splitter I end up with empty elements for each
hyphen, e.g.:
auto word = bla-bla;
auto parts = appender!(string[]);
w.splitter('-').copy(parts);
// parts.data.length == 3 [bla, , bla]
This is not ideal for my purposes,
Chris:
auto word = bla-bla;
auto parts = appender!(string[]);
w.splitter('-').copy(parts);
// parts.data.length == 3 [bla, , bla]
With the current dmd 2.066alpha this code:
void main() {
import std.stdio, std.string, std.algorithm;
const txt = bla-bla;
txt.split(-).writeln;
On Monday, 9 June 2014 at 10:14:40 UTC, bearophile wrote:
Chris:
auto word = bla-bla;
auto parts = appender!(string[]);
w.splitter('-').copy(parts);
// parts.data.length == 3 [bla, , bla]
With the current dmd 2.066alpha this code:
void main() {
import std.stdio, std.string,
On Monday, 9 June 2014 at 10:23:16 UTC, Chris wrote:
Ok, thanks. I'll keep that in mind for the next version.
Seems to me to also work with 2.065 and 2.064.
On Monday, 9 June 2014 at 10:54:09 UTC, monarch_dodra wrote:
On Monday, 9 June 2014 at 10:23:16 UTC, Chris wrote:
Ok, thanks. I'll keep that in mind for the next version.
Seems to me to also work with 2.065 and 2.064.
From the library reference:
assert(equal(splitter(hello world, ' '), [
On Monday, 9 June 2014 at 11:04:12 UTC, Chris wrote:
From the library reference:
assert(equal(splitter(hello world, ' '), [ hello, ,
world ]));
and
If a range with one separator is given, the result is a range
with two empty elements.
My problem was that if I have input like
auto word
On Monday, 9 June 2014 at 11:16:18 UTC, monarch_dodra wrote:
On Monday, 9 June 2014 at 11:04:12 UTC, Chris wrote:
From the library reference:
assert(equal(splitter(hello world, ' '), [ hello, ,
world ]));
and
If a range with one separator is given, the result is a range
with two empty
On Monday, 9 June 2014 at 07:58:25 UTC, Timothee Cour via
Digitalmars-d-learn wrote:
Is there a more idiomatic/elegant way to achieve the following,
while
remaining as efficient as possible?
Same question in the simpler case n==0?
using retro seems inefficient because of all the decodings
//
On Monday, 9 June 2014 at 11:40:24 UTC, Chris wrote:
On Monday, 9 June 2014 at 11:16:18 UTC, monarch_dodra wrote:
On Monday, 9 June 2014 at 11:04:12 UTC, Chris wrote:
From the library reference:
assert(equal(splitter(hello world, ' '), [ hello, ,
world ]));
and
If a range with one
On Monday, 9 June 2014 at 12:16:30 UTC, monarch_dodra wrote:
On Monday, 9 June 2014 at 11:40:24 UTC, Chris wrote:
On Monday, 9 June 2014 at 11:16:18 UTC, monarch_dodra wrote:
On Monday, 9 June 2014 at 11:04:12 UTC, Chris wrote:
From the library reference:
assert(equal(splitter(hello world,
On Mon, 09 Jun 2014 07:04:11 -0400, Chris wend...@tcd.ie wrote:
On Monday, 9 June 2014 at 10:54:09 UTC, monarch_dodra wrote:
On Monday, 9 June 2014 at 10:23:16 UTC, Chris wrote:
Ok, thanks. I'll keep that in mind for the next version.
Seems to me to also work with 2.065 and 2.064.
From
On Monday, 9 June 2014 at 14:21:21 UTC, Steven Schveighoffer
wrote:
On Mon, 09 Jun 2014 07:04:11 -0400, Chris wend...@tcd.ie
wrote:
On Monday, 9 June 2014 at 10:54:09 UTC, monarch_dodra wrote:
On Monday, 9 June 2014 at 10:23:16 UTC, Chris wrote:
Ok, thanks. I'll keep that in mind for the
On Mon, 09 Jun 2014 10:39:39 -0400, Chris wend...@tcd.ie wrote:
Atm, I have
auto parts = appender!(string[]);
w.splitter('-').filter!(a = !a.empty).copy(parts);
Which looks more elegant and gives me what I want. IMO, the module that
handles the splitting of hyphenated words should be able
will the sorry state of the win64 headers and programs like dfl
be fixed or is it time to leave the language to linux and move on
to something else?
On Monday, 9 June 2014 at 14:47:45 UTC, Steven Schveighoffer
wrote:
On Mon, 09 Jun 2014 10:39:39 -0400, Chris wend...@tcd.ie
wrote:
Atm, I have
auto parts = appender!(string[]);
w.splitter('-').filter!(a = !a.empty).copy(parts);
Which looks more elegant and gives me what I want. IMO, the
On Monday, 9 June 2014 at 14:21:21 UTC, Steven Schveighoffer
wrote:
Just looked at std.string for a strip function that allows
custom character strippage, but apparently not there. The above
is quite awkward.
-Steve
It's in algorithm, because it's more generic than just strings.
On Monday, 9 June 2014 at 15:19:05 UTC, Chris wrote:
On Monday, 9 June 2014 at 14:47:45 UTC, Steven Schveighoffer
wrote:
On Mon, 09 Jun 2014 10:39:39 -0400, Chris wend...@tcd.ie
wrote:
Atm, I have
auto parts = appender!(string[]);
w.splitter('-').filter!(a = !a.empty).copy(parts);
Which
The D language pays certain attention to avoiding hijacking [1].
So I was surprised when I hijacked a function override from a
template mixin by mistake. Here is a commented example. The
comments explain the relevant part of the life cycle of the
program.
-
// Start with class A with
On Monday, 9 June 2014 at 15:54:29 UTC, Steven Schveighoffer
wrote:
On Mon, 09 Jun 2014 11:49:29 -0400, monarch_dodra
monarchdo...@gmail.com wrote:
On Monday, 9 June 2014 at 14:21:21 UTC, Steven Schveighoffer
wrote:
Just looked at std.string for a strip function that allows
custom character
On Monday, 9 June 2014 at 15:54:21 UTC, Ivan Kazmenko wrote:
I'd expect a multiple overrides of same function error, much
like if I just paste the mixin code by hand. Is that a bug or
working by design? In the latter case, please explain the
reasoning.
AFAIK, the rationale is that *should*
i agree with you, but you should have posted in announce, so
that adrei can use it for some marketing.
i too wait now for a long, long time to use it with win64. i am
also giving up - i guess it will stay a linux/apple show.
maybe, as a multiple os compiler, you can use lazarus or code
typhon.
using retro seems inefficient because of all the decodings
Phobos git master just got support for next-gen string processing:
https://github.com/D-Programming-Language/phobos/pull/2043
I believe
x.byChar.retro
is what you want
Can I use the version keyword or static if to perform conditional
compilation that depends on the version of DMD?
I typicall something like
version(= DMD_2.0.66)
{
// use new byChar, byWchar, byDchar, byCodepoint
}
else
{
// use old style slower version
}
If so how?
On Monday, 9 June 2014 at 17:36:10 UTC, Nordlöw wrote:
Can I use the version keyword or static if to perform
conditional compilation that depends on the version of DMD?
The __VERSION__ magic token should do the job.
David
Thx
On Mon, 09 Jun 2014 12:06:13 -0400, monarch_dodra monarchdo...@gmail.com
wrote:
On Monday, 9 June 2014 at 15:54:29 UTC, Steven Schveighoffer wrote:
On Mon, 09 Jun 2014 11:49:29 -0400, monarch_dodra
monarchdo...@gmail.com wrote:
On Monday, 9 June 2014 at 14:21:21 UTC, Steven Schveighoffer
On Monday, 9 June 2014 at 17:57:24 UTC, Steven Schveighoffer
wrote:
I think we are confusing things here, I was talking about strip
:)
strip and split are actually both pretty much in the same boat
actually in regards to that, so just 's/split/strip/g', and the
same answer will apply.
On Monday, 9 June 2014 at 15:52:24 UTC, monarch_dodra wrote:
On Monday, 9 June 2014 at 15:19:05 UTC, Chris wrote:
On Monday, 9 June 2014 at 14:47:45 UTC, Steven Schveighoffer
wrote:
On Mon, 09 Jun 2014 10:39:39 -0400, Chris wend...@tcd.ie
wrote:
Atm, I have
auto parts =
On Monday, 9 June 2014 at 18:09:07 UTC, monarch_dodra wrote:
On Monday, 9 June 2014 at 17:57:24 UTC, Steven Schveighoffer
wrote:
I think we are confusing things here, I was talking about
strip :)
strip and split are actually both pretty much in the same boat
actually in regards to that, so
On Monday, 9 June 2014 at 19:47:29 UTC, Chris wrote:
Uh, I see, I misread the signature of std.string.strip(). So
that's one option now, to strip all trailing hyphens with
std.string.strip(). Well, I'll give it a shot tomorrow.
No, you read the documentation of std.*STRING*.strip correctly.
On Monday, 9 June 2014 at 19:54:08 UTC, Chris wrote:
I think it makes sense to put any generic range based
algorithms (split and so forth) into std.algorithm. It's always
my first port of call, when I have a range. However, that you
can do
std.string.split([1, 2, 3], 2);
is not exactly a
On Monday, 9 June 2014 at 20:01:05 UTC, monarch_dodra wrote:
On Monday, 9 June 2014 at 19:47:29 UTC, Chris wrote:
Uh, I see, I misread the signature of std.string.strip(). So
that's one option now, to strip all trailing hyphens with
std.string.strip(). Well, I'll give it a shot tomorrow.
No,
Should this work? It seems like the short circuit booleans are not
working:
import std.traits;
enum isPrimitive(T) = isBasicType!T || (isArray!T isBasicType!
(ForeachType!T));
void main() {
assert(isPrimitive!int);
assert(isPrimitive!char);
34 matches
Mail list logo