Re: T[] (array of generic type)

2013-11-19 Thread Dejan Lekic
On Mon, 18 Nov 2013 21:32:11 +0100, Philippe Sigaud wrote: On Mon, Nov 18, 2013 at 9:20 PM, seany se...@uni-bonn.de wrote: I read that book, but dont find this constructtion, that is why the question. IIRC I talk a bit about function templates in my tutorial. JR gave the link (thanks!),

Re: T[] (array of generic type)

2013-11-19 Thread Craig Dillabaugh
On Monday, 18 November 2013 at 20:32:25 UTC, Philippe Sigaud wrote: On Mon, Nov 18, 2013 at 9:20 PM, seany se...@uni-bonn.de wrote: I read that book, but dont find this constructtion, that is why the question. IIRC I talk a bit about function templates in my tutorial. JR gave the link

Instantiating templates where type is known only at run time

2013-11-19 Thread Craig Dillabaugh
this question came up in some C++ work I am doing, but since the solutions are likely nicer in D, I wanted to ask how it could be solved in D. First for some motivation. I am doing image processing work where the images are simply an array of data, where the data type can be any numeric type.

Re: Instantiating templates where type is known only at run time

2013-11-19 Thread bearophile
Craig Dillabaugh: // Assume images are of the same dimensions. Result is // saved in Out. void add(T,U,V)(Image!T A, Image!U B, Image!V Out) { ... } Take a look at the out annotation in D. Anyway, thanks to whoever takes the time to read all that, let alone come up with an answer.

comparing two arrays ..

2013-11-19 Thread seany
Is there a built in function or operator in D that can compare two arrays (prefereably any dimensional) for being elementwise equal? thnak you

Re: comparing two arrays ..

2013-11-19 Thread Adam D. Ruppe
On Tuesday, 19 November 2013 at 14:12:14 UTC, seany wrote: Is there a built in function or operator in D that can compare two arrays (prefereably any dimensional) for being elementwise equal? a == b works on single dimension. Not sure about beyond that though.

array reinitialization

2013-11-19 Thread seany
Say I defined an array as int[] a = [1,2,3,4]; Now if I do a = function(a); will that make a to equal [1,2,3,4,5] the function is defined as: int[] function(int[] b) { return b ~ 5;}

Re: array reinitialization

2013-11-19 Thread bearophile
seany: Say I defined an array as int[] a = [1,2,3,4]; Now if I do a = function(a); will that make a to equal [1,2,3,4,5] the function is defined as: int[] function(int[] b) { return b ~ 5;} D dynamic arrays are partially values, so use: int[] function(ref int[] b) Bye, bearophile

Re: comparing two arrays ..

