Re: Array Defenitions

2013-11-13 Thread Andrej Mitrovic
On 11/13/13, Jeroen Bollen wrote: > I feel there is a lack of resources/documentation on array > definitions. I cannot believe the official documentation tries to > explain how D handles arrays without defining an array a single > time. > > http://dlang.org/arrays.html > See if this helps: http:/

Re: The D Programming Language page 161.

2013-11-13 Thread Andrej Mitrovic
On 11/13/13, Adam D. Ruppe wrote: > On Wednesday, 13 November 2013 at 08:16:34 UTC, Tor Einar > Tønnessen wrote: >> void writeln(string a0, int a1, string a2, int[new] a3) { > > Around the time the book was written, there was a debate as to if > we should make dynamic arrays and slices two differe

Re: [challenge] Lazy flatten/avoiding type forward reference with map

2013-11-01 Thread Andrej Mitrovic
On 11/1/13, David Nadlinger wrote: > I just thought I'd be interested to see what the best solution we > can find in terms of conciseness is. Note that I've already asked this in D.learn: http://forum.dlang.org/thread/mailman.43.1383090512.9546.digitalmars-d-le...@puremagic.com

Re: How do you implement a recursive walker of a tree with a lazy range?

2013-10-30 Thread Andrej Mitrovic
On 10/30/13, Philippe Sigaud wrote: > Does that syntax come with DMD 2.064? The (T) part, I mean. Yes. Glad to see you here btw, do you have your own solution to the problem?

Re: How do you implement a recursive walker of a tree with a lazy range?

2013-10-30 Thread Andrej Mitrovic
On 10/30/13, Chris Cain wrote: > I'm not confident that this is the most efficient way, but it > works. It allocates, I'm looking for a lazy range. I would be surprised that such a common task as iterating a tree is not possible without using classes and workarounds.

How do you implement a recursive walker of a tree with a lazy range?

2013-10-29 Thread Andrej Mitrovic
Instead of the usual opApply approach, how would you implement an auto return walker function *without* defining a special external struct that holds all the logic? In other words, using existing Phobos functionality only, composing functions like map and chain. Example code which isn't correct: -

Re: Array of associative array.

2013-10-28 Thread Andrej Mitrovic
On 10/28/13, Ali Çehreli wrote: > Looks like a compiler bug to me. Reduced: > Is there a reason why the last line cannot be compiled? Could be one of these: http://d.puremagic.com/issues/show_bug.cgi?id=9295 http://d.puremagic.com/issues/show_bug.cgi?id=9520 There's a bunch of these array liter

Re: conv text and pure

2013-10-23 Thread Andrej Mitrovic
On 10/23/13, H. S. Teoh wrote: > Furthermore, the above function is a template function, which means the > compiler will perform attribute inference on it. So provided textImpl > has no impure operations, it should be inferred as pure, unless args has > some impure methods in it that's being used

Re: conv text and pure

2013-10-23 Thread Andrej Mitrovic
On 10/23/13, Daniel Davidson wrote: > Great, thanks. What is the best way to get on that version for > the Mac (pointer to instructions)? You can download the beta here: http://forum.dlang.org/thread/52605c84.6010...@walterbright.com

Re: conv text and pure

2013-10-23 Thread Andrej Mitrovic
On Wednesday, 23 October 2013 at 19:55:26 UTC, Daniel Davidson wrote: Should text be pure? It's pure in 2.064, the upcoming release.

Re: Dynamic associative array, to hold many values per key

2013-10-20 Thread Andrej Mitrovic
On Sunday, 20 October 2013 at 13:54:48 UTC, Logesh Pillay wrote: I want an associative array in d programming language. The key is a struct with two shorts. Easy so far. struct kie { short a; short b; } short[kie] possibles; Problem is I want to hold more than value per key. Dynamic would be

Re: Error: cannot call public/export function someFunction from invariant

2013-10-18 Thread Andrej Mitrovic
On 10/18/13, Jonathan M Davis wrote: > If you want to call a member function from an invariant, it > should be static, or it should be a free function. I can also be private, the diagnostic is pretty clear about that. :)

Re: Method of another module is callable, even if they is private.

