Re: The lifetime of reduce's internal seed

2014-04-23 Thread monarch_dodra via Digitalmars-d-learn
On Tuesday, 22 April 2014 at 18:49:41 UTC, Steven Schveighoffer wrote: On Tue, 22 Apr 2014 14:47:19 -0400, monarch_dodra monarchdo...@gmail.com wrote: In this case no, but; // int[1] foo(); int[] a = foo(); // *is* slicing an rvalue, and it *does* compile. I don't think there needs

Re: Function to print a diamond shape

2014-04-23 Thread Jay Norwood via Digitalmars-d-learn
On Tuesday, 22 April 2014 at 15:25:04 UTC, monarch_dodra wrote: Yeah, that's because join actually works on RoR, R, rather than R, E. This means if you feed it a string[], string, then it will actually iterate over individual *characters*. Not only that, but since you are using char[], it will

Re: Best way to check for an element in an array?

2014-04-23 Thread FrankLike via Digitalmars-d-learn
Hi,everyone, This code must add the 'break', import std.stdio; int x=0; template isin(T){ bool isin(T[] Array,T Element){ bool rtn=false; foreach(T ArrayElement; Array){ if(Element==ArrayElement){ rtn=true; break; ← //here add break

Re: Best way to check for an element in an array?

2014-04-23 Thread FrankLike via Digitalmars-d-learn
Hi,everyone, It works maybe the best: import std.stdio; template isin(T){ bool isin(T[] Array,T Element){ foreach(T ArrayElement; Array){ if(Element==ArrayElement){ return true;} } return false; } } void main(string[] args) { int[]

Partial ordering of constructors with type parameters

2014-04-23 Thread Charles McAnany via Digitalmars-d-learn
Friends, I have a class that needs two constructors: class Foo{ this(int x){} this(T)(T x) if(!is(T == int)){} } void main(){} But this does not compile because the two constructors conflict: buggy.d(3): Error: template buggy.Foo.__ctor(T)(T x) if (!is(T == int)) conflicts with

Re: Partial ordering of constructors with type parameters

2014-04-23 Thread bearophile via Digitalmars-d-learn
Charles McAnany: this(int x){} this(T)(T x) if(!is(T == int)){} } void main(){} But this does not compile because the two constructors conflict: Try adding the negative constraint: this(T)(in T x) pure nothrow if(is(T == int)) {} this(T)(in T x) pure nothrow if(!is(T == int)) {}

Re: Partial ordering of constructors with type parameters

2014-04-23 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 23 April 2014 at 16:44:37 UTC, Charles McAnany wrote: Friends, I have a class that needs two constructors: class Foo{ this(int x){} this(T)(T x) if(!is(T == int)){} } void main(){} But this does not compile because the two constructors conflict: buggy.d(3): Error:

Re: Partial ordering of constructors with type parameters

2014-04-23 Thread John Colvin via Digitalmars-d-learn
On Wednesday, 23 April 2014 at 18:04:05 UTC, monarch_dodra wrote: If you can't update your compiler, an alternative is to make your non-template version an actual template: class Foo{ this(T : int)(T x){} this(T)(T x) {} } I haven't tested, but wouldn't this be more precisely

Re: Auto return type inference issue?

2014-04-23 Thread Matthew Dudley via Digitalmars-d-learn
On Wednesday, 23 April 2014 at 00:02:29 UTC, Jesse Phillips wrote: On Tuesday, 22 April 2014 at 07:54:34 UTC, Matthew Dudley wrote: Here's the gist of what I'm trying to do. https://gist.github.com/pontifechs/11169069 I'm getting an error I don't understand: tinker.d(42): Error: mismatched

Undefined symbol ModuleInfoZ when including a SWIG generated module

2014-04-23 Thread Walter Gray via Digitalmars-d-learn
Hi there, I'm currently trying to set up a small demo project using the Leap Motion API in D. I've run SWIG with -d -d2, and created the intermediate C++ DLL along with a pair of .d files, leap.d and leap_im.d. I'm new to D, but very interested and I'd like to set this up in an idiomatic

Re: Undefined symbol ModuleInfoZ when including a SWIG generated module

2014-04-23 Thread Steven Schveighoffer via Digitalmars-d-learn
On Wed, 23 Apr 2014 20:34:11 -0400, Walter Gray walter.r.g...@gmail.com wrote: Hi there, I'm currently trying to set up a small demo project using the Leap Motion API in D. I've run SWIG with -d -d2, and created the intermediate C++ DLL along with a pair of .d files, leap.d and

Re: Undefined symbol ModuleInfoZ when including a SWIG generated module

2014-04-23 Thread bearophile via Digitalmars-d-learn
Walter Gray: the files contain the entire definitions, so why would it be necessary to link to them AND specify them as imports? What am I missing here? I don't understand why that's not regarded as a job for the compiler. But in the standard D distribution there are programs like rdmd that

Re: Auto return type inference issue?

2014-04-23 Thread Jesse Phillips via Digitalmars-d-learn
On Wednesday, 23 April 2014 at 23:05:39 UTC, Matthew Dudley wrote: tuple in this case would be the member variable of type T (from T...) So wouldn't elem be the actual object, and not the type? The effective lowering I was hoping for would be something like this if (names[0] == one)

Is it possible to make replaces of multiple regexes at once?

2014-04-23 Thread Maaaks via Digitalmars-d-learn
Hi. I'm looking for a function that can perform multiple replaces at once. For example, there's such function in PHP, here's example from its site: ?php $patterns = array ('/(19|20)(\d{2})-(\d{1,2})-(\d{1,2})/', '/^\s*{(\w+)}\s*=/'); $replace = array ('\3/\4/\1\2', '$\1