Re: appender!(dchar[]) put fail

2015-06-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/13/15 6:45 AM, kerdemdemir wrote: I have two strings(stringB,stringC) which I need to repeat(bCount times, cCountTimes) and then chain. auto charAppender = appender!(dchar[]); auto totalStr = stringB.repeat(bCount).chain(stringC.repeat(cCount)); This compiles and works ok, But when I try

Re: What is D's minimum requirements on Mac?

2015-06-13 Thread Rikki Cattermole via Digitalmars-d-learn
On 14/06/2015 12:32 p.m., Adam D. Ruppe wrote: On Friday, 12 June 2015 at 07:17:44 UTC, Jacob Carlborg wrote: I'm running a OS X 10.7 on Macbook from 2006, it's working perfectly fine. Although the whole computer it's quite slow, it only has 2 GB of RAM. Thanks everyone. A coworker says he

how come is this legal? 'void fun(int){ }' ?

2015-06-13 Thread Timothee Cour via Digitalmars-d-learn
I understand this is legal for declaration wo definition (void fun(int);) but why allow this: void test(int){} ?

Re: how come is this legal? 'void fun(int){ }' ?

2015-06-13 Thread ketmar via Digitalmars-d-learn
On Sun, 14 Jun 2015 05:11:17 +, Maxim Fomin wrote: On Sunday, 14 June 2015 at 01:20:39 UTC, Timothee Cour wrote: I understand this is legal for declaration wo definition (void fun(int);) but why allow this: void test(int){} ? Actually it is void test(int _param_0) { } You can test by

Are stack+heap classes possible in D?

2015-06-13 Thread FujiBar via Digitalmars-d-learn
I have read that in D structs are always allocated on the stack while classes are always allocated on the heap. Well, I often have classes where I want some instances on the stack, some on the heap. So.. what to do?

Re: Are stack+heap classes possible in D?

2015-06-13 Thread FujiBar via Digitalmars-d-learn
On Sunday, 14 June 2015 at 01:31:25 UTC, Adam D. Ruppe wrote: On Sunday, 14 June 2015 at 00:52:20 UTC, FujiBar wrote: I have read that in D structs are always allocated on the stack while classes are always allocated on the heap. That's not true; it is a really common misconception. Putting

Re: appender!(dchar[]) put fail

2015-06-13 Thread Ali Çehreli via Digitalmars-d-learn
On 06/13/2015 04:23 AM, Quentin Ladeveze wrote: The problem is that your appender is a char appender, and you try to put a dstring into it. Replace : charAppender.put(totalStr); by : foreach(elem; totalStr){ charAppender.put(elem); } elem will be a dchar, so it will work. To

Re: how come is this legal? 'void fun(int){ }' ?

2015-06-13 Thread Maxim Fomin via Digitalmars-d-learn
On Sunday, 14 June 2015 at 01:20:39 UTC, Timothee Cour wrote: I understand this is legal for declaration wo definition (void fun(int);) but why allow this: void test(int){} ? Actually it is void test(int _param_0) { } You can test by compiling void test(int) { _param_0 = 0; } Nameless

Re: how come is this legal? 'void fun(int){ }' ?

2015-06-13 Thread Adam D. Ruppe via Digitalmars-d-learn
Sometimes you have empty functions and/or unused parameters just to fulfill some interface but you don't actually care about the arguments passed. No need to name them if you aren't going to use them.

Re: Are stack+heap classes possible in D?

2015-06-13 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 14 June 2015 at 00:52:20 UTC, FujiBar wrote: I have read that in D structs are always allocated on the stack while classes are always allocated on the heap. That's not true; it is a really common misconception. Putting a struct on the heap is trivial and built into the language:

Re: __traits getMember is context sensetive?

