Re: Windows SetConsoleScreenBufferSize() returning an odd error code

2013-10-10 Thread webwraith
On Saturday, 5 October 2013 at 21:33:32 UTC, Andrej Mitrovic wrote: On 10/5/13, webwraith webwra...@fastmail.fm wrote: I don't know about you, but it's beginning to look to me like SetConsoleScreenBufferSize() takes pixels as its unit of measurement, and not columns and rows, as is stated in

Re: mutable, const, immutable guidelines

2013-10-10 Thread Daniel Davidson
On Wednesday, 9 October 2013 at 23:05:27 UTC, qznc wrote: On Wednesday, 9 October 2013 at 15:50:55 UTC, Daniel Davidson wrote: void foo(const(MutableType) mt); void foo(immutable(MutableType) mt); Naturally the inclination is to choose the second as it is a stronger guarantee that no threads

fill array using a lambda function

2013-10-10 Thread dominic jones
Hello, I want to fill an array with random numbers without resorting to loops, i.e. by doing something like the following, if it were possible: fill!(function double(){ return uniform(0.0, 1.0);})(x[]); Is there a simple way of doing this? Thank you, Dominic Jones P.S. I am aware of the

Re: fill array using a lambda function

2013-10-10 Thread bearophile
dominic jones: I want to fill an array with random numbers without resorting to loops, i.e. by doing something like the following, if it were possible: fill!(function double(){ return uniform(0.0, 1.0);})(x[]); Is there a simple way of doing this? Generally it's a good idea to use only

Call a function with a function pointer

