Re: what's wrong with my class?

2016-05-04 Thread Jonathan Villa via Digitalmars-d-learn
On Thursday, 5 May 2016 at 00:03:34 UTC, Brian Schott wrote: On Wednesday, 4 May 2016 at 23:19:08 UTC, Jonathan Villa wrote: What I'm doing wrong? :< All right. D's type system is marking the `Session` constructor as `shared`. This makes the check `static if

Re: what's wrong with my class?

2016-05-04 Thread Brian Schott via Digitalmars-d-learn
On Wednesday, 4 May 2016 at 23:19:08 UTC, Jonathan Villa wrote: What I'm doing wrong? :< All right. D's type system is marking the `Session` constructor as `shared`. This makes the check `static if (is(typeof(result.__ctor(args` in std.conv.emplace fail because `result` is a non-shared

Re: what's wrong with my class?

2016-05-04 Thread Brian Schott via Digitalmars-d-learn
On Wednesday, 4 May 2016 at 23:34:52 UTC, Jonathan Villa wrote: On Wednesday, 4 May 2016 at 23:33:28 UTC, Brian Schott wrote: On Wednesday, 4 May 2016 at 23:19:08 UTC, Jonathan Villa wrote: What I'm doing wrong? :< I see that the types of `id_user` aren't necessarily the same between

Re: what's wrong with my class?

2016-05-04 Thread Jonathan Villa via Digitalmars-d-learn
On Wednesday, 4 May 2016 at 23:33:28 UTC, Brian Schott wrote: On Wednesday, 4 May 2016 at 23:19:08 UTC, Jonathan Villa wrote: What I'm doing wrong? :< I see that the types of `id_user` aren't necessarily the same between `create` and `this`. Oh, they are indeed same (alias). I wrote uint

Re: what's wrong with my class?

2016-05-04 Thread Brian Schott via Digitalmars-d-learn
On Wednesday, 4 May 2016 at 23:19:08 UTC, Jonathan Villa wrote: What I'm doing wrong? :< I see that the types of `id_user` aren't necessarily the same between `create` and `this`.

what's wrong with my class?

2016-05-04 Thread Jonathan Villa via Digitalmars-d-learn
... import std.experimental.allocator : make, dispose; import std.experimental.allocator.mallocator : Mallocator; public synchronized class Session { private: ASI parent; cUser user; public: static Session create(ASI _parent, accounts.user.id_user_t id_user)

template auto instantiation when parameters empty

2016-05-04 Thread Erik Smith via Digitalmars-d-learn
I want to have a struct template auto instantiate when the template parameters are defaulted or missing. Example: struct Resource(T=int) { static auto create() {return Resource(null);} this(string s) {} } auto resource = Resource.create; As a plain struct it works, but not as a

Re: Strange stack variable corruption error after calling extern(C) function

2016-05-04 Thread cc via Digitalmars-d-learn
On Wednesday, 4 May 2016 at 09:40:55 UTC, Benjamin Thaut wrote: On Tuesday, 3 May 2016 at 19:06:30 UTC, cc wrote: it fails to link with "Error 42: Symbol Undefined _FMOD_System_CreateSound@20". With extern(C) it compiles and runs but the problem from above persists. Is this on Windows

Re: Accepting function or delegate as function argument

2016-05-04 Thread Rene Zwanenburg via Digitalmars-d-learn
On Wednesday, 4 May 2016 at 14:54:39 UTC, chmike wrote: Two constructors, one accepting a function and the other one accepting a delegate would do the job for the API. Is there a simple method to convert a function pointer into a delegate pointer that is also efficient ?

Re: Accepting function or delegate as function argument

2016-05-04 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 4 May 2016 at 14:54:39 UTC, chmike wrote: Two constructors, one accepting a function and the other one accepting a delegate would do the job for the API. Is there a simple method to convert a function pointer into a delegate pointer that is also efficient ? Do the overload and

Accepting function or delegate as function argument

2016-05-04 Thread chmike via Digitalmars-d-learn
I have implemented the following class (simplified ;) ) class Foo(K,T) { this(T delegate (K) factory) { m_factory = factory; } T delegate (K) m_factory; T bar(K key) { return m_factory(key); } } string dummyFactory(string key) { return "Hello "~key; } void main() { auto

Re: Code example for function/delegate as template argument ?

2016-05-04 Thread chmike via Digitalmars-d-learn
Thank you Basile and Teoh.

Re: Code example for function/delegate as template argument ?

2016-05-04 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 4 May 2016 at 11:19:59 UTC, chmike wrote: I think you misunderstood the second question. Here is another attempt with an example. // function accepting a function as argument void foo(function void fg(int)) { fg(5); } // A class with a none static method with the same

Re: Code example for function/delegate as template argument ?

2016-05-04 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 04, 2016 at 06:21:36AM +, chmike via Digitalmars-d-learn wrote: > Hello, > > I failed to find some code example for a template class/struct that > accept a function/delegate as template argument. All examples I could > find use simple value types like int or double. The usual way

Re: Code example for function/delegate as template argument ?

2016-05-04 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 4 May 2016 at 10:58:04 UTC, chmike wrote: On Wednesday, 4 May 2016 at 06:59:00 UTC, Basile B. wrote: . . . void main(string[] args) { alias fun = (a) => a.writeln; auto foo = Foo!fun("hello"); } Is this equivalent to Foo!(a => a.writeln) or is it required to split this

Re: Code example for function/delegate as template argument ?

2016-05-04 Thread chmike via Digitalmars-d-learn
I think you misunderstood the second question. Here is another attempt with an example. // function accepting a function as argument void foo(function void fg(int)) { fg(5); } // A class with a none static method with the same signature as the argument function of foo class Bar {

Re: Code example for function/delegate as template argument ?

2016-05-04 Thread chmike via Digitalmars-d-learn
On Wednesday, 4 May 2016 at 06:59:00 UTC, Basile B. wrote: . . . void main(string[] args) { alias fun = (a) => a.writeln; auto foo = Foo!fun("hello"); } Is this equivalent to Foo!(a => a.writeln) or is it required to split this in two instructions as you did ? I also thought the

Re: What can cause error: Previous Definition Different

2016-05-04 Thread Suliman via Digitalmars-d-learn
On Wednesday, 4 May 2016 at 10:01:54 UTC, Suliman wrote: After some minor modification of my code I begun to get error: Error 1: Previous Definition Different : _D3app14onlinetestdataFC4vibe4http6server17HTTPServerRequestC4vibe4http6server18HTTPServerResponseZv Here is my code:

What can cause error: Previous Definition Different

2016-05-04 Thread Suliman via Digitalmars-d-learn
After some minor modification of my code I begun to get error: Error 1: Previous Definition Different : _D3app14onlinetestdataFC4vibe4http6server17HTTPServerRequestC4vibe4http6server18HTTPServerResponseZv Here is my code: https://gist.github.com/bubnenkoff/db0632bb14eebb7690b6563c47395831

Re: ubyte[] -> immutable(ubyte)[]

2016-05-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/3/16 5:31 PM, vino wrote: On Friday, 10 September 2010 at 15:15:38 UTC, Andrej Mitrovic wrote: Yeah, one would think the destination is on the left (just like the standard C way of doing it), but it's not. I checked it in the docs and the source. And idup works, thanks. Kagamin Wrote:

Re: Strange stack variable corruption error after calling extern(C) function

2016-05-04 Thread Benjamin Thaut via Digitalmars-d-learn
On Tuesday, 3 May 2016 at 19:06:30 UTC, cc wrote: it fails to link with "Error 42: Symbol Undefined _FMOD_System_CreateSound@20". With extern(C) it compiles and runs but the problem from above persists. Is this on Windows x64? Try replacing FMOD_RESULT by int. When declaring the fmod

Re: Stacktraces in static constructors

2016-05-04 Thread Benjamin Thaut via Digitalmars-d-learn
On Wednesday, 4 May 2016 at 06:37:28 UTC, Nordlöw wrote: On Tuesday, 3 May 2016 at 12:31:10 UTC, Benjamin Thaut wrote: I assume this is on windows? Yes its a known issue (I know No, the problem occurs on my Linux aswell. From core.runtime: static this() { // NOTE: Some module ctors

Re: Code example for function/delegate as template argument ?

2016-05-04 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 4 May 2016 at 06:21:36 UTC, chmike wrote: Hello, I failed to find some code example for a template class/struct that accept a function/delegate as template argument. All examples I could find use simple value types like int or double. I piggy bag another question. Defining a

Re: Code example for function/delegate as template argument ?

2016-05-04 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 4 May 2016 at 06:21:36 UTC, chmike wrote: Hello, I failed to find some code example for a template class/struct that accept a function/delegate as template argument. All examples I could find use simple value types like int or double. I piggy bag another question. Defining a

Re: Stacktraces in static constructors

2016-05-04 Thread Nordlöw via Digitalmars-d-learn
On Tuesday, 3 May 2016 at 12:31:10 UTC, Benjamin Thaut wrote: I assume this is on windows? Yes its a known issue (I know No, the problem occurs on my Linux aswell.

Code example for function/delegate as template argument ?

2016-05-04 Thread chmike via Digitalmars-d-learn
Hello, I failed to find some code example for a template class/struct that accept a function/delegate as template argument. All examples I could find use simple value types like int or double. I piggy bag another question. Defining a function/delegate as function argument is shown in