Re: import doesn't import jpg

2012-09-04 Thread Andrej Mitrovic
On 9/4/12, Zhenya wrote: > -J Chrysanthemium.jpg That's the issue. -J needs to be followed by a path, e.g. -J. (notice the dot), or -JC:\some\folder, and no spaces so don't use -J C:\some\folder. Remember that you're putting a directory path, not a file path with -J.

Re: import doesn't import jpg

2012-09-04 Thread Andrej Mitrovic
On 9/4/12, Zhenya wrote: > immutable char[] texture = import("Chrysanthemum.jpg"); Works for me on win32 & DMD2.060 and with "-J." switch. Which system/compiler are you using?

Re: segfault

2012-08-31 Thread Andrej Mitrovic
On 8/31/12, Ellery Newcomer wrote: > hey, is anyone else getting a segfault from dmd on this code? Yep on win32.

Re: static struct definition

2012-08-27 Thread Andrej Mitrovic
On 8/27/12, bearophile wrote: >Truly inner structs like Baz > should have a hidden pointer field that points to the enclosing > struct. Isn't this limited to just classes?

Re: Lazy range of hashes?

2012-08-25 Thread Andrej Mitrovic
On 8/26/12, bearophile wrote: > This seems to work: It seems it's as simple as defining a struct: struct LazyHash(T...) { T hashes; bool opIn_r(X)(X x) { foreach (hash; hashes) { if (x in hash) return true; } return false;

Lazy range of hashes?

2012-08-25 Thread Andrej Mitrovic
I could use something like this: void main() { int[string] x = ["foo":1]; int[string] y = ["bar":1]; assert("bar" in lazyHash(x, y)); } Essentially it would turn into lazy 'in' checks, meaning first opIn_r would be called for 'x', and then for 'y'. Otherwise it might be expensive to

Re: Global variables read at compile time?

2012-08-15 Thread Andrej Mitrovic
On 8/15/12, d_follower wrote: > I don't really know why, but it seems that you can only > initialize globals with constants. That's what the static constructor is for: http://dlang.org/class.html#StaticConstructor http://dlang.org/class.html#SharedStaticConstructor

Re: char ***argc problems.

2012-08-12 Thread Andrej Mitrovic
On 8/12/12, Simen Kjaeraas wrote: > That don't sound too stupid. File an enhancement request, wouldya? http://d.puremagic.com/issues/show_bug.cgi?id=8544

Re: char ***argc problems.

2012-08-12 Thread Andrej Mitrovic
On 8/12/12, Simen Kjaeraas 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 if argc & argv were stored somewhere. druntime/src/rt/dmain2.d is where the action begins: extern (C) int main(i

Re: DWiki tables

2012-08-08 Thread Andrej Mitrovic
On 8/8/12, Justin C Calvarese wrote: > Try editing this page: > http://prowiki.org/wiki4d/wiki.cgi?dTemplate > > (I think it's determined by the "TemplateFile" setting at > http://prowiki.org/wiki4d/wiki.cgi?Context.) Thanks, that did it.

Re: How to create TypeTuple/ExpressionTuple from tuple/tuples

2012-08-08 Thread Andrej Mitrovic
On 8/8/12, Philippe Sigaud wrote: > Hey, every time I do something like that, you ask me to put it in my > template tutorial ;) Well yeah, we don't want a future Banana(tm) company patenting our codez, we need prior art! :p So maybe it's not book-worthy. Perhaps there should be a github repo wit

Re: How to create TypeTuple/ExpressionTuple from tuple/tuples

2012-08-08 Thread Andrej Mitrovic
On 8/8/12, Philippe Sigaud wrote: > Like this.. That's really cool. Could you put this in the DT book, along with your previous sample? Good job btw!

Re: DMD out of memory issues

2012-08-07 Thread Andrej Mitrovic
On 8/6/12, Andrej Mitrovic wrote: > Unfortunately anything big won't work because I get out of memory errors when > compiling the > D wrapper. It doesn't seem to be caused by any infinite loops, DMD just simply runs out of memory. I've enabled some printf's and c

Re: How to create TypeTuple/ExpressionTuple from tuple/tuples

