Re: opApply with Type Inference and Templates?

2017-02-15 Thread Basile B. via Digitalmars-d-learn
On Thursday, 16 February 2017 at 03:20:12 UTC, Jerry wrote: I am trying to do opApply to work when the delegate passed when it is and isn't nogc/nothrow. As soon as you involve a template though, type inference goes out the door. I want to be able to use opApply with templates (to get the auto

opApply with Type Inference and Templates?

2017-02-15 Thread Jerry via Digitalmars-d-learn
I am trying to do opApply to work when the delegate passed when it is and isn't nogc/nothrow. As soon as you involve a template though, type inference goes out the door. I want to be able to use opApply with templates (to get the auto @nogc/nothrow deducation passed on the delegate passed) but

Re: User imput string int and float[DOUBT]

2017-02-15 Thread Ali Çehreli via Digitalmars-d-learn
On 02/15/2017 05:49 PM, Jean Cesar wrote: > So I'm a beginner in this language and have very little time I started > I'm interested in apprehending concepts of object orientation > polymorphism inheritance, multiple inheritance as in c ++ D is similar to C++ but also very different. > but I

Re: User imput string int and float[DOUBT]

2017-02-15 Thread Jean Cesar via Digitalmars-d-learn
On Wednesday, 15 February 2017 at 23:40:41 UTC, Ali Çehreli wrote: On 02/15/2017 03:20 PM, Jean Cesar wrote: How do I make a class person where I use set and get methods to imput the user type: I have some information here: http://ddili.org/ders/d.en/input.html You should also know how

Re: Declaring constant references in struct members

2017-02-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 16 February 2017 at 01:05:58 UTC, David Zhang wrote: Is there a similar mechanism for one struct holding another? You'd have to make the member a pointer to the struct. immutable(B)* b;

Re: Declaring constant references in struct members

2017-02-15 Thread David Zhang via Digitalmars-d-learn
On Thursday, 16 February 2017 at 00:49:45 UTC, Adam D. Ruppe wrote: On Thursday, 16 February 2017 at 00:43:30 UTC, David Zhang wrote: struct S { O object; } import std.typecons; Rebindable!O object; http://dpldocs.info/experimental-docs/std.typecons.Rebindable.html Is there a similar

Re: Declaring constant references in struct members

