Re: What's equivalent to C#'s select?

2018-01-14 Thread Simen Kjærås via Digitalmars-d-learn
On Sunday, 14 January 2018 at 22:07:22 UTC, Marc wrote: thanks, can i use it at compile time as well? enum isMutableString(string field) = is(typeof(__traits(getMember, >C, field)) == string); static foreach(field; [FieldNameTuple!C].filter!(f => isMutableString!(f))) {

Re: String Type Usage. String vs DString vs WString

2018-01-14 Thread SimonN via Digitalmars-d-learn
On Monday, 15 January 2018 at 02:05:32 UTC, Chris P wrote: Is usage of one type over the others encouraged? I would use string (UTF-8) throughout the program, but there seems to be no style guideline for this. Keep in mind two gotchas: D's foreach and D's ranges will autodecode and silently

Re: String Type Usage. String vs DString vs WString

2018-01-14 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, January 15, 2018 03:14:02 Tony via Digitalmars-d-learn wrote: > On Monday, 15 January 2018 at 02:09:25 UTC, rikki cattermole > > wrote: > > Unicode has three main variants, UTF-8, UTF-16 and UTF-32. > > The size of a code point is 1, 2 or 4 bytes. > > I think to be technically correct,

Re: SegFault with HibernateD

2018-01-14 Thread Venkat via Digitalmars-d-learn
On Saturday, 13 January 2018 at 06:18:43 UTC, Ali Çehreli wrote: On 01/12/2018 06:50 PM, Venkat wrote: > Sorry about all these posts. Wish there were an edit button. That's ok. :) These are actually newsgroups (see NNTP protocol). Newsgroups don't have any edit functionality. The "forum" is

Re: How do I get the value cache()?

2018-01-14 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 15 January 2018 at 02:54:16 UTC, Marc wrote: let's assume I have class C { static string foo() { writeln("got called!"); // } } then I want to cache foo at some point: import std.algorithm; auto v = cache(c.foo); That doesn't do what I think you think it does.

Re: String Type Usage. String vs DString vs WString

2018-01-14 Thread Tony via Digitalmars-d-learn
On Monday, 15 January 2018 at 02:09:25 UTC, rikki cattermole wrote: Unicode has three main variants, UTF-8, UTF-16 and UTF-32. The size of a code point is 1, 2 or 4 bytes. I think to be technically correct, 1 (UTF-8), 2 (UTF-16) or 4 (UTF-32) bytes are referred to as "code units" and the

How do I get the value cache()?

2018-01-14 Thread Marc via Digitalmars-d-learn
let's assume I have class C { static string foo() { writeln("got called!"); // } } then I want to cache foo at some point: import std.algorithm; auto v = cache(c.foo); I call do: for(int i = 0; i <10; i++) { writeln(v); } then it'll print "got called" only once, which is what I

Re: String Type Usage. String vs DString vs WString

2018-01-14 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, January 15, 2018 02:22:09 Chris P via Digitalmars-d-learn wrote: > On Monday, 15 January 2018 at 02:15:55 UTC, Nicholas Wilson wrote: > > On Monday, 15 January 2018 at 02:05:32 UTC, Chris P wrote: > >> [...] > >> > > string == immutable( char)[], char == utf8 > > > > wstring ==

Re: Using Postgres connection functions

2018-01-14 Thread Matthias Klumpp via Digitalmars-d-learn
On Saturday, 13 January 2018 at 17:58:14 UTC, Joe wrote: On Saturday, 13 January 2018 at 10:10:41 UTC, Jacob Carlborg wrote: There's a native D library, ddb [1], for connecting to Postgres. Then you don't have to worry about null-terminated strings. There are several D libraries that I would

Re: String Type Usage. String vs DString vs WString

2018-01-14 Thread Chris P via Digitalmars-d-learn
On Monday, 15 January 2018 at 02:15:55 UTC, Nicholas Wilson wrote: On Monday, 15 January 2018 at 02:05:32 UTC, Chris P wrote: [...] string == immutable( char)[], char == utf8 wstring == immutable(wchar)[], char == utf16 dstring == immutable(dchar)[], char == utf32 Unless you are dealing

Re: String Type Usage. String vs DString vs WString

2018-01-14 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 15 January 2018 at 02:05:32 UTC, Chris P wrote: Hello, I'm extremely new to D and have a quick question regarding common practice when using strings. Is usage of one type over the others encouraged? When using 'string' it appears there is a length mismatch between the string

String Type Usage. String vs DString vs WString

2018-01-14 Thread Chris P via Digitalmars-d-learn
Hello, I'm extremely new to D and have a quick question regarding common practice when using strings. Is usage of one type over the others encouraged? When using 'string' it appears there is a length mismatch between the string length and the char array if large Unicode characters are used.

Re: String Type Usage. String vs DString vs WString

2018-01-14 Thread rikki cattermole via Digitalmars-d-learn
On 15/01/2018 2:05 AM, Chris P wrote: Hello, I'm extremely new to D and have a quick question regarding common practice when using strings. Is usage of one type over the others encouraged? When using 'string' it appears there is a length mismatch between the string length and the char array

Re: Range over a container r-value with disabled postblit

2018-01-14 Thread Andrei Alexandrescu via Digitalmars-d-learn
On 1/14/18 4:59 PM, Nordlöw wrote: On Sunday, 14 January 2018 at 21:57:37 UTC, Nordlöw wrote: Note that __trait(isLvalue, this) cannot be used to detect whether `this` is an l-value or an r-value, which I find strange. Shall be __traits(isRef, this) That would be difficult because

Re: What's equivalent to C#'s select?

2018-01-14 Thread Marc via Digitalmars-d-learn
On Sunday, 14 January 2018 at 21:59:26 UTC, Seb wrote: On Sunday, 14 January 2018 at 21:21:52 UTC, Marc wrote: give a list, how can I select only the elements of a range according to a condition give by a lamba function? something like this: auto l = myList.select(e => e.id < 300); it

Re: What's equivalent to C#'s select?

2018-01-14 Thread Marc via Digitalmars-d-learn
On Sunday, 14 January 2018 at 21:38:39 UTC, drug wrote: 15.01.2018 00:21, Marc пишет: give a list, how can I select only the elements of a range according to a condition give by a lamba function? something like this: auto l = myList.select(e => e.id < 300); it would return a range.

Re: Range over a container r-value with disabled postblit

2018-01-14 Thread Nordlöw via Digitalmars-d-learn
On Sunday, 14 January 2018 at 21:57:37 UTC, Nordlöw wrote: Note that __trait(isLvalue, this) cannot be used to detect whether `this` is an l-value or an r-value, which I find strange. Shall be __traits(isRef, this)

Re: What's equivalent to C#'s select?

2018-01-14 Thread Seb via Digitalmars-d-learn
On Sunday, 14 January 2018 at 21:21:52 UTC, Marc wrote: give a list, how can I select only the elements of a range according to a condition give by a lamba function? something like this: auto l = myList.select(e => e.id < 300); it would return a range. Similar to C#'s select:

Re: Range over a container r-value with disabled postblit

2018-01-14 Thread Nordlöw via Digitalmars-d-learn
On Sunday, 14 January 2018 at 14:04:46 UTC, kinke wrote: That sounds reasonable. For something like `foreach (e; makeRange().wrapRangeByRef())`, referencing the makeRange() struct rvalue by pointer in the wrapped range won't work, as the underlying range lifetime ends with the foreach range

Re: What's equivalent to C#'s select?

2018-01-14 Thread drug via Digitalmars-d-learn
15.01.2018 00:21, Marc пишет: give a list, how can I select only the elements of a range according to a condition give by a lamba function? something like this: auto l = myList.select(e => e.id < 300); it would return a range. Similar to C#'s select:

What's equivalent to C#'s select?

2018-01-14 Thread Marc via Digitalmars-d-learn
give a list, how can I select only the elements of a range according to a condition give by a lamba function? something like this: auto l = myList.select(e => e.id < 300); it would return a range. Similar to C#'s select: https://msdn.microsoft.com/en-us/library/bb548891(v=vs.110).aspx

Re: How do I get class member type?

2018-01-14 Thread Marc via Digitalmars-d-learn
On Sunday, 14 January 2018 at 19:08:44 UTC, Marc wrote: On Sunday, 14 January 2018 at 18:18:50 UTC, Marc wrote: I didn't find how using traits I could get a class member type? I need to test if give class member is not immutable, I find isMutable but not how get a type from give class member

Re: How do I get class member type?

2018-01-14 Thread Marc via Digitalmars-d-learn
On Sunday, 14 January 2018 at 18:18:50 UTC, Marc wrote: I didn't find how using traits I could get a class member type? I need to test if give class member is not immutable, I find isMutable but not how get a type from give class member to pass to it. for clarify, I want all this at compile

Re: variable template question

2018-01-14 Thread ag0aep6g via Digitalmars-d-learn
On Sunday, 14 January 2018 at 16:23:18 UTC, kdevel wrote: Why does this compile while both of the commented lines give a compile error. The code boils down to this: struct decimal32 { this(int x) {} } immutable decimal32 c = 3; /* works */ void main () { immutable decimal32 i =

How do I get class member type?

2018-01-14 Thread Marc via Digitalmars-d-learn
I didn't find how using traits I could get a class member type? I need to test if give class member is not immutable, I find isMutable but not how get a type from give class member to pass to it.

Re: Problem with function taking variable number of arguments with -m64

2018-01-14 Thread tipdbmp via Digitalmars-d-learn
So is this a bug, or am I misunderstanding something?

variable template question

2018-01-14 Thread kdevel via Digitalmars-d-learn
vartmpl.d ``` import std.stdio : writeln; import decimal : decimal32; template F(T) { immutable T c = 3; } void foo (T) () { immutable T t = 1; } void main () { // immutable decimal32 i = 1; // Error: none of the overloads of '__ctor' are callable using a immutable object //

Re: Range over a container r-value with disabled postblit

2018-01-14 Thread kinke via Digitalmars-d-learn
On Sunday, 14 January 2018 at 01:38:17 UTC, Nordlöw wrote: My current proposal for a solution is to make `byElement` a free unary function byElement(auto ref X x) which statically checks via static if (__traits(isRef, x)) whether the `X`-instance is passed as either an - l-value,

Re: function template specialization question D vs. C++

2018-01-14 Thread kdevel via Digitalmars-d-learn
On Sunday, 14 January 2018 at 02:24:52 UTC, Adam D. Ruppe wrote: On Sunday, 14 January 2018 at 02:14:50 UTC, Jonathan M Davis wrote: If you're using template constraints rather than template specializations, then you can't have any unconstrained templates. Not true: see the tip of the week

Re: Where can get the Number Convert module?Thanks.

2018-01-14 Thread FrankLike via Digitalmars-d-learn
On Sunday, 14 January 2018 at 03:49:05 UTC, Jonathan M Davis wrote: I get the result "1000" from byte[] byteData =[0,0,0,8]; Thank you very much. Good to hear. On a side note, I would point out that you almost certainly want to be using ubyte and not byte. byte is signed, whereas ubyte