static this not run?

2017-09-29 Thread Nicholas Wilson via Digitalmars-d-learn
I want a module level initialised delegate. if I try module foo; enum Status { success, } class StatusException : Exception { Status s; // usual exception constructors } void delegate(Status) onError = (Status s) { throw new StatusException(s);}; I get a error like cannot initi

AliasSeq of T.tupleof for class and all base classes

2017-09-29 Thread bitwise via Digitalmars-d-learn
As far as I can tell, this code should compile: class B { int a; } class D1 : B { int b; } class D2 : D1 { int c; } template TupleOf(Classes...) { static if(Classes.length > 1) alias TupleOf = AliasSeq!(Classes[0].tupleof, TupleOf!(Classes[1..$])); else static if(Classes

Re: problem with opIndex

2017-09-29 Thread Ilya Yaroshenko via Digitalmars-d-learn
On Friday, 29 September 2017 at 19:31:14 UTC, Joseph wrote: I am trying to have a multi-dimensional array and opIndex has to have both an arbitrary number of parameters and allow for slicing. You may want to look into ndslice package source code [1] --Ilya [1] https://github.com/libmir/mir-a

Re: Creating a dynamic library

2017-09-29 Thread Tony via Digitalmars-d-learn
On Saturday, 30 September 2017 at 01:02:08 UTC, Elronnd wrote: dmd bla.d bla2.d -shared -fPIC -oflibbla.so Thanks. I don't normally compile right into a .so, but I think this is OK: dmd my_file.o my_other_file.o -shared -of=libutest.so One thing I picked up from SCons is creating dynami

Re: Creating a dynamic library

2017-09-29 Thread Elronnd via Digitalmars-d-learn
dmd bla.d bla2.d -shared -fPIC -oflibbla.so

Creating a dynamic library

2017-09-29 Thread Tony via Digitalmars-d-learn
I would like to know that command line (I am on Linux) I would use to compile a D file and create an object file that is suitable for a Linux dynamic library (.so). I believe it is probably dmd -c -fPIC my_file.d Also, what is the command line to create a dynamic library from one or more obj

Re: Is it possible to specify the address returned by the address of operator?

2017-09-29 Thread Mengu via Digitalmars-d-learn
On Friday, 29 September 2017 at 02:34:08 UTC, DreadKyller wrote: On Thursday, 28 September 2017 at 14:01:33 UTC, user1234 wrote: [...] I understand that, but because the operator isn't defined normally for classes unless overloaded, then your statement about this being an inconsistency on th

Region-based memory management and GC?

2017-09-29 Thread Jon Degenhardt via Digitalmars-d-learn
Have there been any investigations into using region-based memory management (aka memory arenas) in D, possibly in conjunction with GC allocated memory? This would be a very speculative idea, but it'd be interesting to know if there have been looks at this area. My own interest is request-resp

Re: Is prime missing in photos?

2017-09-29 Thread Elronnd via Digitalmars-d-learn
Well the purpose of the exercise kind of *is* to write a prime number generator. You can look up prime number sieves and algorithms. For REALLY large numbers, that takes an insane amount of time, and you can instead use algorithms such as the ones outlined at https://csrc.nist.gov/csrc/media

Is prime missing in photos?

2017-09-29 Thread Andre Pany via Digitalmars-d-learn
Hi, Does Phobos have an isPrime function? I cannot find it in the library. I currently have a look at projecteuler.net problem no 7. Such a function makes it a lot easier to solve the problem. https://projecteuler.net/problem=7 Kind regards Andre

Re: dub cross compilation binary extension

2017-09-29 Thread Andre Pany via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 04:08:39 UTC, Joakim wrote: On Tuesday, 26 September 2017 at 17:48:06 UTC, Andre Pany wrote: Hi, I had set up a cross compilation from Windows to Raspberry Pi using LDC and GCC toolchain. Almost everything is working fine. Dub creates a binary which is runna

Re: problem with opIndex

2017-09-29 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Sep 29, 2017 at 07:31:14PM +, Joseph via Digitalmars-d-learn wrote: > I am trying to have a multi-dimensional array and opIndex has to have > both an arbitrary number of parameters and allow for slicing. > > The problem is if I create opIndex for non-slicing, it looks like > > ref aut

Re: Allocating byte aligned array

2017-09-29 Thread Igor via Digitalmars-d-learn
On Wednesday, 27 September 2017 at 21:48:35 UTC, timvol wrote: On Wednesday, 27 September 2017 at 21:44:48 UTC, Ali Çehreli wrote: On 09/27/2017 02:39 PM, timvol wrote: [...] void main() { auto mem = new ubyte[1024+15]; auto ptr = cast(ubyte*)(cast(ulong)(mem.ptr + 15) & ~0x0FUL);

problem with opIndex

2017-09-29 Thread Joseph via Digitalmars-d-learn
I am trying to have a multi-dimensional array and opIndex has to have both an arbitrary number of parameters and allow for slicing. The problem is if I create opIndex for non-slicing, it looks like ref auto opIndex(T...)(T index) and this one catches all templates. But slices do not return the

Re: Detect if variable defined

2017-09-29 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/29/17 2:03 PM, Joseph wrote: static if () {  enum x; } static if (isDefined!x) { } What's the correct way to check if a variable has been defined? (note x may or may not be defined above. I need to know if it is) Check to see that it has a type: static if(is(typeof(x))) { } -Steve

Re: opDollar any

2017-09-29 Thread Ali Çehreli via Digitalmars-d-learn
On 09/29/2017 11:34 AM, Joseph wrote: Trying to do multi-dimension array but op-dollar doesn't seem to support arbitrary dimensions @property int opDollar(size_t dim : k)() { return dims[k]; } It's called by multi-dimensional opIndex (or opSlice and perhaps others?; can be very complicate

Re: Detect if variable defined

2017-09-29 Thread arturg via Digitalmars-d-learn
On Friday, 29 September 2017 at 18:03:52 UTC, Joseph wrote: static if () { enum x; } static if (isDefined!x) { } What's the correct way to check if a variable has been defined? (note x may or may not be defined above. I need to know if it is) import std.traits; static if(hasMember!(T, "x")

opDollar any

2017-09-29 Thread Joseph via Digitalmars-d-learn
Trying to do multi-dimension array but op-dollar doesn't seem to support arbitrary dimensions @property int opDollar(size_t dim : k)() { return dims[k]; }

Detect if variable defined

2017-09-29 Thread Joseph via Digitalmars-d-learn
static if () { enum x; } static if (isDefined!x) { } What's the correct way to check if a variable has been defined? (note x may or may not be defined above. I need to know if it is)

Re: Day of week from date

2017-09-29 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, September 29, 2017 14:34:04 aberba via Digitalmars-d-learn wrote: > On Friday, 29 September 2017 at 03:42:18 UTC, Jonathan M Davis > > wrote: > > On Friday, September 29, 2017 04:32:44 rikki cattermole via > > > > Digitalmars-d- learn wrote: > >> On 29/09/2017 4:25 AM, Joel wrote: > >> >

Re: Day of week from date

2017-09-29 Thread aberba via Digitalmars-d-learn
On Friday, 29 September 2017 at 03:42:18 UTC, Jonathan M Davis wrote: On Friday, September 29, 2017 04:32:44 rikki cattermole via Digitalmars-d- learn wrote: On 29/09/2017 4:25 AM, Joel wrote: > With a given date, I want to know what day it is (like > Sunday, Monday, > etc). > > I had a look u