2013-10-10 Thread Namespace
I have this function: void foo(T)(void function(T*) test) { } And want to call it with a C function: foo!(SDL_Surface)(SDL_FreeSurface); but I get: Fehler 1 Error: foo (void function(SDL_Surface*) test) is not callable using argument types (extern (C) void

Re: Call a function with a function pointer

2013-10-10 Thread Dicebot
On Thursday, 10 October 2013 at 14:13:47 UTC, Namespace wrote: I have this function: void foo(T)(void function(T*) test) { } And want to call it with a C function: foo!(SDL_Surface)(SDL_FreeSurface); but I get: Fehler 1 Error: foo (void function(SDL_Surface*) test) is not

Re: Call a function with a function pointer

2013-10-10 Thread Benjamin Thaut
Am 10.10.2013 16:13, schrieb Namespace: I have this function: void foo(T)(void function(T*) test) { } And want to call it with a C function: foo!(SDL_Surface)(SDL_FreeSurface); but I get: Fehler1Error: foo (void function(SDL_Surface*) test) is not callable using

Re: Call a function with a function pointer

2013-10-10 Thread Dicebot
On Thursday, 10 October 2013 at 14:40:09 UTC, Namespace wrote: Example? I do not use lambdas often. void foo(T)(void function(T*) test) { } extern(C) void bar(int*) { } void main() { foo( (int* a) = bar(a) ); } I don't know to what extent IFTI can work here though.

Re: Call a function with a function pointer

2013-10-10 Thread Namespace
On Thursday, 10 October 2013 at 14:28:20 UTC, Dicebot wrote: On Thursday, 10 October 2013 at 14:13:47 UTC, Namespace wrote: I have this function: void foo(T)(void function(T*) test) { } And want to call it with a C function: foo!(SDL_Surface)(SDL_FreeSurface); but I get:

Re: Call a function with a function pointer

2013-10-10 Thread Namespace
On Thursday, 10 October 2013 at 14:44:00 UTC, Dicebot wrote: On Thursday, 10 October 2013 at 14:40:09 UTC, Namespace wrote: Example? I do not use lambdas often. void foo(T)(void function(T*) test) { } extern(C) void bar(int*) { } void main() { foo( (int* a) = bar(a) ); } I don't

Re: Call a function with a function pointer

2013-10-10 Thread Namespace
On Thursday, 10 October 2013 at 15:15:45 UTC, bearophile wrote: Namespace: You mean like this? void foo(T)(extern(C) void function(T*) func) { } That prints: Error: basic type expected, not extern In theory that's correct, in practice the compiler refuses

Re: Call a function with a function pointer

2013-10-10 Thread bearophile
Namespace: /d917/f732.d(8): Error: basic type expected, not extern /d917/f732.d(8): Error: semicolon expected to close alias declaration /d917/f732.d(8): Error: no identifier for declarator void function(T*) It seems that even the new alias syntax doesn't support the extern :-) Perhaps

Re: Call a function with a function pointer

2013-10-10 Thread Dicebot
On Thursday, 10 October 2013 at 15:15:45 UTC, bearophile wrote: Namespace: You mean like this? void foo(T)(extern(C) void function(T*) func) { } That prints: Error: basic type expected, not extern In theory that's correct, in practice the compiler refuses

How to check for instantiation of specific template?

2013-10-10 Thread H. S. Teoh
I have a template used for storing compile-time values: template Def(int x, string y) { alias impl = TypeTuple!(x,y); } How do I define a template isDef that, given some template alias A, evaluates to true if A is some instantiation of Def? template

Re: Call a function with a function pointer

2013-10-10 Thread Namespace
import std.stdio; void foo1(void function(void*) fp) { } void foo2(void function(int) fp) { } void foo3(void*) { } void main() { foo1((void* ptr) = ( assert(ptr is null) )); foo2((int a) = ( a + 1 )); /// Fails: Error: function foo2 (void function(int) fp) is not callable using

Re: How to check for instantiation of specific template?

2013-10-10 Thread Simen Kjaeraas
On 2013-10-10, 19:23, H. S. Teoh wrote: I have a template used for storing compile-time values: template Def(int x, string y) { alias impl = TypeTuple!(x,y); } How do I define a template isDef that, given some template alias A, evaluates to true if A is some

Re: fill array using a lambda function

2013-10-10 Thread Simen Kjaeraas
On 2013-10-10, 16:04, bearophile wrote: dominic jones: I want to fill an array with random numbers without resorting to loops, i.e. by doing something like the following, if it were possible: fill!(function double(){ return uniform(0.0, 1.0);})(x[]); Is there a simple way of doing this?

Re: fill array using a lambda function

2013-10-10 Thread bearophile
Simen Kjaeraas: You've got the order wrong - copy takes first the source, then the target. I'd like it to be (re)named copyTo to avoid me such common mistake. Bye, bearophile

Re: mutable, const, immutable guidelines

2013-10-10 Thread Christian Köstlin
On 10/10/13 1:05 , qznc wrote: Very interesting discussion! contract between caller and callee. If an argument is const, it means the callee says he can handle others changing the state concurrently. i think what the usual understanding of const for an argument to callee is, what is written

Re: Call a function with a function pointer

2013-10-10 Thread Dicebot
On Thursday, 10 October 2013 at 17:47:54 UTC, Namespace wrote: import std.stdio; void foo1(void function(void*) fp) { } void foo2(void function(int) fp) { } void foo3(void*) { } void main() { foo1((void* ptr) = ( assert(ptr is null) )); foo2((int a) = ( a + 1 )); /// Fails:

Begining with D

2013-10-10 Thread Alejandro
Hi I'm new in D, have some experience in JavaScript and PHP, and learned, for long time ago, C and a bit little C++ I remember that when I learned C with console output, it was two easy ways to catch input : one witch a required Enter keydown, and an other witch catched a single character,

Re: Begining with D

2013-10-10 Thread Ali Çehreli
On 10/10/2013 11:56 AM, Alejandro wrote: catched a single character, a single keydown The following program is based on the following newsgroup post: http://forum.dlang.org/post/mailman.2665.1300747084.4748.digitalmars-d-le...@puremagic.com The program prints character codes in hex until it

Re: Starting D with a project in mind.

2013-10-10 Thread Adam D. Ruppe
On Thursday, 10 October 2013 at 19:49:15 UTC, Andrew wrote: Hence my interest in D. I've spent a few hours trying to get GDC working on my Pi which is proving to be a bitch but I'm hoping that it will be worth it. I haven't done a serious program on the Pi, but I was able to get gdc and some

Re: How to check for instantiation of specific template?

2013-10-10 Thread simendsjo
On Thursday, 10 October 2013 at 17:24:37 UTC, H. S. Teoh wrote: I have a template used for storing compile-time values: template Def(int x, string y) { alias impl = TypeTuple!(x,y); } How do I define a template isDef that, given some template alias A,

Re: Call a function with a function pointer

2013-10-10 Thread Andrej Mitrovic
On 10/10/13, bearophile bearophileh...@lycos.com wrote: Perhaps this bug is not yet in Bugzilla. I'm pretty sure I saw it filed somewhere. Can't find it though..

Re: Call a function with a function pointer

2013-10-10 Thread bearophile
Andrej Mitrovic: I'm pretty sure I saw it filed somewhere. Can't find it though.. I have just added the new test case :-) http://d.puremagic.com/issues/show_bug.cgi?id=6754 Bye, bearophile

Re: Starting D with a project in mind.

2013-10-10 Thread qznc
On Thursday, 10 October 2013 at 19:49:15 UTC, Andrew wrote: Hi All, I've been writing a MUD for a little while, initially using Haskell but now using C. I develop on MacOS X but deploy to a Raspberry Pi. I loved using Haskell especially using the Parsec parser but unfortunately I couldn't

how to handle memory ownership when interfacing with C/C++ via internal pointers

2013-10-10 Thread Timothee Cour
Short version: I have a struct A* aptr allocated in C/C++ with an internal pointer aptr-ptr (say a double*) I want to store a reference x (say double[]) in D to aptr only through aptr-ptr, not through aptr directly as it's inconvenient in my use case. How do I achieve that, so that when x goes

Re: mutable, const, immutable guidelines

2013-10-10 Thread qznc
On Wednesday, 9 October 2013 at 04:31:55 UTC, Ali Çehreli wrote: On 10/08/2013 03:12 PM, qznc wrote: On Monday, 7 October 2013 at 17:57:11 UTC, Ali Çehreli wrote: To look at just one usage example, the following line carries two requirements: auto a = T(); immutable b = a; 1) b

Re: mutable, const, immutable guidelines

2013-10-10 Thread qznc
On Thursday, 10 October 2013 at 18:39:32 UTC, Christian Köstlin wrote: On 10/10/13 1:05 , qznc wrote: Very interesting discussion! contract between caller and callee. If an argument is const, it means the callee says he can handle others changing the state concurrently. i think what the usual

Re: mutable, const, immutable guidelines

2013-10-10 Thread Daniel Davidson
On Thursday, 10 October 2013 at 23:06:23 UTC, qznc wrote: Maybe the fact that D allows this implicit copy to immutable is the problem? If one could require the use of a specific function, this function could be overridden with working behavior. The following code works. Yes - the issue

Re: mutable, const, immutable guidelines

2013-10-10 Thread Joseph Rushton Wakeling
On 11/10/13 01:43, Daniel Davidson wrote: That is probably a reasonable interpretation... but I think it will only get you pain. The fact is, regardless of your interpretation of const arguments - the general guideline is prefer const because immutables and mutables can be passed in. Which

Re: Traits

2013-10-10 Thread Ali Çehreli
On 10/10/2013 09:13 PM, Agustin wrote: I have a function that needs to check if the template provided inherit a class. For example: public void function(T, A...)(auto ref A values) function happens to be a keyword. :) { // static assert(IsBaseOf(L, T)); } Check if T inherit class

Re: Traits

2013-10-10 Thread Jonathan M Davis
On Thursday, October 10, 2013 21:35:37 Ali Çehreli wrote: One of the uses of the is expression determines whether implicitly convertible to. It may work for you: public void foo(T, A...)(auto ref A values) { static assert(is (T : L)); } Actually, checking for implicit conversion will

Re: Traits

2013-10-10 Thread luminousone
On Friday, 11 October 2013 at 04:13:55 UTC, Agustin wrote: I have a function that needs to check if the template provided inherit a class. For example: public void function(T, A...)(auto ref A values) { // static assert(IsBaseOf(L, T)); } Check if T inherit class L. Same result that