2013-10-12 Thread Andrej Mitrovic
On 10/12/13, Namespace wrote: > Bug or feature? :P Has to be a bug. Reduced: - module a; import b; void main() { auto s = S(); auto f = &s.f; // no error f(); // no error auto sf = &S.sf; // error } - - module b; struct S { private void f() { } private s

Re: Call a function with a function pointer

2013-10-10 Thread Andrej Mitrovic
On 10/10/13, bearophile wrote: > Perhaps this bug is not yet in Bugzilla. I'm pretty sure I saw it filed somewhere. Can't find it though..

Re: Getting the missing Windows functions

2013-10-07 Thread Andrej Mitrovic
On 10/7/13, Matt wrote: > The missing functions (or at least the one I'm interested in at > the moment) that I'm trying to use are supposed to be IN > kernel32, and have been in there since Windows Vista. That's why > I'm a little confused. The kernel32.lib distributed with DMD is likely out of d

Re: isAsciiString in Phobos?

2013-10-07 Thread Andrej Mitrovic
On 10/7/13, monarch_dodra wrote: > If we want even more efficiency, we could iterate on the string, > interpreting it as a size_t[]. We mask each of its elements with > 0x80808080/0x80808080_80808080, and if one of the resulting > masked elements is not null, then the string isn't ASCII. Clever!

Re: isAsciiString in Phobos?

2013-10-07 Thread Andrej Mitrovic
On 10/7/13, Adam D. Ruppe wrote: > If you want strict ASCII, it should be <= 127 rather than 255 > because the high bit can be all kinds of different encodings (the > first 255 of unicode codepoints I think match latin-1 > numerically, but that's different than windows-1252 or various > non-Englis

Re: isAsciiString in Phobos?

2013-10-07 Thread Andrej Mitrovic
On 10/7/13, Andrej Mitrovic wrote: > If I want to transfer some string to a C function that expects > ascii-only string. Minus the "If".

isAsciiString in Phobos?

2013-10-07 Thread Andrej Mitrovic
If I want to transfer some string to a C function that expects ascii-only string. What can I use to verify there are no non-ascii characters in a D string? I haven't seen anything in Phobos. I was thinking of using: bool isAscii = mystring.all!(a => a <= 0xFF); Is this safe? I'm thinking of whe

Re: Getting the missing Windows functions

2013-10-07 Thread Andrej Mitrovic
On 10/7/13, Matt wrote: > I have never had to specify any Windows libs for linking under > DMD. What is different about these? DMD links in user32.lib and kernel32.lib by default. But if you want to use other libs like GDI you're going to have to pass them at the command line.

Re: Getting the missing Windows functions

2013-10-06 Thread Andrej Mitrovic
On Sunday, 6 October 2013 at 19:44:16 UTC, Matt wrote: I have noticed that a number of the current Windows C functions are not in core.sys.windows.windows.d I tried adding them to the module (after setting up source control so I can roll back any errors I might make), and found that Optlink w

Re: My design need friends

2013-10-06 Thread Andrej Mitrovic
On 10/6/13, Namespace wrote: > And I should write a blog post about your and my solution. :) Let me try to hack on __PRETTY_FUNCTION__ first and I'll post a working example here soon.

Re: My design need friends

2013-10-05 Thread Andrej Mitrovic
On 10/6/13, Namespace wrote: > Any further suggestions or improvements? That's nice. You could also hack away with templates, extracting the full module path (e.g. foo.bar) of the calling module and comparing this with the module a symbol is in, and then do this sort of thing: In a module like

Re: My design need friends

2013-10-05 Thread Andrej Mitrovic
On 10/5/13, Adam D. Ruppe wrote: > It isn't really a fix, but in these situations what I've been > doing in my code is just writing: > > // don't use this > /* private */ final public void foo() {} Me too, as have other library writers (like DFL).

Re: Windows SetConsoleScreenBufferSize() returning an odd error code

2013-10-05 Thread Andrej Mitrovic
On 10/5/13, webwraith wrote: > I don't know about you, but it's beginning to look to me like > SetConsoleScreenBufferSize() takes pixels as its unit of > measurement, and not columns and rows, as is stated in its > documentation. I don't suppose you could confirm this? I don't know, but maybe the

Re: Windows SetConsoleScreenBufferSize() returning an odd error code

2013-10-05 Thread Andrej Mitrovic
On 10/5/13, webwraith wrote: > ...And that will teach me to look further. SM_CXMIN and SM_CYMIN > are measured in pixels. I'll need to find out how big my font is, > as well, but I'm pretty sure that 60x30 at the default system > font should be bigger. Ah right you are. For that I think you can u

Re: Windows SetConsoleScreenBufferSize() returning an odd error code

2013-10-05 Thread Andrej Mitrovic
On 10/5/13, webwraith wrote: > Could someone give this code the quick once over and tell me > where I'm going wrong, or simply how to get this to work? In the docs: http://msdn.microsoft.com/en-us/library/windows/desktop/ms686044%28v=vs.85%29.aspx It says: dwSize [in] A COORD structure tha

Re: directx bindings problem

2013-10-03 Thread Andrej Mitrovic
On 10/3/13, evilrat wrote: > // Create a render target view > ID3D11Texture2D* pBackBuffer; > > // C++ version > //hr = g_pSwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D > ),(LPVOID*)&pBackBuffer ); > > // D version(crashes) > hr = g_pSwapChain.GetBuffer( 0, &IID_ID3D11Texture2D, > cast

Re: Conflict between std.file write() and std.stdio write()

2013-10-02 Thread Andrej Mitrovic
On 10/3/13, Craig Dillabaugh wrote: > void main( string[] args ) { > string str = "Hello"; > write( "file.txt", str ); > > string hello_file = readText("file.txt"); > > writeln( hello_file ); > } You can also disambiguate by preferring one symbol over another with an alias: alias

Re: Trouble creating bidirectional range

2013-09-29 Thread Andrej Mitrovic
On Sunday, 29 September 2013 at 20:42:20 UTC, Andrej Mitrovic wrote: On Sunday, 29 September 2013 at 20:37:13 UTC, Martin Drasar wrote: static assert(is(typeof(tmp.save) == MyRange!string)); You should call it like this: static assert(is(typeof(tmp.save()) == MyRange!string)); Btw, as for

Re: Trouble creating bidirectional range

2013-09-29 Thread Andrej Mitrovic
On Sunday, 29 September 2013 at 20:37:13 UTC, Martin Drasar wrote: static assert(is(typeof(tmp.save) == MyRange!string)); You should call it like this: static assert(is(typeof(tmp.save()) == MyRange!string));

Re: Is there a way to see if .init has been set by the user?

2013-09-21 Thread Andrej Mitrovic
On 9/21/13, bearophile wrote: > I think there is no simple > way to know if a variable has being default-initialized or not. > Why do you want to know it? There is however a way to extract it if it's a part of an aggregate: - struct S { int x = 1; } void main() { static assert(S.x.i

Re: Odd compiler complaints with import declarations

2013-09-13 Thread Andrej Mitrovic
On Friday, 13 September 2013 at 19:54:30 UTC, Orfeo wrote: // in gadget.d : import std.stdio; : import acme.goodies.io.string; : public void wun() { } Add the module declaration "module acme.gadget;" at the top of this file and it should work.

Re: isRandomAccessRange!(const(size_t[])) is false ... ?

2013-09-12 Thread Andrej Mitrovic
On 9/12/13, Joseph Rushton Wakeling wrote: > import std.range; > > void main() > { > assert(isRandomAccessRange!(const(size_t[]))); > } > > results in an assertion error. This is a bug, no ... ? I think ranges have to be non-const. I mean how can you iterate over one if e.g. popFront c

Re: What does __parameters return?

2013-09-12 Thread Andrej Mitrovic
On 9/12/13, simendsjo wrote: > Thanks. I just ended up using both is(__parameters and > is(function to fetch the parameter names. Sometimes it seems > things are added to D without a very thorough design phase, but > then again, it starts with "__", so I guess I'm on my own :) Have you tried usin

Re: No 'is not implemented' message with final?

2013-09-10 Thread Andrej Mitrovic
> Bug or feature? You will get a linker error when you try to use the function. This is a feature, because you can implement this function later or even in another module (and set mangling to match). Example of the former: - interface A { public: final void bar(); // declaration /

Re: What's about virtual?

2013-09-09 Thread Andrej Mitrovic
On 9/9/13, H. S. Teoh wrote: > Well, then I stand corrected. :) You may sit. You get a D.

Re: What's about virtual?

2013-09-09 Thread Andrej Mitrovic
On 9/9/13, H. S. Teoh wrote: > And even then, it may anger a lot of existing users. I'm not sure about that. It seems people who actually write class-based code would prefer to have this (that's my limited analysis of IRC comments :p).

Re: Limited type matching?

2013-09-09 Thread Andrej Mitrovic
On 9/8/13, Namespace wrote: > What is the problem? If the compiler is able to cast implicit > from ushort to short, what is the problem of casting ushort[2] to > short[2]? Oh I didn't even noticed it was a signed/unsigned issue. I'm not sure whether or not it's a bug. But file it anyways and some

Re: Limited type matching?

2013-09-09 Thread Andrej Mitrovic
On 9/9/13, Namespace wrote: > Ok I fill a bug for that... Please do, that code should compile.

Re: Using traits how do i get a function's parameters as a string?

2013-09-04 Thread Andrej Mitrovic
On 9/3/13, Adam D. Ruppe wrote: > On Tuesday, 3 September 2013 at 21:20:04 UTC, Andrej Mitrovic > wrote: >> foreach (id; ParameterIdentifierTuple!func) > > How do I keep missing these new std.traits things? Very nice. > It's really funky that an is() expressi

Re: Using traits how do i get a function's parameters as a string?

2013-09-03 Thread Andrej Mitrovic
On 9/3/13, Gary Willoughby wrote: > Using traits how do i get a methods's parameters as a string? Say > i have the following method: Here's a first attempt: - import std.range; import std.string; import std.stdio; import std.traits; class C { void setAge(int age, int) { } } tem

Re: Any trick for defining an operator overload in a different namespace?

2013-08-31 Thread Andrej Mitrovic
On 9/1/13, Ali Çehreli wrote: > This is the limitation of inner structs' not having an 'outer' > reference, right? Right, but this was just a workaround. Anyway I did just realize I can use opDispatch for this: - class C { this() { this.opts["foo"] = 1; } private aut

Any trick for defining an operator overload in a different namespace?

2013-08-31 Thread Andrej Mitrovic
I'm trying to achieve the syntax "opts[...] = 123", rather than using the more direct "this[...] = 123". I can use this code: - class C { this() { opts = Opts(this); opts["foo"] = 1; } struct Opts { C c; void opIndexAssign(T)(T value, strin

Re: Regarding emplace, arrays, and helper functions

2013-08-30 Thread Andrej Mitrovic
On 8/30/13, Namespace wrote: > I hate this "magic" library fix.. Why cannot we use 'scope' for > this? > I know currently it is an unsafe feature that was also proposed > for rejection, but it would look better, feel better, and the > compiler could take the dirty work for us. And maybe better > o

Re: Regarding emplace, arrays, and helper functions

2013-08-30 Thread Andrej Mitrovic
On 8/30/13, Ali Çehreli wrote: > Now your program works with a single change: > > enum Size = paddedSize!C(); Excellent. However will the compiler align all static arrays so their memory begins at a proper offset? Maybe a more appropriate question is: Is all stack data guaranteed to be pro

Re: Template overload causing an error even when a better non-template match is found

2013-08-30 Thread Andrej Mitrovic
On 8/30/13, Andrej Mitrovic wrote: > On 8/30/13, Andrej Mitrovic wrote: >> I'm not looking for a workaround (there's plenty of ways to work >> around this) > > Here's one way: Sorry, better version, the second function doesn't need to be a template (in

Re: Template overload causing an error even when a better non-template match is found

2013-08-30 Thread Andrej Mitrovic
On 8/30/13, Andrej Mitrovic wrote: > I'm not looking for a workaround (there's plenty of ways to work > around this) Here's one way: void opAssign(T)(T t) if (is(typeof(Constraint!T)) && Constraint!T) { pragma(msg, "T"); }

Template overload causing an error even when a better non-template match is found

2013-08-30 Thread Andrej Mitrovic
You're going to need DMD git-head to run this reduced example: - struct S { void opAssign(T)(T t) if (Constraint!T) { } void opAssign(typeof(null)) { } template Constraint(T) if (is(T == int)) { enum bool Constraint = false; } } vo

Re: UFCS in template function

2013-08-29 Thread Andrej Mitrovic
On 8/29/13, Jacob Carlborg wrote: > UFCS only works for module level functions. However it does work for local imports (I think this was new in 2.063): void main() { import std.range; assert([].empty); // ok }

Regarding emplace, arrays, and helper functions

2013-08-29 Thread Andrej Mitrovic
The emplace docs state that the chunk where to store the class object instance needs to be aligned to the class type alignment. But it doesn't say much on how to get this alignment from a class (we could add a note about using the classInstanceAlignment template), or even how to use it to create e.

Re: Using C/C++-DLL in D

2013-08-26 Thread Andrej Mitrovic
On 8/27/13, S0urc3C0de wrote: > Actually, I was trying to use ffmpeg and isn't this a C-Lib? Seems so. > Because when I tried to call a simple function > (av_register_all()), I got the same error as described above > though only with the leading underscore in the error message. Try calling impl

Re: Using C/C++-DLL in D

2013-08-26 Thread Andrej Mitrovic
On 8/27/13, S0urc3C0de wrote: > Hello guys, > > I'm trying to use a C++-DLL in D. > I compiled it via GCC, created a .lib-File with implib I don't think you'll be able to match the name mangling, GCC might use one convention, DMD another. There was a pragma(mangle) feature introduced in git-head

Re: bug or feature? shared objects and tuples

2013-08-26 Thread Andrej Mitrovic
On 8/27/13, Jack Applegame wrote: > It is impossible to pack a structure with shared object into > tuple. Bug. Please file it to bugzilla: http://d.puremagic.com/issues/enter_bug.cgi?product=D Thanks!

Re: What's the right way for doing this in D?

2013-08-24 Thread Andrej Mitrovic
On 8/24/13, Namespace wrote: > Until now I used Method A, but because of UFCS and the fact, that > the dot product doesn't affect the object, I thought about which > way would make more sense. I still like Method A but I'm curious > what you think. Note also that UFCS can introduce the function h

Re: alias and extern(C) for callbacks

2013-08-23 Thread Andrej Mitrovic
On 8/23/13, Jacob Carlborg wrote: > On 2013-08-23 02:00, Andrej Mitrovic wrote: > >> static assert(functionLinkage!test2 != "C"); // D calling convention > > Or Windows, Pascal or C++. I'd prefer if functionLinkage returned an enum, it's too easy to write &

Re: alias and extern(C) for callbacks

2013-08-22 Thread Andrej Mitrovic
On Thursday, 22 August 2013 at 23:55:44 UTC, Carl Sturtivant wrote: Is Callback here a name for the same type as if it was defined by the following? alias extern(C) int function(int, int) Callback; Yes. If you want to make sure, you can use a trait: import std.traits; extern(C) { void tes

Re: Typeof woes

2013-08-20 Thread Andrej Mitrovic
On 8/21/13, H. S. Teoh wrote: > and typeof(this.Smth) is invalid because this.Smth is already a > type, so you can't apply typeof to it. I am beginning to wonder if typeof(typeof(expr)) is worthy of an error. Would we end up having any bugs if we were to allow typeof() to work on types (IOW it wo

Re: Win32: How to get the stack trace when compiling with a windows subsystem?

2013-08-19 Thread Andrej Mitrovic
On 8/19/13, Andrej Mitrovic wrote: > Nevermind, I was printing out the wrong file, there really is some > kind of bug here. Anyway I'll file a small test-case to bugzilla. So it turns out it has nothing to do with the win32 subsystem: http://d.puremagic.com/issues/show_bug.cgi?id=10851

Re: Win32: How to get the stack trace when compiling with a windows subsystem?

2013-08-19 Thread Andrej Mitrovic
On 8/19/13, Andrej Mitrovic wrote: > Thinking about it some more I think the .info field is empty because > there's nothing really to trace, if I write the whole exception via > writeln(thr) rather than writeln(thr.info), I'll get back the > file+line of the failed assert,

Re: Win32: How to get the stack trace when compiling with a windows subsystem?

2013-08-19 Thread Andrej Mitrovic
On 8/19/13, Benjamin Thaut wrote: > D should be calling the module constructors in the correct order so that > the windows stack trace module (core.sys.windows.stacktrace) is > initialized first. If this is not the case you might need to import the > module into your main file to make sure that it

Re: Win32: How to get the stack trace when compiling with a windows subsystem?

2013-08-18 Thread Andrej Mitrovic
On 8/18/13, Adam D. Ruppe wrote: > extern(Windows) void AllocConsole(); // not sure if that's the > perfect signature but it works > > void main() { > debug AllocConsole(); > throw new Exception("test"); > } > > > The problem is the console will close before you can actually > read it! But

Re: Win32: How to get the stack trace when compiling with a windows subsystem?

2013-08-18 Thread Andrej Mitrovic
On 8/18/13, Andrej Mitrovic wrote: > if (!GetConsoleWindow()) Actually it would be even better if I could create a console window when building with subsystem:windows, for debugging purposes. I'll have a look at MSDN on ways to do this, unless someone already knows this and posts

Win32: How to get the stack trace when compiling with a windows subsystem?

2013-08-18 Thread Andrej Mitrovic
When you compile with -L/SUBSYSTEM:WINDOWS you're essentially building an app without a console, so if you want to print out messages you'd have to log them to a file. For example: - import core.sys.windows.windows; import std.stdio; extern(Windows) HWND GetConsoleWindow(); void main() {

Re: Get class size of object

2013-08-11 Thread Andrej Mitrovic
On 8/11/13, JS wrote: > Given an object, is there a built in way to get the size of the > class the object represents? Try: import core.memory; auto size = GC.sizeOf(object);

Re: Is -1 > 7 ?

2013-08-09 Thread Andrej Mitrovic
On 8/9/13, Manfred Nowak wrote: > michaelc37 wrote: >> WTF -> -1 is greater than 7 > > From the docs: > > It is an error to have one operand be signed and the other unsigned for a > <, <=, > or >= expression. > > -manfred > Chances are generic code would break, so maybe that part of the docs

Re: Is enum static?

2013-08-08 Thread Andrej Mitrovic
On Thursday, 8 August 2013 at 21:46:02 UTC, Borislav Kosharov wrote: If I have any enum in a class is it one for all instances or one per instance? Also are enums one per thread or only one? Every field in a class is per-instance, unless it's marked with 'static', which makes it for all instan

Re: Weird error occurance

2013-08-08 Thread Andrej Mitrovic
On 8/8/13, Josh wrote: > The error that I'm getting is an infinite loop of: > object.Error: Access Violation It seems like another case of: http://d.puremagic.com/issues/show_bug.cgi?id=6329 I think you should add your test-case there and re-open that issue.

Re: Smart way to convert a C string to a D string

2013-08-07 Thread Andrej Mitrovic
On 8/7/13, andrea9940 wrote: > auto cstr2dstr(inout(char)* cstr) > { > import core.stdc.string: strlen; > return cstr ? cstr[0 .. strlen(cstr)] : ""; > } There's a small issue in your ternary operator, if 'cstr' is non-const but null, you will end up returning an immutable rather than a

Re: Which option is faster...

2013-08-06 Thread Andrej Mitrovic
On 8/5/13, H. S. Teoh wrote: > If you really want optimal performance, use std.regex: Yes and if you also want to bloat your executable to the point that other parts of the system start slowing down.

Re: Getting number of messages in MessageBox

2013-08-05 Thread Andrej Mitrovic
On 8/6/13, Marek Janukowicz wrote: > I'm using std.concurrency message passing and I'd like to check which thread > might be a bottleneck. The easiest would be check number of messages piled > up for each of them, but I could not find a way to do that. Is it possible? > > Every detail about Messag

Re: How to create mixin template and pass name of a variable?

2013-08-02 Thread Andrej Mitrovic
On Friday, 2 August 2013 at 11:37:27 UTC, Bosak wrote: I want to create a mixin template such that: mixin template ArgNull(alias arg, string name) { if(arg is null) throw new Exception(name~" cannot be null."); } But is there a way to do that with only one template argument. And th

Re: Template for extracting types with staticMap?

2013-07-31 Thread Andrej Mitrovic
On 8/1/13, Justin Whear wrote: > I find this template to be really handy for use with staticMap, and I'm > wondering if it exists in Phobos in some form so that I can stop > rewriting it: Try this: import std.typetuple; template ExtractTypes(T) { static if (is(T : T!Y, Y...)) alias

Re: chunks equivalent with unpacking?

2013-07-31 Thread Andrej Mitrovic
On 7/31/13, Andrej Mitrovic wrote: > It's not the only one either, my opApply version works ok alone, but > when put into another module with package imports it fails to compile, > which is yet another new regression.. It's frustrating having to hit > so many regressions l

Re: chunks equivalent with unpacking?

2013-07-31 Thread Andrej Mitrovic
On 7/31/13, Andrej Mitrovic wrote: > On 7/31/13, bearophile wrote: >> How nice. Have we just won another bug report? > > It's not the only one either, my opApply version works ok alone, but > when put into another module with package imports it fails to compile, >

Re: chunks equivalent with unpacking?

2013-07-31 Thread Andrej Mitrovic
On 7/31/13, bearophile wrote: > How nice. Have we just won another bug report? It's not the only one either, my opApply version works ok alone, but when put into another module with package imports it fails to compile, which is yet another new regression.. It's frustrating having to hit so many r

Re: chunks equivalent with unpacking?

2013-07-31 Thread Andrej Mitrovic
On 7/31/13, Andrej Mitrovic wrote: > Can it? I've tried alternatively with opApply but it's problematic to > support both ref/non-ref argument versions. Ajh nevermind there's no issue with ref-ness, I just had a bug in my code. So this is easily implementable with opApply bu

Re: chunks equivalent with unpacking?

2013-07-31 Thread Andrej Mitrovic
On 7/31/13, bearophile wrote: > Those four variables x y z w influence the type of the foreach, > while 4 is a run-time argument. This API can be used: > > foreach (x, y, z, w; arr.chunks!4) Yeah it will have to be CT. > A forward range like that seems easy to implement. Can it? I've tried alte

chunks equivalent with unpacking?

2013-07-31 Thread Andrej Mitrovic
std.range.chunks is useful for iterating through a range like so: - import std.range; import std.stdio : writeln; void main() { float[] arr = [ 0.0, 0.15, 0.0, 1.0, 0.25, -0.25, 0.0, 1.0, -0.25, -0.25, 0.0, 1.0, ]; foreach (xyzw; arr.chunks(4)) {

Re: Associative array key order

2013-07-31 Thread Andrej Mitrovic
On Wednesday, 31 July 2013 at 15:00:34 UTC, Daniel Kozak wrote: Thanks I will use plain array, it is not perfect but better than nothing :) For some reason this (unordered keys) wasn't documented on the website, but it will be soon.

Re: Using alias parameters with class members in CTFE (related to UDAs)

2013-07-23 Thread Andrej Mitrovic
On 7/23/13, Johannes Pfau wrote: > Does anyone know why this code is not working? > http://dpaste.dzfl.pl/b89e7b3f Add 'static' to getAttribute and it will work. I know, it's weird, and I've seen this sort of workaround used before. I think it's a compiler bug.

Re: Why is size_t unsigned?

2013-07-22 Thread Andrej Mitrovic
On 7/22/13, monarch_dodra wrote: > 99% sure that's unspecified behavior. I wouldn't rely on anything > like that. Actually it used to be a bug that writing to the index /without/ ref would end up changing the iteration order, but this was fixed in 2.063. It's in the changelog: http://dlang.org/c

Re: Why is size_t unsigned?

2013-07-22 Thread Andrej Mitrovic
On 7/22/13, JS wrote: > foreach doesn't allow you to modify the index to skip over > elements. It does: - import std.stdio; void main() { int[] x = [1, 2, 3, 4, 5]; foreach (ref i; 0 .. 5) { writeln(x[i]); ++i; } } - Writes: 1 3 5

Re: passing __FILE__, __MODULE__, etc... with varadic types

2013-07-19 Thread Andrej Mitrovic
On 7/19/13, JS wrote: > The problem is, with varadic types being passed I can't do this: > > template T!(T..., string file = __FILE__) Yeah it's a known (and common) issue. http://d.puremagic.com/issues/show_bug.cgi?id=8687

Re: How do I specify a variadic template constraint on all the whole tuple?

2013-07-18 Thread Andrej Mitrovic
On Thursday, 18 July 2013 at 13:18:29 UTC, Atila Neves wrote: bool func(SYMBOLS...)() if(!is(typeof(SYMBOLS[0]) == string)) { } and bool func(STRINGS...)() if(is(typeof(STRINGS[0]) == string)) { } Here you go: - import std.string; import std.traits; import std.typetuple; import std.functi

Re: How to unittest nested functions

2013-07-04 Thread Andrej Mitrovic
On Wednesday, 9 May 2012 at 21:37:13 UTC, Era Scarecrow wrote: An idea is coming to mind to change it all to a struct You don't even need to convert it all to a struct. Since having function-nested unittests is just a parser issue, you can do this: - int foo() { static int bar()

Re: Unable to compile Phobos using wiki's instruction

2013-06-29 Thread Andrej Mitrovic
On Saturday, 29 June 2013 at 15:14:19 UTC, Andrej Mitrovic wrote: On Saturday, 29 June 2013 at 15:03:05 UTC, Geod24 wrote: Hi folks, As I'm learning phobos, I wanted a more inside look and did a co of the libs + dmd. Try getting the latest druntime from git-head, since these symbols

Re: Unable to compile Phobos using wiki's instruction

2013-06-29 Thread Andrej Mitrovic
On Saturday, 29 June 2013 at 15:15:08 UTC, Andrej Mitrovic wrote: On Saturday, 29 June 2013 at 15:14:19 UTC, Andrej Mitrovic wrote: On Saturday, 29 June 2013 at 15:03:05 UTC, Geod24 wrote: Hi folks, As I'm learning phobos, I wanted a more inside look and did a co of the libs + dmd.

Re: Unable to compile Phobos using wiki's instruction

2013-06-29 Thread Andrej Mitrovic
On Saturday, 29 June 2013 at 15:03:05 UTC, Geod24 wrote: Hi folks, As I'm learning phobos, I wanted a more inside look and did a co of the libs + dmd. Try getting the latest druntime from git-head, since these symbols were moved from phobos into druntime a few pull requests ago.

Re: Opaque structs

2013-06-29 Thread Andrej Mitrovic
On 6/29/13, Johannes Pfau wrote: > Shouldn't doing anything value-related on > an empty struct be invalid anyway? Maybe, maybe not. I could imagine it would cause problems if we simply disallowed it, e.g. if you want to copy attributes from one declaration to another.

Re: Opaque structs

2013-06-28 Thread Andrej Mitrovic
On 6/28/13, Johannes Pfau wrote: > A naive question: Why isn't struct S {} enough? This should be a struct > with size 0 so why do we need to disable the constructor and postblit > explicitly? Because the user should never be able to use such a struct by value, in other words a user might mistake

Re: Opaque structs

2013-06-28 Thread Andrej Mitrovic
On 6/28/13, Andrej Mitrovic wrote: > Unfortunately this tends to spawn unreadable error messages: It looks like there's also a blocking bug: http://d.puremagic.com/issues/show_bug.cgi?id=10497 So I'll have to use my new technique instead anyway. :p

Opaque structs

2013-06-27 Thread Andrej Mitrovic
Traditionally using opaque structs in D when interfacing with C (where one should only ever use such structs with a pointer) are implemented like so: - struct S; void main() { S* s1; // ok S s2; // linker error } - Unfortunately this tends to spawn unreadable error messages: -

Re: auto in function signature for defaulted arguments?

2013-06-27 Thread Andrej Mitrovic
On 6/27/13, bearophile wrote: >> On the other hand it could be useful in non-public and generic >> code. > > Do you have a realistic use case for generic code? No, I'm just speaking out loud about the possibility.

Re: auto in function signature for defaulted arguments?

2013-06-27 Thread Andrej Mitrovic
On 6/27/13, bearophile wrote: > So is it a good idea to allow "auto" in the function signature > for the arguments that have a default value? > > void foo(in auto x = VeryLongNamedStruct(1)) {} I've wanted this too once. Although there's a tradeoff here, now the user has to work more to figure ou

Re: How would you solve this 'interview' question in D?

2013-06-26 Thread Andrej Mitrovic
On 6/27/13, Andrej Mitrovic wrote: > On 6/27/13, H. S. Teoh wrote: >> Well, it's still cheating, though. :-P I think the 4-cycle algorithm is >> probably still the best one I've seen. > > What I don't understand is why the CPU is so slow that it takes ages >

Re: How would you solve this 'interview' question in D?

2013-06-26 Thread Andrej Mitrovic
On 6/27/13, H. S. Teoh wrote: > Well, it's still cheating, though. :-P I think the 4-cycle algorithm is > probably still the best one I've seen. What I don't understand is why the CPU is so slow that it takes ages to go through int.min .. int.max in a loop.

Re: How would you solve this 'interview' question in D?

2013-06-26 Thread Andrej Mitrovic
On 6/26/13, Gary Willoughby wrote: > Just for a bit of fun, I saw this question posted on reddit the > other day and wondered how *you* would solve this in D? > > http://stackoverflow.com/questions/731832/interview-question-ffn-n Silly mathematicians, nobody said you had to make it performant. i

Re: Trouble with lockstep

2013-06-25 Thread Andrej Mitrovic
On 6/25/13, Andrej Mitrovic wrote: > It's a regression which I've caused. I've made a fixup pull: > > http://d.puremagic.com/issues/show_bug.cgi?id=10468 > > I'm very sorry for this mishap. It's now fixed in git-head. Chances are we're not going

Re: Trouble with lockstep

2013-06-24 Thread Andrej Mitrovic
On 6/24/13, Ali Çehreli wrote: > Strangely, the error message points at two comment lines in my > installation of 2.063: It's a regression which I've caused. I've made a fixup pull: http://d.puremagic.com/issues/show_bug.cgi?id=10468 I'm very sorry for this mishap.

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