2017-02-15 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Feb 16, 2017 at 12:43:30AM +, David Zhang via Digitalmars-d-learn wrote: > Hi, > > Say I have a struct S that holds a reference to an object O. Is there > a way to express that I want to be able to change the reference, but > not what the reference points to? Thanks. > > struct S {

Re: Declaring constant references in struct members

2017-02-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 16 February 2017 at 00:43:30 UTC, David Zhang wrote: struct S { O object; } import std.typecons; Rebindable!O object; http://dpldocs.info/experimental-docs/std.typecons.Rebindable.html

Declaring constant references in struct members

2017-02-15 Thread David Zhang via Digitalmars-d-learn
Hi, Say I have a struct S that holds a reference to an object O. Is there a way to express that I want to be able to change the reference, but not what the reference points to? Thanks. struct S { O object; } class O { size_t things. }

Re: User imput string int and float[DOUBT]

2017-02-15 Thread Ali Çehreli via Digitalmars-d-learn
On 02/15/2017 03:20 PM, Jean Cesar wrote: How do I make a class person where I use set and get methods to imput the user type: I have some information here: http://ddili.org/ders/d.en/input.html You should also know how to read strings: http://ddili.org/ders/d.en/strings.html And this

Re: Convert call to a string

2017-02-15 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 15 February 2017 at 22:07:22 UTC, data pulverizer wrote: That's great, thanks both of you!

User imput string int and float[DOUBT]

2017-02-15 Thread Jean Cesar via Digitalmars-d-learn
How do I make a class person where I use set and get methods to imput the user type: Import std.stdio; class person { private: string name, address; int age; float height; public: void setNome() { write("Enter Your Name:"); // the problem is here how am I going to read the

Re: Convert call to a string

2017-02-15 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Feb 15, 2017 at 10:58:42PM +, ag0aep6g via Digitalmars-d-learn wrote: > On Wednesday, 15 February 2017 at 22:34:22 UTC, H. S. Teoh wrote: > > auto debugPrint(alias fun, A...)(A args) { > > writefln("%s(%(%s, %))", __traits(identifier, fun), [args]); > >

Re: Convert call to a string

2017-02-15 Thread ag0aep6g via Digitalmars-d-learn
On Wednesday, 15 February 2017 at 22:34:22 UTC, H. S. Teoh wrote: auto debugPrint(alias fun, A...)(A args) { writefln("%s(%(%s, %))", __traits(identifier, fun), [args]); return fun(args); } string arg = "hello"; string myCall =

Re: Convert call to a string

2017-02-15 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Feb 15, 2017 at 02:18:48PM -0800, H. S. Teoh via Digitalmars-d-learn wrote: [...] > Try this: > > auto debugPrint(string expr)() { > writeln(expr); > return mixin(expr); > } > > string myCall = debugPrint!`someFunction(1, "hello")`; [...]

Re: Convert call to a string

2017-02-15 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Feb 15, 2017 at 10:07:22PM +, data pulverizer via Digitalmars-d-learn wrote: > I'd like to convert a call to a string for debug printing purposes for > example: > > > ``` > import std.stdio : writeln; > void someFunction(int x, string y){} > string myCall =

Convert call to a string

2017-02-15 Thread data pulverizer via Digitalmars-d-learn
I'd like to convert a call to a string for debug printing purposes for example: ``` import std.stdio : writeln; void someFunction(int x, string y){} string myCall = debugPrint(someFunction(1, "hello")); writeln(myCall); ``` writes: someFunction(1, "hello") Does this functionality exists? If

Re: Get the address of an object, within the object itself

2017-02-15 Thread Andrew Chapman via Digitalmars-d-learn
On Wednesday, 15 February 2017 at 21:37:12 UTC, Jonathan M Davis wrote: On Wednesday, February 15, 2017 13:33:23 Jonathan M Davis via Digitalmars-d- learn wrote: On Wednesday, February 15, 2017 21:27:00 Andrew Chapman via Digitalmars-d- learn wrote: > Hi all, sorry if this question is silly,

Re: Get the address of an object, within the object itself

2017-02-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, February 15, 2017 13:33:23 Jonathan M Davis via Digitalmars-d- learn wrote: > On Wednesday, February 15, 2017 21:27:00 Andrew Chapman via Digitalmars-d- > learn wrote: > > Hi all, sorry if this question is silly, but is it possible to > > get the address of an object within the

Re: Get the address of an object, within the object itself

2017-02-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, February 15, 2017 21:27:00 Andrew Chapman via Digitalmars-d- learn wrote: > Hi all, sorry if this question is silly, but is it possible to > get the address of an object within the object itself? > > e.g. > > class Node > { > this() > { > writeln(); // Doesn't

Get the address of an object, within the object itself

2017-02-15 Thread Andrew Chapman via Digitalmars-d-learn
Hi all, sorry if this question is silly, but is it possible to get the address of an object within the object itself? e.g. class Node { this() { writeln(); // Doesn't work } } auto node = new Node(); writeln(); // Does work Thanks very much, Cheers, Andrew.

Re: Better than "Clock.currStdTime()/10000000"

2017-02-15 Thread berni via Digitalmars-d-learn
On Wednesday, 15 February 2017 at 15:58:41 UTC, Jonathan M Davis wrote: [...] MonoTime before = MonoTime.currTime; Thread.sleep(dur!"msecs"(1000)); MonoTime after = MonoTime.currTime; Duration timeElapsed = after - before; writeln(timeElapsed); } ``` I get: "1 sec, 26

Re: A bug?

2017-02-15 Thread berni via Digitalmars-d-learn
On Wednesday, 15 February 2017 at 16:11:36 UTC, drug wrote: No, you recursively call main() and get segfault (due to stack overflow) as expected I thought, that an stack overflow leeds to an exception. But that's not true, as I now see. Thanks for your answer.

Re: Getting a segfault here, why?

2017-02-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 15 February 2017 at 18:19:18 UTC, aberba wrote: Trying to find it but working with a debugger in D is not straight forward. Not yo talk of interpretating the debugger output. On linux it is pretty easy. Just compile with `-g` to dmd and run the program in gdb. Run till it

Getting a segfault here, why?

2017-02-15 Thread aberba via Digitalmars-d-learn
I'm getting a segmentation fault in vibe.d web interface class. Does referring "this" in an "if" or "switch" within a method cause segfault? Trying to find it but working with a debugger in D is not straight forward. Not yo talk of interpretating the debugger output. How has things

Re: A bug?

2017-02-15 Thread drug via Digitalmars-d-learn
15.02.2017 19:00, berni пишет: I'm not sure if this is considered a bug: import std.stdio; import std.string; int c = 0; void main() { try { write(++c," "); stdout.flush(); int[10] tmp; throw new Exception(format("%s",tmp)); } finally {

A bug?

2017-02-15 Thread berni via Digitalmars-d-learn
I'm not sure if this is considered a bug: import std.stdio; import std.string; int c = 0; void main() { try { write(++c," "); stdout.flush(); int[10] tmp; throw new Exception(format("%s",tmp)); } finally { main(); } } Output: 1 2 3 4 5 6

Re: Better than "Clock.currStdTime()/10000000"

2017-02-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, February 15, 2017 16:27:34 drug via Digitalmars-d-learn wrote: > 15.02.2017 16:19, berni пишет: > > I need to measure time elapsed in seconds, like this: > >> auto start = Clock.currStdTime(); > >> // some stuff > >> auto stop = Clock.currStdTime(); > >> auto duration =

Re: Better than "Clock.currStdTime()/10000000"

2017-02-15 Thread Seb via Digitalmars-d-learn
On Wednesday, 15 February 2017 at 13:19:57 UTC, berni wrote: I need to measure time elapsed in seconds, like this: auto start = Clock.currStdTime(); // some stuff auto stop = Clock.currStdTime(); auto duration = (stop-start)/1000; This works, but I wonder if there is something better

Re: Better than "Clock.currStdTime()/10000000"

2017-02-15 Thread drug via Digitalmars-d-learn
15.02.2017 16:19, berni пишет: I need to measure time elapsed in seconds, like this: auto start = Clock.currStdTime(); // some stuff auto stop = Clock.currStdTime(); auto duration = (stop-start)/1000; This works, but I wonder if there is something better that using the magic constant

Better than "Clock.currStdTime()/10000000"

2017-02-15 Thread berni via Digitalmars-d-learn
I need to measure time elapsed in seconds, like this: auto start = Clock.currStdTime(); // some stuff auto stop = Clock.currStdTime(); auto duration = (stop-start)/1000; This works, but I wonder if there is something better that using the magic constant 1000. I read about 10.secs

Re: Mallocator and 'shared'

2017-02-15 Thread Kagamin via Digitalmars-d-learn
On Tuesday, 14 February 2017 at 15:57:47 UTC, Moritz Maxeiner wrote: You seem to be trying to argue against someone stating memory barriers should be emitted automatically, though I don't know why you think that's me; You initially stated that Memory barriers are a bad idea because they don't