2012-08-07 Thread Andrej Mitrovic
On 8/7/12, Philippe Sigaud wrote: > You can also take the 'dual' of your solution and have a template that > makes a function automatically expand tuples But that doesn't work for variadic templates, which is the OP's case: int foo(T...)(T t) { return 1; } alias expander!foo efoo; // error

Re: How to create TypeTuple/ExpressionTuple from tuple/tuples

2012-08-07 Thread Andrej Mitrovic
On 8/7/12, "Øivind" wrote: > The last one then becomes f(v0.expand, v1.expand) Yeah. It's somewhat possible to use a helper function for multiple TypeTuples, but the problem is D functions cannot return language tuples (only TypeTuple from std.typecons which is what the tuple() call creates) so y

Re: How to create TypeTuple/ExpressionTuple from tuple/tuples

2012-08-07 Thread Andrej Mitrovic
On 8/7/12, "Øivind" wrote: > How can I call this function with an already-constructed tuple > but pass the pule as an expressiontuple? > > auto v = tuple(1, 2, 3); > f(v); Use the .expand property: f(v.expand)

Re: Nested struct member has no access to the enclosing class data

2012-08-06 Thread Andrej Mitrovic
On 8/6/12, H. S. Teoh wrote: > Try outer.i instead of just i. There is no "outer". A nested struct has the same access as a nested static class, meaning no access to any outer members unless they're static. OP could use a nested non-static class, but I don't know if the complications are worth it

Re: Function that calculates in compile time when it can

2012-08-06 Thread Andrej Mitrovic
On 8/6/12, Philippe Sigaud wrote: > Which reminds me... What if someone wants Fibonacci values depending > on a runtime value, but would like them to be calculated really fast? I think TDPL had some use of the memoize template and used fibonacci as sample code. It even used it internally for a re

Re: Error while trying to allocate memory (malloc)

2012-08-06 Thread Andrej Mitrovic
On 8/6/12, CrudOMatic wrote: > another quick question - are these allocations automatically > entered into the GC heap? If so then I can just disable garbage > collection? No, there is the standard C malloc/free in std.c.stdlib which you're using, and then there's the GC.malloc and GC.free in cor

Re: Error while trying to allocate memory (malloc)

2012-08-06 Thread Andrej Mitrovic
On 8/6/12, Eyyub wrote: > Tell me if I'm wrong. (I did not programming in C since 2 years) You're not wrong. m_blockList is a pointer and OP needs to allocate an s_blockHeader instance before he uses it: s_blockHeader* m_blockList = cast(s_blockHeader*)malloc(s_blockHeader.sizeof);

Re: Tiny/Small C++ libraries

2012-08-05 Thread Andrej Mitrovic
On 8/6/12, Jonathan M Davis wrote: > Last I heard, it never releases _any_ memory, and the one attempt to fix > that via a garbage collector tanked performance. If anyone has a patch/diff/branch for the GC-enabling code I'd like to know about it. I'd be willing to trade performance in this case s

Tiny/Small C++ libraries

2012-08-05 Thread Andrej Mitrovic
I need some relatively small C++ libraries to test my wrapper codegenerator. Unfortunately anything big (like WX or even DMD as a lib) won't work because I get out of memory errors when compiling the D wrapper. Speaking of which, how can I debug/fix this? It seems like a front-end issue because it

Re: Return doesn't really return

2012-08-04 Thread Andrej Mitrovic
On 8/4/12, Jacob Carlborg wrote: > Have I done a mistake somewhere or is this a bug in DMD? Could be related to: http://d.puremagic.com/issues/show_bug.cgi?id=7453 IOW, maybe your opApply function needs fixing?

Re: Templates and stringof...

2012-08-03 Thread Andrej Mitrovic
On 8/4/12, Andrej Mitrovic wrote: > On 8/3/12, Era Scarecrow wrote: >> Now, how do I get the template's stringof to print out 'i_num.i' >> and not 'i'? > > Courtesy of Philippe Sigaud, slightly edited to my style: In fact, this should really be

Re: Templates and stringof...

2012-08-03 Thread Andrej Mitrovic
On 8/4/12, Andrej Mitrovic wrote: > On 8/3/12, Era Scarecrow wrote: >> Now, how do I get the template's stringof to print out 'i_num.i' >> and not 'i'? > snip Ahh crap, it doesn't return the *instance* name. Sorry!! Maybe there can be a fix though, I'll give it a try..

