Re: Where to place function attributes?

2012-08-19 Thread Simen Kjaeraas
On Sun, 19 Aug 2012 10:15:42 +0200, Jonathan M Davis jmdavisp...@gmx.com wrote: it's generally considered good practice to put const and immutable on the right-hand side. I would also say that putting function attributes on a separate line above the function is fairly common: const

Re: Stringy Weirdness

2012-08-18 Thread Simen Kjaeraas
On Sat, 18 Aug 2012 07:11:38 +0200, 1100110 10equa...@gmail.com wrote: I haven't been quite able to figure this one out. string[string][] Dict;//sure ok. alias string[string][] dict;//Error void main() { Dict = [[Cow:moo ],[Duck:quack]];//cool Dict

Re: Question on Octal

2012-08-15 Thread Simen Kjaeraas
On Wed, 15 Aug 2012 20:07:59 +0200, Jonathan M Davis jmdavisp...@gmx.com wrote: 1) The specification is clear that the if the template has only one member and the member has the same name with the template's, the member is implicitly referred to in the instantiation. The template octal has

Re: passing 0 to const char[]

2012-08-14 Thread Simen Kjaeraas
On Tue, 14 Aug 2012 21:27:25 +0200, Andrew andrew.sp...@gmail.com wrote: I'm trying to interface with C code, where I have a function definition that takes two const char[]'s: PetscErrorCode PetscInitialize(int*, char***, const char[], const char[]); However, the typical way that you pass

Re: char ***argc problems.

2012-08-12 Thread Simen Kjaeraas
On Sun, 12 Aug 2012 22:30:57 +0200, Andrew andrew.sp...@gmail.com wrote: I'm attempting to create a wrapper for MPI, however, MPI_Init wants to read the arguments for main(): MPI_Init(int *argv, char ***argc); How do I get this last level of pointer reference? So far, I have: void main

Re: char ***argc problems.

2012-08-12 Thread Simen Kjaeraas
On Sun, 12 Aug 2012 23:02:43 +0200, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: On 8/12/12, Simen Kjaeraas simen.kja...@gmail.com wrote: // Array of pointers to command line parameters. char*[] argv = args.map!((a)=(a.dup~'\0').ptr).array; You know.. it'd be much simpler

Re: How does immutable work.

2012-08-09 Thread Simen Kjaeraas
On Thu, 09 Aug 2012 19:25:47 +0200, egslava egsl...@gmail.com wrote: Hello! Sorry for my English. I read manual about immutable and const keyword: http://dlang.org/const3.html And tried to build my program: http://dpaste.dzfl.pl/f803ae94 If I will change immutable to const output will not

Re: Error: SIMD vector types not supported on this platform

2012-08-08 Thread Simen Kjaeraas
On Wed, 08 Aug 2012 15:46:23 +0200, ixid nuacco...@gmail.com wrote: I'm using the recently released DMD2 version 2.060. SIMD operations are not supported for Windows at the moment, I think. Of course, if you're running Linux, ignore this answer. -- Simen

Re: Why __traits(compile,...) fails here?

2012-08-08 Thread Simen Kjaeraas
On Wed, 08 Aug 2012 11:13:30 +0200, Timon Gehr timon.g...@gmx.ch wrote: Yes, but note that this distinction does not make any sense. alias int Int; // works isType!Int // 'Int' is clearly a symbol, yet the instantiation fails. I'm not sure it is 'clearly' a symbol. To the compiler, there is

Re: how implement takeWhile

2012-08-06 Thread Simen Kjaeraas
On Mon, 06 Aug 2012 11:53:18 +0200, bioinfornatics bioinfornat...@gmail.com wrote: Dear, 1/ i would like have a code near as this haskell code: fibs = 1 : 1 : zipWith (+) fibs (tail fibs) main = do print $ sum (filter even (takeWhile (400) fibs)) Ii know in D: - auto fib =

Re: how implement takeWhile

2012-08-06 Thread Simen Kjaeraas
On Mon, 06 Aug 2012 11:59:29 +0200, Simen Kjaeraas simen.kja...@gmail.com wrote: This is what you want, isn't it? recurrence!((a,n)=a[n-1]+a[n-2])(1,1).until!(a=a=4)() That is, the meat of it. The full line: writeln(recurrence!((a,n)=a[n-1]+a[n-2])(1,1).until!(a=a=4)().filter

Re: how implement takeWhile

2012-08-06 Thread Simen Kjaeraas
On Mon, 06 Aug 2012 17:49:19 +0200, Philippe Sigaud philippe.sig...@gmail.com wrote: On Mon, Aug 6, 2012 at 5:32 PM, Philippe Sigaud philippe.sig...@gmail.com wrote: What I'd like to know and may test myself is: is there any speed difference in this functional-oriented D code and a more

Re: Is delete really going away?

