Re: if Condition expression can't have function?

2014-04-25 Thread Matthias Walter via Digitalmars-d
On 04/25/2014 09:14 AM, FrankLike via Digitalmars-d wrote: Hi,everyone, Here has a error after run: main.exe 11 or main.exe 10 : template find(T) { size_t find(T[] Array,T Element) { find returns a size_t being a nonnegativ number. return -1; But here it returns -1. In

Re: Testing presence of member functions with same name but different signature.

2014-02-08 Thread Matthias Walter
On 02/06/2014 10:44 PM, Timon Gehr wrote: On 02/06/2014 10:32 PM, Matthias Walter wrote: Is this a bug? Yes. Okay, added a ticket: http://d.puremagic.com/issues/show_bug.cgi?id=12102

Testing presence of member functions with same name but different signature.

2014-02-06 Thread Matthias Walter
Hi, I realized the following behavior and want to ask whether this is expected behavior and if yes, I'd like to know a reason. The check of MyClass.func(MyClass.A) and MyClass.func(MyClass.B) in the main() function succeeds, but the alias line *in* the class definition fails with template

inout type constructor applied to this-reference

2014-01-10 Thread Matthias Walter
Hi, I read about inout functions in the language documentation which allows to use inout in order to set the constness of the return type based on the constness of some argument. What is not mentioned is that this also works for the this-reference by marking the function itself inout: So instead

Member-assignment for std.container.Array!Struct

2014-01-09 Thread Matthias Walter
Hi, about 2 years ago I stopped using D for my projects since there were too many bugs that hindered me from making quick progress. Since I got several mails from bugzilla about those bugs being fixed I wanted to give it another try. Unfortunately, the following non-working code made me think to

Re: Initialization of std.typecons.RefCounted objects

2012-07-19 Thread Matthias Walter
On 07/18/2012 03:32 PM, Christophe Travert wrote: Matthias Walter , dans le message (digitalmars.D:172673), a écrit : I looked at Bug #6153 (Array!(Array!int) failure) and found that the This exactly is what makes the following code fail: Array!(Array!int) array2d; array2d.length = 1

Re: Initialization of std.typecons.RefCounted objects

2012-07-19 Thread Matthias Walter
On 07/19/2012 10:14 AM, Christophe Travert wrote: monarch_dodra , dans le message (digitalmars.D:172700), a écrit : I think it would be better to initialize on copy, rather than default initialize. There are too many cases an empty array is created, then initialized on the next line, or

Re: Initialization of std.typecons.RefCounted objects

2012-07-19 Thread Matthias Walter
the user explicitly initialized the reference counter. Or is there a reasonable alternative? Best regards, Matthias Walter

Re: Getting a range over a const Container

2012-07-19 Thread Matthias Walter
On 07/19/2012 06:44 AM, Jonathan M Davis wrote: On Thursday, July 19, 2012 04:39:26 Francisco Soulignac wrote: So, my question is how can I (correctly) traverse a const SList, const DList, etc? Right now? I'm pretty sure that that's impossible. Hopefully that will change, but getting

Re: ~= call copy ctor?

2012-07-19 Thread Matthias Walter
On 07/19/2012 02:27 PM, Namespace wrote: I have a 2 questions. I have this code: [code] import std.stdio; struct Test { public: this(int i = 0) { writeln(Test CTor.); } this(this) { writeln(Test Copy CTor); } ~this() {

Re: ~= call copy ctor?

2012-07-19 Thread Matthias Walter
On 07/19/2012 03:00 PM, Namespace wrote: Is there any way to avoid the implizit copy ctor by array concatenation? Or is the only way to use a pointer? Yes, in some way you have to. If you want to not copy a lot of data (or avoid additional on-copy effort) you either have to you pointers

Initialization of std.typecons.RefCounted objects

2012-07-18 Thread Matthias Walter
enlarging the outer array, the inner array is a null pointer which must be created by new. Best regards, Matthias Walter

Progress on std.container

2012-07-16 Thread Matthias Walter
Hi, I'd like to know who is currently working on std.container - at some point I read that Andrei works on user-controlled allocation and then the issues of container structures will be addressed. Unforntunately, at the moment std.container.Array is unusable for me because of missing const Range

Re: Progress on std.container

2012-07-16 Thread Matthias Walter
On 07/17/2012 12:41 AM, Andrei Alexandrescu wrote: On 7/16/12 4:19 AM, Matthias Walter wrote: Hi, I'd like to know who is currently working on std.container - at some point I read that Andrei works on user-controlled allocation and then the issues of container structures will be addressed

Re: foreach syntax

2012-06-29 Thread Matthias Walter
On 06/29/2012 12:47 PM, Namespace wrote: A friend of mine ask me why D's foreach isn't like C# Means, why is it like int[] arr = [1, 2, 3]; foreach (int val; arr) { and not foreach (int val in arr) { which it is more intuitive. I could give him no clever answer to, so maybe

Re: Primary Ranges of Containers

2012-06-20 Thread Matthias Walter
On 06/19/2012 04:04 PM, Timon Gehr wrote: On 06/19/2012 02:54 PM, Christophe Travert wrote: Jonathan M Davis , dans le message (digitalmars.D:170054), a écrit : I'd propose to always add a bool template parameter (maybe isConst?) to the range since most of the write-functionality can be

Re: Primary Ranges of Containers

2012-06-19 Thread Matthias Walter
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 06/18/2012 01:08 PM, Jonathan M Davis wrote: On Monday, June 18, 2012 10:06:44 Matthias Walter wrote: Hi, last week I realized that a const version of std.container.Array.opSlice() is missing. Now I looked at the code and I think

Re: How to break const

2012-06-18 Thread Matthias Walter
On 06/18/2012 07:36 AM, Mehrdad wrote: Is it just me, or did I subvert the type system here? import std.stdio; struct Const { this(void delegate() increment) { this.increment = increment; } int a; void delegate() increment; void oops() const { this.increment(); }

Re: How to break const

2012-06-18 Thread Matthias Walter
On 06/18/2012 08:04 AM, Mehrdad wrote: On Monday, 18 June 2012 at 06:00:11 UTC, Matthias Walter wrote: On 06/18/2012 07:36 AM, Mehrdad wrote: Is it just me, or did I subvert the type system here? import std.stdio; struct Const { this(void delegate() increment) { this.increment

Re: How to break const

2012-06-18 Thread Matthias Walter
On 06/18/2012 08:19 AM, Mehrdad wrote: On Monday, 18 June 2012 at 06:14:22 UTC, Matthias Walter wrote: Its not, that a const method cannot modify an object, it just ensures that the const method cannot modify the object *by using the this-pointer*. I see... So that means you /can't

Primary Ranges of Containers

2012-06-18 Thread Matthias Walter
Hi, last week I realized that a const version of std.container.Array.opSlice() is missing. Now I looked at the code and I think that it is a general design problem. The docs state that c.Range is The primary range type associated with the container.. I think we really always need two Range types

Getting a range over a const Container

2012-06-15 Thread Matthias Walter
Hi, I have a const std.container object (e.g., a const(Array!int)) of which I'd like to have a range which can traverse that container having read-only access. This does not seem to be possible with opSlice(). Is there an alternative? Best regards, Matthias

Re: const version for foreach/opApply

2012-06-11 Thread Matthias Walter
On 06/10/2012 12:30 AM, Era Scarecrow wrote: On Saturday, 9 June 2012 at 10:09:25 UTC, Matthias Walter wrote: First, thank you for your answer. I've already made some tiny modifications in order to make BitArray work for my purposes: https://github.com/xammy/phobos/commit

Re: const version for foreach/opApply

2012-06-09 Thread Matthias Walter
On 2012-06-08 22:47, Era Scarecrow wrote: On Friday, 8 June 2012 at 16:33:28 UTC, Matthias Walter wrote: Hi, trying to traverse the entries of a std.bitmanip.BitArray I stumbled upon the following problem: In case I want to accept const(BitArray) objects, it shall look like the following

const version for foreach/opApply

2012-06-08 Thread Matthias Walter
++) { bool b = opIndex(i); result = dg(b); if (result) break; } return result; } Can one glue both things together into a single routine (using inout magic or whatever)? Best regards, Matthias Walter

Re: Website

2012-06-01 Thread Matthias Walter
On 06/01/2012 07:42 AM, d coder wrote: Why am I being taken to Digital Daemon when I goto http://dlang.org ? Seems like the DNS entry points still to the original IP address. That's all I could find out. Where can I find official D language site now? http://erdani.com/d/web/index.html exists

Re: How to test for equality of types?

2012-05-19 Thread Matthias Walter
On 2012-05-19 09:05, Philippe Sigaud wrote: On Fri, May 18, 2012 at 11:51 PM, Simen Kjaeraas simen.kja...@gmail.com wrote: Because Wrapper!(AliasStruct).Wrap does not exist. And _error_ is not equal to any other type. Yes. Wrap is included in the complete template name (Wrapper!(Wrap))

Re: How to test for equality of types?

2012-05-19 Thread Matthias Walter
On 2012-05-19 15:28, Philippe Sigaud wrote: On Sat, May 19, 2012 at 12:23 PM, Matthias Walter xa...@xammy.homelinux.net wrote: I would open a bug report with the following code which is a bit smaller than my first wrong version: = (...) pragma(msg, typeof

How to test for equality of types?

2012-05-18 Thread Matthias Walter
Hi, how do I test two types for equality? Suppose I have A and B aliasing some type(s), how do I find out if they are aliases the same thing? I tried the is(A == B) expression, but this does not always work (tell me if I shall give an example). On the other hand, according to the spec the

Re: How to test for equality of types?

2012-05-18 Thread Matthias Walter
On 2012-05-18 16:12, Steven Schveighoffer wrote: On Fri, 18 May 2012 06:06:45 -0400, Matthias Walter wrote: how do I test two types for equality? Suppose I have A and B aliasing some type(s), how do I find out if they are aliases the same thing? I tried the is(A == B) expression

Re: Keyword arguments / Named parameters library implementation

2012-03-20 Thread Matthias Walter
On 03/19/2012 08:21 PM, Andrej Mitrovic wrote: On 3/19/12, Matthias Walter xa...@xammy.homelinux.net wrote: Hi, I've written a small module (at the moment called utils.keywordargs) which simulates keyword arguments (aka named parameters). Cool. A small tip (in case you didn't already know

Re: Keyword arguments / Named parameters library implementation

2012-03-20 Thread Matthias Walter
On 03/19/2012 07:53 PM, bearophile wrote: Matthias Walter: I've written a small module (at the moment called utils.keywordargs) which simulates keyword arguments (aka named parameters). The documentation can be found here, Regardless the implementation quality of your code, I wait

Keyword arguments / Named parameters library implementation

2012-03-19 Thread Matthias Walter
Hi, I've written a small module (at the moment called utils.keywordargs) which simulates keyword arguments (aka named parameters). The documentation can be found here, http://xammy.xammy.homelinux.net/~xammy/utils_keywordargs.html while the code is at

Remarks on std.container

2012-03-08 Thread Matthias Walter
Hi, I wanted to have a binary heap where I can update entries and restore the heap structure. 1. First I observed that due to the implementation of std.container.BinaryHeap, keeping track of the position of a certain value in the heap cannot be done directly, but it would be helpful to pass a

Named parameters workaround

2012-02-09 Thread Matthias Walter
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi, named parameters have been discussed awhile ago and it seems to me that they won't get into the language soon. I came up with a workaround that makes it possible to use them with some extra typing. Suppose we have a function foo(int a, int b,

Mixture of type tuple and expression tuple

2012-02-06 Thread Matthias Walter
Hi, I'd like to have a function foo which shall depend on several compile-time expressions (e.g. strings) and gets several arguments whose types are templatized. Here, several means in both cases that the number of expressions/arguments are to be determined at compile-time. Here is an example:

dup method const or not?

2011-11-27 Thread Matthias Walter
Hi, Recently, I realized that several dup methods in D2's phobos are declared like the one for BitArray: @property BitArray dup() My question is why it is declared without const? Is it a bug or is there a reason for it? I can think of a case where one only has implemented a shallow copy and

Re: dup method const or not?

2011-11-27 Thread Matthias Walter
On 2011-11-27 23:48, mta`chrono wrote: that's a real good question. it fails with the following error: Error: function std.bitmanip.BitArray.dup () is not callable using argument types () const here is a hack: --- import std.bitmanip; import core.stdc.string; void main() {

Stable sort in std.algorithm throws Range violation

2011-04-08 Thread Matthias Walter
regards, Matthias Walter

Re: greatest common divisor implementation

2011-02-14 Thread Matthias Walter
1. Are there any further suggestions on the implementations / Did I forget something? Are benchmarks done with BigInt and long too? (If you test bigints you need bigger numbers too, and to test that the results are correct). Yeah, so I did tests for long now, too. Unfortunately with gdc I

Re: greatest common divisor implementation

2011-02-14 Thread Matthias Walter
1. Are there any further suggestions on the implementations / Did I forget something? Are benchmarks done with BigInt and long too? (If you test bigints you need bigger numbers too, and to test that the results are correct). I'd like to work on the BigInt things but there are a couple of

Re: greatest common divisor implementation

2011-02-13 Thread Matthias Walter
On 02/07/2011 05:13 PM, Andrei Alexandrescu wrote: On 2/7/11 3:18 PM, Matthias Walter wrote: Hi everyone, as I'm currently working on a C++ project which involves gcd computations I had a quick look at phobos' implementation. 1. First thing I saw is that gcd(-3,6) raises an exception

greatest common divisor implementation

2011-02-07 Thread Matthias Walter
Hi everyone, as I'm currently working on a C++ project which involves gcd computations I had a quick look at phobos' implementation. 1. First thing I saw is that gcd(-3,6) raises an exception, although mathematically it is just 2. Of course checking the sign of the arguments takes computation

Re: On 80 columns should (not) be enough for everyone

2011-01-30 Thread Matthias Walter
On 01/30/2011 01:01 PM, Peter Alexander wrote: On 30/01/11 5:17 PM, Andrej Mitrovic wrote: The unittest topic is about to get derailed so I want to continue this silly discussion here. Wheres Nick? I want to see the CRT vs LCD discussion heated up again with Andrei claiming that LCDs are

Re: structs vs classes

2011-01-29 Thread Matthias Walter
On 01/29/2011 09:13 AM, Jim wrote: so Wrote: I'm a bit troubled with the class/struct dichotomy. I would prefer them both to use the same keyword. Heap/stack allocation could be specified during instantiation instead. Why? Now you need to choose one over the other. Not even C++ has

Re: thin heaps

2010-12-20 Thread Matthias Walter
On 12/20/2010 05:01 PM, Andrei Alexandrescu wrote: Just saw this: http://www.reddit.com/r/programming/comments/eoq15/implementing_shortest_path_in_c_is_much_easier/ in which a reader points to this paper on thin heaps:

Re: Binary heap method to update an entry.

2010-12-16 Thread Matthias Walter
On 12/16/2010 04:17 AM, Andrei Alexandrescu wrote: On 12/15/10 10:21 PM, Matthias Walter wrote: Hi all, I uploaded [1] a patch for std.container to use BinaryHeap as a priority queue. For the latter one it is often necessary to change a value (often called decreaseKey in a MinHeap

Re: Binary heap method to update an entry.

2010-12-16 Thread Matthias Walter
On 12/16/2010 10:53 AM, Andrei Alexandrescu wrote: On 12/16/10 7:55 AM, Matthias Walter wrote: On 12/16/2010 04:17 AM, Andrei Alexandrescu wrote: On 12/15/10 10:21 PM, Matthias Walter wrote: Hi all, I uploaded [1] a patch for std.container to use BinaryHeap as a priority queue

Re: (Improved) Benchmark for Phobos Sort Algorithm

2010-12-16 Thread Matthias Walter
On 12/16/2010 09:36 PM, Craig Black wrote: It was brought to my attention that the quick sort has a very bad worst case, so I implemented a simple fix for it. Now the worst case (completely ordered) is the best case, and it only slows down the general case by a small percentage. I thought to

Binary heap method to update an entry.

2010-12-15 Thread Matthias Walter
Hi all, I uploaded [1] a patch for std.container to use BinaryHeap as a priority queue. For the latter one it is often necessary to change a value (often called decreaseKey in a MinHeap). For example, Dijkstra's shortest path algorithm would need such a method. My implementation expects that the

BinaryHeap usage

2010-12-14 Thread Matthias Walter
Hi all, suppose I have an array of comparable Foo structs which I want to access in a sorted order (e.g. a priority queue) using a BinaryHeap object (I know that for just sorting, the BinHeap is not the right tools), but I do not want to change the order of the objects in the original array. I

Re: Casting functions to delegates

2010-12-12 Thread Matthias Walter
On 12/12/2010 06:15 AM, Dmitry Olshansky wrote: On 12.12.2010 7:25, Matthias Walter wrote: Hi all, there was a discussion in 2006 but w/o a result, and I didn't find any bugs about implicitely casting functions to delegates. It seems to be impossible as long as function-pointer calls work

Re: ByToken Range

2010-12-12 Thread Matthias Walter
On 12/12/2010 02:04 AM, Christopher Nicholson-Sauls wrote: On 12/11/10 22:41, Matthias Walter wrote: Hi all, I wrote a ByToken tokenizer that models Range, i.e. it can be used in a foreach loop to read from a std.stdio.File. For it to work one has to supply it with a delegate, taking

Casting functions to delegates

2010-12-11 Thread Matthias Walter
Hi all, there was a discussion in 2006 but w/o a result, and I didn't find any bugs about implicitely casting functions to delegates. It seems to be impossible as long as function-pointer calls work differently than delegate calls in the ABI. Will this at some point be fixed? If not, is there a

ByToken Range

2010-12-11 Thread Matthias Walter
Hi all, I wrote a ByToken tokenizer that models Range, i.e. it can be used in a foreach loop to read from a std.stdio.File. For it to work one has to supply it with a delegate, taking a current buffer and a controller class instance. It is called to extract a token from the unprocessed part of

Re: D2 byChunk

2010-12-11 Thread Matthias Walter
On 12/11/2010 01:00 AM, Christopher Nicholson-Sauls wrote: On 12/10/10 22:36, Matthias Walter wrote: On 12/10/2010 09:57 PM, Matthias Walter wrote: Hi all, I currently work on a parser for some file format. I wanted to use the std.stdio.ByChunk Range to read from a file and extract tokens

Re: setting array dimensions at runtime

2010-12-05 Thread Matthias Walter
The only thing I've been able to think of is byte[][] a; a.length = size; for (int i; i size; i++) { a[i].length = size; } Well, you can do at least: auto a = new byte[][size]; foreach (ref row; a) row = new byte[size]; Matthias

Re: bigint

2010-11-28 Thread Matthias Walter
On 11/27/2010 02:05 PM, bearophile wrote: Reduced case for bugzilla: http://d.puremagic.com/issues/show_bug.cgi?id=5281 I investigated into the bug and the reason is the signature of opEquals, which currently is bool opEquals(Tdummy=void)(ref const BigInt y) const bool opEquals(T:

Re: value range propagation for %

2010-11-27 Thread Matthias Walter
On 11/27/2010 12:54 PM, Ellery Newcomer wrote: Hello. Today I've been thinking about calculating the range of values for x % y You might want to state the problem more precisely. What exactly is a range of values x % y ? Do you look at the result for x,y in some sets? Or is either x or y

Re: Basic coding style

2010-11-23 Thread Matthias Walter
On 11/23/2010 12:12 AM, Jonathan M Davis wrote: On Monday 22 November 2010 21:03:27 Walter Bright wrote: Matthias Walter wrote: What about adding a compiler switch that one can turn on and that warns on obviously wrong names? Is this realistic? At least to check the usage

Re: Basic coding style

2010-11-22 Thread Matthias Walter
On 11/22/2010 06:21 PM, JimBob wrote: bearophile bearophileh...@lycos.com wrote in message news:icdnn4$2cn...@digitalmars.com... I have four or five times tried to explain why coding standards are important for the development of the D community And them there stupid people just

Re: Repairing BigInt const

2010-11-21 Thread Matthias Walter
On 11/21/2010 04:33 PM, Don wrote: Matthias Walter wrote: as it seems, the current version of BigInt is not capable of const, i.e. BigInt(1) + const(BigInt)(1) does not work. Is there already an effort to fix this or would it make sense if I had taken some time to create a fix for it? I have

Repairing BigInt const

2010-11-20 Thread Matthias Walter
Hi all, as it seems, the current version of BigInt is not capable of const, i.e. BigInt(1) + const(BigInt)(1) does not work. Is there already an effort to fix this or would it make sense if I had taken some time to create a fix for it? I have no idea of all the asm in the x86 specialization but

Current status of toString in phobos

2010-11-17 Thread Matthias Walter
Hi, I'm currently using DMD v2.049 with phobos. I found an old discussion about how toString should be designed and how it is supposed to work. As the following code does not print out the number, I wonder what is the current status of how to implement a toString function for a struct/class: |

Re: A module comprehensive template-specialization

2010-06-28 Thread Matthias Walter
On 06/28/2010 05:32 AM, Simen kjaeraas wrote: Matthias Walter xa...@xammy.homelinux.net wrote: Can I handle this in another way (like making the template a conditional one)? Template constraints[1] sounds like what you want. Basically, you want the following: == Module a == | module

Re: A module comprehensive template-specialization

2010-06-28 Thread Matthias Walter
On 06/28/2010 09:49 AM, Justin Spahr-Summers wrote: On Sun, 27 Jun 2010 18:51:35 +0200, Matthias Walter xa...@xammy.homelinux.net wrote: Hi list, I tried to write a traits class comparable to iterator_traits in C++ STL or graph_traits in Boost Graph Library in D 2.0, but failed to do so

A module comprehensive template-specialization

2010-06-27 Thread Matthias Walter
; | } The error message is: bug.d(8): Error: template instance ambiguous template declaration b.Base(T : T*) and a.Base(T) Can I handle this in another way (like making the template a conditional one)? best regards Matthias Walter