delegates, functions, and literals confusion

2013-07-03 Thread CJS
Confusion over delegates seems to be a somewhat common topic, judging from http://forum.dlang.org/thread/jbkahhlvevgectisd...@forum.dlang.org and http://stackoverflow.com/questions/6431884/function-and-delegate-literals-in-d. I'm also somewhat confused by functions vs. function literals and h

std.conv.to vs. casting

2013-07-03 Thread CJS
I'm having trouble understanding the difference between casting and std.conv.to. Any help?

Re: reading a structure (eg header info) from file

2013-07-03 Thread Jonathan M Davis
On Wednesday, July 03, 2013 15:37:28 captaindet wrote: > hi, > > whilst converting some of my C code into D i got stuck. > > in C: > > typedef struct { /* info */ } INFO; > INFO info; > size_t checkio; > // read INFO from data file: > pf_datafile = fopen("datafile","rb"); > checkio = fread((char

Re: reading a structure (eg header info) from file

2013-07-03 Thread Ali Çehreli
On 07/03/2013 01:37 PM, captaindet wrote: > in C: > > typedef struct { /* info */ } INFO; > INFO info; > size_t checkio; > // read INFO from data file: > pf_datafile = fopen("datafile","rb"); > checkio = fread((char *) &info, sizeof(info), 1, pf_datafile); Just a reminder: The operation above is

Re: reading a structure (eg header info) from file

2013-07-03 Thread Rikki Cattermole
On Wednesday, 3 July 2013 at 20:37:24 UTC, captaindet wrote: hi, whilst converting some of my C code into D i got stuck. in C: typedef struct { /* info */ } INFO; INFO info; size_t checkio; // read INFO from data file: pf_datafile = fopen("datafile","rb"); checkio = fread((char *) &info, sizeo

inverse of std.demangle?

2013-07-03 Thread Timothee Cour
I'd like to have a function: string mangle(string mangled_string); unittest{ void foo(int x){} assert(foo.mangleof.demangle.mangle == foo.mangleof); } is there such a functionality, even partially?

Re: Can't print inout parameter

2013-07-03 Thread gerleim
inout(int) foo (inout int a) { writeln(a); return a; } I don't know if this is the official method, but writeln(cast(const)x); works. Trying to get answers at: http://stackoverflow.com/questions/17460065/how-to-print-inout-parameters

stdout in binary mode

