Re: How to repeat structure C++

2017-01-15 Thread MGW via Digitalmars-d-learn
On Monday, 16 January 2017 at 00:07:44 UTC, Adam D. Ruppe wrote: That's just interfaces and classes in D, so change struct to those words and go fro there. // --- jd.d: compile: dmd -c jd import std.stdio; extern (C++) interface IHome { int sum(int, int); }; extern (C++) void printIHome(vo

Re: Quine using strings?

2017-01-15 Thread Basile B. via Digitalmars-d-learn
On Sunday, 15 January 2017 at 19:43:22 UTC, Nestor wrote: I was reading some of the examples of writing a quine with D, but apparently the language has evolved and they no longer compiled unchanged. So I tried to program one by myself using strings and std.stdio, but the result seems long and

Re: Quine using strings?

2017-01-15 Thread Michael Coulombe via Digitalmars-d-learn
A quine I came up with a while ago, using q{} string notation: enum s = q{enum s = q{%s}; void main() { import std.stdio; writefln(s,s); }}; void main() { import std.stdio; writefln(s,s); }

Re: Is it ok to inherit multiple times same templated interface?

2017-01-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 15 January 2017 at 20:33:30 UTC, Alexandru Ermicioi wrote: Currently doing so is allowed, though, it is impossible to call implemented methods directly from implementation. You should be able to do obj.Wr!(ubyte).get() too.

Re: How to repeat structure C++

2017-01-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 15 January 2017 at 19:05:06 UTC, MGW wrote: struct IInterface {}; struct IMsgBox : public IInterface { virtual bool Confirm(const wchar* queryText, tVariant* retVal) = 0; virtual bool Alert(const wchar* text) = 0; }; That's just interfaces and classes in D, so change struc

Re: Accessing a function within an object's superclass from the outside

2017-01-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 15 January 2017 at 02:32:29 UTC, Meta wrote: Is this documented anywhere? I had no idea this was a feature. Used in some examples here: http://dlang.org/spec/class.html

Re: Quine using strings?

2017-01-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 15 January 2017 at 22:35:26 UTC, Nestor wrote: You forgot to include the program... or is this a joke? ;) Neither: the empty program compiles and runs, outputting nothing. Since its empty output matches its empty source file, it technically fits the definition of the quine :)

Re: Is it ok to inherit multiple times same templated interface?