2012-07-29 Thread Simen Kjaeraas
On Sun, 29 Jul 2012 15:03:09 +0200, Minas Mina minas_mina1...@hotmail.co.uk wrote: Having a destructor and that you know when is going to be called is VERY useful! So by removing the delete keyword, what happens? We won't have a way to destroy objects in a predictable way anymore? (I'm not

Re: template with more than one tuple parameter

2012-07-29 Thread Simen Kjaeraas
On Sun, 29 Jul 2012 16:13:03 +0200, Timon Gehr timon.g...@gmx.ch wrote: On 07/28/2012 06:47 PM, Simen Kjaeraas wrote: On Sat, 28 Jul 2012 18:17:14 +0200, Zhenya zh...@list.ru wrote: Why do not D allow templates with more than one tuple parameters,at the same time that C++11 support

Re: Differing levels of type-inference: Can D do this?

2012-07-29 Thread Simen Kjaeraas
On Sun, 29 Jul 2012 19:11:17 +0200, Chad J chadjoan@__spam.is.bad__gmail.com wrote: So there. Now, you simply use auto a = constrain!isInputRange( expression );. Is this what you wanted? That's pretty good. It's still not as concise or easy to discover as the language's natural syntax

Re: A few questions

2012-07-28 Thread Simen Kjaeraas
On Sat, 28 Jul 2012 10:20:56 +0200, Namespace rswhi...@googlemail.com wrote: This is a NotNull I just implemented. It is designed to create a strict division between things that can be null, and those that cannot. The idea being that the programmer should be aware of it when he needs to

Re: A few questions

2012-07-27 Thread Simen Kjaeraas
On Fri, 27 Jul 2012 14:44:35 +0200, bearophile bearophileh...@lycos.com wrote: Namespace: Then: What is the problem to introduce such shorthand? I don't know. I have a partial enhancement on the topic: http://d.puremagic.com/issues/show_bug.cgi?id=4571 Bye, bearophile I believe at

Re: A few questions

2012-07-27 Thread Simen Kjaeraas
On Fri, 27 Jul 2012 16:39:49 +0200, Namespace rswhi...@googlemail.com wrote: What's wrong with the solution that void some_function(Foo? f) { is converted to void some_function(Foo f, string filename = __FILE__, uint line = __LINE__) in { assert(f !is null, std.string.format(Null

Re: A few questions

2012-07-27 Thread Simen Kjaeraas
On Fri, 27 Jul 2012 17:35:19 +0200, Jonathan M Davis jmdavisp...@gmx.com wrote: Many of us think that const Foo func() {} should just become illegal inconsistency or not because of all of this confusion, but Walter doesn't buy into that. Like monarch_dodra said, this is also a style

Re: copying the targets of pointers

2012-07-27 Thread Simen Kjaeraas
On Fri, 27 Jul 2012 19:28:06 +0200, monarch_dodra monarchdo...@gmail.com wrote: I'm kind of confused, because every time I see pointer usage, the deference operator is omitted? For example: struct S { void foo(){}; } S* p = new S(); p.foo(); When and where

Re: Simple D Questions (static if / #pragma / int[3][3])

2012-07-26 Thread Simen Kjaeraas
On Thu, 26 Jul 2012 13:34:34 +0200, bearophile bearophileh...@lycos.com wrote: static assert(0, ...); But in release mode it doesn't print the message. Now that'd be something. :p -- Simen

Re: an enum inside another enum

2012-07-26 Thread Simen Kjaeraas
On Thu, 26 Jul 2012 15:07:56 +0200, bearophile bearophileh...@lycos.com wrote: but isn't D supporting mixins inside enums? Nope. The text contents of the string must be compilable as a valid StatementList, and is compiled as such. And enums don't allow statements in their body. --

Re: an enum inside another enum

2012-07-26 Thread Simen Kjaeraas
I've also written this implementation of enumerations. It's a bit different from normal D enums, but supports inheritance, guarantees unique values, as is much more conservative in what conversions and operations it allows. I'm considering adding addition and subtraction of integers as

Re: an enum inside another enum

2012-07-26 Thread Simen Kjaeraas
On Thu, 26 Jul 2012 18:08:24 +0200, maarten van damme maartenvd1...@gmail.com wrote: The newly generated ExtendEnum will try to convert my old enum with string fields to integer fields. the mixin should generated ExtendEnum : string when passing in an enum with type string. Same problem

Re: normal function and template function conflict

2012-07-26 Thread Simen Kjaeraas
On Thu, 26 Jul 2012 19:18:21 +0200, monarch_dodra monarchdo...@gmail.com wrote: So here are my two questions: 1) Is what I was originally trying to do actually illegal, or is it some sort of compiler limitation? TDPL implies this should work perfectly fine... Compiler limitation. It's

Re: normal function and template function conflict