2013-11-19 Thread bearophile
Adam D. Ruppe: a == b works on single dimension. Not sure about beyond that though. It works on nD arrays: void main() { immutable m1 = [[1, 2], [3, 4]]; immutable m2 = [[1, 2], [3, 4]]; immutable m3 = [[1, 2], [3, 5]]; assert(m1 == m2); assert(m1 != m3); assert(m1

Re: comparing two arrays ..

2013-11-19 Thread Ali Akhtarzada
You'd usually find stuff like this (i.e. generic algorithms that act on collections) in std.algorithms http://dlang.org/phobos/std_algorithm.html#equal On Tue, Nov 19, 2013 at 3:12 PM, seany se...@uni-bonn.de wrote: Is there a built in function or operator in D that can compare two arrays

How does noexcept work?

2013-11-19 Thread Jeroen Bollen
If I have a function: @safe pure void functionName() { return; } Where do I put the noexcept?

Re: How does noexcept work?

2013-11-19 Thread Namespace
On Tuesday, 19 November 2013 at 18:01:19 UTC, Jeroen Bollen wrote: If I have a function: @safe pure void functionName() { return; } Where do I put the noexcept? Did you mean nothrow? You can put it unfortunately on both sides. left: @safe pure nothrow void

Re: How does noexcept work?

2013-11-19 Thread Jeroen Bollen
On Tuesday, 19 November 2013 at 18:09:29 UTC, Namespace wrote: On Tuesday, 19 November 2013 at 18:01:19 UTC, Jeroen Bollen wrote: If I have a function: @safe pure void functionName() { return; } Where do I put the noexcept? Did you mean nothrow? You can put it

MSG_WAITALL for Sockets

2013-11-19 Thread Jeroen Bollen
Is there a way I can call a receive method on a socket with MSG_WAITALL as a flag? There doesn't seem to be an enum for that.

returning different types via function

2013-11-19 Thread seany
Consider this: I have a function FUNC, it takes a string array, and does something with it, and retruns the same. Implemented based on a previous thread, here is what i have string[] FUNC (ref string[] ZZ) { /* do something */ } and the calling is, ZZ = FUNC(ZZ) Now, I want, should the

Re: returning different types via function

2013-11-19 Thread seany
Uh I forgot to mention that it should do this without global variables, and without try / catch

Re: returning different types via function

2013-11-19 Thread Brad Anderson
On Tuesday, 19 November 2013 at 19:15:10 UTC, seany wrote: Consider this: I have a function FUNC, it takes a string array, and does something with it, and retruns the same. Implemented based on a previous thread, here is what i have string[] FUNC (ref string[] ZZ) { /* do something */ }

Re: returning different types via function

2013-11-19 Thread bearophile
seany: I have a function FUNC, it takes a string array, and does something with it, and retruns the same. Implemented based on a previous thread, here is what i have string[] FUNC (ref string[] ZZ) I told you to use ref if you want to modify in-place the length of the array, as in the

Re: returning different types via function

2013-11-19 Thread Ali Çehreli
On 11/19/2013 11:15 AM, seany wrote: Consider this: I have a function FUNC, it takes a string array, and does something with it, and retruns the same. Implemented based on a previous thread, here is what i have string[] FUNC (ref string[] ZZ) { /* do something */ } and the calling

Re: returning different types via function

2013-11-19 Thread Dicebot
On Tuesday, 19 November 2013 at 19:31:41 UTC, bearophile wrote: A Nullable in usually efficient enough (there is even an alternative Nullable that doesn't increase the data size), it makes typing stronger, and it should become more common in system languages (and indeed it's commonly used in

Re: Newbie Question: SOAP Module

2013-11-19 Thread Rick Catano
Anyone? I know it's a very basic question, but an honest and friendly answer will suffice.

Re: Newbie Question: SOAP Module

2013-11-19 Thread Adam D. Ruppe
On Monday, 18 November 2013 at 23:49:56 UTC, Rick Catano wrote: My first question of the D language is, is there a SOAP module that I can consume web services with? I don't know, but I don't think so. Maybe it wouldn't be too hard to make out by combining http get (with curl or whatever) with

Re: Newbie Question: SOAP Module

2013-11-19 Thread Rick Catano
On Tuesday, 19 November 2013 at 20:38:00 UTC, Adam D. Ruppe wrote: On Monday, 18 November 2013 at 23:49:56 UTC, Rick Catano wrote: My first question of the D language is, is there a SOAP module that I can consume web services with? I don't know, but I don't think so. Maybe it wouldn't be too

How do you overload opEquals?

2013-11-19 Thread Dale Matthews
I'm brand new to D and I'm taking on a project. In the midst, I've overloaded a whole load of operators for my Vec3 class. Most seem to be working (I haven't tested them all yet) but opEquals is refusing to be called. I've followed the guidelines here:

Re: returning different types via function

2013-11-19 Thread Jesse Phillips
On Tuesday, 19 November 2013 at 19:15:10 UTC, seany wrote: (so i want liek a C style fopen -like function, that , although called with the syntax: file *f = fopen(balh, bla); can set f to be false) I think you have a misunderstanding here. C does not allow you to return false. Instead C

Re: How do you overload opEquals?

2013-11-19 Thread Adam D. Ruppe
On Tuesday, 19 November 2013 at 20:59:31 UTC, Dale Matthews wrote: I feel like I'm missing something simple. opEquals doesn't work on classes with class references. It doesn't call a method with obj = other_obj, it just rebinds the reference. If you want full control over opEquals, it'll

Re: How do you overload opEquals?

2013-11-19 Thread Chris Nicholson-Sauls
On Tuesday, 19 November 2013 at 20:59:31 UTC, Dale Matthews wrote: I'm brand new to D and I'm taking on a project. In the midst, I've overloaded a whole load of operators for my Vec3 class. Most seem to be working (I haven't tested them all yet) but opEquals is refusing to be called. I've

Accessing a Hash table as a Value-Sorted Range

2013-11-19 Thread Nordlöw
If I have a hash-table `File[string] _subs` and want to access its values in a sorted way is there a better than simply through auto ssubs = new File[_subs.length]; // preallocate sorted subs size_t ix = 0; foreach (sub; _subs) { ssubs[ix++] = sub; // set new reference

Re: Accessing a Hash table as a Value-Sorted Range

2013-11-19 Thread Brad Anderson
On Tuesday, 19 November 2013 at 21:11:42 UTC, Nordlöw wrote: If I have a hash-table `File[string] _subs` and want to access its values in a sorted way is there a better than simply through auto ssubs = new File[_subs.length]; // preallocate sorted subs size_t ix = 0; foreach

Re: How do you overload opEquals?

2013-11-19 Thread Adam D. Ruppe
On Tuesday, 19 November 2013 at 21:05:23 UTC, Adam D. Ruppe wrote: opEquals doesn't work on classes with class references. IGNORE ME, I am wrong here. I mixed up opEquals and opAssign in my head. Sorry!

Re: Enum with base type string and switch

2013-11-19 Thread Chris Nicholson-Sauls
This was a bug and has since been fixed, so the solution is simply to update your compiler. If there is some reason you can't (company required version, etc) then your cast() is sadly probably the only way.

Re: returning different types via function

2013-11-19 Thread bearophile
Dicebot: I don't want to argue this in details right now but I think that simply banning null references as valid arrays in program as a whole via contracts is better approach than adding extra level of indirection via Nullable ;) Nullable is a struct, it doesn't introduce a new leavel of

Re: How do you overload opEquals?

2013-11-19 Thread Dale Matthews
On Tuesday, 19 November 2013 at 21:22:27 UTC, Adam D. Ruppe wrote: IGNORE ME, I am wrong here. I mixed up opEquals and opAssign in my head. Sorry! Will do :]