2015-06-13 Thread JDemler via Digitalmars-d-learn
I have another one :) module test; struct S{ string member1; int member2; } string test(string[] a) { const S s = { member1:It is also important to go to Mars!}; const string y = a[0]; return y; } void main() { enum e = [member1,member2]; pragma(msg, e[0]); pragma(msg,

Re: __traits getMember is context sensetive?

2015-06-13 Thread ketmar via Digitalmars-d-learn
oh, seems that i managed to make everything even less understandable... signature.asc Description: PGP signature

Re: __traits getMember is context sensetive?

2015-06-13 Thread ketmar via Digitalmars-d-learn
On Sat, 13 Jun 2015 23:55:53 +, JDemler wrote: After a bit of rethinking: I guess the compiler goes through 2 loops: the first resolves __traits, the second does ctfe. That would explain this behavior. a is not present to the compiler while it tries to resolve my __traits call, but

Re: appender!(dchar[]) put fail

2015-06-13 Thread kerdemdemir via Digitalmars-d-learn
On Saturday, 13 June 2015 at 13:09:20 UTC, Dennis Ritchie wrote: auto stringB = readln.chomp.map!(to!dchar).array; auto stringC = readln.chomp.map!(to!dchar).array; auto charAppender = appender!(dchar[][]); auto totalStr = stringB.repeat(3).chain(stringC.repeat(5));

Re: appender!(dchar[]) put fail

2015-06-13 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 13 June 2015 at 13:32:19 UTC, kerdemdemir wrote: One more question I am asking those kind of questions to understand and not ask same stuff over and over, : auto totalStr = chain(stringB.replicate(bCount), stringC.replicate(cCount)); writeln(typeof(totalStr.array()).stringof);

Re: appender!(dchar[]) put fail

2015-06-13 Thread Quentin Ladeveze via Digitalmars-d-learn
On Saturday, 13 June 2015 at 12:02:10 UTC, kerdemdemir wrote: The problem is that your appender is a char appender, and you try to put a dstring into it. Replace : charAppender.put(totalStr); by : foreach(elem; totalStr){ charAppender.put(elem); } elem will be a dchar, so it will work.

Re: appender!(dchar[]) put fail

2015-06-13 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 13 June 2015 at 13:01:29 UTC, kerdemdemir wrote: Sorry to making the discussion longer and wasting your times. But I am looking for a way without for loops. Also looping every element one by one does not seems very efficient to me. Any advices for that? Maybe it fit? auto

Re: appender!(dchar[]) put fail

2015-06-13 Thread kerdemdemir via Digitalmars-d-learn
It is the same, but totalStr is not a dchar[]. It's a Result (a type internal to the chain function ) which is a range. The foreach loop iterates over Result, which returns dchar[]. So if you try to do something like that : charAppender.put(totalStr.array), it won't work because

Re: appender!(dchar[]) put fail

2015-06-13 Thread Quentin Ladeveze via Digitalmars-d-learn
On Saturday, 13 June 2015 at 13:32:19 UTC, kerdemdemir wrote: Thanks lot that is really good. One more question I am asking those kind of questions to understand and not ask same stuff over and over, : Don't worry, there is learn in D.learn auto totalStr =

Re: Conditional Compilation Multiple Versions

2015-06-13 Thread anonymous via Digitalmars-d-learn
On Saturday, 13 June 2015 at 00:47:37 UTC, Mike Parker wrote: // config.d version(One) enum One = true; else enum One = false; version(Two) enum Two = true; else enum Two = false; // other.d import config; static if(One || Two) { ... } Taking it one step further: template Version(string

Re: Qualified destructors / immutable objects

2015-06-13 Thread Daniel Kozak via Digitalmars-d-learn
On Friday, 12 June 2015 at 15:36:22 UTC, anonymous wrote: no need for ~this() to modify immutable data: class C { int a; this(int a) { this.a = a; } } struct S { C elem = new C(42); } void main() { import std.stdio; immutable(S) s1;

Re: char[][] to std::vectorstd::string - DIP or dmd-issue?

2015-06-13 Thread anonymous via Digitalmars-d-learn
On Saturday, 13 June 2015 at 15:21:19 UTC, Dennis Ritchie wrote: Hello, everyone! I like to work with arrays of strings like `string[] strArray`, but unfortunately, they are immutable. I do not like to work with arrays of strings such as `char[][] strArray`, because it is necessary to apply

Serialization array of structure

2015-06-13 Thread Suliman via Digitalmars-d-learn
Look like I am doing serialization wrong way: struct DBFields { Date date; string tag; int popularity; } DBFields [] dbfields; DBFields dbfield; . dbfields ~= dbfield; writeln(serializeToJson(dbfields)); As result I am getting only first string.

Re: char[][] to std::vectorstd::string - DIP or dmd-issue?

2015-06-13 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 13 June 2015 at 15:45:34 UTC, anonymous wrote: Please show an example of .dup you'd like to avoid. For example, if you need to create a five-dimensional array of strings :)

Re: Serialization array of structure

2015-06-13 Thread Suliman via Digitalmars-d-learn
Oh, sorry, the error was in another place.

Re: char[][] to std::vectorstd::string - DIP or dmd-issue?

2015-06-13 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 13 June 2015 at 16:20:46 UTC, anonymous wrote: Do you like to write? char[][] strArray = [foo.dup, bar.dup, baz.dup]; Ok. That's all you're on about? Basically you'd like this: char[] s = foo; and this: char[][] a = [[foo]]; etc. Yes. That's right, and not otherwise :)

Re: char[][] to std::vectorstd::string - DIP or dmd-issue?

2015-06-13 Thread anonymous via Digitalmars-d-learn
On Saturday, 13 June 2015 at 17:02:06 UTC, Dennis Ritchie wrote: On Saturday, 13 June 2015 at 16:20:46 UTC, anonymous wrote: [...] Yeah, that would be neat. But typing out .dup isn't that bad, and converting a `string[]` to a `char[][]` is simple: import std.conv: to; auto a =

Re: char[][] to std::vectorstd::string - DIP or dmd-issue?

2015-06-13 Thread Kagamin via Digitalmars-d-learn
Type is probably possible, though conversion method will be simpler. You can even try to write a specialization of `to` for multidimentional arrays if it doesn't work.

char[][] to std::vectorstd::string - DIP or dmd-issue?

2015-06-13 Thread Dennis Ritchie via Digitalmars-d-learn
Hello, everyone! I like to work with arrays of strings like `string[] strArray`, but unfortunately, they are immutable. I do not like to work with arrays of strings such as `char[][] strArray`, because it is necessary to apply the method .dup each substring to make them work :) I

Re: char[][] to std::vectorstd::string - DIP or dmd-issue?

2015-06-13 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 13 June 2015 at 15:45:34 UTC, anonymous wrote: Before jumping to a solution, please elaborate on the perceived problem. I have a feeling that there is none. Do you like to write? char[][] strArray = [foo.dup, bar.dup, baz.dup]; I suggest that such an option: str[] strArray =

Re: Conditional Compilation Multiple Versions

2015-06-13 Thread bitwise via Digitalmars-d-learn
On Sat, 13 Jun 2015 08:21:50 -0400, ketmar ket...@ketmar.no-ip.org wrote: On Fri, 12 Jun 2015 20:41:59 -0400, bitwise wrote: Is there a way to compile for multiple conditions? Tried all these: version(One | Two){ } version(One || Two){ } version(One Two){ } version(One) | version(Two){ }

Re: char[][] to std::vectorstd::string - DIP or dmd-issue?

2015-06-13 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 13 June 2015 at 15:45:34 UTC, anonymous wrote: Huh? You mean with string literals? That would be a rather silly reason to avoid `char[]`. Please show an example of .dup you'd like to avoid. Yes, string literals. I understand that the type of `string[]` to D is a simple data

Re: Conditional Compilation Multiple Versions

2015-06-13 Thread ketmar via Digitalmars-d-learn
On Sat, 13 Jun 2015 13:49:49 +, anonymous wrote: Taking it one step further: template Version(string name) { mixin( version(~name~) enum Version = true; else enum Version = false; ); } static if(Version!One || Version!Two) { ... } very

Re: char[][] to std::vectorstd::string - DIP or dmd-issue?

2015-06-13 Thread anonymous via Digitalmars-d-learn
On Saturday, 13 June 2015 at 15:58:44 UTC, Dennis Ritchie wrote: On Saturday, 13 June 2015 at 15:45:34 UTC, anonymous wrote: Before jumping to a solution, please elaborate on the perceived problem. I have a feeling that there is none. Do you like to write? char[][] strArray = [foo.dup,

Re: char[][] to std::vectorstd::string - DIP or dmd-issue?

2015-06-13 Thread anonymous via Digitalmars-d-learn
On Saturday, 13 June 2015 at 16:09:58 UTC, Dennis Ritchie wrote: On Saturday, 13 June 2015 at 15:45:34 UTC, anonymous wrote: [...] Are you saying that `string[]` is simpler than `char[][]`? That's not true: `string` is an alias for `immutable(char)[]`, so `string[]` is the same as

Re: Conditional Compilation Multiple Versions

2015-06-13 Thread ketmar via Digitalmars-d-learn
On Sat, 13 Jun 2015 12:01:29 -0400, bitwise wrote: nope. Walter is against that, so we'll not have it, despite the triviality of the patch. Any idea what the rationale was for not allowing it? i don't remember. that murmuring about it makes the code harder to read goes beyond me, so it's

Re: Conditional Compilation Multiple Versions

2015-06-13 Thread bitwise via Digitalmars-d-learn
On Sat, 13 Jun 2015 12:20:40 -0400, ketmar ket...@ketmar.no-ip.org wrote: On Sat, 13 Jun 2015 13:49:49 +, anonymous wrote: Taking it one step further: template Version(string name) { mixin( version(~name~) enum Version = true; else enum Version = false; ); }

Re: char[][] to std::vectorstd::string - DIP or dmd-issue?

2015-06-13 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 13 June 2015 at 15:21:19 UTC, Dennis Ritchie wrote: I wish to propose the creation of new types of data D: str, wstr, dstr, which will be the analogs of C++ `std::vectorstd::string`. Ie str, wstr, dstr be mutable counterparts immutable strings respectively str (mutable(char[])),

__traits getMember is context sensetive?

2015-06-13 Thread JDemler via Digitalmars-d-learn
Hey, i am trying to wrap my head around __traits. One thing i just do not understand is following: struct S{ string member1; int member2; } void main(string[] args) { foreach(typeStr; __traits(allMembers, S)) { auto tp = __traits(getMember, S, typeStr); static if

Re: appender!(dchar[]) put fail

2015-06-13 Thread kerdemdemir via Digitalmars-d-learn
The problem is that your appender is a char appender, and you try to put a dstring into it. Replace : charAppender.put(totalStr); by : foreach(elem; totalStr){ charAppender.put(elem); } elem will be a dchar, so it will work. But I can see in the example of

Re: Conditional Compilation Multiple Versions

2015-06-13 Thread ketmar via Digitalmars-d-learn
On Fri, 12 Jun 2015 20:41:59 -0400, bitwise wrote: Is there a way to compile for multiple conditions? Tried all these: version(One | Two){ } version(One || Two){ } version(One Two){ } version(One) | version(Two){ } version(One) || version(Two){ } version(One) version(Two){ }

Re: __traits getMember is context sensetive?

2015-06-13 Thread JDemler via Digitalmars-d-learn
On Saturday, 13 June 2015 at 10:26:06 UTC, Marc Schütz wrote: On Saturday, 13 June 2015 at 10:01:45 UTC, JDemler wrote: Hey, i am trying to wrap my head around __traits. One thing i just do not understand is following: struct S{ string member1; int member2; } void main(string[] args) {

appender!(dchar[]) put fail

2015-06-13 Thread kerdemdemir via Digitalmars-d-learn
I have two strings(stringB,stringC) which I need to repeat(bCount times, cCountTimes) and then chain. auto charAppender = appender!(dchar[]); auto totalStr = stringB.repeat(bCount).chain(stringC.repeat(cCount)); This compiles and works ok, But when I try to append new string to charAppender

Re: __traits getMember is context sensetive?

2015-06-13 Thread ketmar via Digitalmars-d-learn
On Sat, 13 Jun 2015 10:36:39 +, John Colvin wrote: *for some reason it's not public, but it's very short and simple: it's funny how many useful things are there in Phobos, carefully hidden from user. i believe each D book should include an advice like this: to fully learn what you can do

Re: How to realize copyable/postblit class

2015-06-13 Thread John Colvin via Digitalmars-d-learn
On Saturday, 13 June 2015 at 05:20:42 UTC, SimonN wrote: Hi, I have a few classes with need for deeper copying. I don't want a bitwise copy necessarily. Ideally, I'd implement this(this). I've thought about changing them to struct. However, the type feels much more like a D class than a D

Re: __traits getMember is context sensetive?

2015-06-13 Thread via Digitalmars-d-learn
On Saturday, 13 June 2015 at 10:01:45 UTC, JDemler wrote: Hey, i am trying to wrap my head around __traits. One thing i just do not understand is following: struct S{ string member1; int member2; } void main(string[] args) { foreach(typeStr; __traits(allMembers, S)) { auto

Re: __traits getMember is context sensetive?

2015-06-13 Thread John Colvin via Digitalmars-d-learn
On Saturday, 13 June 2015 at 10:01:45 UTC, JDemler wrote: Hey, i am trying to wrap my head around __traits. One thing i just do not understand is following: struct S{ string member1; int member2; } void main(string[] args) { foreach(typeStr; __traits(allMembers, S)) { auto

Re: appender!(dchar[]) put fail

2015-06-13 Thread Quentin Ladeveze via Digitalmars-d-learn
On Saturday, 13 June 2015 at 10:45:58 UTC, kerdemdemir wrote: I have two strings(stringB,stringC) which I need to repeat(bCount times, cCountTimes) and then chain. auto charAppender = appender!(dchar[]); auto totalStr = stringB.repeat(bCount).chain(stringC.repeat(cCount)); This compiles and

Re: Qualified destructors / immutable objects

2015-06-13 Thread anonymous via Digitalmars-d-learn
Is there an existing issue on issue.dlang.org? If not can you report it https://issues.dlang.org/show_bug.cgi?id=10376

Re: char[][] to std::vectorstd::string - DIP or dmd-issue?

2015-06-13 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 13 June 2015 at 18:15:30 UTC, Dennis Ritchie wrote: Actually, I will file issue `std.conv` in Phobos to add such specifications. It will suit me. *specializations

Re: char[][] to std::vectorstd::string - DIP or dmd-issue?

2015-06-13 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 13 June 2015 at 17:39:25 UTC, Kagamin wrote: Type is probably possible, though conversion method will be simpler. You can even try to write a specialization of `to` for multidimentional arrays if it doesn't work. It appears the problem can be solved by creating specifications

new pragma(inline) syntax

2015-06-13 Thread Ilya Yaroshenko via Digitalmars-d-learn
Are `foo` and `bar` always inlined? struct S { pragma(inline, true): void foo(T)(T t) {} void bar(T)(T t) {} }

Re: new pragma(inline) syntax

2015-06-13 Thread Ilya Yaroshenko via Digitalmars-d-learn
On Saturday, 13 June 2015 at 19:13:20 UTC, Ilya Yaroshenko wrote: Are `foo` and `bar` always inlined? struct S { pragma(inline, true): void foo(T)(T t) {} void bar(T)(T t) {} } I am confused becuase they are templates.

Re: char[][] to std::vectorstd::string - DIP or dmd-issue?

2015-06-13 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 13 June 2015 at 17:37:31 UTC, anonymous wrote: Please show how it is not. Seems to work just fine. OK. Still, this method works: char[][][][][][] strArr = [foo, baz], [bar, tor.to!(char[][][][][])]; But I don't want to write this `.to!(char[][][][][])`. On Saturday,

Re: How to realize copyable/postblit class

2015-06-13 Thread SimonN via Digitalmars-d-learn
On Saturday, 13 June 2015 at 08:52:59 UTC, John Colvin wrote: perhaps: class A { struct S { // ... } S s; alias s this; this(A rhs) { s = rhs.s; } } I'm using this now, and it doesn't feel like a workaround too much. For something with 5