How to get runtime type of this?

2013-10-04 Thread Zhouxuan
import std.stdio; class A { static int id = 0; this() { writeln(typeid=, typeid(this)); writeln(id=,typeof(this).id); //how to get runtime type of this ?? } } class B : A { static int id = 1; } class C : A { static int id = 2;

Re: How to get runtime type of this?

2013-10-04 Thread Jacob Carlborg
On 2013-10-04 10:03, Zhouxuan wrote: import std.stdio; class A { static int id = 0; this() { writeln(typeid=, typeid(this)); writeln(id=,typeof(this).id); //how to get runtime type of this ?? } } class B : A { static int id = 1; } class C : A {

Re: How to get runtime type of this?

2013-10-04 Thread Zhouxuan
On Friday, 4 October 2013 at 08:23:11 UTC, Jacob Carlborg wrote: On 2013-10-04 10:03, Zhouxuan wrote: import std.stdio; class A { static int id = 0; this() { writeln(typeid=, typeid(this)); writeln(id=,typeof(this).id); //how to get runtime type of this ?? } }

Re: How to get runtime type of this?

2013-10-04 Thread Zhouxuan
On Friday, 4 October 2013 at 08:23:11 UTC, Jacob Carlborg wrote: On 2013-10-04 10:03, Zhouxuan wrote: import std.stdio; class A { static int id = 0; this() { writeln(typeid=, typeid(this)); writeln(id=,typeof(this).id); //how to get runtime type of this ?? } }

Re: How to get runtime type of this?

2013-10-04 Thread Dicebot
I am afraid if you want true polymorphic behavior, `id` needs to become a virtual getter function. D runtime reflection is quite lacking in that are.

Re: Ddoc WEB function

2013-10-04 Thread Joseph Rushton Wakeling
On 03/10/13 20:06, Jonathan M Davis wrote: I don't see the problem. If you want the standard set of macros, then look at the docs. If you want more, then add your own. We need more in the Phobos docs, so we define more - many of which wouldn't even make sense as standard macros. I see no reason

Re: How to get runtime type of this?

2013-10-04 Thread Jacob Carlborg
On 2013-10-04 10:42, Zhouxuan wrote: Unfortunately it doesn't work if C inherits from B. What you need is a template constructor in B, just as in A. But it seems it's not possible to forward the template type to the base class. -- /Jacob Carlborg

Re: Conflict between std.file write() and std.stdio write()

2013-10-04 Thread Craig Dillabaugh
On Thursday, 3 October 2013 at 21:58:18 UTC, Jonathan M Davis wrote: On Thursday, October 03, 2013 22:57:22 Craig Dillabaugh wrote: On Thursday, 3 October 2013 at 19:49:07 UTC, Jonathan M Davis wrote: On Thursday, October 03, 2013 20:57:20 Craig Dillabaugh wrote: On Thursday, 3 October

Check for build errors with out actually building?

2013-10-04 Thread Jeremy DeHaan
So, I'm about to start working on a new project, but I want to be able to check for any D build errors without actually building anything. I was wondering if anything like this would be possible.

Re: Check for build errors with out actually building?

2013-10-04 Thread Adam D. Ruppe
If you did dmd -c -o- *.d that'd be as close as you can get (I think). -c means compile only, don't link, and -o- means don't write the object file, so it will skip the final part of building. and *.d of course is the files in your project. Compiling them all at once by putting them all on

Re: Check for build errors with out actually building?

2013-10-04 Thread Jeremy DeHaan
On Friday, 4 October 2013 at 17:49:49 UTC, Jeremy DeHaan wrote: So, I'm about to start working on a new project, but I want to be able to check for any D build errors without actually building anything. I was wondering if anything like this would be possible. I'm dumb. I missed some stuff on

Executable memory

2013-10-04 Thread Alan
Hello! Sorry if I appear to be posting a lot of questions (if you saw my LLVM one, thanks again for the help) I'm trying to throw some things together and learn a lot. So I've been researching compilers and virtual machines recently, I've managed to implement some fairly good front ends and

Re: Executable memory

2013-10-04 Thread Adam D. Ruppe
On Friday, 4 October 2013 at 19:58:54 UTC, Alan wrote: fault) I've seen ways to do this in Linux and Windows in C/C++ but I have no clue where to start with this in D. You can often almost copy+paste code from C into D and get it working. My guess is the C examples use mmap on Linux and

Re: Executable memory

2013-10-04 Thread Adam D. Ruppe
BTW I'm not sure if GC.malloc supports the executable flag or not. A quick search at druntime's source doesn't turn up anything, but maybe I missed it. Regardless though, the operating system functions definitely work and knowing about them are useful anyway since it makes using C examples

Re: Executable memory

2013-10-04 Thread Alan
Interesting... I was not aware of those functions in the D runtime, thanks for the help! Just some simple conditional compile statements will probably do the job!

Re: Executable memory

2013-10-04 Thread Adam D. Ruppe
On Friday, 4 October 2013 at 20:26:35 UTC, Alan wrote: Interesting... I was not aware of those functions in the D runtime Technically, they're part of the operating system. If druntime didn't provide them, you could also just add // copy pasted from msdn extern(Windows) LPVOID VirtualAlloc(

How close can one get to overload parameter names only?

2013-10-04 Thread deed
Simple example: struct Circle { double radius; this(double radius) { this.radius = radius; } this(double diameter) { this.radius = diameter / 2; } } void main() { auto c1 = Circle(radius = 1.0); auto c2 = Circle(diameter = 2.0); assert(c1.radius == c2.radius); }

Re: Executable memory

2013-10-04 Thread Alan
Great! So that's exactly what happens! Does anyone have an example of how to maybe print a character to the string with a system call? I'm on a 64bit intel pentium and running ubuntu linux. Any help is appreciated, thanks again Adam.

Re: Executable memory

2013-10-04 Thread Alan
On Friday, 4 October 2013 at 20:50:09 UTC, Alan wrote: Great! So that's exactly what happens! Does anyone have an example of how to maybe print a character to the string with a system call? I'm on a 64bit intel pentium and running ubuntu linux. Any help is appreciated, thanks again Adam.

Re: Executable memory

2013-10-04 Thread Alan
On Friday, 4 October 2013 at 21:10:30 UTC, Adam D. Ruppe wrote: On Friday, 4 October 2013 at 20:50:09 UTC, Alan wrote: Does anyone have an example of how to maybe print a character to the string with a system call? yeah on Linux the assembly is: string a = hello!; auto sptr = a.ptr;

Re: Executable memory

2013-10-04 Thread Adam D. Ruppe
On Friday, 4 October 2013 at 20:50:09 UTC, Alan wrote: Does anyone have an example of how to maybe print a character to the string with a system call? yeah on Linux the assembly is: string a = hello!; auto sptr = a.ptr; auto slen = a.length; version(D_InlineAsm_X86) asm { // 32 bit

How to add time to Clock.currTime

2013-10-04 Thread JohnnyK
Hi All, I did search but I cannot find it anywhere. All I want to do is add 300 seconds to the output of Clock.currTime. So basically if Clock.currTime equals 2013-Oct-04 17:19:31.3338333 then I want to subtract 300 seconds from that to get the time that it was 300 seconds ago. In other

Re: How to add time to Clock.currTime

2013-10-04 Thread Brad Anderson
On Friday, 4 October 2013 at 21:50:31 UTC, Brad Anderson wrote: On Friday, 4 October 2013 at 21:46:43 UTC, JohnnyK wrote: Hi All, I did search but I cannot find it anywhere. All I want to do is add 300 seconds to the output of Clock.currTime. So basically if Clock.currTime equals

Re: How to add time to Clock.currTime

2013-10-04 Thread Brad Anderson
On Friday, 4 October 2013 at 21:46:43 UTC, JohnnyK wrote: Hi All, I did search but I cannot find it anywhere. All I want to do is add 300 seconds to the output of Clock.currTime. So basically if Clock.currTime equals 2013-Oct-04 17:19:31.3338333 then I want to subtract 300 seconds from

Re: Executable memory

2013-10-04 Thread Adam D. Ruppe
I'm just playing at this point and I'm pretty sure these hacks won't quite work or might even be kinda useless... but one way to avoid the hassle of making the machine code yourself is to get the compiler to do it. So we'll write our function (just 32 bit here, the 64 bit didn't work and I'm

Re: Executable memory

2013-10-04 Thread Alan
On Friday, 4 October 2013 at 22:00:36 UTC, Adam D. Ruppe wrote: I'm just playing at this point and I'm pretty sure these hacks won't quite work or might even be kinda useless... but one way to avoid the hassle of making the machine code yourself is to get the compiler to do it. So we'll

Re: Executable memory

2013-10-04 Thread Alan
On Friday, 4 October 2013 at 22:00:36 UTC, Adam D. Ruppe wrote: I'm just playing at this point and I'm pretty sure these hacks won't quite work or might even be kinda useless... but one way to avoid the hassle of making the machine code yourself is to get the compiler to do it. So we'll

Re: Write to file in a function

2013-10-04 Thread Paul
Wow. I'm really embarrased. But thanks guys. On Wednesday, 2 October 2013 at 21:57:08 UTC, Ali Çehreli wrote: On 10/02/2013 02:44 PM, Paul wrote: I would like to open a file before I enter a function and be able to write to it while I'm in the function. I'm not having any luck. Shared?

Re: How to add time to Clock.currTime

2013-10-04 Thread JohnnyK
On Friday, 4 October 2013 at 21:54:19 UTC, Brad Anderson wrote: On Friday, 4 October 2013 at 21:50:31 UTC, Brad Anderson wrote: On Friday, 4 October 2013 at 21:46:43 UTC, JohnnyK wrote: Hi All, I did search but I cannot find it anywhere. All I want to do is add 300 seconds to the output of

Re: How to add time to Clock.currTime

2013-10-04 Thread Jonathan M Davis
On Saturday, October 05, 2013 03:31:33 JohnnyK wrote: Wow I appreciate the quick response. Ok I have seen this before. What is the dur? Where is dur defined? Also I am confused how 300.seconds would work. How can a literal number have properties? dur is in core.time as are the aliases for each

Re: Conflict between std.file write() and std.stdio write()

2013-10-04 Thread Jonathan M Davis
On Friday, October 04, 2013 16:12:14 Craig Dillabaugh wrote: I guess the more fundamental question is, what is the purpose of the documentation? Is it a quick reference for D users, or is it a resource for people trying to learn the language? I learned C++ using Qt, largely from their online

Re: How to add time to Clock.currTime

2013-10-04 Thread Jesse Phillips
On Saturday, 5 October 2013 at 01:31:35 UTC, JohnnyK wrote: Wow I appreciate the quick response. Ok I have seen this before. What is the dur? Where is dur defined? Also I am confused how 300.seconds would work. How can a literal number have properties?

Re: How close can one get to overload parameter names only?

2013-10-04 Thread Jonathan M Davis
On Friday, October 04, 2013 22:40:35 deed wrote: Simple example: struct Circle { double radius; this(double radius) { this.radius = radius; } this(double diameter) { this.radius = diameter / 2; } } void main() { auto c1 = Circle(radius = 1.0); auto c2 = Circle(diameter = 2.0);

UDA usage

2013-10-04 Thread Matt Soucy
So, I was away from active D development for a while, and I'm having trouble finding info about how to use UDAs. I can see the basics, like how to apply a UDA to a symbol, but now how to do specific things, like: * Check to see if a specific attribute exists * Check to see if an attribute of a

Re: UDA usage

2013-10-04 Thread Adam D. Ruppe
On Saturday, 5 October 2013 at 02:51:21 UTC, Matt Soucy wrote: * Check to see if a specific attribute exists * Check to see if an attribute of a specific type exists, something like: The helper functions from my web.d might help: // checks to see if it has one of a type // static

Re: UDA usage

2013-10-04 Thread Matt Soucy
On 10/04/2013 11:04 PM, Adam D. Ruppe wrote: On Saturday, 5 October 2013 at 02:51:21 UTC, Matt Soucy wrote: * Check to see if a specific attribute exists * Check to see if an attribute of a specific type exists, something like: The helper functions from my web.d might help: // checks to