Re: How do you overload opEquals?

2013-11-19 Thread Dale Matthews
On Tuesday, 19 November 2013 at 21:10:57 UTC, Chris Nicholson-Sauls wrote: override bool opEquals (Object o) const { if ( auto v = cast( typeof( this ) ) o ) return x == v.x y == v.y z == v.z; return false; } You need: 1) 'override' in order to override

Re: How do you overload opEquals?

2013-11-19 Thread Adam D. Ruppe
On Tuesday, 19 November 2013 at 21:25:47 UTC, Dale Matthews wrote: Adam, do you recommend using a struct instead of a class? Yes, I would use a struct instead of a class here. The key question to ask in D is: do you need inheritance? If yes, use a class, if no, struct is usually better,

Re: Newbie Question: SOAP Module

2013-11-19 Thread Jacek Furmankiewicz
is there any particular reason you are forced to use SOAP? It is more or less an obsolete and generally frowned upon approach. if you were willing to adopt REST, vibe.d seems to have some nice functionality for creating REST APIs. Look at the 'Routing' section here:

Re: Accessing a Hash table as a Value-Sorted Range

2013-11-19 Thread Nordlöw
On Tuesday, 19 November 2013 at 21:14:01 UTC, Brad Anderson wrote: On Tuesday, 19 November 2013 at 21:11:42 UTC, Nordlöw wrote: If I have a hash-table `File[string] _subs` and want to access its values in a sorted way is there a better than simply through auto ssubs = new