2012-07-26 Thread Simen Kjaeraas
On Thu, 26 Jul 2012 20:14:10 +0200, monarch_dodra monarchdo...@gmail.com wrote: On Thursday, 26 July 2012 at 17:57:31 UTC, Simen Kjaeraas wrote: On Thu, 26 Jul 2012 19:18:21 +0200, monarch_dodra monarchdo...@gmail.com wrote: 2) Is there a correct workaround? Exactly what you did. Though

Re: float[] → Vertex[] – decreases performance by 1000%

2012-07-24 Thread Simen Kjaeraas
On Tue, 24 Jul 2012 22:53:05 +0200, David d...@dav1d.de wrote: Am 24.07.2012 21:46, schrieb David: Hmm. Could this be a GC-related issue? Actually this could be. They are stored inside a Vertex* array which is allocated which is allocated with `malloc`, maybe the GC scans all of the created

Re: Explicit call of ternary compare

2012-07-23 Thread Simen Kjaeraas
On Mon, 23 Jul 2012 16:32:15 +0200, monarch_dodra monarchdo...@gmail.com wrote: Is there any (efficient and correct) way to do ternary comparison on two objects? You know the: if(ab) return -1; if(ba) return 1; return 0; I'm using the above method in a template, and the problem

Re: opDot == alias this?

2012-07-18 Thread Simen Kjaeraas
On Wed, 18 Jul 2012 16:58:34 +0200, Namespace rswhi...@googlemail.com wrote: First: Why is opDot not listed here: http://dlang.org/operatoroverloading.html ? How much other operators exists which are not listed there? I believe it's being deprecated. As far as I know, no other operators are

Re: readonly?

2012-07-10 Thread Simen Kjaeraas
On Tue, 10 Jul 2012 21:27:54 +0200, Namespace rswhi...@googlemail.com wrote: Maybe D need's a readonly keyword. Sometimes i have a class which can take an object from everywhere to store it. So it can not be const, because i didn't just initialized it with a ctor. But i don't want to

Re: Idea: writeln and file functions that return the data passed to them

2012-06-14 Thread Simen Kjaeraas
On Tue, 12 Jun 2012 14:12:19 +0200, ixid nuacco...@gmail.com wrote: Perhaps there is already a way to do this. With the UFCS one tends to make elegant chains of statements, it would be useful to have writeln and file functions that can easily be dropped in the middle of such chains without

Re: How to test for equality of types?

2012-05-18 Thread Simen Kjaeraas
On Fri, 18 May 2012 23:06:00 +0200, Matthias Walter xa...@xammy.homelinux.net wrote: [snip] prints out false Because Wrapper!(AliasStruct).Wrap does not exist. And _error_ is not equal to any other type. true Indeed, they are the same. false And here I disagree. This prints true

Re: is there a common type?

2012-05-17 Thread Simen Kjaeraas
On Thu, 17 May 2012 16:28:56 +0200, Christian Köstlin christian.koest...@gmail.com wrote: On 5/15/12 19:44 , H. S. Teoh wrote: On Tue, May 15, 2012 at 07:29:38PM +0200, Christian Köstlin wrote: for [1, 2, 3] and iota(2, 10)? [...] What are you trying to accomplish? T actually i just

Re: Translating C const

2012-05-15 Thread Simen Kjaeraas
On Tue, 15 May 2012 21:58:46 +0200, Jacob Carlborg d...@me.com wrote: On 2012-05-15 21:50, Ali Çehreli wrote: Not possible in D. D's const is transitive. If b is const, then what it points to is also const. Ali Then it would be best to not declare that as const? That depends. Will the

Re: Ref / NotNull struct

2012-05-06 Thread Simen Kjaeraas
I would be glad for criticism and suggestions and maybe a solution/workaround for the infinite loop bug, if it's the case, that it's really a bug. First thought (after just copying the code and compiling it, not reading the post :p), was 'where are the unittest blocks?' Then I saw you

Re: cannot cast

2012-05-03 Thread Simen Kjaeraas
On Thu, 03 May 2012 00:38:35 +0200, Namespace rswhi...@googlemail.com wrote: I'm not very skillful in such template stories. Maybe someone can help me? The main problem here is your opCast is non-const. (it's always an indication of const problems when DMD says X is not callable using

Re: Transforming a range back to the original type?

2012-05-03 Thread Simen Kjaeraas
On Wed, 02 May 2012 23:01:21 +0200, Jacob Carlborg d...@me.com wrote: Is there a general function for transforming a range back to the original type? If not, would it be possible to create one? In addition to std.array.array, as others have pointed out, there is also

Re: Use of mutex in destructors

2012-04-27 Thread Simen Kjaeraas
On Fri, 27 Apr 2012 13:23:00 +0200, Dmitry Olshansky dmitry.o...@gmail.com wrote: On 27.04.2012 15:15, Rene Zwanenburg wrote: Since an OpenGL context is owned by one thread, any OpenGL calls made from other threads will fail. I've wrapped OpenGL 'objects' in D classes to automate destruction