2017-01-15 Thread Ryan via Digitalmars-d-learn
On Sunday, 15 January 2017 at 20:33:30 UTC, Alexandru Ermicioi wrote: Good day, Given following code example, where a templated interface Wr, and an implementation Im is present: interface Wr(T) { T get(); } class Im(T : ubyte) : Wr!ubyte, Wr!ushort, Wr!string { public T t; ubyte

Re: Convert duration to years?

2017-01-15 Thread Nestor via Digitalmars-d-learn
Thank you all.

Re: Quine using strings?

2017-01-15 Thread Nestor via Digitalmars-d-learn
On Sunday, 15 January 2017 at 22:08:47 UTC, pineapple wrote: On Sunday, 15 January 2017 at 21:37:53 UTC, Nestor wrote: Any ideas for a shorter version (preferably without using pointers)? When compiling with the -main flag, this D program is a quine: You forgot to include the program... or i

Re: Quine using strings?

2017-01-15 Thread pineapple via Digitalmars-d-learn
On Sunday, 15 January 2017 at 21:37:53 UTC, Nestor wrote: Any ideas for a shorter version (preferably without using pointers)? When compiling with the -main flag, this D program is a quine:

Re: Quine using strings?

2017-01-15 Thread Nestor via Digitalmars-d-learn
On Sunday, 15 January 2017 at 19:43:22 UTC, Nestor wrote: I was reading some of the examples of writing a quine with D, but apparently the language has evolved and they no longer compiled unchanged. So I tried to program one by myself using strings and std.stdio, but the result seems long and

Re: Is it ok to inherit multiple times same templated interface?

2017-01-15 Thread Dmitry Olshansky via Digitalmars-d-learn
On Sunday, 15 January 2017 at 20:33:30 UTC, Alexandru Ermicioi wrote: Good day, Given following code example, where a templated interface Wr, and an implementation Im is present: From the standpoint of the compiler they are 3 distinct interfaces, so all is good. interface Wr(T) { T g

Is it ok to inherit multiple times same templated interface?

2017-01-15 Thread Alexandru Ermicioi via Digitalmars-d-learn
Good day, Given following code example, where a templated interface Wr, and an implementation Im is present: interface Wr(T) { T get(); } class Im(T : ubyte) : Wr!ubyte, Wr!ushort, Wr!string { public T t; ubyte get() { return cast(ubyte) this.t; } ushort get() {

Re: Convert duration to years?

2017-01-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, January 15, 2017 03:43:32 Nestor via Digitalmars-d-learn wrote: > Hi, > > I would simply like to get someone's age, but I am a little lost > with time and date functions. I can already get the duration, but > after reading the documentation it's unclear to me how to convert > that into y

Re: Querying parameter passing semantics for `auto ref const` variables

2017-01-15 Thread Nordlöw via Digitalmars-d-learn
On Sunday, 15 January 2017 at 17:41:36 UTC, Nordlöw wrote: This struct S { int x, y; } void f()(auto ref const S s) { pragma(msg, "type:", typeof(s), " isRef:", isRef!s); } f(S.init); S s; f(s); prints type:const(S) isRef:false type:const(S) isRef:tr

Re: Parsing a UTF-16LE file line by line, BUG?

2017-01-15 Thread Nestor via Digitalmars-d-learn
On Sunday, 15 January 2017 at 16:29:23 UTC, Daniel Kozák wrote: This is because byLine does return range, so until you do something with that it does not cause any harm :) I see. So correcting my original doubt: How could I parse an UTF16LE file line by line (producing a proper string in each

Quine using strings?

2017-01-15 Thread Nestor via Digitalmars-d-learn
I was reading some of the examples of writing a quine with D, but apparently the language has evolved and they no longer compiled unchanged. So I tried to program one by myself using strings and std.stdio, but the result seems long and redundant: import std.stdio;void main(){string s=`import

Re: Convert duration to years?

2017-01-15 Thread Nestor via Digitalmars-d-learn
On Sunday, 15 January 2017 at 16:57:35 UTC, biozic wrote: On Sunday, 15 January 2017 at 14:20:04 UTC, Nestor wrote: On second thought, if a baby was born in march 1 of 1999 (non-leap year), in march 1 of 2000 (leap year) the age would have been one year plus one day (because of february 29).

Re: How to repeat structure C++

2017-01-15 Thread MGW via Digitalmars-d-learn
On Sunday, 15 January 2017 at 19:00:49 UTC, MGW wrote: Hi! struct IInterface {}; struct IMsgBox : public IInterface { virtual bool Confirm(const wchar* queryText, tVariant* retVal) = 0; virtual bool Alert(const wchar* text) = 0; };

How to repeat structure C++

2017-01-15 Thread MGW via Digitalmars-d-learn
Hi! I write plugin for 1C:Enterprise 8.3 on dmd now. https://youtu.be/apLppufZulI I try to repeat structure C++ (interface) on dmd. But D no inheritance of structures. What it is possible to replace with the D following code on C ++struct IInterface {}; C++ - struct IMsgBox : public IInter

Re: Using Dub

2017-01-15 Thread cym13 via Digitalmars-d-learn
On Sunday, 15 January 2017 at 13:23:25 UTC, Russel Winder wrote: Is there any way of setting dub to default to ldc2 rather than dmd as the compiler of use? (I do not want to have to put --compiler ldc2 on every dub command.) Create a file ~/.dub/settings.json with the following content: {

Re: Querying parameter passing semantics for `auto ref const` variables

2017-01-15 Thread Nordlöw via Digitalmars-d-learn
On Sunday, 15 January 2017 at 17:00:41 UTC, kinke wrote: On Sunday, 15 January 2017 at 14:33:25 UTC, Nordlöw wrote: A call to `isRef!T` inside the function `f` is always `false` for `l-value` and `r-value` passing. According to https://dlang.org/spec/template.html#auto-ref-parameters, it sho

Re: Using Dub

2017-01-15 Thread Daniel N via Digitalmars-d-learn
On Sunday, 15 January 2017 at 13:23:25 UTC, Russel Winder wrote: Is there any way of setting dub to default to ldc2 rather than dmd as the compiler of use? (I do not want to have to put --compiler ldc2 on every dub command.) I have never used dub, but I know it's now also bundled with ldc2. I

Re: Querying parameter passing semantics for `auto ref const` variables

2017-01-15 Thread kinke via Digitalmars-d-learn
On Sunday, 15 January 2017 at 14:33:25 UTC, Nordlöw wrote: A call to `isRef!T` inside the function `f` is always `false` for `l-value` and `r-value` passing. According to https://dlang.org/spec/template.html#auto-ref-parameters, it should be `__traits(isRef, x)`.

Re: Convert duration to years?

2017-01-15 Thread biozic via Digitalmars-d-learn
On Sunday, 15 January 2017 at 14:20:04 UTC, Nestor wrote: On Sunday, 15 January 2017 at 14:04:39 UTC, Nestor wrote: ... For example, take a baby born in february 29 of year 2000 (leap year). In february 28 of 2001 that baby was one day short to one year. Family can make a concession and cele

Re: Parsing a UTF-16LE file line by line, BUG?

2017-01-15 Thread Daniel Kozák via Digitalmars-d-learn
V Sun, 15 Jan 2017 14:48:12 + Nestor via Digitalmars-d-learn napsáno: > On Friday, 6 January 2017 at 11:42:17 UTC, Mike Wey wrote: > > On 01/06/2017 11:33 AM, pineapple wrote: > >> On Friday, 6 January 2017 at 06:24:12 UTC, rumbu wrote: > > I'm not sure if this works quite as in

Re: Parsing a UTF-16LE file line by line, BUG?

2017-01-15 Thread Nestor via Digitalmars-d-learn
On Sunday, 15 January 2017 at 14:48:12 UTC, Nestor wrote: After some testing I realized that byLine was not the one failing, but any string manipulation done to the obtained line. Compile the following example with and without -debug and run to see what I mean: import std.stdio, std.string;

Re: Parsing a UTF-16LE file line by line, BUG?

2017-01-15 Thread Nestor via Digitalmars-d-learn
On Friday, 6 January 2017 at 11:42:17 UTC, Mike Wey wrote: On 01/06/2017 11:33 AM, pineapple wrote: On Friday, 6 January 2017 at 06:24:12 UTC, rumbu wrote: I'm not sure if this works quite as intended, but I was at least able to produce a UTF-16 decode error rather than a UTF-8 decode error

Re: Querying parameter passing semantics for `auto ref const` variables

2017-01-15 Thread Nordlöw via Digitalmars-d-learn
On Sunday, 15 January 2017 at 14:33:25 UTC, Nordlöw wrote: Is there a way to query at compile-time whether a call to Further, overloading such as struct S { int x, y; } static f(in S s) {} static f(const ref S s) {} f(S.init); S s; f(s); fails as declaration f is

Querying parameter passing semantics for `auto ref const` variables

2017-01-15 Thread Nordlöw via Digitalmars-d-learn
Is there a way to query at compile-time whether a call to f(T)(auto ref const T x) passed the variable `x` from a l-value or r-value? A call to `isRef!T` inside the function `f` is always `false` for `l-value` and `r-value` passing. I need this to detect automatic delayed evaluation of

Re: Convert duration to years?

2017-01-15 Thread Nestor via Digitalmars-d-learn
On Sunday, 15 January 2017 at 14:04:39 UTC, Nestor wrote: ... For example, take a baby born in february 29 of year 2000 (leap year). In february 28 of 2001 that baby was one day short to one year. Family can make a concession and celebrate birthdays in february 28 of non-leap years, but marc

Re: Convert duration to years?

2017-01-15 Thread Nestor via Digitalmars-d-learn
On Sunday, 15 January 2017 at 11:01:28 UTC, biozic wrote: On Sunday, 15 January 2017 at 08:40:37 UTC, Nestor wrote: I cleaned up the function a little, but it still feels like a hack: uint getAge(uint , uint mm, uint dd) { import std.datetime; SysTime t = Clock.currTime; ubyte correc

Re: std.container.array.Array is not @nogc?

2017-01-15 Thread Jack Stouffer via Digitalmars-d-learn
On Sunday, 15 January 2017 at 13:08:52 UTC, drug007 wrote: Thanks for answer. Looking forward for your PR. https://github.com/dlang/phobos/pull/5036

Using Dub

2017-01-15 Thread Russel Winder via Digitalmars-d-learn
Is there any way of setting dub to default to ldc2 rather than dmd as the compiler of use? (I do not want to have to put --compiler ldc2 on every dub command.) -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip

Re: std.container.array.Array is not @nogc?

2017-01-15 Thread drug007 via Digitalmars-d-learn
On 15.01.2017 15:49, Jack Stouffer wrote: No you're not. Array was designed before the @nogc attribute was created, so it wasn't coded with it's requirements in mind. Looking at the code, Array allocates GC memory for exception throwing in some cases. These can and should be changed to asserts.

Re: std.container.array.Array is not @nogc?

2017-01-15 Thread Jack Stouffer via Digitalmars-d-learn
On Sunday, 15 January 2017 at 11:47:06 UTC, drug007 wrote: Is there a way to use Array in @nogc code: ``` import std.container.array : Array; @nogc: void main(string[ ] args) { Array!int ai; ai ~= 1; assert(ai[0] == 1); } ``` fails: ``` main.d(8): Error: @nogc function 'D main' cannot c

std.container.array.Array is not @nogc?

2017-01-15 Thread drug007 via Digitalmars-d-learn
Is there a way to use Array in @nogc code: ``` import std.container.array : Array; @nogc: void main(string[ ] args) { Array!int ai; ai ~= 1; assert(ai[0] == 1); } ``` fails: ``` main.d(8): Error: @nogc function 'D main' cannot call non-@nogc function 'std.container.array.Array!int.Array

Re: Convert duration to years?

2017-01-15 Thread biozic via Digitalmars-d-learn
On Sunday, 15 January 2017 at 08:40:37 UTC, Nestor wrote: I cleaned up the function a little, but it still feels like a hack: uint getAge(uint , uint mm, uint dd) { import std.datetime; SysTime t = Clock.currTime; ubyte correction = 0; if( (t.month < mm) || ( (t.month == mm)

Re: Convert duration to years?

2017-01-15 Thread ag0aep6g via Digitalmars-d-learn
On 01/15/2017 07:58 AM, Nestor wrote: I eventually came up with this, but it seems an ugly hack: import std.stdio; uint getAge(int , ubyte mm, ubyte dd) { ubyte correction; import std.datetime; SysTime t = Clock.currTime(); if (t.month < mm) correction = 1; else if (t.month == mm)

Re: Convert duration to years?

2017-01-15 Thread rikki cattermole via Digitalmars-d-learn
On 15/01/2017 9:40 PM, Nestor wrote: I cleaned up the function a little, but it still feels like a hack: uint getAge(uint , uint mm, uint dd) { import std.datetime; SysTime t = Clock.currTime; ubyte correction = 0; if( (t.month < mm) || ( (t.month == mm) && (t.day < dd) ) )

Re: Convert duration to years?

2017-01-15 Thread Nestor via Digitalmars-d-learn
I cleaned up the function a little, but it still feels like a hack: uint getAge(uint , uint mm, uint dd) { import std.datetime; SysTime t = Clock.currTime; ubyte correction = 0; if( (t.month < mm) || ( (t.month == mm) && (t.day < dd) ) ) correction += 1; return (t.year -

Re: template instance does not match template declaration

2017-01-15 Thread Fabrice Marie via Digitalmars-d-learn
On Sunday, 8 January 2017 at 05:45:52 UTC, Meta wrote: On Sunday, 8 January 2017 at 03:27:26 UTC, Fabrice Marie wrote: void main() { Cache!(BasicObject, string, lookupBasicObject); } In addition to what Nicholas Wilson said, what you're doing here is the equivalent of writin

Re: Convert duration to years?

2017-01-15 Thread Nestor via Digitalmars-d-learn
On Sunday, 15 January 2017 at 07:25:26 UTC, rikki cattermole wrote: So I had a go at this and found I struggled looking at "magic" functions and methods. Turns out there is a much simpler answer. int getAge(int , int mm, int dd) { import std.datetime; auto t1 = cast(DateTime)SysTime(Dat