Re: Accessing a Hash table as a Value-Sorted Range

2013-11-19 Thread Nordlöw
On Tuesday, 19 November 2013 at 22:42:10 UTC, Nordlöw wrote: On Tuesday, 19 November 2013 at 21:14:01 UTC, Brad Anderson wrote: On Tuesday, 19 November 2013 at 21:11:42 UTC, Nordlöw wrote: If I have a hash-table `File[string] _subs` and want to access its values in a sorted way is there a

Re: Accessing a Hash table as a Value-Sorted Range

2013-11-19 Thread Ali Çehreli
On 11/19/2013 02:42 PM, Nordlöw wrote: On Tuesday, 19 November 2013 at 21:14:01 UTC, Brad Anderson wrote: On Tuesday, 19 November 2013 at 21:11:42 UTC, Nordlöw wrote: If I have a hash-table `File[string] _subs` and want to access its values in a sorted way is there a better than simply through

Alocating memory depending of a variable value INT variable

2013-11-19 Thread Carlos
Well in C I just declared an array during execution with an array with a multiplied variable for the size of the array. Since I only need two spaces in the array for each line of process it was multiplied by two. so it was like this : scanf(%d, Num); int array[Num*2]; When I tried to do

Re: Alocating memory depending of a variable value INT variable

2013-11-19 Thread Ali Çehreli
On 11/19/2013 03:16 PM, Carlos wrote: Well in C I just declared an array during execution with an array with a multiplied variable for the size of the array. Since I only need two spaces in the array for each line of process it was multiplied by two. so it was like this : scanf(%d, Num);

Re: MSG_WAITALL for Sockets

2013-11-19 Thread Rob T
On Tuesday, 19 November 2013 at 18:35:08 UTC, Jeroen Bollen wrote: Is there a way I can call a receive method on a socket with MSG_WAITALL as a flag? There doesn't seem to be an enum for that. module core.sys.posix.sys.socket; enum : uint { MSG_CTRUNC = 0x08,

Re: about std.string.representation

2013-11-19 Thread bioinfornatics
On Tuesday, 19 November 2013 at 06:11:26 UTC, Ali Çehreli wrote: On 11/18/2013 07:48 PM, bioinfornatics wrote: On Thursday, 14 November 2013 at 12:01:04 UTC, Ali Çehreli wrote: On 11/13/2013 04:32 PM, bioinfornatics wrote: Hi, I try to understand which type char, dchar, wchar will give

Re: about std.string.representation

2013-11-19 Thread bioinfornatics
On Tuesday, 19 November 2013 at 23:53:33 UTC, bioinfornatics wrote: On Tuesday, 19 November 2013 at 06:11:26 UTC, Ali Çehreli wrote: On 11/18/2013 07:48 PM, bioinfornatics wrote: On Thursday, 14 November 2013 at 12:01:04 UTC, Ali Çehreli wrote: On 11/13/2013 04:32 PM, bioinfornatics wrote:

Re: How do you overload opEquals?

2013-11-19 Thread Andrea Fontana
On Tuesday, 19 November 2013 at 21:33:31 UTC, Adam D. Ruppe wrote: On Tuesday, 19 November 2013 at 21:25:47 UTC, Dale Matthews wrote: Adam, do you recommend using a struct instead of a class? Yes, I would use a struct instead of a class here. The key question to ask in D is: do you need

Re: How do you overload opEquals?