Re: Use of mutex in destructors

2012-04-27 Thread Simen Kjaeraas
On Fri, 27 Apr 2012 14:57:52 +0200, Rene Zwanenburg renezwanenb...@gmail.com wrote: On Friday, 27 April 2012 at 11:53:37 UTC, Simen Kjaeraas wrote: On Fri, 27 Apr 2012 13:23:00 +0200, Dmitry Olshansky dmitry.o...@gmail.com wrote: On 27.04.2012 15:15, Rene Zwanenburg wrote: Since

Re: Returning a tuple

2012-04-27 Thread Simen Kjaeraas
On Fri, 27 Apr 2012 14:52:08 +0200, Joseph Rushton Wakeling joseph.wakel...@webdrake.net wrote: Hello all, Just recently I tried returning a Tuple from a function and received an error message about this not being allowed. Reading up a bit on the D site I'm not clear -- is it a

Re: Use of mutex in destructors

2012-04-27 Thread Simen Kjaeraas
On Fri, 27 Apr 2012 17:55:02 +0200, Rene Zwanenburg renezwanenb...@gmail.com wrote: I _could_ modify the system to use ref counting everywhere, but I'm reluctant to do that. You wouldn't really need to. Only the texture struct would need that. Look to std.typecons's RefCounted[1] for

Re: alias this and null reference

2012-04-27 Thread Simen Kjaeraas
On Friday, 27 April 2012 at 16:36:04 UTC, Namespace wrote: By the following code i get a normal Access Violation. My question is: why? Even if f0 is null, the object must be converted to Ref and there i check if the given object is null. When trying to convert f0 to Ref, the compiler has to

Re: alias this and null reference

2012-04-27 Thread Simen Kjaeraas
On Friday, 27 April 2012 at 16:57:52 UTC, Namespace wrote: On Friday, 27 April 2012 at 16:49:49 UTC, Simen Kjaeraas wrote: On Friday, 27 April 2012 at 16:36:04 UTC, Namespace wrote: By the following code i get a normal Access Violation. My question is: why? Even if f0 is null, the object must

Re: Avoid compile time evaluation

2012-04-13 Thread Simen Kjaeraas
On Fri, 13 Apr 2012 14:52:05 +0200, Andrea Fontana nos...@example.com wrote: If I have something like: static int var = myFunction(); dmd will evaluate myFunction() at compile time. If it can't, it gives me a compile error, doesn't it? If I'm not wrong, static force this. Indeed. If i

Re: Whats the best way to get a struct/class member type?

2012-04-02 Thread Simen Kjaeraas
On Mon, 02 Apr 2012 09:58:18 +0200, simendsjo simend...@gmail.com wrote: On Mon, 02 Apr 2012 00:04:58 +0200, Simen Kjærås simen.kja...@gmail.com wrote: On Sat, 31 Mar 2012 15:20:42 +0200, simendsjo simend...@gmail.com wrote: Seems __traits doesn't have a __traits(getMemberType, T,

Re: FIFO stack

2011-10-26 Thread Simen Kjaeraas
On Wed, 26 Oct 2011 17:15:37 +0200, Simen Kjaeraas simen.kja...@gmail.com wrote: On Wed, 26 Oct 2011 10:58:12 +0200, Dominic Jones dominic.jo...@qmul.ac.uk wrote: Hello, I was looking for a FIFO stack in std.containers but only found SList and Array which both appear to essentially

Re: Heap fucntion calls

2011-09-22 Thread Simen Kjaeraas
On Thu, 22 Sep 2011 00:43:09 +0200, deadalnix deadal...@gmail.com wrote: Great answer ! Thank you very much, it answered almost everything ! But what about, in the exemple you gave me (which is great by the way) if foo as parameters ? Those parameters are passed on the stack by copy to the

Re: Heap fucntion calls

2011-09-21 Thread Simen Kjaeraas
On Wed, 21 Sep 2011 18:32:49 +0200, deadalnix deadal...@gmail.com wrote: D has a wonderfull feature named delegate. Delegate can acess local data, thus would be dangerous if thoses data were on the stack. For what I understand, when a delegate can access the local data of a function, those

Re: A little puzzle

2011-09-19 Thread Simen Kjaeraas
On Mon, 19 Sep 2011 23:20:47 +0200, bearophile bearophileh...@lycos.com wrote: A tiny puzzle I've shown on IRC. This is supposed to create an inverted array of cards, but what does it print instead? import std.stdio, std.algorithm, std.range; void main() { int[52] cards;

Re: Why can't templates with default arguments be instantiated without the bang syntax?

