Filling a char array with letters and element type of char[]

2015-03-03 Thread Kadir Erdem Demir via Digitalmars-d-learn
I have an char[]; char[] strArr = "http://www.hurriyet.com.tr/ekonomi".dup; I stripped the domain out of url like: auto domain = findSplitAfter(strArr, "http://";)[1].until('/'); Than because I am new to the language I became curious if I change domain(which I believe a input iterator); the v

Re: Filling a char array with letters and element type of char[]

2015-03-03 Thread Tobias Pankrath via Digitalmars-d-learn
I have three questions? If I change the iterator which I get from algorithm, the owner data will change or not? How to use std.algorithm.fill with char types? What is the type of char array holds why it does not matches char? Regards Kadir Erdem I have no time to dig into this, but: i

Re: Implicit fall through not detected (Example from lex.html)

2015-03-03 Thread Andre via Digitalmars-d-learn
On Tuesday, 3 March 2015 at 07:27:33 UTC, ketmar wrote: implicit fallthru is not a fatal bug (but i believe it should be), it generates only warning. I am also not really happy with the actual behavor (w / wi switch needed) because the documentation is clear about that it is an error: --

Re: Implicit fall through not detected (Example from lex.html)

2015-03-03 Thread bearophile via Digitalmars-d-learn
Andre: I am also not really happy with the actual behavor (w / wi switch needed) You shall always compile your D code with warnings active, unless you need them disabled for some real reason. Eventually the fall through warning will become a deprecation and then an error. It's meant to be

Re: Filling a char array with letters and element type of char[]

2015-03-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, March 03, 2015 09:06:03 Tobias Pankrath via Digitalmars-d-learn wrote: > > > I have three questions? > > > > If I change the iterator which I get from algorithm, the owner > > data will change or not? > > > > How to use std.algorithm.fill with char types? > > > > What is the type of ch

Strange alias behaviour in template arguments

2015-03-03 Thread Stefan Frijters via Digitalmars-d-learn
So this is a strange thing I ran into while trying to streamline some templates in my code, where fixed-length arrays are passed as runtime arguments. I started out by trying variant fun2(), which disappointingly didn't work. fun3() then did its job but I was suspicious and tried fun4() and fun

Re: Filling a char array with letters and element type of char[]

2015-03-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/3/15 4:06 AM, Tobias Pankrath wrote: I have three questions? If I change the iterator which I get from algorithm, the owner data will change or not? I'm not sure about this question. How to use std.algorithm.fill with char types? You cannot currently. What is the type of char ar

Re: @trusted and return ref

2015-03-03 Thread Kagamin via Digitalmars-d-learn
Hmm... that means in OOP class is a unit of safety instead of a method, but it also applies to free methods, which access static members.

Re: strage heisenbug (has scoped destruction, cannot build closure)

