Re: Accessing __FILE__ and __LINE__ of caller in combination with varargs?

2016-04-16 Thread Simen Kjaeraas via Digitalmars-d-learn
On Saturday, 16 April 2016 at 00:03:59 UTC, Jonathan M Davis wrote: On Friday, April 15, 2016 20:52:42 WebFreak001 via Digitalmars-d-learn wrote: void assertf(string file = __FILE__, size_t line = __LINE__, Args...)(lazy bool condition, in string message, Args args) { Yes, you can do that, b

Re: infer type argument in classe constructor?

2016-03-29 Thread Simen Kjaeraas via Digitalmars-d-learn
On Tuesday, 29 March 2016 at 10:13:28 UTC, Puming wrote: Hi, I'm writing a generic class: ```d struct Message { ... } class Decoder(MsgSrc) { } ``` When using it, I'd have to include the type of its argument: ``` void main() { Message[] src = ...; auto decoder = new Decoder!(Message[

Re: Does something like std.algorithm.iteration:splitter with multiple seperators exist?

2016-03-23 Thread Simen Kjaeraas via Digitalmars-d-learn
On Wednesday, 23 March 2016 at 18:10:05 UTC, ParticlePeter wrote: Thanks Simen, your tokenCounter is inspirational, for the rest I'll take some time for testing. My pleasure. :) Testing it on your example data shows it to work there. However, as stated above, the documentation says it's unde

Re: Does something like std.algorithm.iteration:splitter with multiple seperators exist?

2016-03-23 Thread Simen Kjaeraas via Digitalmars-d-learn
On Wednesday, 23 March 2016 at 11:57:49 UTC, ParticlePeter wrote: I need to parse an ascii with multiple tokens. The tokens can be seen as keys. After every token there is a bunch of lines belonging to that token, the values. The order of tokens is unknown. I would like to read the file in as

Re: How do I extend an enum?

2016-03-19 Thread Simen Kjaeraas via Digitalmars-d-learn
On Saturday, 19 March 2016 at 17:40:27 UTC, Lass Safin wrote: Why: enum Base { A, B, } enum Derived : Base { C, // Gives error, says it can't implicitly convert expression to Base. D = 1, // Same error E = cast(Base)294, // Finally works. Can only be cast(Derived) instead

Re: classInstanceSize and vtable

2014-10-23 Thread Simen Kjaeraas via Digitalmars-d-learn
On Friday, 24 October 2014 at 00:21:52 UTC, Etienne Cimon wrote: On 2014-10-23 20:12, bearophile wrote: In D all class instances contain a pointer to the class and a monitor pointer. The table is used for run-time reflection, and for standard virtual methods like toString, etc. Bye, bearophil

Re: this() immutable

2013-10-16 Thread Simen Kjaeraas
On 2013-10-16, 18:54, Daniel Davidson wrote: On Thursday, 13 June 2013 at 12:29:57 UTC, Simen Kjaeraas wrote: On Thu, 13 Jun 2013 14:17:22 +0200, Stephan Schiffels wrote: For example, is there a way of instantiating an object normally (i.e. mutable), and then later "freeze&q

Re: fill array using a lambda function

2013-10-10 Thread Simen Kjaeraas
On 2013-10-10, 16:04, bearophile wrote: dominic jones: I want to fill an array with random numbers without resorting to loops, i.e. by doing something like the following, if it were possible: fill!(function double(){ return uniform(0.0, 1.0);})(x[]); Is there a simple way of doing this?

Re: How to check for instantiation of specific template?

2013-10-10 Thread Simen Kjaeraas
On 2013-10-10, 19:23, H. S. Teoh wrote: I have a template used for storing compile-time values: template Def(int x, string y) { alias impl = TypeTuple!(x,y); } How do I define a template isDef that, given some template alias A, evaluates to true if A is some ins

Re: What's about virtual?

2013-09-10 Thread Simen Kjaeraas
On Tue, 10 Sep 2013 02:28:24 +0200, Andrei Alexandrescu wrote: On 9/9/13 12:47 PM, H. S. Teoh wrote: On Mon, Sep 09, 2013 at 09:37:07PM +0200, Namespace wrote: It's been a while since Manu convinced Walter and Andrei to introduce a virtual Keyword and to change the default from virtual meth

Re: What is a concise way to test if floating point value is integral?

2013-08-29 Thread Simen Kjaeraas
On 2013-08-29, 10:25, Jonathan M Davis wrote: On Thursday, August 29, 2013 10:07:31 Paul Jurczak wrote: On Thursday, 29 August 2013 at 07:51:40 UTC, Jonathan M Davis wrote: [..] > as any integral value in a float will fit in an > int. [..] Will it? Most of them will not fit Sure, they will

Re: Get class size of object

2013-08-11 Thread Simen Kjaeraas
On 2013-08-11, 20:33, JS wrote: I think you're missing the point to some degree(I realize there is a diff between an object and a type, but I should be able to easily get the class size of an object at run time regardless if the object is typed as a base class). The code below does this, bu

Re: trouble with long

2013-07-16 Thread Simen Kjaeraas
On Tue, 16 Jul 2013 12:37:58 +0200, eles wrote: $cat test.cpp: #include int main() { long long x = 125000 * 2; std::cout << x << std::endl; return 0; } g++-generated exe displays: -1794967296 $cat test.d: import std.stdio; int main() { long x = 125

Re: Types of regex

2013-07-15 Thread Simen Kjaeraas
On 2013-07-15, 11:32, Larry wrote: Hello, I read the library reference for regex. I really miss python's equivalent of finditer. Sometimes matching is not on purpose and one will want to match all the occurences to iterate over it since it is much more regarding concerning the orders and

Re: Conditional Inheritance

2013-07-14 Thread Simen Kjaeraas
On 2013-07-14, 07:40, JS wrote: On Sunday, 14 July 2013 at 05:30:57 UTC, lomereiter wrote: On Sunday, 14 July 2013 at 05:04:37 UTC, JS wrote: and while I'm at it I need to conditionally constrain types. interface A(T) where(!isBasicType!T, (T : B)); which is suppose to require T to inherit f

Re: Conditional Inheritance

2013-07-14 Thread Simen Kjaeraas
On 2013-07-14, 07:00, JS wrote: I need to conditionally inherit: interface A(T) : conditionallyInherit!(isBasicType!T, B); A!(double) will inherit B but A!(mytype) won't. template conditionallyInherit(bool choice, T...) { static if (choice) { alias conditionallyInherit = T; }

Re: Reference to D class instance with a C library

2013-07-13 Thread Simen Kjaeraas
On 2013-07-13, 20:53, Leandro Motta Barros wrote: Hey, thanks! This makes sense :-) Am I now wondering... how safe, portable and future proof would this be? If some future version of D implements a garbage collector capable of moving objects around the heap, I could get in trouble, right? Als

Re: for loop parens

2013-07-12 Thread Simen Kjaeraas
On 2013-07-12, 22:38, ixid wrote: On Friday, 12 July 2013 at 20:30:59 UTC, bearophile wrote: ixid: Similarly what are D user's potential issues with Go-like semi-colon rules? And would this be possible as a subset of current D code? Such changes will not happen even in D4. Walter is strong

Re: Style question

2013-07-12 Thread Simen Kjaeraas
On 2013-07-11, 20:22, Namespace wrote: What should he do? As far as I can see he has 3 options: 1. An external file with the enum information. Both classes would import it and could use the same enum. But he cannot change the API, so this is no real option. 2. Change test1 into this:

Re: Style question

2013-07-11 Thread Simen Kjaeraas
On 2013-07-11, 21:05, Namespace wrote: It seems to me that MyClass has access to MyStaticClass, and thus should also have access to B. If this is the case, why is MyClass using an A instead of a B? No, they are sadly not part of the same file / module. The // should symbolize that. :D I

Re: Style question

2013-07-11 Thread Simen Kjaeraas
On 2013-07-11, 20:22, Namespace wrote: What should he do? As far as I can see he has 3 options: 1. An external file with the enum information. Both classes would import it and could use the same enum. But he cannot change the API, so this is no real option. 2. Change test1 into this:

Re: Tuple indexing and slicing

2013-07-11 Thread Simen Kjaeraas
On 2013-07-11, 00:52, Timothee Cour wrote: Why not support Tuple indexing and slicing with [] syntax? (see below for a way to index/slice a tuple) void main(){ alias T=Tuple!(int,double); pragma(msg,T[0].stringof);//_expand_field_0 //pragma(msg,T[0..2].stringof); //Error: cannot slice ty

Re: How can i increase max number recursive template expansions?

2013-07-08 Thread Simen Kjaeraas
On 2013-07-08, 11:03, bearophile wrote: Simen Kjaeraas: However, you can amend std.traits.EnumMembers to work with larger enums by using this version: Worth putting in Phobos? Filed: http://d.puremagic.com/issues/show_bug.cgi?id=10569 And created a pull request: https://github.com/D

Re: How can i increase max number recursive template expansions?

2013-07-07 Thread Simen Kjaeraas
On 2013-07-07, 22:28, John Colvin wrote: We came up with almost identical solutions, posted within 19 seconds of each other! Sorta. Mine does repeated halving, and makes DMD run out of memory with 16384 enum members. Yours balks at an enum of > about 1000 elements. -- Simen

Re: How can i increase max number recursive template expansions?

2013-07-07 Thread Simen Kjaeraas
On 2013-07-07, 21:55, QAston wrote: I have a large enum in my code (opcodes for a protocol) - using std.traits.EnumMembers gives me a recursive template error. How can i increase max number recursive template expansions? You can't. However, you can amend std.traits.EnumMembers to work with

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: Windows parameter

2013-06-30 Thread Simen Kjaeraas
On Sun, 30 Jun 2013 20:24:17 +0200, shuji wrote: int setHWND(HWND extHwnd){ hwnd = extHwnd; return 0; } And: extern (C++) { int setHWND(HWND hwnd); } See how these are different? One of them is an extern (C++) function, the other is a D function. In other word

Re: [Question] Could a function return a list of arguments to call another function?

2013-06-28 Thread Simen Kjaeraas
On Fri, 28 Jun 2013 20:07:23 +0200, MattCoder wrote: Hi, I would like to know if it's possible to pass the return of a function as argument to another function as below: import std.stdio; auto foo(int x, int y){ writeln(x, y); return 3, 4; } void main(){ foo(foo

Re: mutable constant?

2013-06-25 Thread Simen Kjaeraas
On Wed, 26 Jun 2013 00:07:38 +0200, Namespace wrote: I want to ask if this code should compile or if it's a bug, because I circumvent the const system: import std.stdio; struct Point { int x, y; } Point*[] points; struct TplPoint(T) { public: Point _point;

Re: Possble bug ? Adding

2013-06-24 Thread Simen Kjaeraas
On 2013-06-24, 22:30, Temtaime wrote: Hello, guys ! http://dpaste.1azy.net/8917c253 I'm not sure I've seen this bug before, but yes, it is one. The cause is that the grammar for the new alias syntax is apparently not complete. Please file: http://d.puremagic.com/issues/enter_bug.cgi -- Si

Re: Multiple return type from object factory possible?

2013-06-22 Thread Simen Kjaeraas
On Sat, 22 Jun 2013 18:58:22 +0200, deed wrote: class A { ... } class NonContainer : A { ... } class Container : A { A[] container; } class NC1 : NonContainer {} ... class C1 : Container {} ... A getO(string info) { switch (info) { default : retur

Re: A little of coordination for Rosettacode

2013-06-18 Thread Simen Kjaeraas
On 2013-06-18, 05:00, bearophile wrote: With your code I have found a dmd compiler bug, are you able and willing to further reduce this? Tried this with 2.063.2, and there are three errors in the code - deserializeInto should return its buffer, the switch on line 19 needs a default: case,

Re: this() immutable

2013-06-13 Thread Simen Kjaeraas
On Thu, 13 Jun 2013 14:17:22 +0200, Stephan Schiffels wrote: For example, is there a way of instantiating an object normally (i.e. mutable), and then later "freeze" it to immutable via a simple cast or so? In std.exception there is assumeUnique. It's basically just a cast, but might be g

Re: Why TypeTuple can be assigned to a variable

2013-06-12 Thread Simen Kjaeraas
On Wed, 12 Jun 2013 11:44:19 +0200, Zhenya wrote: OK,you say that TypeTuple!("foo","bar") is a cool value of type TypeTuple!(string,string),right? Well, yes and no, not really. It's a bit magical. In your case, it's assigned to an auto variable, and that variable gets that type. There are oth

Re: Why TypeTuple can be assigned to a variable

2013-06-12 Thread Simen Kjaeraas
On Wed, 12 Jun 2013 10:01:59 +0200, Zhenya wrote: Hi! I was just surprised when realized, that this code compiles and runs: import std.typetuple; import std.stdio; void main() { auto foo = TypeTuple!("foo","bar"); writeln(typeid(typeof(foo))); writeln(foo); } If I were compiler expert,I

Re: Why there is too many uneccessary casts?

2013-06-11 Thread Simen Kjaeraas
On Tue, 11 Jun 2013 13:46:11 +0200, Temtaime wrote: No. I means, that uint a = uint.max; uint b = a + 1; writeln(b); Works OK. Why? Compiler doesn't know if a + b fits in uint, right? Then why overflow with ints are accepted? Because there's a limit to how far this goes without introducing

Re: Why there is too many uneccessary casts?

2013-06-11 Thread Simen Kjaeraas
On Tue, 11 Jun 2013 13:15:11 +0200, Simen Kjaeraas wrote: On Tue, 11 Jun 2013 12:39:47 +0200, Temtaime wrote: There is overflow and it can be with int too. It's standard behavior. Indeed. And a class is a void* is an int is a char is a double? That's perfectly possible - it&

Re: Why there is too many uneccessary casts?

2013-06-11 Thread Simen Kjaeraas
On Tue, 11 Jun 2013 12:39:47 +0200, Temtaime wrote: There is overflow and it can be with int too. It's standard behavior. Indeed. And a class is a void* is an int is a char is a double? That's perfectly possible - it's all just memory anyway. D has chosen to do it like this to prevent common

Re: Why there is too many uneccessary casts?

2013-06-11 Thread Simen Kjaeraas
On Tue, 11 Jun 2013 12:12:25 +0200, Temtaime wrote: ubyte k = 10; ubyte c = k + 1; This code fails to compile because of: Error: cannot implicitly convert expression (cast(int)k + 1) of type int to ubyte Why? It's pain in the ass, i think. My code contains only casts then. Because it's u

Re: Are heap objects never moved by the garbage collector?

2013-05-31 Thread Simen Kjaeraas
On 2013-05-31, 18:31, Carl Sturtivant wrote: "The D Programming Language" (TDPL) p.178 asserts the following. "The objects themselves stay put, that is their locations in memory never change after creation." I take this to mean that the D garbage collector doesn't move live objects and a

Re: alias this

2013-05-31 Thread Simen Kjaeraas
On 2013-05-31, 14:12, Namespace wrote: I thougth that in dmd 2.063 alias this : foo; would be allowed. That was what the preview of dmd 2.063 said: http://dlang.org/changelog.html#new2_062 Why wasn't it implemented? Probably not enough time. I've not read anything about it no longer being plan

Re: and/or/not/xor operators

2013-05-30 Thread Simen Kjaeraas
On 2013-05-30, 13:56, Shriramana Sharma wrote: Hello. I have always loved the readability of C++'s and/or/not/xor word-like logical operators but It doesn't seem to be available in D. Isn't this possible in D? I tried doing: alias && and ; import std.stdio ; void main () { writeln ( tru

Re: Passing large or complex data structures to threads

2013-05-27 Thread Simen Kjaeraas
On Mon, 27 May 2013 14:08:12 +0200, Joseph Rushton Wakeling wrote: On 05/26/2013 05:59 PM, Ali Çehreli wrote: On 05/26/2013 05:38 AM, Simen Kjaeraas wrote: Tuple!(size_t, size_t)[][] data = createData(); immutable dataImm = assumeUnique(data); data = null; // Simply to

Re: Passing large or complex data structures to threads

2013-05-26 Thread Simen Kjaeraas
On Sun, 26 May 2013 17:59:32 +0200, Ali Çehreli wrote: On 05/26/2013 05:38 AM, Simen Kjaeraas wrote: > Tuple!(size_t, size_t)[][] data = createData(); > immutable dataImm = assumeUnique(data); > data = null; // Simply to ensure no mutable references exist. The las

Re: Passing large or complex data structures to threads

2013-05-26 Thread Simen Kjaeraas
On Sun, 26 May 2013 14:06:39 +0200, Joseph Rushton Wakeling wrote: On 05/24/2013 04:39 PM, Simen Kjaeraas wrote: First, *is* it read-only? If so, store it as immutable and enjoy free sharing. If not, how and why not? I can confess that it's as simple as feeling extremely uncomfor

Re: Passing large or complex data structures to threads

2013-05-26 Thread Simen Kjaeraas
On Sun, 26 May 2013 14:06:39 +0200, Joseph Rushton Wakeling wrote: On 05/24/2013 04:39 PM, Simen Kjaeraas wrote: First, *is* it read-only? If so, store it as immutable and enjoy free sharing. If not, how and why not? I can confess that it's as simple as feeling extremely uncomfor

Re: class MyClass(T) : Base if (ConstraintExpression) {} compilation error

2013-05-24 Thread Simen Kjaeraas
On 2013-05-24, 16:49, ref2401 wrote: Version D 2.062 Please explain what is causing the error class Base { } class Class(T) : Base if (is(T == int)) { } Error: unrecognized declaration Error: members expected Error: Declaration expected, not 'if' Error: { } expected following aggregate decla

Re: Passing large or complex data structures to threads

2013-05-24 Thread Simen Kjaeraas
On 2013-05-24, 15:26, Joseph Rushton Wakeling wrote: Hello all, Are there any recommended strategies for passing large or complex data structures (particularly reference types) to threads? For the purpose of this discussion we can assume that it's read-only data, so if we're talking about ju

Re: Copy instead of reference?

2013-05-23 Thread Simen Kjaeraas
On Thu, 23 May 2013 13:29:49 +0200, Namespace wrote: That was what I also expected. But opAssign is not called. Because you have a postblit. It's called instead of opAssign. -- Simen

Re: WindowProc in a class - function and pointer problem

2013-05-22 Thread Simen Kjaeraas
On 2013-05-22, 21:30, D-sturbed wrote: Hello, is there a way to wrap a WindowProc (so "LRESULT WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) nothrow") in a class and to link it to a WindowClass without puting it as "static" ? Because defacto every datum used in the Windo

Re: how to have alias this with an unaccessible member?

2013-05-19 Thread Simen Kjaeraas
On Sat, 18 May 2013 02:12:00 +0200, Timothee Cour wrote: so in what you suggest, the exact same problem remains with 'get' being exposed instead of 'x', so the situation didn't improve... looks like it's impossible to achieve this? Well, there is also opDot: struct A(T) { private T x;

Re: how to have alias this with an unaccessible member?

2013-05-17 Thread Simen Kjaeraas
On Sat, 18 May 2013 01:13:00 +0200, Timothee Cour wrote: How to have alias this with an unaccessible member (x below). Making the member private won't work as it'll disable all operations on said member. struct A(T){ T x; //private T x would prevent alias this from doing anything us

Re: Recursive mixin templates

2013-05-16 Thread Simen Kjaeraas
On Thu, 16 May 2013 17:01:54 +0200, Sebastian Graf wrote: I aim to use a simplistic, rough edged property generator, but I'm having issues. See http://dpaste.dzfl.pl/72837a7a. My code and mixin logic seems to work basically, but it gets hairy when using mixinMap to generate getters and setter

Re: Cross product template

2013-05-14 Thread Simen Kjaeraas
On Wed, 15 May 2013 03:31:40 +0200, Diggory wrote: I have a vector struct, Vector(T, uint N) templated on the type T and number of components, N. I'm trying to write a function "cross" which will calculate the cross product of a number of vectors. For a given number of components, N, the c

Re: Structure's inheritance

2013-05-12 Thread Simen Kjaeraas
On 2013-05-12, 14:00, evilrat wrote: On Sunday, 12 May 2013 at 11:56:53 UTC, Maxim Fomin wrote: You can place base struct instance inside nested and use alias this. Note that currently multiple alias this are not supported. Also note that you cannot override functions because there are no virt

Re: Check if tuple contains value at compile time

2013-05-04 Thread Simen Kjaeraas
On 2013-05-05, 01:42, Diggory wrote: I'm trying to test using a "static if" statement if a tuple of strings contains a particular string. What's the easiest/best way to do this? http://dlang.org/phobos/std_typetuple#.staticIndexOf -- Simen

Re: a FOR loop and floating variables

2013-05-02 Thread Simen Kjaeraas
On 2013-05-02, 20:14, Carlos wrote: I have this code : import std.stdio; import std.c.stdlib; void main() { int fahr; write("F\tC\n"); for (fahr = 0; fahr <= 300; fahr = fahr + 20) write(fahr, "\t", (5.0/9.0)*(fahr-32), "\n"); write("Done!\n"); exit (0); } Which works. but if I change the "5.

Re: Calculation differences between Debug and Release mode

2013-04-20 Thread Simen Kjaeraas
On Sat, 13 Apr 2013 18:36:21 +0200, Jeremy DeHaan wrote: I'm on Windows, and I my compilation was nothing more than "dmd -O -release main.d" to get the issue I described. Turns out, the problem starts here: static const(float) pi = 3.141592654f; If we compare that to std.math.PI, we

Re: Why are fixed length arrays passed by value while variable are passed by reference?

2013-04-18 Thread Simen Kjaeraas
On 2013-04-18, 16:20, ixid wrote: An array is represent using a struct with a pointer to the array data and the length, like this: struct Array { void* ptr; size_t length; } The struct is passed by value, but since it contains a pointer to the data it will be passed by reference. N

Re: Use enum base type?

2013-04-17 Thread Simen Kjaeraas
On 2013-04-17, 19:15, Janissary wrote: Is it possible to evaluate an enum's base type? Ideally something like: enum somestrs : string { ... } enum d = 0.0; template EnumBaseType(E) if (is(E==enum)) { ... } unittest { static assert( is(EnumBaseType!somestrs == string) ); static assert( i

Re: Calculation differences between Debug and Release mode

2013-04-13 Thread Simen Kjaeraas
On Sat, 13 Apr 2013 08:07:39 +0200, Jeremy DeHaan wrote: In debug mode this works as expected. Let's say the radius is 50. getPoint(0) returns a vector that prints X: 50 Y: 0. For some reason, the same function will return a vector that prints X: 50 Y: 4.77673e-14. Now, 4.77673e-14 is a

Re: operator +=

2013-04-08 Thread Simen Kjaeraas
On 2013-04-08, 14:23, Minas Mina wrote: How can I define operator += for a struct? http://dlang.org/operatoroverloading.html In short: struct S { auto opOpAssign( string op : "+" )( S other ) { // Do stuff here. } } -- Simen

Re: Allocating large 2D array in D

2013-02-04 Thread Simen Kjaeraas
On 2013-13-04 17:02, Steven Schveighoffer wrote: BTW, "all (but last of) the dimensions" isn't correct, you know them all in your example, and it looks great! I believe his point was that this also works if you don't know the last dimension beforehand. -- Simen

Re: Variadic constructor conflict

2013-01-30 Thread Simen Kjaeraas
On 2013-01-30, 17:08, andrea9940 wrote: This code compiles fine: struct Vector(T, uint SIZE) { T[SIZE] vector; this(T value) { foreach (ref v; vector) v = value; } } alias Vector!(int, 3) Vec3i; but if I add a variadic construct

Re: UFCS > opDispatch

2013-01-16 Thread Simen Kjaeraas
On 2013-01-16, 22:02, Nick Sabalausky wrote: Unfortunately, opDispatch [silently] takes precedence over UFCS. I don't suppose there's any way to make a UFCS function call override opDispatch without either ditching UFCS or altering/removing the opDispatch itself? Only solution I know of is to

Re: Does the new alias syntax not support extern for function types?

2013-01-15 Thread Simen Kjaeraas
On 2013-04-15 13:01, Mike Parker wrote: On Monday, 14 January 2013 at 21:00:12 UTC, Simen Kjaeraas wrote: alias foo = extern(System) void function(); Gives me an error about expecting basic type, not extern. extern(System) alias void function() foo; But that's the old syntax, with

Re: Specifying eponymous template "internal parameter"

2013-01-08 Thread Simen Kjaeraas
On 2013-16-08 11:01, monarch_dodra wrote: On Tuesday, 8 January 2013 at 09:59:26 UTC, Simen Kjaeraas wrote: alias fun2 = fun!("++a", "--a"); auto m = fun2!(ubyte)(1); Nice! And now, for the 1M$ question: Can I rely on this behavior, or is this an accepts invalid..

Re: Specifying eponymous template "internal parameter"

2013-01-08 Thread Simen Kjaeraas
On 2013-55-08 09:01, monarch_dodra wrote: Sometimes (especially in phobos), one defines a parametrized template, that resolves to a templated function. This is a nifty trick, because it allows specifying a vararg before the current type parameter, eg: // auto r = [1, 2, 3]; auto m =

Re: Why is immutable not possible as a result of a reduce expression?

2013-01-05 Thread Simen Kjaeraas
On 2013-52-05 20:01, Michael Engelhardt wrote: Hi, just playing around with the functional capabilities of D. One concept of the pure functional programming is that variables should not be reassigned, so the best(?) way to assure this is using immutable: immutable auto gen = sequence

Re: std.range lockstep is not input range but opApply entity. Workarounds?

2012-12-29 Thread Simen Kjaeraas
On 2012-52-29 20:12, mist wrote: Not clever enough to expand like this though: map!( (a, b) => a+b )( zip(Range1, Range2) ); Using a => a[0]+a[1] is not that big deal though. That oughta be doable. However, seeing as std.functional only contains unaryFun and binaryFun (dranges has naryFun),

Re: std.range lockstep is not input range but opApply entity. Workarounds?

2012-12-29 Thread Simen Kjaeraas
On 2012-48-29 14:12, mist wrote: I basically want to be able to do stuff like this: auto result = map!( (a, b) => a+b )( lockstep(range1, range2) ); Are there any standard short ways to wrap an input range around struct with opApply (which Lockstep is)? Also what about redesigning Lockstep

Re: checking whether the number is NaN

2012-12-28 Thread Simen Kjaeraas
On 2012-42-28 16:12, Zhenya wrote: Hi! Tell me please,are there any way to check whether number is NaN? us std.math.isNaN. But if you really don't want to: float x = ...; if (x != x) { writeln( "x is NaN" ); } I'm unsure how aggressive the optimizer is allowed to be in cases like this.

Re: bio parser

2012-12-16 Thread Simen Kjaeraas
On 2012-09-16 17:12, bioinfornatics wrote: Dear, I wrote a fasta format parser and fastq format parser. These parser used MmFile and do not load all file these will save memory. Fastq http://dpaste.dzfl.pl/9b23574d Fasta http://dpaste.dzfl.pl/228dba11 The way to iterate over it is really cl

Re: Marking bug entires as fixed/closed on bugzilla

2012-12-14 Thread Simen Kjaeraas
On 2012-47-14 12:12, monarch_dodra wrote: I have a whole list of bugs/issues that have since been corrected in 2.060alpha. I was wondering when and how these were to be closed? Am I supposed to wait for an official 2.061 first? Do I have to prove it was fixed, or just a simple "verified fi

Re: Operator overloading of native types?

2012-12-13 Thread Simen Kjaeraas
On 2012-12-14, 00:19, H. S. Teoh wrote: I'd like to overload the '*' operator to work with string arguments. Is it possible? I tried the following, but apparently operator overloading doesn't work at the package level? string opBinary(string op)(string repeatMe, int thisManyTimes)

Re: constructor is not callable using argument types ()

2012-12-06 Thread Simen Kjaeraas
On 2012-12-06, 20:48, Suliman wrote: When I should use keyword this? I dropped it from my class and now I can make instance of class without in sych way: auto file = new GetFileName(); file.name = "test"; Indeed. If you have not defined a constructor, the language defines one for you, whic

Re: constructor is not callable using argument types ()

2012-12-06 Thread Simen Kjaeraas
On 2012-12-06, 20:17, Suliman wrote: I am learning D classes and I am getting error when I am try to make instance of class. erorr: C:\code\main.d(9): Error: constructor GetFileName.GetFileName.this (string name) is not callable using argument types () http://www.everfall.com/paste/id.php?x

Re: Getting memory size of class

2012-12-05 Thread Simen Kjaeraas
On 2012-12-05, 20:03, js.mdnq wrote: sizeof always returns 4 or 8 regardless of size of class: class myclass(T) { public: T v1; T v2; T v3; T v4; T v5; T v6; } writeln((myclass!byte).sizeof, (myclass!double).sizeof); or even writeln((myclass!int).classinfo.init.sizeo

Re: Can operators "return" type?

2012-11-29 Thread Simen Kjaeraas
On 2012-11-29, 17:33, Zhenya wrote: Hi! It would useful for some my project,if operators could be a template,that "return" type.Something like alias TypeTuple!(int,char) types; static assert(types[1] == char) //opIndex So can I define something like that? This works out of the box. If yo

Re: Strange template alias behaviour

2012-11-18 Thread Simen Kjaeraas
On 2012-05-18 17:11, Maxim Fomin wrote: Changing template parameter to Bar.f or bar.f affects value of bar.f.data. Seems to be a bug. It's a bug. Further reduction: import std.stdio; mixin template Foo() { string data = "default"; } struct Bar { mixin Foo f; } string get_data(alias u

Re: how to count number of letters with std.algorithm.count / std.algorithm.reduce / std.algorithm.map ?

2012-11-16 Thread Simen Kjaeraas
On 2012-11-16, 17:37, bearophile wrote: Simen Kjaeraas: There. Now it works, and returns a Tuple!(ulong,ulong)(8, 8). One thing I think is ugly in my implementation is acc + (seq == 'G'). This adds a bool and a ulong together. For more points, replace that with acc + (seq == &

Re: how to count number of letters with std.algorithm.count / std.algorithm.reduce / std.algorithm.map ?

2012-11-16 Thread Simen Kjaeraas
On 2012-11-16, 16:49, bioinfornatics wrote: hi, I would like to count number of one ore more letter into a string or list of string (string[]) without use a for loop but instead using std.algorithm to compute efficiently. if you have: string seq1 = "ACGATCGATCGATCGCGCTAGCTAGCTAG"; s

Re: shouldn't const cast always be allowed (even if shunned)

2012-11-15 Thread Simen Kjaeraas
On 2012-23-15 15:11, Dan wrote: There are times when casting away const is needed. Structs that define opCast can get in the way of this. For instance, the cast below fails, but I think it should always be allowed. So, if the source type and cast type are the same except for const qualifiers,

Re: Fasta parser

2012-11-11 Thread Simen Kjaeraas
On 2012-34-11 18:11, bioinfornatics wrote: Hi, I wrote a fasta parser for biology computing http://pastebin.geany.org/yheQN/ I would like to get your experience to know if the writer could be better. The given parser use MmFile and Phobos range. fasta specification format => http://en.wikip

Re: Extracting template parameters

2012-11-06 Thread Simen Kjaeraas
On 2012-11-06, 16:20, Joseph Rushton Wakeling wrote: Suppose that I have two struct templates which take identical parameter lists: struct Foo(T1, T2, T3) { ... } struct Bar(T1, T2, T3) { ... } Now suppose that I have a Foo which has been inst

Re: Tuples and variable-length template parameter lists

2012-11-05 Thread Simen Kjaeraas
On 2012-11-05, 15:53, Joseph Rushton Wakeling wrote: Hello all, Suppose I want to define a tuple type which may have a variable length, e.g.: template Tup(ID, Properties...) { static if(Properties.length == 0) alias Tuple!(ID, "id") Tu

Re: SList of chars not possible?

2012-11-02 Thread Simen Kjaeraas
On 2012-18-01 23:11, They call me Mr. D wrote: auto i = SList!int(1, 2, 3, 4, 5, 6, 7); auto f = SList!float(1.1, 2.234, 3.21, 4.3, 5.001, 6.2, 7.0); auto s = SList!string(["I", "Hello", "World"]); auto c = SList!char('a', 'b' ,'c'); // doesn't compile, get the following C:\D\dmd2\wind

Re: How to add n items to TypeTuple?

2012-11-01 Thread Simen Kjaeraas
On 2012-11-01, 19:52, Justin Whear wrote: On Thu, 01 Nov 2012 19:42:07 +0100, denizzzka wrote: For example, adding 3 strings to type tuple t: foreach( i; 0..2 ) alias TypeTuple!( t, string ) t; // this is wrong code and result should be: TypeTuple!( string, string, string ); Use a recur

Re: What is the proper way to handle pointers in variable arguments list?

2012-10-28 Thread Simen Kjaeraas
On 2012-08-28 22:10, Tyro[17] wrote: On 10/28/12 4:44 PM, Dmitry Olshansky wrote: On 29-Oct-12 00:36, Tyro[17] wrote: The following fails because the compiler assumes I am trying to dereference non-pointer variables. Can this be done? void main() { int i; int* pi; double d;

Re: Narrow string is not a random access range

2012-10-23 Thread Simen Kjaeraas
On 2012-41-24 01:10, Adam D. Ruppe wrote: On Tuesday, 23 October 2012 at 23:07:28 UTC, Jonathan M Davis wrote: I think that Andrei was arguing for changing how the compiler itself handles arrays of char and wchar so that they wouldn't As I said last time this came up, we could actually do t

Re: Narrow string is not a random access range

2012-10-23 Thread Simen Kjaeraas
On 2012-10-23, 19:21, mist wrote: Hm, and all phobos functions should operate on narrow strings as if they where not random-acessible? I am thinking about something like commonPrefix from std.algorithm, which operates on code points for strings. Preferably, yes. If there are performance (

Re: Reordered class fields?

2012-10-22 Thread Simen Kjaeraas
On 2012-36-22 01:10, bearophile wrote: This benchmark shows that if you allocate the class instances on the heap one at a time the total amount of memory used is the same for the various Bar (maybe because of the GC), so that optimization is useful for emplace() only and similar in-place a

Re: opCast using in template struct

2012-10-18 Thread Simen Kjaeraas
On 2012-10-18, 17:45, Oleg wrote: Sorry. My problem more complex and my simplification is not correct. I want use mixin for math operations. mixin template vectOp( string DataName, int DataLen, T, vecType ) { mixin( "alias " ~ DataName ~ " this;" ); auto opBinary(string op,E)( E[

Re: opCast using in template struct

2012-10-18 Thread Simen Kjaeraas
On 2012-10-18, 16:54, Oleg wrote: Hello. How to cast template struct to itself? struct vec(string S,T=double) { T[S.length] data; auto opCast(string K,E)() if( S.length == K.length && is( T : E ) ) { vec!(K,E) ret; foreach( i, ref m; ret.d

Re: Returning dynamic array from the function

2012-10-17 Thread Simen Kjaeraas
On 2012-10-17, 21:17, m0rph wrote: I tryed to learn how arrays works and found another strange thing: import std.stdio; int[] create() { int[5] a1 = [ 10, 20, 30, 40, 50 ]; int[] b1 = a1; writeln("b1: ", b1); return b1; } void main() { int[] a2 = create

Re: templated static array

2012-10-15 Thread Simen Kjaeraas
On 2012-35-15 17:10, Namespace wrote: But bar([1, 2, 3]); not. The compiler does not realize that [1, 2, 3] means a static array in this context. You have to write bar(cast(int[3]) [1, 2, 3]); but I think the compiler have to recognize this on it's own. This is true. The problem is, as you

Re: templated static array

2012-10-15 Thread Simen Kjaeraas
On 2012-23-15 16:10, Simen Kjaeraas wrote: On 2012-05-15 16:10, Namespace wrote: How can I do this? I have this code: http://dpaste.dzfl.pl/d9165502 And as you can see, the templated function 'receive2' take automatically dynamic arrays. But how can I tell the compiler, t

Re: templated static array

2012-10-15 Thread Simen Kjaeraas
On 2012-05-15 16:10, Namespace wrote: How can I do this? I have this code: http://dpaste.dzfl.pl/d9165502 And as you can see, the templated function 'receive2' take automatically dynamic arrays. But how can I tell the compiler, that this function takes (preferably) static arrays? My littl

Re: What am I doing wrong here?

2012-10-14 Thread Simen Kjaeraas
On 2012-10-14, 14:28, Martin wrote: Hey everyone, I'm new to D so bare with me please. I've been trying to figure out what's up with the strange forward refernce errors the compiler (DMD 2.060) is giving me. Here's a code snippet that's generating a forward reference error: public class A

Re: Detect if running 32 bit program on 64 bit Windows OS

2012-10-09 Thread Simen Kjaeraas
On 2012-01-10 02:10, Josh wrote: Is there a way to do that? I've tried getenv("PROCESSOR_ARCHITECTURE") and shell("echo %PROCESSOR_ARCHITECTURE%"), and both of them return "x86" instead of "AMD64" like cmd. I want to use this to run a 64 bit version of an external program if the OS is 64 b

  1   2   3   4   5   6   >