Re: Fast removal of character

2017-10-12 Thread Laeeth Isharc via Digitalmars-d-learn
On Wednesday, 11 October 2017 at 22:22:43 UTC, Johan Engelen wrote: std.string.removechars is now deprecated. https://dlang.org/changelog/2.075.0.html#pattern-deprecate What is now the most efficient way to remove characters from a string, if only one type of character needs to be removed?

Re: Get and add to function body

2017-10-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, October 12, 2017 23:33:39 Psychological Cleanup via Digitalmars-d-learn wrote: > Is there any way to get the function body of a function, > delegate, and lambda? I'd also like to extend functions by > "wrapping" them at compile time generically. For example, I'd > like to get all the

Re: Assert and undefined behavior

2017-10-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, October 12, 2017 21:22:29 kdevel via Digitalmars-d-learn wrote: > On Thursday, 12 October 2017 at 20:27:03 UTC, Jonathan M Davis > > wrote: > > On Thursday, October 12, 2017 20:15:41 kdevel via > > > >> --- > >> void main () > >> { > >> > >> assert (false); > >> > >> } > >> --- >

Re: Alias on an array element

2017-10-12 Thread Meta via Digitalmars-d-learn
On Friday, 13 October 2017 at 01:12:38 UTC, solidstate1991 wrote: On Friday, 13 October 2017 at 01:09:56 UTC, solidstate1991 wrote: I'm making a struct for easy color handling Here's a code sample: ublic struct Color{ union{ uint raw; ///Raw representation in integer form, also

Re: Alias on an array element

2017-10-12 Thread solidstate1991 via Digitalmars-d-learn
On Friday, 13 October 2017 at 01:09:56 UTC, solidstate1991 wrote: I'm making a struct for easy color handling Here's a code sample: ublic struct Color{ union{ uint raw; ///Raw representation in integer form, also forces the system to align in INT32. ubyte[4] colors; ///Normal

Alias on an array element

2017-10-12 Thread solidstate1991 via Digitalmars-d-learn
I'm making a struct for easy color handling Here's a code sample: ublic struct Color{ union{ uint raw; ///Raw representation in integer form, also forces the system to align in INT32. ubyte[4] colors; ///Normal representation, aliases are used for color naming.

Re: Get and add to function body

2017-10-12 Thread Psychological Cleanup via Digitalmars-d-learn
I'd also like to be able to save and store delegates, functions, and lambdas. One can't store the pointer to the function because it will be invalid, so another means is required, any ideas? Save("f", (int){ ... }); // Saves to disk auto f = Load("f"); // Loads from disk f(3);

Get and add to function body

2017-10-12 Thread Psychological Cleanup via Digitalmars-d-learn
Is there any way to get the function body of a function, delegate, and lambda? I'd also like to extend functions by "wrapping" them at compile time generically. For example, I'd like to get all the properties of a class and add some code to them(sort of like adding a scope, prolog, and/or

Re: Undo?

2017-10-12 Thread Jesse Phillips via Digitalmars-d-learn
On Thursday, 12 October 2017 at 02:18:49 UTC, Mr. Jonse wrote: A simple(incomplete) undo system. I'd think that for D you'd want to do type wrapping where a new type is created which saves changes and can manage an Undo tree. __gshared Data data = new Data(); auto undoable =

Re: Undo?

2017-10-12 Thread bitwise via Digitalmars-d-learn
On Tuesday, 10 October 2017 at 02:36:56 UTC, Mr. Jonse wrote: I requiring an undo feature in my code. Rather than go the regular route of using commands, I'm wondering if D can facilitate an undo system quite easily? We can think of an undo system in an app as a sort of recorder. The

Re: Assert and undefined behavior

2017-10-12 Thread kdevel via Digitalmars-d-learn
On Thursday, 12 October 2017 at 20:27:03 UTC, Jonathan M Davis wrote: On Thursday, October 12, 2017 20:15:41 kdevel via --- void main () { assert (false); } --- qualifies as "invalid, and therefore has undefined behaviour." A statement, which makes no sense to me. Either it is a

Re: Why do I have to cast arguments from int to byte?

2017-10-12 Thread kdevel via Digitalmars-d-learn
On Wednesday, 11 October 2017 at 07:09:26 UTC, Daniel Kozak wrote: You can avoid cast: void foo(T)(T bar){...} byte bar = 9; foo!byte(bar + byte(1)); Sure? --- void foo(T)(T bar) { } byte bar = 9; void main () { foo!byte(bar + byte(1)); } --- byte2.d(7): Error: function

Re: Assert and undefined behavior

2017-10-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, October 12, 2017 20:15:41 kdevel via Digitalmars-d-learn wrote: > On Thursday, 12 October 2017 at 15:37:23 UTC, John Burton wrote: > > C++ compilers can and do perform such optimizations so I was > > wondering if assert in D could cause such behavior according to > > the spec. > > In

Re: Assert and undefined behavior

2017-10-12 Thread kdevel via Digitalmars-d-learn
On Thursday, 12 October 2017 at 15:37:23 UTC, John Burton wrote: C++ compilers can and do perform such optimizations so I was wondering if assert in D could cause such behavior according to the spec. In the context of ISO-C++ it is meaningless to reason about the "actual behavior" of a

Re: Does D have an equivalent to C#'s String.IsNullOrWhiteSpace?

2017-10-12 Thread Daniel Kozak via Digitalmars-d-learn
Wow, C# is really wierd. They have method IsNullOrEmpty (OK why not), but they have IsNullOrWhiteSpace OK little akward but still OK until you realized it is more like IsNullOrEmptyOrWhiteSpace :D On Thu, Oct 12, 2017 at 8:11 PM, Nieto via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com>

Re: Does D have an equivalent to C#'s String.IsNullOrWhiteSpace?

2017-10-12 Thread Jesse Phillips via Digitalmars-d-learn
On Thursday, 12 October 2017 at 18:17:54 UTC, Adam D. Ruppe wrote: On Thursday, 12 October 2017 at 18:11:55 UTC, Nieto wrote: Does D have an equivalent to C#'s String.IsNullOrWhiteSpace() in the standard library? import std.string; if(str.strip().length == 0) { // is null, empty, or all

Re: Does D have an equivalent to C#'s String.IsNullOrWhiteSpace?

2017-10-12 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 12 October 2017 at 18:11:55 UTC, Nieto wrote: Does D have an equivalent to C#'s String.IsNullOrWhiteSpace() in the standard library? import std.string; if(str.strip().length == 0) { // is null, empty, or all whitespace }

Does D have an equivalent to C#'s String.IsNullOrWhiteSpace?

2017-10-12 Thread Nieto via Digitalmars-d-learn
Does D have an equivalent to C#'s String.IsNullOrWhiteSpace() in the standard library? just asking if there's a native one, so I don't need reinvente the wheel https://msdn.microsoft.com/en-us/library/system.string.isnullorwhitespace%28v=vs.110%29.aspx?f=255=-2147217396

Re: Assert and undefined behavior

2017-10-12 Thread John Burton via Digitalmars-d-learn
On Thursday, 12 October 2017 at 14:22:43 UTC, Timon Gehr wrote: On 11.10.2017 11:27, John Burton wrote: Yes, that's what it is saying. (The other answers, that say or try to imply that this is not true or true but not a bad thing, are wrong.) ... However, in practice, I think none of the

Re: Assert and undefined behavior

2017-10-12 Thread Timon Gehr via Digitalmars-d-learn
On 11.10.2017 11:27, John Burton wrote: The spec says this :- "As a contract, an assert represents a guarantee that the code must uphold. Any failure of this expression represents a logic error in the code that must be fixed in the source code. A program for which the assert contract is

Re: Dustmite always reduced to empty set after two iterations

2017-10-12 Thread Jacob Carlborg via Digitalmars-d-learn
On 2017-10-11 22:36, Nordlöw wrote: My first idea is to make stderr "core dumped" the invariant. Therefore my first try becomes to redirect stderr to stdout (in bash) and grep for the pattern 'core dumped' as follows IIRC, segmentation faults are printed by the shell and not the