2015-03-03 Thread anonymous via Digitalmars-d-learn
On Tuesday, 3 March 2015 at 07:26:13 UTC, ketmar wrote: hi. the following (manually "dustmited" ;-)) code gives the error from subj on git HEAD: === ztest.d === module ztest; auto streamAsRange(STP) (STP st) { static struct StreamRange(ST) { private: ST strm; public:

Re: @trusted and return ref

2015-03-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/3/15 9:28 AM, Kagamin wrote: If one wants to prevent a leak, then counter can be wrapped --- struct Unsafe(T) { private T _payload; T payload() @system { return _payload; } alias payload this; } --- And somehow disallow Unsafe template in safe function signatures, then having Uns

Re: @trusted and return ref

2015-03-03 Thread Kagamin via Digitalmars-d-learn
If one wants to prevent a leak, then counter can be wrapped --- struct Unsafe(T) { private T _payload; T payload() @system { return _payload; } alias payload this; } --- And somehow disallow Unsafe template in safe function signatures, then having Unsafe!(int*) _counter; would be ok?

Re: @trusted and return ref

2015-03-03 Thread Kagamin via Digitalmars-d-learn
Being a safety measure, it becomes trusted code's responsibility to provide this safety. BTW it also needs @system postblit; meh, I hope it's enough to make untouchable.

Re: Strange alias behaviour in template arguments

2015-03-03 Thread anonymous via Digitalmars-d-learn
On Tuesday, 3 March 2015 at 13:42:09 UTC, Stefan Frijters wrote: So this is a strange thing I ran into while trying to streamline some templates in my code, where fixed-length arrays are passed as runtime arguments. I started out by trying variant fun2(), which disappointingly didn't work. fun3

Re: @trusted and return ref

2015-03-03 Thread Kagamin via Digitalmars-d-learn
Unsafe!(int*)* _c; class A { Unsafe!(int*) _counter; void escape() @safe { _c = &_counter; } } Not sure if it's legal. It should be really untouchable.

"is" expression and type tuples

2015-03-03 Thread Jack Applegame via Digitalmars-d-learn
Seems like "is" expression doesn't support type tuples: pragma(msg, is(short : int)); // true enum Test(ARGS...) = is(ARGS[0..2] : ARGS[2..4]); pragma(msg, is(Test!(int, int, int, int))); // false pragma(msg, Test!(int, short, int, int)); // false Is it by design, or jus

Re: "is" expression and type tuples

2015-03-03 Thread bearophile via Digitalmars-d-learn
Jack Applegame: Seems like "is" expression doesn't support type tuples: pragma(msg, is(short : int)); // true enum Test(ARGS...) = is(ARGS[0..2] : ARGS[2..4]); pragma(msg, is(Test!(int, int, int, int))); // false pragma(msg, Test!(int, short, int, int)); // false Is it

Re: "is" expression and type tuples

2015-03-03 Thread Jack Applegame via Digitalmars-d-learn
On Tuesday, 3 March 2015 at 16:42:22 UTC, bearophile wrote: But it should be not too much hard to implement it your code. Just use two is(), or use recursion (with splitting in two, and not 1 + n-1). Bye, bearophile I already have one: template Is(ARGS...) if(ARGS.length % 2 == 0) { en

Cycle detected between modules with ctors/dtors

2015-03-03 Thread rumbu via Digitalmars-d-learn
I encountered the following error: First-chance exception: object.Exception Aborting: Cycle detected between modules with ctors/dtors: system.globalization -> internals.locale -> system.runtime.interopservices -> system.io -> system.globalization at src\rt\minfo.d(162) Only one of the listed

Re: "is" expression and type tuples

2015-03-03 Thread bearophile via Digitalmars-d-learn
Jack Applegame: or use recursion (with splitting in two, and not 1 + n-1). Bye, bearophile I already have one: template Is(ARGS...) if(ARGS.length % 2 == 0) { enum N = ARGS.length/2; static if(N == 1) enum Is = is(ARGS[0] : ARGS[1]); else enum Is = is(ARGS[0] : ARGS[N]) && Is!(ARGS

Re: Cycle detected between modules with ctors/dtors

2015-03-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/3/15 12:40 PM, rumbu wrote: I encountered the following error: First-chance exception: object.Exception Aborting: Cycle detected between modules with ctors/dtors: system.globalization -> internals.locale -> system.runtime.interopservices -> system.io -> system.globalization at src\rt\minfo.

Re: Filling a char array with letters and element type of char[]

2015-03-03 Thread Ali Çehreli via Digitalmars-d-learn
On 03/03/2015 12:18 AM, Kadir Erdem Demir wrote: > I have an char[]; > > char[] strArr = "http://www.hurriyet.com.tr/ekonomi".dup; > > I stripped the domain out of url like: > > auto domain = findSplitAfter(strArr, "http://";)[1].until('/'); > > Than because I am new to the language I became curi

Re: Filling a char array with letters and element type of char[]

2015-03-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, March 03, 2015 08:50:35 Steven Schveighoffer via Digitalmars-d-learn wrote: > >> What is the type of char array holds why it does not matches char? > > Because D is schizophrenic ;) Phobos considers char[] arrays not to be > arrays of char, only ranges of dchar. Unless you talk to the

Re: Filling a char array with letters and element type of char[]

2015-03-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/3/15 2:32 PM, Jonathan M Davis via Digitalmars-d-learn wrote: On Tuesday, March 03, 2015 08:50:35 Steven Schveighoffer via Digitalmars-d-learn wrote: What is the type of char array holds why it does not matches char? Because D is schizophrenic ;) Phobos considers char[] arrays not to be

Re: Filling a char array with letters and element type of char[]

2015-03-03 Thread Ali Çehreli via Digitalmars-d-learn
On 03/03/2015 11:38 AM, Steven Schveighoffer wrote: > Sure, but I think that for phobos to say you can't fill a large char[] > with a repeat of small char[], but you can fill a large int[] with a > repeat of small int[], is more of a problem than somehow fixing the > underlying situation. > > Oth

Re: @trusted and return ref

2015-03-03 Thread w0rp via Digitalmars-d-learn
On Wednesday, 25 February 2015 at 06:48:17 UTC, Ola Fosheim Grøstad wrote: On Tuesday, 24 February 2015 at 22:49:17 UTC, w0rp wrote: In general, @trusted means "I have proven myself that this code is actually safe, eeven though it uses unsafe features." The compiler has to be pessimistic and as

Re: Cycle detected between modules with ctors/dtors

2015-03-03 Thread rumbu via Digitalmars-d-learn
On Tuesday, 3 March 2015 at 18:55:49 UTC, Steven Schveighoffer wrote: Only one of the listed modules has a static contructor (system.globalization) and that constructor doesn't use any information from other modules. It's a complex problem. Because we don't control the linker, we cannot e

Re: Strange alias behaviour in template arguments

2015-03-03 Thread Stefan Frijters via Digitalmars-d-learn
On Tuesday, 3 March 2015 at 14:40:45 UTC, anonymous wrote: On Tuesday, 3 March 2015 at 13:42:09 UTC, Stefan Frijters wrote: So this is a strange thing I ran into while trying to streamline some templates in my code, where fixed-length arrays are passed as runtime arguments. I started out by tr

Re: @trusted and return ref

2015-03-03 Thread via Digitalmars-d-learn
On Tuesday, 3 March 2015 at 20:56:50 UTC, w0rp wrote: The key phrase is "guaranteed by the programmer." Which means that the programmer, not the compiler, is providing a guarantee that calling a @trusted function will not violate memory safety. If the programmer cannot make that guarantee, the

mixin template scope inconsistency?

2015-03-03 Thread Timothee Cour via Digitalmars-d-learn
Template mixin scope seems to have a weird behavior: I don't understand 'WEIRD(1)' and 'WEIRD(2)' below. import std.stdio; struct A{ int b; this(int b){ this.b=b; writeln("A.begin"); } ~this(){ writeln("A.end"); } } mixin template Entry(){ auto a=A(12); } void test1(){

Re: mixin template scope inconsistency?

2015-03-03 Thread Timothee Cour via Digitalmars-d-learn
posted as bugzilla/14243. Am I misunderstanding something here? On Tue, Mar 3, 2015 at 10:20 PM, Timothee Cour wrote: > Template mixin scope seems to have a weird behavior: > I don't understand 'WEIRD(1)' and 'WEIRD(2)' below. > > import std.stdio; > struct A{ > int b; > this(int b){ > t

Re: "is" expression and type tuples

2015-03-03 Thread Jack Applegame via Digitalmars-d-learn
On Tuesday, 3 March 2015 at 17:49:24 UTC, bearophile wrote: That's 1 + n-1 :-) Could you please explain what does '1 + n-1' mean?

Re: Cycle detected between modules with ctors/dtors

2015-03-03 Thread rumbu via Digitalmars-d-learn
Now I see: this "bug" is 7 years old, but is filled in for D1: https://issues.dlang.org/show_bug.cgi?id=2457 Does this mean it will be ignored for D2?