bug, or is this also intended?

2016-10-03 Thread deed via Digitalmars-d-learn
Unexpected auto-concatenation of string elements: string[] arr = ["a", "b" "c"];// ["a", "bc"], length==2 int[] arr2 = [[1], [2] [3]];// Error: array index 3 is out of bounds [2][0 .. 1] // Error: array index 3 is out of bounds [0..1] dmd 2.071.2-b2

Re: Meta-programming: iterating over a container with different types

2016-09-23 Thread deed via Digitalmars-d-learn
On Friday, 23 September 2016 at 09:21:56 UTC, Claude wrote: ... // Maybe you can try using std.variant? import std.variant; alias Component = Variant; class Entity { void register (Component v) { components ~= v; } void unregister (T) () { foreach (i, c; components) if (c.type

Re: bug?

2016-09-15 Thread deed via Digitalmars-d-learn
On Thursday, 15 September 2016 at 14:42:13 UTC, Jonathan M Davis wrote: On Thursday, September 15, 2016 14:07:18 deed via Digitalmars-d-learn wrote: On Thursday, 15 September 2016 at 13:57:13 UTC, rikki cattermole wrote: > Not a bug, it is never used. I'd expect an "Error:

Re: bug?

2016-09-15 Thread deed via Digitalmars-d-learn
On Thursday, 15 September 2016 at 13:57:13 UTC, rikki cattermole wrote: Not a bug, it is never used. I'd expect an "Error: ... no effect ..." from the compiler.

bug?

2016-09-15 Thread deed via Digitalmars-d-learn
void main () { new int[](1); } Compiles with dmd 2.071.2-b2, but no code is generated for `new int[](1);`. Caused a bug due to: char[] arr; got updated to char[] arr; new char[](SIZE); If it's considered a bug and someone would file it, I'd be thankful.

Re: Chaining opIndex

2016-05-10 Thread deed via Digitalmars-d-learn
On Monday, 9 May 2016 at 22:33:37 UTC, John Colvin wrote: There are lots of ways to approach this. Here's one possibility: auto cars(Bar bar) { static struct Res { Bar bar; Car opIndex(size_t i) { return /* e.g. getCar(bar, i); */ } } r

Chaining opIndex