2013-07-03 Thread bearophile
How do you open stdout in binary mode with D/Phobos? In C++ you use something like: setmode(fileno(stdout), O_BINARY); (I don't even know where to find O_BINARY in core.stdc). Bye and thank you, bearophile

Re: Address of overloaded functions

2013-07-03 Thread Tyro[17]
On 7/3/13 12:52 PM, Artur Skawina wrote: import std.stdio; void foo(int a){ writeln("overload int"); } void foo(long b){ writeln("overload long"); } auto pickOverload(alias FP, A...)() @property { typeof(FP(A.init)) function(A) fp = &FP; return fp;} void main() { a

Re: Address of overloaded functions

2013-07-03 Thread Artur Skawina
On 07/03/13 22:44, H. S. Teoh wrote: > On Wed, Jul 03, 2013 at 10:10:08PM +0200, Artur Skawina wrote: >> On 07/03/13 21:02, H. S. Teoh wrote: >>> On Wed, Jul 03, 2013 at 06:52:56PM +0200, Artur Skawina wrote: void main() { auto b = pickOverload!(foo, long); >>> >>> Now *

Re: Address of overloaded functions

2013-07-03 Thread H. S. Teoh
On Wed, Jul 03, 2013 at 10:10:08PM +0200, Artur Skawina wrote: > On 07/03/13 21:02, H. S. Teoh wrote: > > On Wed, Jul 03, 2013 at 06:52:56PM +0200, Artur Skawina wrote: > >>void main() > >>{ > >>auto b = pickOverload!(foo, long); > > > > Now *that's* what I call coolness. Self-docu

reading a structure (eg header info) from file

2013-07-03 Thread captaindet
hi, whilst converting some of my C code into D i got stuck. in C: typedef struct { /* info */ } INFO; INFO info; size_t checkio; // read INFO from data file: pf_datafile = fopen("datafile","rb"); checkio = fread((char *) &info, sizeof(info), 1, pf_datafile); how do i do this in D? i'd like to

Re: Address of overloaded functions

2013-07-03 Thread Artur Skawina
On 07/03/13 21:02, H. S. Teoh wrote: > On Wed, Jul 03, 2013 at 06:52:56PM +0200, Artur Skawina wrote: >>void main() >>{ >>auto b = pickOverload!(foo, long); > > Now *that's* what I call coolness. Self-documenting and convenient to > use (though in this case it's arguable whether it

Re: ref tuples

2013-07-03 Thread Artur Skawina
On 07/03/13 19:10, Brad Anderson wrote: > On Wednesday, 3 July 2013 at 16:35:18 UTC, Artur Skawina wrote: >> On 07/03/13 18:29, Brad Anderson wrote: >>> On Wednesday, 3 July 2013 at 11:54:39 UTC, Artur Skawina wrote: On 07/03/13 02:22, Brad Anderson wrote: > C++11's std::tuple includes a f

Re: Error: this for needs to be type S not type MapResult!...

2013-07-03 Thread Michael
On Saturday, 29 June 2013 at 19:44:00 UTC, Peter Neubauer wrote: Please explain why this error happens in the following code: import std.algorithm; struct S { void foo () { int f1 (int a) { return conv(a); } int delegate (int) f2 = &conv; int[] x = [1, 2, 3]; x.map!conv;

Re: Address of overloaded functions

2013-07-03 Thread H. S. Teoh
On Wed, Jul 03, 2013 at 06:52:56PM +0200, Artur Skawina wrote: > On 07/03/13 18:24, H. S. Teoh wrote: > > On Wed, Jul 03, 2013 at 06:07:07PM +0200, Artur Skawina wrote: > >> The context dependence isn't ideal, but what's the alternative?... > > [...] > > > > Explicit syntax for specifying overload

Re: Stop to! rounding?

2013-07-03 Thread H. S. Teoh
On Wed, Jul 03, 2013 at 07:56:28PM +0200, Marco Leise wrote: > Am Tue, 2 Jul 2013 22:21:52 -0700 > schrieb "H. S. Teoh" : > > > On Tue, Jul 02, 2013 at 10:14:33PM -0700, Ali Çehreli wrote: > > [...] > > > import std.stdio; > > > import std.conv; > > > > > > void main() > > > { > > > auto a =

Re: ref tuples

2013-07-03 Thread Simen Kjaeraas
On 2013-07-03, 02:22, Brad Anderson wrote: C++11's std::tuple includes a function std::tie that takes references to the arguments and returns a tuple that maintains the references to the arguments. Along with the usual cases where you'd want reference semantics it also enables this intere

Re: Stop to! rounding?

2013-07-03 Thread Marco Leise
Am Tue, 2 Jul 2013 22:21:52 -0700 schrieb "H. S. Teoh" : > On Tue, Jul 02, 2013 at 10:14:33PM -0700, Ali Çehreli wrote: > [...] > > import std.stdio; > > import std.conv; > > > > void main() > > { > > auto a = to!double("151.42499"); > > writefln("%.60f", a); > > } > > I wouldn't write i

Re: How to get warnings about unused imports ?

2013-07-03 Thread Namespace
You have to parse the unnamed import files, list all their identifiers (global variables, public functions etc.) and search for them. ;) That could be a bit complicated. ;) Therefore I don't want to do it. Even with named imports you can get false positives. But if you like it, you could impro

Re: Ping qznc: Re: A little of coordination for Rosettacode

2013-07-03 Thread Marco Leise
Am Sat, 22 Jun 2013 23:27:00 +0200 schrieb "bearophile" : > Ali Çehreli: > > > The code compiles under 32-bit (e.g. with the -m32 compiler > > switch) where size_t is an alias of uint. > > Oh, I see. I compile most of the code on a 32 bit system. > > I asked Walter to warn d programmers agains

Re: ref tuples

2013-07-03 Thread Brad Anderson
On Wednesday, 3 July 2013 at 16:35:18 UTC, Artur Skawina wrote: On 07/03/13 18:29, Brad Anderson wrote: On Wednesday, 3 July 2013 at 11:54:39 UTC, Artur Skawina wrote: On 07/03/13 02:22, Brad Anderson wrote: C++11's std::tuple includes a function std::tie that takes references to the arguments

Re: Address of overloaded functions

2013-07-03 Thread Artur Skawina
On 07/03/13 18:24, H. S. Teoh wrote: > On Wed, Jul 03, 2013 at 06:07:07PM +0200, Artur Skawina wrote: >> The context dependence isn't ideal, but what's the alternative?... > [...] > > Explicit syntax for specifying overloads? ;-) Not like that would happen > in D, though. Real Programmers need no

Re: ref tuples

2013-07-03 Thread Artur Skawina
On 07/03/13 18:29, Brad Anderson wrote: > On Wednesday, 3 July 2013 at 11:54:39 UTC, Artur Skawina wrote: >> On 07/03/13 02:22, Brad Anderson wrote: >>> C++11's std::tuple includes a function std::tie that takes references to >>> the arguments and returns a tuple that maintains the references to t

Re: ref tuples

2013-07-03 Thread Brad Anderson
On Wednesday, 3 July 2013 at 11:54:39 UTC, Artur Skawina wrote: On 07/03/13 02:22, Brad Anderson wrote: C++11's std::tuple includes a function std::tie that takes references to the arguments and returns a tuple that maintains the references to the arguments. Along with the usual cases where y

Re: Address of overloaded functions

2013-07-03 Thread H. S. Teoh
On Wed, Jul 03, 2013 at 06:07:07PM +0200, Artur Skawina wrote: > On 07/03/13 17:43, H. S. Teoh wrote: > > On Wed, Jul 03, 2013 at 05:41:25PM +0200, Artur Skawina wrote: > >> On 07/03/13 17:27, H. S. Teoh wrote: > >>> On Wed, Jul 03, 2013 at 05:15:48PM +0200, John Colvin wrote: > On Wednesday,

Re: Address of overloaded functions

2013-07-03 Thread Artur Skawina
On 07/03/13 17:43, H. S. Teoh wrote: > On Wed, Jul 03, 2013 at 05:41:25PM +0200, Artur Skawina wrote: >> On 07/03/13 17:27, H. S. Teoh wrote: >>> On Wed, Jul 03, 2013 at 05:15:48PM +0200, John Colvin wrote: On Wednesday, 3 July 2013 at 15:03:46 UTC, Artur Skawina wrote: > On 07/03/13 16:52

Re: Address of overloaded functions

2013-07-03 Thread H. S. Teoh
On Wed, Jul 03, 2013 at 05:41:25PM +0200, Artur Skawina wrote: > On 07/03/13 17:27, H. S. Teoh wrote: > > On Wed, Jul 03, 2013 at 05:15:48PM +0200, John Colvin wrote: > >> On Wednesday, 3 July 2013 at 15:03:46 UTC, Artur Skawina wrote: > >>> On 07/03/13 16:52, John Colvin wrote: > Is there any

Re: Address of overloaded functions

2013-07-03 Thread Artur Skawina
On 07/03/13 17:27, H. S. Teoh wrote: > On Wed, Jul 03, 2013 at 05:15:48PM +0200, John Colvin wrote: >> On Wednesday, 3 July 2013 at 15:03:46 UTC, Artur Skawina wrote: >>> On 07/03/13 16:52, John Colvin wrote: Is there any way to take the address of any of an overloaded set of functions? >

Re: Address of overloaded functions

2013-07-03 Thread H. S. Teoh
On Wed, Jul 03, 2013 at 05:15:48PM +0200, John Colvin wrote: > On Wednesday, 3 July 2013 at 15:03:46 UTC, Artur Skawina wrote: > >On 07/03/13 16:52, John Colvin wrote: > >>Is there any way to take the address of any of an overloaded set > >>of functions? > >> > >>import std.stdio; > >> > >>void foo

Re: Address of overloaded functions

2013-07-03 Thread Artur Skawina
On 07/03/13 17:17, John Colvin wrote: > On Wednesday, 3 July 2013 at 15:05:00 UTC, Dicebot wrote: >> On Wednesday, 3 July 2013 at 14:52:32 UTC, John Colvin wrote: >>> Is there any way to take the address of any of an overloaded set of >>> functions? >>> >>> import std.stdio; >>> >>> void foo(int a

Re: Address of overloaded functions

2013-07-03 Thread John Colvin
On Wednesday, 3 July 2013 at 15:03:46 UTC, Artur Skawina wrote: On 07/03/13 16:52, John Colvin wrote: Is there any way to take the address of any of an overloaded set of functions? import std.stdio; void foo(int a){ writeln("overload int"); } void foo(long b){ writeln("overload long"); } voi

Re: Address of overloaded functions

2013-07-03 Thread John Colvin
On Wednesday, 3 July 2013 at 15:05:00 UTC, Dicebot wrote: On Wednesday, 3 July 2013 at 14:52:32 UTC, John Colvin wrote: Is there any way to take the address of any of an overloaded set of functions? import std.stdio; void foo(int a){ writeln("overload int"); } void foo(long b){ writeln("overl

Re: Address of overloaded functions

2013-07-03 Thread Dicebot
On Wednesday, 3 July 2013 at 14:52:32 UTC, John Colvin wrote: Is there any way to take the address of any of an overloaded set of functions? import std.stdio; void foo(int a){ writeln("overload int"); } void foo(long b){ writeln("overload long"); } void main() { auto b = &foo; //ambiguous

Re: Address of overloaded functions

2013-07-03 Thread Artur Skawina
On 07/03/13 17:03, Artur Skawina wrote: > On 07/03/13 16:52, John Colvin wrote: >> Is there any way to take the address of any of an overloaded set of >> functions? >> >> import std.stdio; >> >> void foo(int a){ writeln("overload int"); } >> void foo(long b){ writeln("overload long"); } >> >> void

Re: Address of overloaded functions

2013-07-03 Thread Artur Skawina
On 07/03/13 16:52, John Colvin wrote: > Is there any way to take the address of any of an overloaded set of functions? > > import std.stdio; > > void foo(int a){ writeln("overload int"); } > void foo(long b){ writeln("overload long"); } > > void main() > { > auto b = &foo; //ambiguous => err

Address of overloaded functions

2013-07-03 Thread John Colvin
Is there any way to take the address of any of an overloaded set of functions? import std.stdio; void foo(int a){ writeln("overload int"); } void foo(long b){ writeln("overload long"); } void main() { auto b = &foo; //ambiguous => error b(2); //valid for either overload }

Re: Stop to! rounding?

2013-07-03 Thread Jay Norwood
On Wednesday, 3 July 2013 at 08:23:40 UTC, monarch_dodra wrote: On Wednesday, 3 July 2013 at 06:18:28 UTC, Jonathan M Davis wrote: On Wednesday, July 03, 2013 08:11:50 Josh wrote: Long story short, I think both would be a great addition to phobos/D. I'd personally really want to play with dec

Re: ref tuples

2013-07-03 Thread Dicebot
On Wednesday, 3 July 2013 at 11:54:39 UTC, Artur Skawina wrote: Well, aliases can be used to get a similar effect. template tie(A...) { alias tie = A; } tie!(a, b) = tuple(1, 2); artur Which is actually already in Phobos: TypeTuple!(a, b) = tuple(1, 2);

Re: ref tuples

2013-07-03 Thread Artur Skawina
On 07/03/13 02:22, Brad Anderson wrote: > C++11's std::tuple includes a function std::tie that takes references to the > arguments and returns a tuple that maintains the references to the arguments. > > Along with the usual cases where you'd want reference semantics it also > enables this intere

Re: Stop to! rounding?

2013-07-03 Thread bearophile
Josh: Is there any way I would be able to hold that number then? One way to do that is with a simple rationals library, represented as pairs of bigints. Bye, bearophile

Re: Stop to! rounding?

2013-07-03 Thread monarch_dodra
On Wednesday, 3 July 2013 at 08:27:52 UTC, Maxim Fomin wrote: On Wednesday, 3 July 2013 at 08:23:40 UTC, monarch_dodra wrote: My brother in law writes financial apps, and in that field, using floating points type is *legally* forbidden. Really? What kind of apps? I meant "apps" as in sho

Re: How to get warnings about unused imports ?

2013-07-03 Thread Gabi
On Wednesday, 3 July 2013 at 06:12:46 UTC, Namespace wrote: On Tuesday, 2 July 2013 at 21:49:37 UTC, Gabi wrote: Hi, How to find unused imports ? It seems the compiler doesn't do it, but is there any other tool for that? This seems like small issue, but those unused imports pile up pretty qu

Re: Stop to! rounding?

2013-07-03 Thread Maxim Fomin
On Wednesday, 3 July 2013 at 08:23:40 UTC, monarch_dodra wrote: My brother in law writes financial apps, and in that field, using floating points type is *legally* forbidden. Really? What kind of apps?

Re: Stop to! rounding?

2013-07-03 Thread monarch_dodra
On Wednesday, 3 July 2013 at 06:18:28 UTC, Jonathan M Davis wrote: On Wednesday, July 03, 2013 08:11:50 Josh wrote: Jonathan, do you know of any fixed point D library? If not, would it be worth me making one for phobos? I am unaware of one, and I don't really know why anyone would really wan