2011-09-15 Thread Simen Kjaeraas
On Thu, 15 Sep 2011 16:46:24 +0200, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: struct Foo(T = int) {} void main() { Foo foo; // fail Foo!() bar; // ok } It would be very convenient to be able to default to one type like this. For example, in CairoD there's a Point

Re: Why can't templates with default arguments be instantiated without the bang syntax?

2011-09-15 Thread Simen Kjaeraas
On Thu, 15 Sep 2011 17:54:19 +0200, Christophe trav...@phare.normalesup.org wrote: Simen Kjaeraas , dans le message (digitalmars.D.learn:29539), a écrit : On Thu, 15 Sep 2011 16:46:24 +0200, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: struct Foo(T = int) {} void main() { Foo

Re: Is it possible to check if a type is an instance of a template?

2011-09-15 Thread Simen Kjaeraas
On Thu, 15 Sep 2011 22:24:50 +0200, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: I can do this: struct Foo(T) { } template bar(T : Foo!int) { } I can check if T is a specific instantiation of Foo. But I want to check whether T is *any* instantiation of Foo. Is this possible to do?

Re: Is it possible to check if a type is an instance of a template?

2011-09-15 Thread Simen Kjaeraas
On Thu, 15 Sep 2011 22:45:21 +0200, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: Cool, that works, thanks. Is this in Phobos by any chance? Otherwise I'll just use a more flexible version of that. No more flexible version available, sadly. I wish this worked (I think it's in Bugzilla

Re: defining in What is the proper way in D2?

2011-09-12 Thread Simen Kjaeraas
On Mon, 12 Sep 2011 00:11:11 +0200, Timon Gehr timon.g...@gmx.ch wrote: I think the fact that in for AAs returns a pointer is a mistake and ugly in the first place and any generic code that relies on any container to return a raw internal pointer is flawed by itself imho. If D had a

Re: What does ref means

2011-09-07 Thread Simen Kjaeraas
On Wed, 07 Sep 2011 20:50:04 +0200, Johannes Totz johan...@jo-t.de wrote: On 06/09/2011 12:00, bearophile wrote: malio: Okay, thanks bearophile. But I currently doesn't exactly understand what's the difference between ref and const ref/immutable ref. If ref is syntactic sugar for pointers

Re: How do pure member functions work?

2011-08-22 Thread Simen Kjaeraas
On Mon, 22 Aug 2011 22:19:50 +0200, Don nos...@nospam.com wrote: BTW: The whole weak pure/strong pure naming was just something I came up with, to convince Walter to relax the purity rules. I'd rather those names disappeared, they aren't very helpful. The concepts are useful, but better

Re: count until predicate returns false

2011-08-15 Thread Simen Kjaeraas
On Mon, 15 Aug 2011 21:53:11 +0200, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: This will print the count of whitespace chars in a line: writeln(count!isWhite(line)); What I need is the count of whitspace chars until the first non-whitespace char is found, essentially I need a

Re: enum inheritance?

2011-08-13 Thread Simen Kjaeraas
On Sun, 14 Aug 2011 01:15:29 +0200, mimocrocodil 4deni...@gmail.com wrote: Hi! I am want to extend available enum to provide more items to them. How I can do this job without manual copying of exsisting enum items? If what you want is a new enum that contains the values of an existing

Re: std.concurrency.spawn does not accept delegates

2011-07-18 Thread Simen Kjaeraas
On Mon, 18 Jul 2011 18:06:46 +0200, Jonathan M Davis jmdavisp...@gmx.com wrote: On Monday 18 July 2011 15:55:52 teo wrote: On Mon, 18 Jul 2011 10:26:27 -0400, Steven Schveighoffer wrote: On Sun, 17 Jul 2011 15:29:02 -0400, teo teo.ubu...@yahoo.com wrote: It looks like std.concurrency.spawn

Re: wrapping a void* by a ubyte[] array?

2011-07-14 Thread Simen Kjaeraas
On Thu, 14 Jul 2011 17:07:20 +0200, teo teo.ubu...@yahoo.com wrote: Is there any way of wrapping a void* by a ubyte[] array? The void* comes from mmap. byte[] array = cast(ubyte[])mmap(addr, length, ...)[0..length;] -- Simen

Re: Implicit type conversion for function calls?

2011-07-11 Thread Simen Kjaeraas
On Sun, 10 Jul 2011 22:30:34 +0200, Jonathan M Davis jmdavisp...@gmx.com wrote: Well, if you can do it with alias this, then it's possible. If not, then it probably isn't. But I don't know what opImplicitCast would give you if alias this doesn't (particularly if alias this is working

Implicit type conversion for function calls?

2011-07-10 Thread Simen Kjaeraas
I'm trying to have this sort of code compile: struct Foo { int data; this(int n) { data = n; } } void bar(Foo f) {} bar(3); Is this even possible? I believe the feature was called opImplicitCastFrom, at some point. Conversely, the

Re: Implicit type conversion for function calls?

2011-07-10 Thread Simen Kjaeraas
On Sun, 10 Jul 2011 16:41:17 +0200, bearophile bearophileh...@lycos.com wrote: There is a uncommon syntax that allows you to do it with a class, but I don't know why structs don't work here: class Foo { int data; this(int n) { data = n; } } void bar(Foo f ...) {

Re: Implicit type conversion for function calls?

2011-07-10 Thread Simen Kjaeraas
On Sun, 10 Jul 2011 21:39:54 +0200, Jonathan M Davis jmdavisp...@gmx.com wrote: On Sunday 10 July 2011 20:47:04 David Nadlinger wrote: On 7/10/11 3:29 PM, Simen Kjaeraas wrote: I'm trying to have this sort of code compile: struct Foo { int data; this(int n) { data = n

Re: Float Comparison Returns False

2011-07-07 Thread Simen Kjaeraas
On Thu, 07 Jul 2011 20:19:05 +0200, Loopback elliott.darf...@gmail.com wrote: Hello! I've been programming some miscellaneous code and got stuck in an odd case. While comparing floats, two obviously identical values return false in comparison. I am not sure if this is related to float

Re: Passing a generic struct as parameter

2011-07-01 Thread Simen Kjaeraas
On Fri, 01 Jul 2011 08:58:32 +0200, Zardoz luis.panad...@gmail.com wrote: Well, the problem is that I must do the cast always, see : // alias Matrix!(real,4) Mat4r; // alias Vector!(float, 3) Vec3f; // alias Vector!(real, 4) Vec4r; // In Mat4r, VCol it's aliased to Vector!(real, 4) auto tcol

Re: Forcing compile time evaluation of pure functions

2011-06-30 Thread Simen Kjaeraas
On Thu, 30 Jun 2011 07:11:44 +0200, scarrow shawn.ba...@gmail.com wrote: Hey all, I'd like to embed hashed strings into my code. The C++ version of this engine ran an external tool to preprocess the files. In D my strongly pure function is only evaluated if I assign it to something like

Re: Passing a generic struct as parameter

2011-06-30 Thread Simen Kjaeraas
On Fri, 01 Jul 2011 01:39:53 +0200, Zardoz luis.panad...@gmail.com wrote: I have a parametrized struct (Vector!(T, dim)) that takes two parameters (Type and a number). And made some Alias with defaults parameters. In other struct (Matrix!(T, dim)), that uses these struct to represent a matrix

Re: Get parent Tid of a thread?

2011-06-29 Thread Simen Kjaeraas
On Wed, 29 Jun 2011 22:59:47 +0200, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: Is there any way a newly spawned thread can get the Tid of the thread that spawned it, basically its parent? I'd prefer that over using this: __gshared mainThread; // so workThread can access it {

Re: Using immutable values as template parameter hangs dmd

2011-06-26 Thread Simen Kjaeraas
On Sun, 26 Jun 2011 16:10:04 +0200, simendsjo simen.end...@pandavre.com wrote: This is probably not a minimal test case, but it's as far as I got. Don't know what the actual bug is, so I'd be grateful if someone else could help explain it so I can add it to Bugzilla with a better subject.

Re: is expression on templated types

2011-06-25 Thread Simen Kjaeraas
On Sat, 25 Jun 2011 15:57:03 +0200, simendsjo simen.end...@pandavre.com wrote: I have a templated struct, and I'd like to check if a given type is this struct. I have no idea how I should write the is expression.. struct S(int C, int R, T) { T[C][R] data; } template isS(T) { enum

Re: nested class inheritance

2011-06-01 Thread Simen Kjaeraas
On Wed, 01 Jun 2011 01:57:52 +0200, Michael Shulman viritril...@gmail.com wrote: I've also realized that my proposed workaround actually doesn't work, because 'alias this' doesn't actually behave like subclassing with respect to references. That is, if Inner2 is 'alias this'ed to Inner1, and

Re: Template parameter defaults

2011-05-31 Thread Simen Kjaeraas
On Tue, 31 May 2011 19:49:24 +0200, Steven Schveighoffer schvei...@yahoo.com wrote: Currently, you can omit the template args only in the case of IFTI (Implicit Function Template Instantiation) which actually deduces your template arguments based on the function call. I'd argue actually,

Re: nested class inheritance

2011-05-31 Thread Simen Kjaeraas
On Tue, 31 May 2011 20:17:23 +0200, Michael Shulman viritril...@gmail.com wrote: I have thought of a workaround with 'alias this': class Outer2 : Outer1 { class Inner2 { Inner1 _self; alias _self this; this() { _self = this.outer.new Inner1(); } } } This seems to

Re: Some help on Mixin Template at Class level.

2011-05-22 Thread Simen Kjaeraas
On Sat, 21 May 2011 11:40:22 +0200, Matthew Ong on...@yahoo.com wrote: Using your code I have this error: src\Sample.d(16): Error: undefined identifier btype, did you mean template AType(string name,U,alias V)? src\Sample.d(16): Error: mixin AType!(ClassB,string,_error_) does not match

Re: Some help on Mixin Template at Class level.

2011-05-21 Thread Simen Kjaeraas
On Sat, 21 May 2011 10:54:54 +0200, Matthew Ong on...@yahoo.com wrote: mixin template AType(alias T, U, alias V){ class T : ClassC { // Class level Template This gives you a class called T. You seem to want it to have the name you pass as a string, in which case you have to use string mixins.

Re: What is this strange alias syntax?

2011-05-21 Thread Simen Kjaeraas
On Sat, 21 May 2011 05:12:20 +0200, Andrej Mitrovic n...@none.none wrote: Taken from the docs: alias int func(int); void main() { if ( is(func[]) ) // not satisfied because arrays of writeln(satisfied);// functions are not allowed else writeln(not

Re: char[][] join == string

2011-04-07 Thread Simen kjaeraas
On Thu, 07 Apr 2011 02:13:16 +0200, bearophile bearophileh...@lycos.com wrote: Given an array of strings std.string.join() returns a single string: import std.string; void main() { string[] a1 = [hello, red]; string j1 = join(a1, ); // OK } But in a program I need an array of

Re: Using opDispatch as *magic* getter/setter. Possible or not?

2011-04-04 Thread Simen kjaeraas
On Thu, 31 Mar 2011 02:32:35 +0200, Aleksandar Ružičić ruzicic.aleksan...@gmail.com wrote: Is it possible to use opDispatch as generic getter and setter at the same time? Something like __get() and __set() in PHP.. this is what I've tried: https://gist.github.com/895571 and I get Error:

Re: clear()

2011-03-28 Thread Simen kjaeraas
On Mon, 28 Mar 2011 16:57:17 +0200, Kai Meyer k...@unixlords.com wrote: On 03/25/2011 01:10 PM, Dr.Smith wrote: To empty many arrays of various types, rather than: clear(arr1); clear(arr2); ... clear(arrN); is there something like: clear(ALL); No, but perhaps you can do a: foreach(a; ALL)

Re: Need help in templates

2011-03-24 Thread Simen kjaeraas
On Fri, 25 Mar 2011 06:18:21 +0100, Ishan Thilina ishanthil...@gmail.com wrote: Hi, I'm still new to D. I tried to implement a stack using templates. But I get an Access Violation error when I try to run a test on the stack that I made.The source code is attached with this mail. Can

Re: Want to help DMD bugfixing? Write a simple utility.

2011-03-21 Thread Simen kjaeraas
On Mon, 21 Mar 2011 01:52:45 +0100, Ary Manzana a...@esperanto.org.ar wrote: On 3/19/11 9:11 PM, Don wrote: Here's the task: Given a .d source file, strip out all of the unittest {} blocks, including everything inside them. Strip out all comments as well. Print out the resulting file.

Re: immutable and static this()

2011-03-21 Thread Simen kjaeraas
On Mon, 21 Mar 2011 22:27:17 +0100, teo teo.ubu...@yahoo.com wrote: I cannot initialize immutable class members inside a static this() constructor. Is there any reason for that? Example: class Test { public immutable(int) x; static this() { x = 1; // Error: variable Test.x

Re: Other integral literals?

2011-03-20 Thread Simen kjaeraas
On Sun, 20 Mar 2011 19:37:45 +0100, spir denis.s...@gmail.com wrote: * ideally, I would use the sign to tell signed types apart (1 is unsigned, +1 is signed) I hope you messed that one up. An unadorned int literal should be signed. Period. * get rid of 01 octal bug! Oh gods, yes.

Re: Expression tuples

2011-03-16 Thread Simen kjaeraas
On Wed, 16 Mar 2011 21:07:08 +0100, simendsjo simen.end...@pandavre.com wrote: http://www.digitalmars.com/d/2.0/tuple.html // this example fails Tuple!(3, 7, 'c') typecons.d(298): Error: static assert Attempted to instantiate Tuple with an invalid argument: 3 Even this fails: alias

Re: Expression tuples

2011-03-16 Thread Simen kjaeraas
On Wed, 16 Mar 2011 21:51:37 +0100, Steven Schveighoffer schvei...@yahoo.com wrote: On Wed, 16 Mar 2011 16:28:48 -0400, Simen kjaeraas simen.kja...@gmail.com wrote: On Wed, 16 Mar 2011 21:07:08 +0100, simendsjo simen.end...@pandavre.com wrote: http://www.digitalmars.com/d/2.0

Re: Template string literal?

2011-03-16 Thread Simen kjaeraas
On Wed, 16 Mar 2011 22:39:00 +0100, Denis Koroskin 2kor...@gmail.com wrote: On Thu, 17 Mar 2011 00:30:17 +0300, Jacob Carlborg d...@me.com wrote: Is it possible to declare string literal of a template type, something like this: void bar (const(T)[] a) {} void foo (T) (const(T)[] a) {

Re: Expression tuples

2011-03-16 Thread Simen kjaeraas
On Wed, 16 Mar 2011 22:43:20 +0100, Steven Schveighoffer schvei...@yahoo.com wrote: Now I am concerned, this looks like an oxymoron: TypeTuple!(1, 2, 3) Should we think about changing the name of std.typetuple.TypeTuple since it can clearly contain expressions as well as types? I would

Re: Deducing types for function templates

2011-03-15 Thread Simen kjaeraas
On Tue, 15 Mar 2011 17:36:04 +0100, Michel Fortin michel.for...@michelf.com wrote: On 2011-03-15 10:42:46 -0400, Magnus Lie Hetland mag...@hetland.org said: I've got a function template along these lines: Foo!T foo(T)(T[] bar, real function(T,T) baz) { ... } The main reason I'm using

Re: Points and Vectors in 3D

2011-03-13 Thread Simen kjaeraas
Spacen Jasset spacenjas...@yahoo.co.uk wrote: On 13/03/2011 00:06, Bekenn wrote: On 3/12/2011 2:20 PM, Simon wrote: I've done lots of 3d over the years and used quite a lot of different libraries and I've come to prefer code that makes a distinction between points and vectors. Agreed. This

Re: Points and Vectors in 3D

2011-03-13 Thread Simen kjaeraas
On Sun, 13 Mar 2011 15:43:09 +0100, Simon s.d.hamm...@gmail.com wrote: On 13/03/2011 14:11, Simen kjaeraas wrote: Spacen Jasset spacenjas...@yahoo.co.uk wrote: On 13/03/2011 00:06, Bekenn wrote: On 3/12/2011 2:20 PM, Simon wrote: I've done lots of 3d over the years and used quite a lot

Re: Read file/stream

2011-03-11 Thread Simen kjaeraas
nrgyzer nrgy...@gmail.com wrote: I'm trying to read a png file and I'm having some trouble with the chunk-size. Each chunk of a png file begins with a 4 byte (unsigned) integer. When I read this 4 byte integer (uint) I get an absolutely incorrect length. My code currently looks like: void

Re: enum with classes/structs

2011-03-10 Thread Simen kjaeraas
useo u...@start.bg wrote: Hey guys, is it possible to declare a enum where all entries are instances of a class (or struct), like the following: class a { ... public this(uint i) { ... } ... } enum myEnum : a { entry1 = new a(0); entry2 = new a(1); } ... or does

Re: Access 'this' in inline assembly

2011-03-07 Thread Simen kjaeraas
Martin Kinkelin no...@spam.com wrote: Thanks, movups XMM0, [EAX]; works. The SSE version takes more than 160% of the run-time compared to the naive version though. ;) Yup. Functions using inline assembly are never inlined, so that's rarely a good reason to use it. -- Simen

Re: C const

2011-03-05 Thread Simen kjaeraas
Jesse Phillips jessekphillip...@gmail.com wrote: simendsjo Wrote: On 04.03.2011 23:10, Jesse Phillips wrote: Remember that const/immutable, and other attributes/properties aren't going to change the ABI so dropping them will be safer then leaving them. Thanks. Does this apply to all

Re: Overriding in operator

2011-03-04 Thread Simen kjaeraas
Magnus Lie Hetland mag...@hetland.org wrote: On 2011-03-04 17:06:29 +0100, Mafi said: If you try to use it in the manner of `something in classWhichDefinesThisOpBinary` then it doesn't work because operator overloading normally overloads on the left operand (ie something). Use

Re: Overriding iteration

2011-03-04 Thread Simen kjaeraas
Magnus Lie Hetland mag...@hetland.org wrote: From what I understand, when you override iteration, you can either implement the basic range primitives, permitting foreach to destructively iterate over your object, or you can implement a custom method that's called, and that must perform the

Re: Iterating a typle tuple of templates

2011-03-04 Thread Simen kjaeraas
bearophile bearophileh...@lycos.com wrote: Jacob Carlborg: Maybe you can try something like typeof(t2) in the foreach. If you mean code like this: import std.typetuple; int foo(T)(T x) { return x; } void main() { alias TypeTuple!(foo, foo) t2; foreach (i, t; typeof(t2)) {

Re: Overriding iteration

2011-03-04 Thread Simen kjaeraas
Simen kjaeraas simen.kja...@gmail.com wrote: Magnus Lie Hetland mag...@hetland.org wrote: From what I understand, when you override iteration, you can either implement the basic range primitives, permitting foreach to destructively iterate over your object, or you can implement a custom

Re: Dupping in a nothrow function?

2011-03-04 Thread Simen kjaeraas
bearophile bearophileh...@lycos.com wrote: Simen kjaeraas: It's probably correct that _adDupT is not nothrow. It is also wrong that it shouldn't be. I was about to write a bug report regarding allowing dupping in nothrow functions, because this is now allowed, and I think this is the same

<    1   2   3   4   5   >