2016-05-09 Thread deed via Digitalmars-d-learn
struct Foo { Bars bars; ... } struct Foos { Foo[] arr; Foo opIndex (size_t idx) { return arr[idx]; } ... } struct Bar { // No Car[] cars; ... } struct Bars { Bar[] arr; Bar opIndex (size_t idx) { return arr[idx]; } ... } struct Car { ... } Foos foos

Re: aliasing/referencing expressions in with statements

2016-04-22 Thread deed via Digitalmars-d-learn
On Friday, 22 April 2016 at 01:42:11 UTC, Yuxuan Shui wrote: Maybe use something like: auto a = () => instanceA.verboseFieldA.verboseFieldB; You can certainly declare temporaries and rely on the compiler optimizing those away: auto a = instanceA.verboseFieldA.verboseFieldB; auto b = instanc

aliasing/referencing expressions in with statements

2016-04-21 Thread deed via Digitalmars-d-learn
Often I find myself wanting to alias an expression, such as verbose fields, possibly nested. AFAIK, the with statement makes it easier, but not as good as it could have been. What I'd like to express is for example something like this: with( a = instanceA.verboseFieldA.verboseFieldB, b

Re: Set cursor position in a file

2016-04-10 Thread deed via Digitalmars-d-learn
On Sunday, 10 April 2016 at 16:19:51 UTC, Lucien wrote: Hello, Is there the possibility to set the cursor position in a file ? Example: void main() { File myFile = File("myFile.txt"); showFile(myFile); // set cursor pos to 0 showFile(myFile); } void showFile(Fil

Re: Ternary if and ~ does not work quite well

2015-10-12 Thread deed via Digitalmars-d-learn
On Monday, 12 October 2015 at 15:39:15 UTC, TheFlyingFiddle wrote: How does this compile? { string str = "hello"; foreach (n; [32, 119, 111, 114, 108, 100, 33]) str ~= n; import std.stdio : writeln; str.writeln;// prints "hello world!" writeln(true == 1); /

Re: reading file byLine

2015-09-14 Thread deed via Digitalmars-d-learn
On Monday, 14 September 2015 at 18:36:54 UTC, Meta wrote: As an aside, you should use `sort()` instead of the parentheses-less `sort`. The reason for this is that doing `arr.sort` invokes the old builtin array sorting which is terribly slow, whereas `import std.algorithm; arr.sort()` uses the

Re: reading file byLine

2015-09-13 Thread deed via Digitalmars-d-learn
On Sunday, 13 September 2015 at 03:20:31 UTC, deed wrote: ... and since `string` is an alias for `const(char)[]`, it's not ... string is an alias for immutable(char)[], not const(char)[]. http://dlang.org/arrays.html#strings Sorry about the noise.

Re: reading file byLine

2015-09-13 Thread deed via Digitalmars-d-learn
On Sunday, 13 September 2015 at 03:20:31 UTC, deed wrote: string s = "Some text"; s.retro.find("e"); // `Some te` (Surprising to me. Error? 2.067.1) Sorry, the above is wrong, .retro.find does indeed return what's expected. string s = "Some te

Re: reading file byLine

2015-09-12 Thread deed via Digitalmars-d-learn
On Saturday, 12 September 2015 at 12:51:04 UTC, Namal wrote: Anyway, there is no .reverse for strings I guess, what is the way to completely reverse a string in D? What do you want to do? Do you want to keep your data in original order, but get a reversed view of it for something, or do you a

Re: Adjacent Pairs Range

2015-09-12 Thread deed via Digitalmars-d-learn
On Saturday, 12 September 2015 at 10:17:19 UTC, Nordlöw wrote: How do I most elegantly iterate all the adjacent pairs in an `InputRange` using Phobos? Something like [1,2,3,4] => [(1,2), (2,3), (3,4)] Why not just: zip(arr[0 .. $-1], arr[1 .. $]) ?

Re: Lazy sort

2015-09-11 Thread deed via Digitalmars-d-learn
On Friday, 11 September 2015 at 10:41:16 UTC, ixid wrote: Does sort have to be eager or would it be possible to have a lazy version? It's messy to always have to use array and leap in and out of lazy operations within a UFCS chain. Surely as many functions as possible should be optionally lazy.

Re: using std.algorithm to find intersection of DateTime[][] arg

2015-09-10 Thread deed via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 20:28:35 UTC, Laeeth Isharc wrote: I have a DateTime[][] arg ... I would like to find the intersection of the dates. A suggestion: auto minLength = arg.map!(a => a.length).reduce!min; auto minIdx = arg.map!(a => a.length).countUntil(minLength); a

Re: What is "FilterResult" type?

2015-09-09 Thread deed via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 11:30:26 UTC, Bahman Movaqar wrote: On Wednesday, 9 September 2015 at 08:29:20 UTC, cym13 wrote: The way I would have written it is: auto result = foobars.filter!(fb => nums.all!(n => (fb.x * fb.y) > n)) .filter!(fb => nums.all!(n => fb.x

Re: reading file byLine

2015-09-07 Thread deed via Digitalmars-d-learn
On Sunday, 6 September 2015 at 22:04:55 UTC, Namal wrote: oh, sorry. But I found out what I have been doing wrong besides that. arr.sort.uniq; uniq(arr) or arr.sort.uniq; compiles but doesn't store it in the arr array, I need to store it in a new one. Right, it's like int x = 3; // x + 5;

Re: reading file byLine

2015-09-07 Thread deed via Digitalmars-d-learn
On Monday, 7 September 2015 at 10:25:09 UTC, deed wrote: writeln(x);// or you can pass it to a function. I meant `writeln(x + 5)`

Re: reading file byLine

2015-09-06 Thread deed via Digitalmars-d-learn
On Sunday, 6 September 2015 at 17:57:49 UTC, Namal wrote: Yeah, I just checked, it is 2.066, how can I install the new version on ubuntu with sudo apt-get? sudo apt-get install dmd will give you dmd v2.067.1. Don't know when it will be upgraded to 2.068 though.

Re: reading file byLine

2015-09-05 Thread deed via Digitalmars-d-learn
On Saturday, 5 September 2015 at 17:31:39 UTC, Namal wrote: Yeah, I have have been trying this example from wiki books https://en.wikibooks.org/wiki/Learning_D_With_Project_Euler It is not even compiling. What exactly is not compiling?

Re: reading file byLine

2015-09-05 Thread deed via Digitalmars-d-learn
On Saturday, 5 September 2015 at 14:44:19 UTC, deed wrote: .map!(s => chomp(s, "\"") .map!(s => chompPrefix(s, "\"") should be .map!(s => chomp(s, "\"")) .map!(s => chompPrefix(s, "\""))

Re: reading file byLine

2015-09-05 Thread deed via Digitalmars-d-learn
On Saturday, 5 September 2015 at 12:41:37 UTC, Namal wrote: Thx guys. Now I try out the split function. I read the file as a single string? auto arr = split(cast(string)read(filename),","); where the file has "A", "B", "C" and I get the output ["\"A\"", " \"B\"", " \"C\"\n"] I can understand

Re: reading file byLine

2015-09-04 Thread deed via Digitalmars-d-learn
On Friday, 4 September 2015 at 07:27:54 UTC, Namal wrote: On Friday, 4 September 2015 at 01:55:13 UTC, deed wrote: On Friday, 4 September 2015 at 01:31:28 UTC, Namal wrote: How can I get just the maximum element? Do I need to give a range for it? Use max? http://dlang.org/phobos

Re: reading file byLine

2015-09-03 Thread deed via Digitalmars-d-learn
On Friday, 4 September 2015 at 01:31:28 UTC, Namal wrote: How can I get just the maximum element? Do I need to give a range for it? Use max? http://dlang.org/phobos/std_algorithm_comparison.html#max

Re: Struct template

2014-11-03 Thread deed via Digitalmars-d-learn
static if (is(typeof(T) == int)) should be static if (is(T == int)) T is already a type. Ahh. Thanks!

Struct template

2014-11-03 Thread deed via Digitalmars-d-learn
struct Internal { int i; double d; string s; } struct External_int { Internal internal; @property Internal* ptr () { return &internal; } this (int a) { internal.s = "int"; internal.i = a; } } struct External (T) { Internal internal; @property Internal* ptr () { ret

Re: win64 - win32.oaidl.VARIANT -> error LNK2019

2014-10-31 Thread deed via Digitalmars-d-learn
Your link is failing because the .init value of the struct is not found. The .init will be in the object file corresponding to the module where the struct is defined, so to fix the linker error, add the win32.oaidl module to the list of modules you're compiling and linking. An easy way to do th

win64 - win32.oaidl.VARIANT -> error LNK2019

2014-10-31 Thread deed via Digitalmars-d-learn
// bindings from https://github.com/CS-svnmirror/dsource-bindings-win32/blob/308739a417eaaba85a5d3ce7741fd43d3042efe0/oaidl.d --- import win32.oaidl; // The following gives linker error: error LNK2019: unresolved external // symbol _D5win325oaidl7VARIANT6__initZ referenced // in function ...

Re: Bug?

2014-10-24 Thread deed via Digitalmars-d-learn
OK, I tried with OSX 64-bit compiler. Perhaps 32 bit would not fare as well. What platform are you testing on? Have tried Linux and Windows 64-bit and it seems to be an issue when compiled with -m32. Tests are provided here http://dpaste.dzfl.pl/5f55f4152aa8. I agree that one cannot compare

Re: Bug?

2014-10-24 Thread deed via Digitalmars-d-learn
On Thursday, 23 October 2014 at 21:42:46 UTC, anonymous wrote: On Thursday, 23 October 2014 at 21:17:25 UTC, deed wrote: Some testing can be found on http://dpaste.dzfl.pl/5f55f4152aa8 for both Windows and Linux. This just illustrates the sin function. I think the tests marked "[1]

Re: Bug?

2014-10-23 Thread deed via Digitalmars-d-learn
Some testing can be found on http://dpaste.dzfl.pl/5f55f4152aa8 for both Windows and Linux. This just illustrates the sin function. Replacing double with real makes everything pass on Linux Mint 16 with -m32 and -m64. Replacing double with float seems to give the same problems as before, but

Re: Bug?

2014-10-23 Thread deed via Digitalmars-d-learn
A similar problem was recently (about 2-3 weeks ago IIRC) seen in one of the Phobos PR's. It appears to be related to the autoextension of float to double (or double to real, I forget which) in certain contexts on Windows. @deed Could you please try to reduce the failing test to a mi

Re: Bug?

2014-10-23 Thread deed via Digitalmars-d-learn
On Thursday, 23 October 2014 at 18:26:53 UTC, Steven Schveighoffer wrote: On 10/23/14 2:18 PM, deed wrote: Using equality is not a good idea with floating point. The compiler will on a whim, or depending on whether it can inline or not, use higher precision floats, changing the outcome

Re: Bug?

2014-10-23 Thread deed via Digitalmars-d-learn
Using equality is not a good idea with floating point. The compiler will on a whim, or depending on whether it can inline or not, use higher precision floats, changing the outcome slightly. I cannot say for certain whether this explains all the issues you have, the very last one seems troubl

Re: Bug?

2014-10-23 Thread deed via Digitalmars-d-learn
assert (fasin(a) != fasin(a)); // ? assert (facos(a) != facos(a)); // ? Too quick there.. But: assert (fasin(0.5) != fasin(0.5)); // ? assert (facos(0.5) != facos(0.5)); // ?

Re: Bug?

2014-10-23 Thread deed via Digitalmars-d-learn
-- Why bother? import std.algorithm : max; F fun (F a, F b) { return max(a,b) + 1.; } unittest { assert (gun(1, 2) == gun(2, 1)); } // Passes F pun (F a, F b) { return sin(max(a,b)); } unittest { assert (fun(1, 2) == fun(2, 1)); } // Fails // Fun, gun, pun... unittest { assert (fun(1, 2) =

Bug?

2014-10-23 Thread deed via Digitalmars-d-learn
// DMD v2.066.0 // All asserts pass (!) import std.math : sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh; alias F = double; immutable F a = 3, b = 5; F fmul (F a) pure { return a * b; } F fsin (F a) pure { return sin(a); } struct Smul { F value; this

Re: Error: array operation d1[] + d2[] without assignment not implemented

2014-09-13 Thread deed via Digitalmars-d-learn
Hi! struct Vector (T) { T[]arr; T[] opSlice() { return arr; } } Vector!double v; double[] d; v[][] = d[] + d[]; //first [] call opSlise, second [] for array syntax Best Regards, Ilya Thanks for your suggestion. It's not as attractive though, it would be the same as v.arr[] =

Error: array operation d1[] + d2[] without assignment not implemented

2014-09-13 Thread deed via Digitalmars-d-learn
struct Vector (T) { T[]arr; void opSliceAssign (T[] a) { arr[] = a[]; } } unittest { auto v = Vector!double([1, 2]); double[] d1 = [11, 12]; double[] d2 = [21, 22]; double[] d3 = new double[](2); d3[] = d1[] + d2[]; assert (d3 == [11.+21., 12.+22.]); assert (is(typeof(d1[] + d2[]

Re: std.array.array broken?

2014-02-01 Thread deed
On Saturday, 1 February 2014 at 22:59:12 UTC, bearophile wrote: deed: auto lines = File(filename).byLine.array; writeln(lines); // Crap --- Beside the answers that others have already given you, another way to do that is to read the whole file (with read or readText) and then use

Re: std.array.array broken?

2014-02-01 Thread deed
On Saturday, 1 February 2014 at 22:52:24 UTC, Andrej Mitrovic wrote: On Saturday, 1 February 2014 at 22:47:54 UTC, deed wrote: Docs say: - std.stdio.byLine returns an input range - std.array.array takes an input range Docs also say: /** Note: Each $(D front) will not persist after $(D

std.array.array broken?

2014-02-01 Thread deed
--- import std.stdio; import std.array; auto lines = File(filename).byLine.array; writeln(lines); // Crap --- dmd 2.064(.2 I think) Docs say: - std.stdio.byLine returns an input range - std.array.array takes an input range

Re: VC linker - unresolved external symbols - runtime

2013-11-09 Thread deed
On Saturday, 9 November 2013 at 16:08:15 UTC, evilrat wrote: On Saturday, 9 November 2013 at 15:59:02 UTC, deed wrote: No, it doesn't work. Do I have to compile my own runtime library and pass it on the command line? (Have just grabbed the 3.064.2.zip file and not run any installer.)

Re: VC linker - unresolved external symbols - runtime

2013-11-09 Thread deed
On Saturday, 9 November 2013 at 15:56:12 UTC, deed wrote: On Saturday, 9 November 2013 at 15:49:40 UTC, evilrat wrote: On Saturday, 9 November 2013 at 15:30:55 UTC, deed wrote: core.runtime's import path is specified in the sc.ini file, in DFLAGS If I specify the core.runtime file in the

Re: VC linker - unresolved external symbols - runtime

2013-11-09 Thread deed
On Saturday, 9 November 2013 at 15:49:40 UTC, evilrat wrote: On Saturday, 9 November 2013 at 15:30:55 UTC, deed wrote: core.runtime's import path is specified in the sc.ini file, in DFLAGS If I specify the core.runtime file in the build file everything works Why is it so? in short

VC linker - unresolved external symbols - runtime

2013-11-09 Thread deed
sc.ini [Environment] DFLAGS="-I%@P%\..\..\src\phobos" "-I%@P%\..\..\src\druntime\import" VCINSTALLDIR=C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC WindowsSdkDir=C:\Program Files\Microsoft SDKs\Windows\v7.1 LIB="%@P%\..\lib" [Environment32] LIB="%@P%\..\lib" LINKC

How close can one get to overload parameter names only?

2013-10-04 Thread deed
Simple example: struct Circle { double radius; this(double radius) { this.radius = radius; } this(double diameter) { this.radius = diameter / 2; } } void main() { auto c1 = Circle(radius = 1.0); auto c2 = Circle(diameter = 2.0); assert(c1.radius == c2.radius); }

Re: Multiple return type from object factory possible?

2013-06-22 Thread deed
auto o = getO("info3"); if (cast(Container)o != null) { ... } Thanks Simen. (Compiler requires !is instead of !=)

Multiple return type from object factory possible?

2013-06-22 Thread deed
class A { ... } class NonContainer : A { ... } class Container : A { A[] container; } class NC1 : NonContainer {} ... class C1 : Container {} ... A getO(string info) { switch (info) { default : return new NonContainer(); case "info1": return new

Re: Should it be a compile time error?

2013-06-19 Thread deed
/* SNIP */ int var() @property { return var; } Isn't the problem in this property function? (Shouldn't it return _var :o) that's also an error. changing to _var gives same result though..

Should it be a compile time error?

2013-06-19 Thread deed
The following compiles and crashes with DMD 2.063. Should this be a compile time error? class A { int _var; void var(int i) @property { this.var = i; // oops, crashes. } // should have been this._var int var() @property { return var;

Re: Bug: Accessing return value of type static array with length 1 or 2 by index.

2013-04-21 Thread deed
bug submitted: http://d.puremagic.com/issues/show_bug.cgi?id=9969 Thanks for reporting. By the way, I was compiling for Windows and had only compile time errors.

Re: Bug: Accessing return value of type static array with length 1 or 2 by index.

2013-04-20 Thread deed
Made available on dpaste: http://dpaste.dzfl.pl/7b5c36f8 On dpaste, the struct with an int didn't compile. (Same error message) It turns out that Template!(2, Sint).statArr()[0].writeln(); compiles with $ dmd test.d -m64 but not with $ dmd test.d

Bug: Accessing return value of type static array with length 1 or 2 by index.

2013-04-20 Thread deed
import std.stdio : writeln; template Template (uint n, T) { T[n] statArr() { T[n] arr; return arr; } T[] dynArr() { T[] dynArr = new T[n]; return dynArr; } } void main() { alias statArr9 = Template!(9, int).statArr; alias statArr3

Re: randomAccessRange.sort() vs randomAccessRange.array.sort()

2013-03-04 Thread deed
import std.algorithm, std.array, std.range; void main() { int[] data = [2, 0, 1]; auto mapped = data.map!q{a * 10}; alias R = typeof(mapped); pragma(msg, hasSwappableElements!R); pragma(msg, hasAssignableElements!R); pragma(msg, isRandomAccessRange!R); pragma(msg, ha

randomAccessRange.sort() vs randomAccessRange.array.sort()

2013-03-04 Thread deed
Why randomAccessRange.array() before calling sort? The std.algorithm.sort doc says: "Sorts a random-access range ..." import std.algorithm, std.array; long[] source = [2, 0, 1]; auto mapped = source.map!("a * 10"); assert (isRandomAccessRange!(typeof(mapped))); // Passes. Implies possibilit

Why not name Random access range Index access range?

2013-02-23 Thread deed
as there is no randomness involved, only the possibility to access by index.

Re: DLL supposed to work as specified at http://dlang.org/dll.html?

2013-02-19 Thread deed
D code DLLs called by D code are heavly broken. Don't expect it to work. Any solid workarounds?

DLL supposed to work as specified at http://dlang.org/dll.html?

2013-02-18 Thread deed
I'm running into several issues, so first, is this supposed to work correctly? I'm looking into D code DLLs called by D code.

DWT with phobos on Windows

2013-02-07 Thread deed
Input regaridng DWT with phobos is welcome. See posting here: http://forum.dlang.org/thread/otyfilaasbxrwnqvr...@forum.dlang.org

Re: Assembly - 64-bit registers supported?

2013-01-20 Thread deed
dmd should output coff when compiling with -m64 You are right, no need for conversion. Coff is output. Anyone having a correct sc.ini file they could post? Mine looks like this: [Version] version=7.51 Build 020 [Environment] LIB="%@P%\..\lib" DFLAGS="-I%@P%\..\phobos" "-I%@P%\..\druntime\

Re: Assembly - 64-bit registers supported?

2013-01-20 Thread deed
Do I need another linker? Ach, Windows. Yeah, you need VS Linker when compiling for 64bits on Windows. Can't help you more with this. I think there is somewhere step-by-step guide for 64bits+windows. (wiki.dlang.org maybe? not sure) Thanks for your help! The solution that worked out for me

Re: Assembly - 64-bit registers supported?

2013-01-19 Thread deed
Missing -m64 or something? Probably. I am on Windows using dmd 2.061 and optlink 8.00.12 dmd main.d -m64 Con't run 'bin\amd64\link.exe', check PATH Setting LINKCMD64 to the same path as for LINKCMD in sc.ini: dmd main.d -m64 OPTLINK : Warning 9: Unknown Option : MERGE OPTLINK : Error 8: Illeg

Assembly - 64-bit registers supported?

2013-01-19 Thread deed
void main() { asm { movRAX, 3; } } results in: Error: undefined identifier 'RAX' AX and EAX work. Anything missing or isn't it yet implemented?

Re: Simple makefile problem - implicit rule

2013-01-09 Thread deed
.d.obj: $(DC) $(DFLAGS) -c $< Ali from http://digitalmars.com/ctg/make.html: Implicit Definition lines .targ_ext.dep_ext : [; rule] [# ... ] Isn't targ_ext .obj and dep_ext .d? If so, either the example or the documentation seems incorrect. The example provided works. The .obj is update

Re: Simple makefile problem - implicit rule

2013-01-09 Thread deed
.d.obj: $(DC) $(DFLAGS) -c $< Ali Works like a charm! Case solved. Thank you very much!

Re: Simple makefile problem - implicit rule

2013-01-09 Thread deed
don't know what make you're using, [...] I'am using the make.exe coming with the DMD 2.061 distro in D/dmd2/windows/bin/ Thought/hoped the GNU spec was applicable, but if it works with GNU make and not Digital Mars make, well.. make -man leads to http://digitalmars.com/ctg/make.html, which

Re: Simple makefile problem - implicit rule

2013-01-09 Thread deed
Assuming that this is for GNU make, ensuring that the rule starts with a tab characters, that file works with GNU Make 3.81. Ali It is Digital Mars Make Version 5.06 and it's on Windows 7.

Re: Simple makefile problem - implicit rule

2013-01-09 Thread deed
On Wednesday, 9 January 2013 at 17:57:28 UTC, Ali Çehreli wrote: On 01/09/2013 09:51 AM, deed wrote: $(DC) $< $(DCFLAGS) Your post has spaces at the beginning on that line. (Thunderbird removes those when I reply. Curse!) Target rules must start with a tab character. Ali Yeah, tha

Re: Simple makefile problem - implicit rule

2013-01-09 Thread deed
Yeah, that's not the problem. Replacing %.obj and %.d with main.obj and main.d works. And $< with main.d

Simple makefile problem - implicit rule

2013-01-09 Thread deed
# makefile --- OBJS= main.obj othermodule.obj DC = dmd DCFLAGS = -c all : $(OBJS) %.obj : %.d $(DC) $< $(DCFLAGS) # Error on line 9: expecting target : dependencies * main.d, othermodule.d and makefile are in the same folder. * make is executed in

Re: how to make new C return other static type than C

2012-12-09 Thread deed
Thanks for your replies. How about this: interface I {} interface I1 : I { void setx(int x); int getx(); int getSum(); } interface I2 : I { void sety(int y); int gety(); int getSum(); } class Impl : I1, I2 { int x, y; void setx(int x) { this.x = x; } in

how to make new C return other static type than C

2012-12-09 Thread deed
interface I { void setX(int x); int getX(); } class C : I { int x, y; void setX(int x) { this.x = x; } int getX() { return x; } void setY(int y) { this.y = y } int getY() { return y; } } void main() { auto obj = new C; // Want new C to instantia

Re: opEquals for same type

2012-12-05 Thread deed
What I know about this topic is in the following chapter: http://ddili.org/ders/d.en/object.html Ali Thanks, Ali. That clarifies why it worked with opCmp and not with opEquals.

opEquals

2012-12-04 Thread deed
interface I { bool opEquals(I i); } class C : I { bool opEquals(I i) { return true; } } void main() { I i1 = new C; I i2 = new C; assert(i1 == i2); // Assertino failure assert(i1 != i2); // Passes, although it's the opposite of what I want.. } What's

opEquals for same type

2012-12-04 Thread deed
interface I { // ... bool opEquals(I i); } class C : I { // ... bool opEquals(I i) { return true; } } void main() { I i1 = new C; I i2 = new C; assert(i1 == i2); // Assertion failure assert(i1 != i2); // Passes, although it's the opposite of what

Re: Most elegant representation of a card's rank

2012-12-03 Thread deed
On Monday, 3 December 2012 at 23:42:38 UTC, bearophile wrote: deed: How is a playing card's rank represented most elegantly in code? Maybe with an enum? enum Card { J, Q, ...} If you have to store many of them then maybe giving them a size of one byte is better: enum Card : ubyte

Most elegant representation of a card's rank

2012-12-03 Thread deed
How is a playing card's rank represented most elegantly in code? * Should be a customized uint/an own type representing uints in the range of 2 through 14. * void foo(Rank rank) { } // Accepts only the valid range foo(0); // Error foo(2); // Ok foo(10); // Ok alias J 11; alias Q 1

Re: not expected pointers for struct members from foreach

2012-10-10 Thread deed
Struct pointers are useful and reliable, but before using them you need to know the difference between heap and stack, what a stack frame is, and how structs are handled when they are on the stack. Learning the basics of such things ideas requires only few minutes and it will be useful for many

Re: not expected pointers for struct members from foreach

2012-10-09 Thread deed
On Tuesday, 9 October 2012 at 16:21:47 UTC, bearophile wrote: deed: // Again, why are the three last adresses the same? The D language and its compiler is acting correctly here, so the output you see is correct. All those structs are allocated on the stack. The first three Test are

not expected pointers for struct members from foreach

2012-10-09 Thread deed
import std.stdio; struct Test { static Test[] objects; static Test*[] psObject; static int[] ints; static int*[] psInt; int a; int b; int* pa; this(int a) { this.a = a; this.pa = &this.a; this.b = 2 * a;

WIC and Direct X

2012-09-30 Thread deed
Anyone having experience in using WIC? How can I render, let's say a png file on disk, to the screen?

Re: How to register class member function as lpfnWndProc? Cannot convert delegate to function

2012-09-30 Thread deed
Thanks to all of you for your informative replies. I was testing different code structures and wondered whether this was possible.

How to register class member function as lpfnWndProc? Cannot convert delegate to function

2012-09-28 Thread deed
Hi I am trying to register a class member function as wc.lpfnWndProc, but get the error message "cannot implicitly convert expression (&this.WndProc) of type extern (Windows) int delegate(...) to extern (Windows) int function(...). I have: extern (Windows) class App { HRESULT initialize

Re: Error: WndProc - nothrow

2012-09-16 Thread deed
Exactly. I couldn't remember seeing this error before.

Re: Error: WndProc - nothrow

2012-09-16 Thread deed
But why is the wndProc function nothrow? Why do I have to mark it with nothrow?

Re: Error: WndProc - nothrow

2012-09-16 Thread deed
I did, but then I am not able to use writeln for debugging. Is this restriction something new?

Error: WndProc - nothrow

2012-09-16 Thread deed
I get this error from a minimal windows example: import core.runtime; import std.c.windows.windows; import std.string; pragma(lib, "gdi32.lib"); extern (Windows) { int WinMain( ... ) { ... } HRESULT appMain( ... ) { ... WNDCLASS wc; ... wc.lpfnWndProc = &wndProc; ... } HRESU

Re: import std.random fails

2012-08-31 Thread deed
Reinstallation solved the case. Thanks for your prompt reply.

Re: import std.random fails

2012-08-31 Thread deed
You druntime installation is bad due to some cruft left from a previous install (the installer obviously needs some work). If you used an installer, then uninstall dmd, make sure that it's completely removed, and then reinstall it. If you installed it manually, then make sure that you blow awa

Re: import std.random fails

2012-08-31 Thread deed
On Friday, 31 August 2012 at 22:44:11 UTC, ixid wrote: You're missing the semi-colon after import std.random. Sorry, typo. Semicolon is included in the file. DMD 2.060.

import std.random fails

2012-08-31 Thread deed
import std.random void main() {} --- results in: Error 42: Symbol Undefined _D4core6memory2GC6qallocFkkZS4core6memory8BLkInfo_ Error 42: Symbol Undefined _D4core6memory2GC6extendFPvkkZk Error 42: Symbol Undefined _D4core5bitop3bsrFNaNbkZi --- errorlevel 3 What is wrong?