Re: fast floor

2013-10-10 Thread monarch_dodra
On Thursday, 10 October 2013 at 22:27:14 UTC, Spacen Jasset wrote: Hello, I am after a fast floor function; In fact a fast truncation and conversion to integer. I see that std.math takes a real, and that std.c.math takes a double. Is there a quicker function, and what might cast(int)1.5f do?

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 std:

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 convers

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 inh

Traits

2013-10-10 Thread Agustin
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 std::is_base_ofT>::value using C++. Any clean way to do it, witho

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: mutable, const, immutable guidelines

2013-10-10 Thread Daniel Davidson
On Thursday, 10 October 2013 at 23:12:24 UTC, qznc wrote: The linked page clearly says "It may, however, be changed by another reference to that same data." usually you would think that no one else should change the data while callee runs. but at least with c++ i could imagine running callee

Re: mutable, const, immutable guidelines

2013-10-10 Thread Joseph Rushton Wakeling
On 09/10/13 17:50, Daniel Davidson wrote: Take, for example, LinearCongruentialEngine from random.d. It has a function: bool opEquals(ref const LinearCongruentialEngine rhs) const Why is it using const here instead of immutable? Among other things, because no LinearCongruentialEngine wil

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 aris

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 usua

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

Re: fast floor

2013-10-10 Thread Joseph Rushton Wakeling
On 11/10/13 00:27, Spacen Jasset wrote: I am after a fast floor function; In fact a fast truncation and conversion to integer. I see that std.math takes a real, and that std.c.math takes a double. Is there a quicker function, and what might cast(int)1.5f do? What's wrong with to!int(floor

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 o

fast floor

2013-10-10 Thread Spacen Jasset
Hello, I am after a fast floor function; In fact a fast truncation and conversion to integer. I see that std.math takes a real, and that std.c.math takes a double. Is there a quicker function, and what might cast(int)1.5f do? Regards, Spacen.

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 bui

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: Call a function with a function pointer

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

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, evaluates

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

Starting D with a project in mind.

2013-10-10 Thread Andrew
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 build on the Pi because the resource requirements were just too

Re: Begining with D

2013-10-10 Thread Adam D. Ruppe
On Thursday, 10 October 2013 at 19:19:53 UTC, Ali Çehreli wrote: import std.c.linux.termios; worth noting that this is Linux only. doing it on Windows is a little different. Working with console/terminal input and output can get surprisingly complex, and doing it cross-platform is easiest w

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

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 keydown, and an other witch catched a single character, a sin

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: Erro

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: 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: 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: 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 ins

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

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 isDef(

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 this

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 tha

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 tha

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 kn

Re: Call a function with a function pointer

2013-10-10 Thread bearophile
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 that, it's in Bugzilla, so try to define the type outside the signat

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: Fe

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:26:37 UTC, Benjamin Thaut wrote: 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: Fehler1Err

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 argu

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 c

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 function(SDL_Surf

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 p

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: 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 a

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 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 its documentation. I don