2013-11-19 Thread Adam D. Ruppe
On Tuesday, 19 November 2013 at 23:58:20 UTC, Andrea Fontana wrote: And, of course, struct are value type, class are reference type. Yeah, true in general, though it is possible to have a struct be very similar to a reference type. Consider: struct WrappedClass { Object obj; /* and

Re: Alocating memory depending of a variable value INT variable

2013-11-19 Thread bearophile
Ali Çehreli: That is a VLA. That are currently not present in D. The most common and safe alternatives in D are allocating the memory on the heap with 'new', or over-allocating on the stack a fixed size and then slicing. If the OP really wants to allocate on the stack, there is the

Re: about std.string.representation

2013-11-19 Thread bioinfornatics
I try this import std.traits : isSomeChar; import std.typetuple: TypeTuple; import std.stdio; template CharEncodingType(Char) { // Get representation type alias TypeTuple!(ubyte, ushort, uint) U; // const and immutable storage classes static if (is(Char ==

Re: Instantiating templates where type is known only at run time

2013-11-19 Thread Craig Dillabaugh
On Tuesday, 19 November 2013 at 12:53:50 UTC, bearophile wrote: Craig Dillabaugh: // Assume images are of the same dimensions. Result is // saved in Out. void add(T,U,V)(Image!T A, Image!U B, Image!V Out) { ... } Take a look at the out annotation in D. Anyway, thanks to whoever

Re: about std.string.representation

2013-11-19 Thread bioinfornatics
works as expected import std.traits : isSomeChar; import std.range: ElementEncodingType; import std.stdio; @safe pure nothrow template CharEncodingType(Char) { alias ET = ElementEncodingType!Char; static if (is (ET == char)) { alias CharEncodingType = ubyte; } else

Re: Alocating memory depending of a variable value INT variable

2013-11-19 Thread Carlos
On Tuesday, 19 November 2013 at 23:34:48 UTC, Ali Çehreli wrote: On 11/19/2013 03:16 PM, Carlos wrote: Well in C I just declared an array during execution with an array with a multiplied variable for the size of the array. Since I only need two spaces in the array for each line of process it

Re: How do you overload opEquals?

2013-11-19 Thread Mike Parker
On 11/20/2013 5:59 AM, Dale Matthews wrote: class Vec3 { bool opEquals()(auto ref const Vec3 v) const You don't need to use 'ref' on parameters that are classes. Unlike C++, D classes are already reference types, not value types. More like Java. Structs, OTOH, are value types. With

How to create a library, I mean an external file that holds functions just like std.stdio

2013-11-19 Thread Carlos
So I'm reading this tut from Ali :) And we I got to this part : A code example. http://pastebin.com/ESeL7dfH But I want to declare this functions print outside of the file and call the file to be loaded by the compiler. So I can use the same solution in various program without having to copy

Re: How to create a library, I mean an external file that holds functions just like std.stdio

2013-11-19 Thread Carlos
I just readhow to do it down on the list of tuts. I did : dmd primes.d ./prime.d, and done program ran perfectly

Re: returning different types via function

2013-11-19 Thread Meta
On Tuesday, 19 November 2013 at 19:31:41 UTC, bearophile wrote: The clean design is to use std.typecons.Nullable: Nullable!(string[]) func(string[] zz) { I have found that Nullable is pretty much useless for this type of usage, because it aliases itself to the underlying value, and then any

Re: How to create a library, I mean an external file that holds functions just like std.stdio

2013-11-19 Thread evilrat
On Wednesday, 20 November 2013 at 02:14:29 UTC, Carlos wrote: But I want to declare this functions print outside of the file and call the file to be loaded by the compiler. So I can use the same solution in various program without having to copy paste it to each one. first way - put this

Linking to a library via the linker on Windows?

2013-11-19 Thread Jeremy DeHaan
Like I said in the title, this is related to Windows. Basically, I'm looking to put a command line together to keep things consistent between Windows, OSX and Linux. On OSX and Linux I would do -L-lLibraryName, but is there something similar that one can do on Windows? Or do I have to add

Re: Linking to a library via the linker on Windows?

2013-11-19 Thread Ali Çehreli
On 11/19/2013 11:18 PM, Jeremy DeHaan wrote: Like I said in the title, this is related to Windows. Basically, I'm looking to put a command line together to keep things consistent between Windows, OSX and Linux. On OSX and Linux I would do -L-lLibraryName, but is there something similar that one