Re: Templates and stringof...

2012-08-03 Thread Andrej Mitrovic
On 8/3/12, Era Scarecrow wrote: > Now, how do I get the template's stringof to print out 'i_num.i' > and not 'i'? Courtesy of Philippe Sigaud, slightly edited to my style: /** Return the fully qualified name of a symbol. Implemented by Philippe Sigaud in the D Templates book. See h

Re: how to pass a variable name in the template in this case?

2012-08-02 Thread Andrej Mitrovic
On 8/3/12, Zhenya wrote: > Huh,thank you,I understood.I just thought that by default alias > parameter is an identifier.I was surprised then I saw that > possible to pass value of variable,which is'nt enum.Could you > explain me why it is? I think alias can be seen as "pass by name". The template

Re: how to pass a variable name in the template in this case?

2012-08-02 Thread Andrej Mitrovic
On 8/3/12, Zhenya wrote: > snip You mean how to extract the variable name? import std.stdio; template T(alias a) { enum string T = __traits(identifier, a); } void main(string[] argv) { char f = 'a'; writeln(T!f); // writes 'f' }

Re: Why must bitfields sum to a multiple of a byte?

2012-07-31 Thread Andrej Mitrovic
On 7/31/12, Era Scarecrow wrote: > I wonder, is it really a bug? If you are going to have it fill a > whole size it would fit anyways, why even put it in as a > bitfield? You could just declare it separately. I don't really know, I'm looking at this from a point of wrapping C++. I haven't used

Re: Why must bitfields sum to a multiple of a byte?

2012-07-31 Thread Andrej Mitrovic
On 7/31/12, monarch_dodra wrote: > The bug is only when the field is EXACTLY 32 bits BTW. bitfields > works quite nice with 33 or whatever. More details in the report. Yeah 32 or 64 bits, thanks for changing the title.

Re: Why must bitfields sum to a multiple of a byte?

2012-07-30 Thread Andrej Mitrovic
On 7/31/12, Era Scarecrow wrote: > It assumes the largest type we can currently use which is ulong Ah yes, it makes sense now. Thanks for the brain cereal. :p

Re: Why must bitfields sum to a multiple of a byte?

2012-07-30 Thread Andrej Mitrovic
On 7/31/12, Era Scarecrow wrote: > And likely one I'll be working on fairly soon. I've been > concentrating on the BitArray, but I'll get more of the bitfields > very very soon. > Cool. What about the max limit of 64bits per bitfield instantiation? I don't suppose this is common in C++ but I wo

Re: sorting failed error

2012-07-30 Thread Andrej Mitrovic
On 7/31/12, Timon Gehr wrote: > I like it more because it says "loop". I'd love to have "loop { }". But keyword bloat yada yada. :)

Re: Detector for unused variables

2012-07-30 Thread Andrej Mitrovic
On 7/30/12, Namespace wrote: > BTW: Has anyone test my detector and could give me some > suggestions or critism? > I've tried it out and it didn't find any unused variables, but I doubt this is true, I'm not very tidy when it comes to using variables. I do use a lot of templates so maybe the scri

Re: Detector for unused variables

2012-07-30 Thread Andrej Mitrovic
On 7/30/12, Jonathan M Davis wrote: > Walter doesn't like compiler switches like that Walter is a big fat phony, count the number of switches here: http://www.digitalmars.com/ctg/sc.html#switches :D

Re: Why must butfields sum to a multiple of a byte?

2012-07-30 Thread Andrej Mitrovic
On 7/30/12, monarch_dodra wrote: > By the way, what's a "butfield"? LOL I haven't even noticed.

Re: Why must butfields sum to a multiple of a byte?

2012-07-30 Thread Andrej Mitrovic
On 7/30/12, Ali Çehreli wrote: > The program should be able to detect the placements of the fields. You > can expect a certain bit pattern for a given set of values of the bit > fields, set those values, read them on the D side, detect potential > inconsistencies, and fail the execution (or hopefu

Re: Detector for unused variables

2012-07-30 Thread Andrej Mitrovic
On 7/30/12, Namespace wrote: > IMO something like this should be integrated into the D compiler. As long as it's togglable via a compiler switch. :)

Re: Why must butfields sum to a multiple of a byte?

2012-07-30 Thread Andrej Mitrovic
On 7/30/12, Ali Çehreli wrote: > It is inherently unportable because unlike D, bitfields in C and C++ > give too much freedom to the compiler. The compiler can move the fields > around at will. I really need to figure out a reliable way to extract this information, at least for the target platfor

Re: Why must butfields sum to a multiple of a byte?

2012-07-30 Thread Andrej Mitrovic
On 7/30/12, monarch_dodra wrote: > I think you are supposed to explicitly pad the field yourself: You're right, I missed that part of the documentation. :)

Re: sort strings by interpreting them as integrals

2012-07-30 Thread Andrej Mitrovic
On 7/30/12, Jonathan M Davis wrote: > Boost. Cool. Boost is so large I never noticed it (and maybe because I don't use C++ that much). > In any case, whatever the pros and cons are of a path object rather than > strings, it was discussed for Phobos at one point and decided that it just > wasn't

Re: sort strings by interpreting them as integrals

2012-07-29 Thread Andrej Mitrovic
On 7/30/12, bearophile wrote: > Because sorting numbers as > strings is a very good source of bugs. Thinking about this, pretty much any interpretation of strings is a very good source of bugs. I've been thinking how e.g. path manipulation might better be done with tokenization. For example if yo

Re: sort strings by interpreting them as integrals

2012-07-29 Thread Andrej Mitrovic
On 7/30/12, Jonathan M Davis wrote: > It _does_ assume that all numbers start with an underscore and don't have > leading zeroes though. That's good for me. Nice solution too, very simple. Odd that it uncovered a bug. Oh well..

Re: sort strings by interpreting them as integrals

2012-07-29 Thread Andrej Mitrovic
On 7/30/12, bearophile wrote: > import std.stdio, std.algorithm, std.conv; > void main() { > auto data = ["_100", "_10", "_20"]; > schwartzSort!(s => to!int(s[1 .. $]))(data); > writeln(data); > } Very nice! Thanks.

Re: sort strings by interpreting them as integrals

2012-07-29 Thread Andrej Mitrovic
On 7/30/12, Andrej Mitrovic wrote: > How would you implement that? It could be a nice exercise! :) Here's a super-inefficient way to do it: auto y = to!(size_t[])(pipe!(map!(y => y[1 .. $]))(x).array); sort(y); auto z = map!(y => "_" ~ to!string(y))(y); Heheh, memory waste galore.

sort strings by interpreting them as integrals

2012-07-29 Thread Andrej Mitrovic
void main() { string[] x = ["_100", "_10", "_20"]; sort(x); writeln(x); } result: ["_10", "_100", "_20"] I need to treat these as if they were integrals, although the underscore complicates things here since it should be ignored. So the result I want is: ["_10", "_20", "_100"] How wo

Re: normal function and template function conflict

2012-07-26 Thread Andrej Mitrovic
On 7/26/12, Jacob Carlborg wrote: > void seed () (UIntType value = default_seed) > > Less typing as well. Yep. It's funny how this works at all. I mean a template with no template parameters is somehow still a template. :)

Re: Problem: handling a function dependent on release mode.

2012-07-22 Thread Andrej Mitrovic
On 7/22/12, Jonathan M Davis wrote: > Yeah. Don't have them be template parameters unless you need to, otherwise > you > get a different template instantiation _every_ time that you call the > function. I've just noticed something: @property front(T)(T arr, string file = __FILE__, size_t line =

Re: Swap furthest element type of an array

2012-06-18 Thread Andrej Mitrovic
On 6/19/12, Andrej Mitrovic wrote: > On 6/19/12, Andrej Mitrovic wrote: >> On 6/19/12, Timon Gehr wrote: >>> Indeed. If you are interested, I'll make it work with qualified types as >>> well. =) >> >> I thought it already does? >> > > O

Re: Swap furthest element type of an array

2012-06-18 Thread Andrej Mitrovic
On 6/19/12, Andrej Mitrovic wrote: > On 6/19/12, Timon Gehr wrote: >> Indeed. If you are interested, I'll make it work with qualified types as >> well. =) > > I thought it already does? > Oh you meant to *keep* the qualifier, yeah.

Re: Swap furthest element type of an array

2012-06-18 Thread Andrej Mitrovic
On 6/19/12, Timon Gehr wrote: > Indeed. If you are interested, I'll make it work with qualified types as > well. =) I thought it already does?

Re: Swap furthest element type of an array

2012-06-18 Thread Andrej Mitrovic
On 6/18/12, Timon Gehr wrote: > template SwapElem(A, E){ > static if(is(A X:X[N],size_t N)) alias SwapElem!(X,E)[N] R; > else static if(is(A X:X[])) alias SwapElem!(X,E)[] R; > else static if(is(A X:X*)) alias SwapElem!(X,E)* R; > else alias E R; > alias R SwapElem; > } >

Re: Why doesn't alias this work with arrays?

2012-06-18 Thread Andrej Mitrovic
On 6/18/12, Jonathan M Davis wrote: > At that point, you'd need to be converting from string[] to Wrap[], > which would mean creating a new array It doesn't have to allocate anything because there's the 'alias this' and a single data member. All the compiler has to do is cast the array type to Wr

Why doesn't alias this work with arrays?

2012-06-18 Thread Andrej Mitrovic
struct Wrap { string wrap; alias wrap this; } void main() { Wrap x; x = "foo"; // ok Wrap[] y = ["foo", "bar"]; // fail } Error: cannot implicitly convert expression (["foo","bar"]) of type string[] to Wrap[] Any special reason why this doesn't work? I hope it's just a bug

Re: Simulating rectangular array

2012-06-18 Thread Andrej Mitrovic
On 6/17/12, Andrej Mitrovic wrote: > Has anyone come up with a template that can simulate a rectangular > array and allow one to override opAssign to do special work? Thanks for the replies, guys.

Simulating rectangular array

2012-06-17 Thread Andrej Mitrovic
Has anyone come up with a template that can simulate a rectangular array and allow one to override opAssign to do special work? E.g.: Array!(2, 4) arr; arr[1][3] = "foo"; This would invoke opAssign in some templated struct "Array". This would be super-easy to implement if I had an opIndex that co

Re: Using C macros without massive rewrites

2012-06-12 Thread Andrej Mitrovic
On 6/12/12, Johannes Pfau wrote: > But for simple macros, gcc -E -dM can be useful. > gcc -E -dM '/usr/include/sys/types.h' This could be useful for me, thanks. More options: http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Preprocessor-Options.html

Re: Ddoc inheritance

2012-06-11 Thread Andrej Mitrovic
On 6/12/12, Alex Rønne Petersen wrote: > Would be neat if you could do something like ditto: > > /// inherit > override void foo() > { > } Maybe we should have "// super ditto" :)

Re: Build all combinations of strings

2012-06-11 Thread Andrej Mitrovic
On 6/11/12, Philippe Sigaud wrote: > Does it still work? It must be almost 2 years old now. Yup!

Re: Build all combinations of strings

2012-06-11 Thread Andrej Mitrovic
On 6/11/12, Andrej Mitrovic wrote: > I wouldn't know how to translate that to D though. Found Phillipe's implementation. Cut from dranges.algorithm: http://pastebin.com/26s7wNYJ There's a github clone here: https://github.com/dawgfoto/dranges Problem solved for now. :)

Re: Build all combinations of strings

2012-06-11 Thread Andrej Mitrovic
On 6/11/12, Andrej Mitrovic wrote: > So that's not what I'm looking for. Here's what I'm looking for, but in Python: http://docs.python.org/library/itertools.html#itertools.combinations They also have a version that has repeated elements: http://docs.python.org

Re: Build all combinations of strings

2012-06-11 Thread Andrej Mitrovic
On 6/11/12, Andrej Mitrovic wrote: > Also I think the formal word of what I'm looking for is a "powerset". > Hmm wrong, not looking a powerset. Here's one anyway which bearophile posted in another thread: import std.stdio: writeln; auto powerSet(T)(T[] items) {

Re: Build all combinations of strings

2012-06-11 Thread Andrej Mitrovic
On 6/11/12, Andrej Mitrovic wrote: > On 6/11/12, Andrej Mitrovic wrote: >> Is there a Phobos function.. > > Almost forgot, it can't repeat one string multiple times, so no "foo foo > foo". > Also I think the formal word of what I'm looking for is a "powerset".

Re: Build all combinations of strings

2012-06-11 Thread Andrej Mitrovic
On 6/11/12, Andrej Mitrovic wrote: > Is there a Phobos function.. Almost forgot, it can't repeat one string multiple times, so no "foo foo foo".

Build all combinations of strings

2012-06-11 Thread Andrej Mitrovic
Is there a Phobos function to turn this: string[] words = "foo bar doo".split(); into: string[] res = ["foo bar doo", "foo doo bar", "bar foo doo", "bar doo foo", "doo foo bar", "doo bar foo"]; So basically all comb

Re: gdc and gcc object linking issues

2012-06-08 Thread Andrej Mitrovic
On 6/8/12, Kagamin wrote: > Well, I'm not a C++ pro, but I won't recommend to place > initializer in the header. That sounds odd. What would it mean? I > guess, it will mean definition, so chances are it's not what you > want. Initializers belong to definitions, and definitions belong > to .cpp, t

Re: gdc and gcc object linking issues

2012-06-07 Thread Andrej Mitrovic
On 6/7/12, Kagamin wrote: > You didn't define the variable. Aah, I see what's going on. See, I was using this in the context of wrapping existing C++ libs. Since I was writing a small test-case for wrapping a static field I made a header file with a static field declaration but no .cpp implementa

Re: gdc and gcc object linking issues

2012-06-07 Thread Andrej Mitrovic
On 6/7/12, Kagamin wrote: > If you define a > variable in the header, it will be included in each including > module and you'll get several instances of the variable and > symbol collision at link time. This wasn't a collision error, it was a missing symbol error. The variable is static, so it sh

Re: gdc and gcc object linking issues

2012-06-06 Thread Andrej Mitrovic
On 6/6/12, Dmitry Olshansky wrote: >> Old boring C++ :) >> >> Once you have this definition due to moronic linkage model (and probably >> some other reasonable things) you have to have: >> >> int Class:statField; > > int Class::statField; obviously Thanks, that fixed it! :) Yeah C++ is a weirdo.

gdc and gcc object linking issues

2012-06-06 Thread Andrej Mitrovic
This is a bit more related to C++ than D, it has to do with wrapping. I've got 4 files: test.h: class Class { public: static int statField; }; test.cpp: #include "test.h" extern "C" __attribute__((dllexport)) int getStatField() { return Class::statField; } test.d: extern(C) int getStatFi

Re: Calling main() from WinMain()

2012-06-05 Thread Andrej Mitrovic
On 6/5/12, BLM768 wrote: > I'm working on a cross-platform GUI library and I'd like to be > able to call the user's main() function from WinMain() so users > don't have to write both functions. GUI libraries don't have to work this way. You could instantiate an "App" and then call some internal "

Re: Static function conflicts with Non-Static?!

2012-06-02 Thread Andrej Mitrovic
On 6/2/12, Jonathan M Davis wrote: > The trick is getting Walter to agree. The trick is getting all the people that bought TDPL to burn their books, because by the time all these new changes are set in place the book will have as much dead weight to it as dsource.org. It specifically says on page

Re: Windows - ZeroMemory macro

2012-05-27 Thread Andrej Mitrovic
On 5/27/12, dnewbie wrote: > In C I can write > > OPENFILENAME ofn; > ZeroMemory(&ofn, sizeof(ofn)); > > In D, there is no ZeroMemory. Please help me. > I've never had to use this with WinAPI. The default .init value usually works well, especially if the struct is well-defined, e.g.: struct Foo

Re: Struct hash issues with string fields

2012-05-27 Thread Andrej Mitrovic
On 5/27/12, Ali Çehreli wrote: > On 05/26/2012 05:13 PM, Ali Çehreli wrote: > > > once you define toHash(), you > > must also define opCmp() and opEquals() that are all consistent with > > each other. > > Correction: opEquals() is only for potential optimizations. What is > needed alongside toH

Re: Struct hash issues with string fields

2012-05-26 Thread Andrej Mitrovic
On 5/27/12, Era Scarecrow wrote: > Problem goes > away when not idup-ing, but likely that is the compiler saving > space and assigning the same pointer address (which makes sense). Yes, the .idup was done on purpose here for demonstration.

Re: Struct hash issues with string fields

2012-05-26 Thread Andrej Mitrovic
On 5/27/12, Jonathan M Davis wrote: > Why can't you have a toHash in your struct? I mean it doesn't seem to make any difference: import std.stdio; struct Foo { string x; size_t toHash() { return 1; } } void main() { int[Foo] hash; Foo foo1 = Foo("a".idup); Foo foo2 = Foo("a

Struct hash issues with string fields

2012-05-26 Thread Andrej Mitrovic
I don't understand this: import std.stdio; struct Symbol { string val; } void main() { int[string] hash1; hash1["1".idup] = 1; hash1["1".idup] = 2; writeln(hash1); // writes "["1":2]" int[Symbol] hash2; Symbol sym1 = Symbol("1".idup); Symbol sym2 = Symbol("1".idup);

Why doesn't this throw?

2012-05-25 Thread Andrej Mitrovic
import std.algorithm; import std.stdio; void main() { int[] a = [1, 2, 3]; a = a.remove(3); writeln(a); } writes [1, 2] If I'd called a.remove with index 2 I would get the above result, but index 3 is clearly out of bounds, so why'd it remove the last element instead of throwing?

null matches typed pointers before void pointers

2012-05-24 Thread Andrej Mitrovic
I'm not sure if this is a bug or not: struct Foo { } void test(void* test) { assert(0); } void test(Foo* test) { } void main() { test(null); } The call matches the second overload: "void test(Foo* test)". But shouldn't this be an ambiguous call?

Re: Limit number of compiler error messages

2012-05-22 Thread Andrej Mitrovic
On 5/20/12, cal wrote: > Is there a way to limit the dmd compiler to outputting just the > first few errors it comes across? > If you're getting a ton of unrelated errors it might be related to this: http://d.puremagic.com/issues/show_bug.cgi?id=8082 I regularly get hundreds of lines of errors d

Re: detecting POD types

2012-05-20 Thread Andrej Mitrovic
I don't think there is, but maybe you could use some template constraints from std.traits, like isPointer: if (!isPointer!T && !is(T == class)) There's probably other cases to consider, I'll leave others to fill in. On 5/20/12, japplegame wrote: > I write function template that should works only

Re: allocate array with new

2012-05-15 Thread Andrej Mitrovic
On 5/15/12, Jonathan M Davis wrote: > If you're going to use anything, use clear. He might as well just use this if he wants the GC to take care of things: arr = null; clear(arr) is a little bit of a misnomer. If you have another slice pointing to the same array clear() won't really release memo

Re: optlink

2012-05-13 Thread Andrej Mitrovic
use implib (http://ftp.digitalmars.com/bup.zip): implib /s Crypt32_implib.Lib Crypt32.Lib then use Crypt32_implib.Lib with dmd.

Re: [Derelict2] Code SOMETIMES seg. faults!

2012-05-11 Thread Andrej Mitrovic
On 5/10/12, Minas wrote: > But sometimes (at about 3-5 runs), I get a segmentation fault! Long shot but: I've had crashes before when using write calls in an app that doesn't spawn a console window. What happened was stdout/stderr wasn't opened, so to fix that I'd have to do this before any calls

Re: ref semantics with hashes

2012-05-03 Thread Andrej Mitrovic
On 5/3/12, Artur Skawina wrote: >alias p1.p2.p3.p4.p5.p6.hash hash3; >alias p1.p2?p1.p2.hash:p3.p4.hash hash4; >alias getfoo().hash hash5; I was under the impression that alias would only be used as a compile-time alias to a nested symbol. So this: alias p1.p2.p3.hash foo; test(foo);

Test if an enum value is in a range of a derived enum

2012-05-02 Thread Andrej Mitrovic
import std.stdio; enum Base { One, Two, Three, Four } enum Subset : Base { Two = Base.Two, Three = Base.Three } void main() { Base base = Base.Four; if (cast(Subset)base) { writeln("yes"); } } This writes "yes" so cast is a blunt tool that doesn't

Re: ref semantics with hashes

2012-05-02 Thread Andrej Mitrovic
On 5/3/12, Andrej Mitrovic wrote: > import std.stdio; > > struct Foo > { >int[] hash; > } Sorry that should have been int[int] there.

Re: ref semantics with hashes

2012-05-02 Thread Andrej Mitrovic
On 5/2/12, Jonathan M Davis wrote: > The way that AAs work in this regard is identical to how dynamic arrays > work. Yes but they're very different in other regards. For example, if you add an element to one array it doesn't automatically add an element to the other array: int[] a = new int[

ref semantics with hashes

2012-05-02 Thread Andrej Mitrovic
import std.stdio; struct Foo { int[int] hash; } void main() { test1(); test2(); } void test1() { Foo foo; foo.hash[1] = 1; auto hash2 = foo.hash; hash2[2] = 2; writeln(foo.hash); // [1:1, 2:2] writeln(hash2); // [1:1, 2:2] } void test2() { Foo foo;

Re: "static" means too many things

2012-05-01 Thread Andrej Mitrovic
On 5/2/12, bearophile wrote: > This is the brief of some D code, it shows one consequence of the > excessive overloading of the D "static" keyword: You can almost cheat, but you can't: struct Foo { bool solve() { auto fill = function(int r, int c, int x) { wri

Re: type conversions

2012-04-29 Thread Andrej Mitrovic
On 4/30/12, WhatMeWorry wrote: > I'm trying to get my head around D's type conversion. What is the > best way to convert a string to a char array? Or I should say is > this the best way? > > string s = "Hello There"; > char[] c; > > c = string.dup; > Well it depends . Why do you need a char[]? If

Re: How to avoid crashing win32 app when stdout is unavailable and write is called?

2012-04-27 Thread Andrej Mitrovic
On 4/27/12, Andrej Mitrovic wrote: > I am such an idiot, I've already asked this before. And Vlad gave me a perfectly good answer the last time: if (!GetConsoleWindow()) { stdout.open("stdout.log", "w"); stderr.open("stderr.log", "w"); }

How to avoid crashing win32 app when stdout is unavailable and write is called?

2012-04-26 Thread Andrej Mitrovic
So I've just realized that write() throws an exception if stdout is unavailable and it's called. It throws this: std.exception.ErrnoException@D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\stdio.d(1164): (Bad file descriptor) This happens when an app has a WinMain and is built with -L-Subsystem:Win

Re: Docs: Section on local variables

2012-04-25 Thread Andrej Mitrovic
On 4/25/12, Stewart Gordon wrote: > What is the distinction you're making exactly? > You mean an empty if body should trigger something? Or shouldn't? I'm saying those are exactly the cases presented in the docs and I don't want them to warn by default but have a setting. I mean, the first case

Re: Docs: Section on local variables

2012-04-25 Thread Andrej Mitrovic
On 4/25/12, Andrej Mitrovic wrote: > I'm really only talking about Although I'm not a fan of warnings for unused variables, I would be a fan of this: http://d.puremagic.com/issues/show_bug.cgi?id=3507 But again, other people might not like that. But if it was an option..

Re: Docs: Section on local variables

2012-04-25 Thread Andrej Mitrovic
On 4/25/12, Stewart Gordon wrote: > So you think that > > import std.stdio; > void main() { > int a, b; > a + b; > return; > writefln("Hello, world!"); > } > > should generate no errors or warnings whatsoever? I'm really only talking about: void a() { int x; } And of course:

Re: Docs: Section on local variables

2012-04-25 Thread Andrej Mitrovic
On 4/25/12, Stewart Gordon wrote: > Even if it's left over from debugging, it > looks silly, and > might lead other people reading the code to believe something's wrong. There's about a million ways to make code unreadable, and nobody writes pitch-perfect code that has absolutely no leftover code

Re: D static lib called from C on Mac OS X

2012-04-25 Thread Andrej Mitrovic
On 4/25/12, Nicolas Sicard wrote: > --- file main.c --- > extern void mylib_init(); > extern void mylib_free(); Try changing void to bool there.

Re: Question about arrays

2012-04-21 Thread Andrej Mitrovic
On 4/22/12, Stephen Jones wrote: > My C programming lies in cobwebs but from memory an array was a > pointer to the zeroth index of a set of uniformly sized chunks of > memory. I am perplexed to find that in D a call to an array (of > float vertices for example) cannot be accomplished by handing &

Re: Docs: Section on local variables

2012-04-21 Thread Andrej Mitrovic
On 4/21/12, H. S. Teoh wrote: > It would be a major pain if every > single time you need to temporarily suppress a section of code, you also > have to hunt down every last stray variable that's now no longer > referenced in the function and comment them out as well. Next thing you know the compil

<    1   2   3   4   5   6   7   8   9   10   >