Re: Error: Undefined identifier when moving import to another module

2014-10-19 Thread monarch_dodra via Digitalmars-d-learn
On Sunday, 19 October 2014 at 09:39:05 UTC, nrgyzer wrote: Hi guys, when I do the following: static if ( isCallable!(mixing(m) ) mixing ? void main() { /* do something here */ } What exactly are you doing here? ... I'm getting many error messages like these:

Re: Error: Undefined identifier when moving import to another module

2014-10-19 Thread monarch_dodra via Digitalmars-d-learn
On Sunday, 19 October 2014 at 16:09:41 UTC, nrgyzer wrote: mixing should be replaced with mixin: static if ( isCallable!(mixin(m) ) My main is empty in both cases. So nothing done in my main (currently). Posting full code that actually compiles and reproduces the issue helps.

Re: Formatted output of range of tuples

2014-10-13 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 8 October 2014 at 23:28:34 UTC, bearophile wrote: anonymous: You can turn the tuples into ranges with `only`: writef(%(%(%s %)\n%), zip(indexes, source).map!(t = only(t.expand))); This is a nice idea. Expand can probably be replaced by a []. I presume this works only if the

Re: DList!int.remove(range.takeOne) - workarounds?

2014-10-12 Thread monarch_dodra via Digitalmars-d-learn
On Sunday, 12 October 2014 at 09:45:22 UTC, Algo wrote: DList seems to have an issue with remove: void main() { import std.container, std.range, std.algorithm; auto list = DList!int([1, 2, 4, 6]); auto res = find(list[], 2); list.remove(res); //ok /*

Re: Splitting Ranges using Lambda Predicates

2014-10-10 Thread monarch_dodra via Digitalmars-d-learn
On Friday, 10 October 2014 at 05:55:00 UTC, Nordlöw wrote: On Thursday, 9 October 2014 at 22:01:31 UTC, monarch_dodra wrote: My quick guess is you are missing the *global* imports for the restraints. The compiler doesn't complain because the constraint is in a is(typeof(...)) test. The reason

Re: Splitting Ranges using Lambda Predicates

2014-10-09 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 9 October 2014 at 21:55:03 UTC, Nordlöw wrote: On Wednesday, 11 June 2014 at 08:58:58 UTC, monarch_dodra wrote: auto slicer(alias isTerminator, Range)(Range input) if (((isRandomAccessRange!Range hasSlicing!Range) || isSomeString!Range)

Re: coding practices: include whole module or only the needed function

2014-10-07 Thread monarch_dodra via Digitalmars-d-learn
On Tuesday, 7 October 2014 at 07:33:24 UTC, Gary Willoughby wrote: On Monday, 6 October 2014 at 21:24:56 UTC, AsmMan wrote: Which practice do you use: if you need only one or two functions from a module: import myModule : func, func2; or (import whole module, assuming no function name

Re: coding practices: include whole module or only the needed function

2014-10-07 Thread monarch_dodra via Digitalmars-d-learn
On Tuesday, 7 October 2014 at 17:29:45 UTC, ketmar via Digitalmars-d-learn wrote: On Tue, 07 Oct 2014 17:24:40 + bachmeier via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Tuesday, 7 October 2014 at 08:37:59 UTC, monarch_dodra wrote: As a general rule, avoid imports

Re: array append result type

2014-10-06 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 6 October 2014 at 11:28:16 UTC, John Colvin wrote: string a; char[] b; pragma(msg, typeof(a ~ b)); // char[] why not string? What are the rules that determine this? *Ideally*, I'd have said it returns char[], so that you can chose via purity. However, it's not pure, so that

Re: array append result type

2014-10-06 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 6 October 2014 at 16:38:37 UTC, Steven Schveighoffer wrote: I filed this ER ages ago: https://issues.dlang.org/show_bug.cgi?id=1654 Not sure if anyone has it on their radar at this point. -Steve I didn't read the whole thing, but wouldn't purity be a major game changer for 1654?

Re: slidingSplitter + retro

2014-10-06 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 6 October 2014 at 20:06:41 UTC, Nordlöw wrote: I've almost satisfied with my new range slidingSplitter at https://github.com/nordlow/justd/blob/master/range_ex.d#L19 All unittest work as expected except my radial test https://github.com/nordlow/justd/blob/master/range_ex.d#L243

Re: How to detect start of Unicode symbol and count amount of graphemes

2014-10-05 Thread monarch_dodra via Digitalmars-d-learn
On Sunday, 5 October 2014 at 08:27:58 UTC, Uranuz wrote: I have struct StringStream that I use to go through and parse input string. String could be of string, wstring or dstring type. I implement function popChar that reads codeUnit from Stream. I want to have *debug* mode of parser (via CT

Re: RFC on SlidingSplitter Range

2014-10-03 Thread monarch_dodra via Digitalmars-d-learn
On Friday, 3 October 2014 at 15:22:06 UTC, Nordlöw wrote: Destroy, please! As a quick comment, your definition of moveFront is not what phobos understands with moveFront: https://github.com/D-Programming-Language/phobos/blob/7914fa31cb3b53f4e50421399f2b99d2012e8031/std/range.d#L8267

Re: RFC on SlidingSplitter Range

2014-10-03 Thread monarch_dodra via Digitalmars-d-learn
On Friday, 3 October 2014 at 17:06:41 UTC, Nordlöw wrote: On Friday, 3 October 2014 at 16:32:24 UTC, monarch_dodra wrote: If anything, I'd have expected you to provide something returns the popped element. What you do pops an element, and then returns the *next* one. What good is that? My

Re: RFC on SlidingSplitter Range

2014-10-03 Thread monarch_dodra via Digitalmars-d-learn
On Friday, 3 October 2014 at 19:12:54 UTC, Nordlöw wrote: On Friday, 3 October 2014 at 17:46:18 UTC, monarch_dodra wrote: If your implementation use two ranges that you slice on the fly, then you can trivially support strings, thanks to popFront. Very clever. That's what I wanted. I threw

Re: RFC on SlidingSplitter Range

2014-10-03 Thread monarch_dodra via Digitalmars-d-learn
On Friday, 3 October 2014 at 19:46:10 UTC, Nordlöw wrote: Is prefix ++ preferred in D because of some specific reason? I recall it, for some containers/iterators, gives smaller/faster codegen in C++? Be it C, C++ or D, pre increment is maybe faster, and is never slower. So as a rule of

Re: RFC on SlidingSplitter Range

2014-10-03 Thread monarch_dodra via Digitalmars-d-learn
On Friday, 3 October 2014 at 20:28:24 UTC, Nordlöw wrote: On Friday, 3 October 2014 at 20:15:33 UTC, Nordlöw wrote: Could you please take a look again at I made another update at https://github.com/nordlow/justd/blob/master/range_ex.d#L15 I had forgotten to move front and popFront out of

Re: RFC on SlidingSplitter Range

2014-10-03 Thread monarch_dodra via Digitalmars-d-learn
On Friday, 3 October 2014 at 20:15:33 UTC, Nordlöw wrote: Note that I had to tweak empty() a bit. I don't know if I got right. Could you check? Sounds about right, but I didn't really look. Further I can't get string support to work: writefln(%(%s\n%), slidingSplitter(Nordlöw)); errors

Re: Find Semantically Correct Word Splits in UTF-8 Strings

2014-10-02 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 1 October 2014 at 21:34:40 UTC, Nordlöw wrote: On Wednesday, 1 October 2014 at 17:09:57 UTC, monarch_dodra wrote: Does that even work? takeExactly would pop up to N *codepoints*, whereas your string only has N *codeunits*. Your're right again :) If forgot that takeExactly

Re: How do I check if a function got CTFE?

2014-10-02 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 2 October 2014 at 18:42:56 UTC, AsmMan wrote: I was thiking the dmd compiler did CTFE without someone ask for this, in the way as I've mentioned, checking for constant arguments + function's purity and if all this is true, it did the CTFE rather than generate code to compute it at

Re: Find Semantically Correct Word Splits in UTF-8 Strings

2014-10-01 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 1 October 2014 at 11:47:41 UTC, Nordlöw wrote: On Wednesday, 1 October 2014 at 11:06:24 UTC, Nordlöw wrote: I'm looking for a way to make my algorithm Update: S[] findMeaningfulWordSplit(S)(S word, HLang[] langs = []) if (isSomeString!S)

Re: Find Semantically Correct Word Splits in UTF-8 Strings

2014-10-01 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 1 October 2014 at 11:06:24 UTC, Nordlöw wrote: I'm looking for a way to make my algorithm S[] findWordSplit(S)(S word, HLang[] langs = []) { for (size_t i = 1; i + 1 word.length; i++) { const first = word[0..i];

Re: Find Semantically Correct Word Splits in UTF-8 Strings

2014-10-01 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 1 October 2014 at 11:47:41 UTC, Nordlöw wrote: On Wednesday, 1 October 2014 at 11:06:24 UTC, Nordlöw wrote: I'm looking for a way to make my algorithm Update: S[] findMeaningfulWordSplit(S)(S word, HLang[] langs = []) if (isSomeString!S)

Re: isArray and std.container.Array

2014-09-29 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 29 September 2014 at 10:18:09 UTC, Marc Schütz wrote: On Sunday, 28 September 2014 at 20:24:11 UTC, monarch_dodra wrote: On Sunday, 28 September 2014 at 19:06:09 UTC, Marc Schütz wrote: On Sunday, 28 September 2014 at 16:12:53 UTC, Meta wrote: On Sunday, 28 September 2014 at

Re: Turn function into infinite range

2014-09-29 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 29 September 2014 at 17:02:43 UTC, Martin Nowak wrote: I though I've seen this around somewhere but can no longer find it. AFAIK, this as never existed. We recently merged in cache into phobos. This seems like a prime candidate to expand to also take a function/delegate, as on of

Re: Turn function into infinite range

2014-09-29 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 29 September 2014 at 21:16:27 UTC, Daniel Kozák via Digitalmars-d-learn wrote: V Mon, 29 Sep 2014 19:02:36 +0200 Martin Nowak via Digitalmars-d-learn digitalmars-d-learn@puremagic.com napsáno: Does anyone know a construct to turn a lambda into an infinite range. import

Re: isArray and std.container.Array

2014-09-28 Thread monarch_dodra via Digitalmars-d-learn
On Sunday, 28 September 2014 at 19:06:09 UTC, Marc Schütz wrote: On Sunday, 28 September 2014 at 16:12:53 UTC, Meta wrote: On Sunday, 28 September 2014 at 08:01:00 UTC, Nordlöw wrote: Is there a reason why isArray!T doesn't match T when T is a std.container.Array? I'm asking because after

Re: Non-const std.container.Array.opIndex and alikes blocks serialization

2014-09-28 Thread monarch_dodra via Digitalmars-d-learn
On Sunday, 28 September 2014 at 09:04:42 UTC, Nordlöw wrote: On Sunday, 28 September 2014 at 08:58:27 UTC, Nordlöw wrote: In my strive to add msgpacking support for std.container.Array I've been blocked by the fact that std.container.Array.opIndex only has one overload which is non-const

Re: A few questions regarding GC.malloc

2014-09-26 Thread monarch_dodra via Digitalmars-d-learn
On Friday, 26 September 2014 at 18:03:40 UTC, Steven Schveighoffer wrote: On 9/25/14 6:03 PM, Sean Kelly wrote: On Thursday, 25 September 2014 at 21:43:53 UTC, monarch_dodra wrote: On Thursday, 25 September 2014 at 20:58:29 UTC, Gary Willoughby wrote: What does BlkAttr.FINALIZE do when used in

Re: Remove filename from path

2014-09-25 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 24 September 2014 at 17:15:39 UTC, Ali Çehreli wrote: find() and friends can be used: import std.algorithm; void main() { string path = myFile.doc; string extension = .doc; path = findSplitBefore(path, extension)[0]; assert(path == myFile); } I had thought of

immutable T.init, and pointers to mutable data

2014-09-25 Thread monarch_dodra via Digitalmars-d-learn
I was playing around with how T.init works. And I think I may have found a type loophole. Given that you may initialize a pointer member to the address to a static global: // __gshared int a = 0; struct S { int* p = a; } // Then, in theory, any variable, be they mutable or

Re: immutable T.init, and pointers to mutable data

2014-09-25 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 25 September 2014 at 12:46:01 UTC, Steven Schveighoffer wrote: On 9/25/14 5:47 AM, monarch_dodra wrote: I was playing around with how T.init works. And I think I may have found a type loophole. Given that you may initialize a pointer member to the address to a static global:

Re: immutable T.init, and pointers to mutable data

2014-09-25 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 25 September 2014 at 13:37:52 UTC, Steven Schveighoffer wrote: On 9/25/14 9:00 AM, monarch_dodra wrote: On Thursday, 25 September 2014 at 12:46:01 UTC, Steven Schveighoffer wrote: On 9/25/14 5:47 AM, monarch_dodra wrote: I was playing around with how T.init works. And I think I

Re: Fail to compile phobos

2014-09-25 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 25 September 2014 at 17:20:42 UTC, JJDuck wrote: I tried to compile phobos according to the last paragraph in this page: http://dlang.org/dmd-linux.html but this is the error I have fatal: Not a git repository (or any of the parent directories): .git I dont know what happened,

Re: A few questions regarding GC.malloc

2014-09-25 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 25 September 2014 at 20:58:29 UTC, Gary Willoughby wrote: A few questions regarding GC.malloc. When requesting a chunk of memory from GC.malloc am i right in assuming that this chunk is scanned for pointers to other GC resources in order to make decisions whether to collect them

Re: Remove filename from path

2014-09-24 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 24 September 2014 at 10:11:04 UTC, Suliman wrote: What is the best way to remove file name from full path? string path = thisExePath() Seems like dirName in std.path is a good candidate ;) http://dlang.org/phobos/std_path.html#.dirName You'll find many other path manipulation

Re: Remove filename from path

2014-09-24 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 24 September 2014 at 10:35:29 UTC, Suliman wrote: I can't understand how to use strip? For example I would like to cut just extension. path = path.stripRight(exe); Error: no overload matches for stripRight(C)(C[] str) if stripExtension would be your friend here. If you want

Re: Remove filename from path

2014-09-24 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 24 September 2014 at 10:35:29 UTC, Suliman wrote: I can't understand how to use strip? For example I would like to cut just extension. path = path.stripRight(exe); Error: no overload matches for stripRight(C)(C[] str) if strip doens't work that way. It simply removes

Re: Recursive function call

2014-09-24 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 24 September 2014 at 10:57:27 UTC, Suliman wrote: string getFileName() { //чтобы было проще обрабатываемый файл будем хранить рядом с бинариком string filename = chomp(readln()); string path = getcwd(); writeln((path ~ \\ ~ filename)); if

Re: Remove filename from path

2014-09-24 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 24 September 2014 at 12:29:09 UTC, ketmar via Digitalmars-d-learn wrote: On Wed, 24 Sep 2014 12:21:40 + monarch_dodra via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Unfortunately, there is no generic function that allows striping of a specific ending range

Re: put string[] into a appender without loop?

2014-09-22 Thread monarch_dodra via Digitalmars-d-learn
On Sunday, 21 September 2014 at 23:50:50 UTC, H. S. Teoh via Digitalmars-d-learn wrote: On Sun, Sep 21, 2014 at 11:41:56PM +, AsmMan via Digitalmars-d-learn wrote: I'd like to copy an array string into a appender!string() but I can't see how to do this without loop myself over the string

Re: can't understand why code do not working

2014-09-22 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 22 September 2014 at 20:37:42 UTC, Cliff wrote: Is stdout threadsafe? Yes. All io operations lock in D, so are thread safe. You will never have interlaced io. If you want to do several opeations, then you can use LockingTextWriter, which is faster, s it locks once until you are

Re: can't understand why code do not working

2014-09-22 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 22 September 2014 at 21:19:37 UTC, Steven Schveighoffer wrote: On 9/22/14 4:37 PM, Cliff wrote: Is stdout threadsafe? Yes, stdout is thread safe, it's based on C's stdout which is thread safe. -Steve Techinallly, though thread safe, concurrent writes will create garbled

Re: can't understand why code do not working

2014-09-22 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 22 September 2014 at 20:12:28 UTC, Suliman wrote: std.concurrency.OwnerTerminated@std\concurrency.d(234): Owner terminated You need to make sure your main waits for its workers before exiting. When main dies, it sends an exception message to anyone still working.

Re: destroy(someStruct)

2014-09-21 Thread monarch_dodra via Digitalmars-d-learn
On Saturday, 20 September 2014 at 22:46:10 UTC, John Colvin wrote: import core.stdc.stdio; struct S { ~this() { printf(%x\n.ptr, this); } } void main() { S* sp = new S; destroy(*sp); S s; destroy(s); auto sa = new

Re: std.range.byLine

2014-09-12 Thread monarch_dodra via Digitalmars-d-learn
On Friday, 12 September 2014 at 13:25:22 UTC, Nordlöw wrote: On Thursday, 11 September 2014 at 22:39:40 UTC, H. S. Teoh via Digitalmars-d-learn wrote: foreach (line; myInput.split(regex(`\n|\r\n|\r`))) Shouldn't you use foreach (line; myInput.split(regex(\n|\r\n|\r))) here?

Re: std.conv checking if to will work

2014-09-11 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 11 September 2014 at 08:58:09 UTC, Robert burner Schadek wrote: I like the to template a lot, but sometimes I want to make sure beforehand that a call to it works. Is there anything in phobos in missed to do that. And I don't want to try catch. There's an open request for it, and

Re: std.range.byLine

2014-09-11 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 10 September 2014 at 23:01:44 UTC, Nordlöw wrote: On Wednesday, 10 September 2014 at 22:45:08 UTC, Nordlöw wrote: auto byLine(Range)(Range input) if (isForwardRange!Range) { import std.algorithm: splitter; import std.ascii: newline; static if (newline.length == 1) {

Re: std.conv checking if to will work

2014-09-11 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 11 September 2014 at 09:33:20 UTC, Robert burner Schadek wrote: On Thursday, 11 September 2014 at 09:10:03 UTC, monarch_dodra wrote: There's an open request for it, and plans to have a bool maybeTo!(OUT, WHAT)(WHAT what, ref OUT out), but we aren't quite there yet. The idea is

Re: std.algorithm.reduce on an array of structs

2014-09-11 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 11 September 2014 at 14:56:00 UTC, Daniel Kozak via Digitalmars-d-learn wrote: V Thu, 11 Sep 2014 14:49:02 + bearophile via Digitalmars-d-learn digitalmars-d-learn@puremagic.com napsáno: Daniel Kozak: You can just use min: import std.stdio, std.algorithm; struct Thing {

Re: std.algorithm.reduce on an array of structs

2014-09-11 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 11 September 2014 at 15:29:18 UTC, Daniel Kozak wrote: On Thursday, 11 September 2014 at 15:07:03 UTC, Daniel Kozak wrote: or use alias minimum = reduce!a b; ;) ok this one does not work Yeah, it's actually reduce!a b ? a : b

Re: std.range.byLine

2014-09-11 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 11 September 2014 at 20:03:26 UTC, Nordlöw wrote: On Thursday, 11 September 2014 at 10:19:17 UTC, monarch_dodra wrote: Well, the issue is that this isn't very portable for *reading*, as even on linux, you may read files with \r\n line endings (It's standard for csv files, for

Re: Intended behavior of std.range.cycle?

2014-09-06 Thread monarch_dodra via Digitalmars-d-learn
On Friday, 5 September 2014 at 10:41:22 UTC, Vlad Levenfeld wrote: On Thursday, 4 September 2014 at 11:43:28 UTC, monarch_dodra wrote: *Should* cycle be negatively index-able? Personally, I don't think so. And even if it could, it has been proven non-size_t indexing is not well supported at

Re: How to get nogc to work with manual memory allocation

2014-09-05 Thread monarch_dodra via Digitalmars-d-learn
On Sunday, 24 August 2014 at 09:29:53 UTC, Jacob Carlborg wrote: On 2014-08-24 10:03, Bienlein wrote: I have omitted the code for the TestClass class to save space. Problem is that the compiler outputs this: Error: @nogc function 'main.nogcNew!(TestClass, ).nogcNew' cannot call non-@nogc

Re: Good/Bad? @disable postblit for struct InputRange

2014-09-05 Thread monarch_dodra via Digitalmars-d-learn
On Friday, 5 September 2014 at 19:55:50 UTC, Nick Sabalausky wrote: One issue with struct-based input ranges: Saving the state of an input range is not supported (by definition of input range), and yet, you can trivially and accidentally do so with a simple assignment or passing into a

Re: Intended behavior of std.range.cycle?

2014-09-04 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 4 September 2014 at 11:29:30 UTC, rcor wrote: auto c = cycle([1,2,3]); foreach(i ; iota(-4,4)) { writeln(c[i]); } prints the sequence 1 2 3 1 1 - c[0] == c[-1] 2 3 I understand this is what would happen if I were to just use modulus on an index to access the original

Re: Intended behavior of std.range.cycle?

2014-09-04 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 4 September 2014 at 11:43:28 UTC, monarch_dodra wrote: Indexing is done with the unsigned size_t. I re-read your post, and I don't think I actually answered your question...? I don't know of any case where you'd want to index negativelly. That said, I'm sure it could be

Re: Should formattedWrite take the outputrange by ref?

2014-09-04 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 4 September 2014 at 17:06:00 UTC, Márcio Martins wrote: On Wednesday, 3 September 2014 at 07:43:20 UTC, Guillaume Chatelet wrote: +1 I've been bitten by this also. Same here, +1 It's still on my radar, but it's actually not that trivial of a change, especially if we want to

Re: Allowing Expressions such as (low value high)

2014-09-04 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 4 September 2014 at 20:03:57 UTC, Nordlöw wrote: Are there any programming languages that extend the behaviour of comparison operators to allow expressions such as if (low value high) ? This syntax is currently disallowed by DMD. I'm aware of the risk of a programmer

Re: Building a string from n chars

2014-09-04 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 4 September 2014 at 20:38:39 UTC, Nordlöw wrote: On Thursday, 4 September 2014 at 19:24:00 UTC, Nordlöw wrote: string t1; t1 ~= '*'.repeat(n).array; string t2; t2 ~= *.replicate(n); After having read http://dlang.org/phobos/std_array.html#.replicate I came to the

Re: Building a string from n chars

2014-09-04 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 4 September 2014 at 20:57:43 UTC, monarch_dodra wrote: On Thursday, 4 September 2014 at 20:38:39 UTC, Nordlöw wrote: On Thursday, 4 September 2014 at 19:24:00 UTC, Nordlöw wrote: string t1; t1 ~= '*'.repeat(n).array; string t2; t2 ~= *.replicate(n); After having read

Re: opSlice() or opIndex() for the entire slice?

2014-09-04 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 4 September 2014 at 19:12:27 UTC, Ali Çehreli wrote: The documentation says To overload a[], simply define opIndex with no parameters: http://dlang.org/operatoroverloading.html#Slice And it works with some uses of a[]. However, opSlice() seems to be needed to actually use the

Re: std.container.Array

2014-09-03 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 3 September 2014 at 16:44:45 UTC, Casper Færgemand wrote: Is there a good reason std.container.Array doesn't work with @nogc? The ddoc seems pretty explicit about its purpose: Array type with deterministic control of memory. The memory allocated for the array is reclaimed as

Re: Building a string from n chars

2014-09-03 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 3 September 2014 at 19:43:26 UTC, Nordlöw wrote: Is there a simpler way to way to s ~= repeat('*', n).array.to!string; if s has to be of type string? s ~= repeat('*', n).array(); Should be enough. Why the to!string? There's 1 useless allocation, but I think that's OK for code

Re: Comparing TypeTuples

2014-09-02 Thread monarch_dodra via Digitalmars-d-learn
On Tuesday, 2 September 2014 at 08:27:14 UTC, Tudor Berariu wrote: How can I check if two TypeTuples containing both types and values are the same? This fails: static assert(is(TypeTuple!(3, int, Zorro) == TypeTuple!(3, int, Zorro))); Thank you! Tudor Yeah, this fails because you can't

Re: Implementing Template Restrictions in Different Way

2014-09-02 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 1 September 2014 at 22:46:52 UTC, Nordlöw wrote: Is this a other/newer preferred way to describe the template restriction, using for example __traits(compiles, ...)? Is is(typeof(... AFAIK, those produce the same results 99% of the time. The only cases where they differ are

Re: Implementing Template Restrictions in Different Way

2014-09-02 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 1 September 2014 at 22:46:52 UTC, Nordlöw wrote: BTW: Is there a way to prevent the calls to r1.length and r2.length in this case? Also, this assumes your ranges have front at all. AFAIK, skipOver operates on forward ranges. Related: Your condition could fail if R1/R2 are strings

Re: Implementing Template Restrictions in Different Way

2014-09-02 Thread monarch_dodra via Digitalmars-d-learn
On Tuesday, 2 September 2014 at 11:41:51 UTC, Nordlöw wrote: On Tuesday, 2 September 2014 at 10:22:49 UTC, monarch_dodra wrote: the fastest way to do this? Are you talking about constraints, or implementation of safeSkipOver? The constraint. In that case, I'm not sure what you mean by

Re: Overriding to!string on enum types

2014-09-02 Thread monarch_dodra via Digitalmars-d-learn
On Tuesday, 2 September 2014 at 14:59:41 UTC, evilrat wrote: sorry, i forgot everything. here is example of how to do this - import std.conv : to; enum Test { One, Two, Three, } template to(T: string) { T to(A: Test)(A val) { final switch (val) { case Test.One: return 1;

Re: Overriding to!string on enum types

2014-09-02 Thread monarch_dodra via Digitalmars-d-learn
On Tuesday, 2 September 2014 at 12:54:55 UTC, Nordlöw wrote: Is it possible to override the behaviour of to!string(x) when x is an enum. I'm asking because this enum CxxRefQualifier { none, normalRef, rvalueRef } string toString(CxxRefQualifier refQ) @safe pure nothrow { final

Re: Overriding to!string on enum types

2014-09-02 Thread monarch_dodra via Digitalmars-d-learn
On Tuesday, 2 September 2014 at 15:41:17 UTC, monarch_dodra wrote: Unless we allow defining enum-member functions, AFAIK, it is impossible to override the printing behavior for enums... ... If your enum actually represents strings, then you could: enum CxxRefQualifier : string { none

Re: Reading unicode chars..

2014-09-02 Thread monarch_dodra via Digitalmars-d-learn
On Tuesday, 2 September 2014 at 17:10:57 UTC, Ali Çehreli wrote: 1) To avoid a common gotcha, note that 'line' is reused at every iteration here. You must make copies of portions of it if you need to. Ali I don't know if you are aware, but byLineCopy was recently introduced. It will be

Re: Reading unicode chars..

2014-09-02 Thread monarch_dodra via Digitalmars-d-learn
On Tuesday, 2 September 2014 at 18:30:55 UTC, seany wrote: Your example reads the file by lines, i need to get them by chars. If you are intent on reading the stream character (or wcharacter) 1 by 1, then you will have to decode them manually, as there is no getcd. Unfortunately, the newer

Re: Why is rehash not @safe?

2014-08-30 Thread monarch_dodra via Digitalmars-d-learn
On Saturday, 30 August 2014 at 14:27:04 UTC, Nordlöw wrote: I just noticed that AA rehash is @system. Is there a reason for this? Is it system because bad things can happen or simply because it's a low level function? Should I always tag functions calling rehash as @trusted? AFAIK, the whole

Re: Issue with dmd 2.066, alias this, and sort

2014-08-28 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 27 August 2014 at 21:43:40 UTC, bearophile wrote: rcor: I've tried to express my problem in a mostly minimal example here: https://gist.github.com/murphyslaw480/d4a5f857a104bcf62de1 The class Point has an alias this to its own property 'feature()', which returns a reference to

How to cast to void*, while bypassing alias this or opCast

2014-08-28 Thread monarch_dodra via Digitalmars-d-learn
I'm investigating a phobos regression. From doesPointTo: // static if (isPointer!S || is(S == class) || is(S == interface)) { const m = cast(void*) source; // Basically, given a pointer like structure, I want the void* equivalent. I really don't care about how S

Re: Issue with dmd 2.066, alias this, and sort

2014-08-28 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 28 August 2014 at 10:38:12 UTC, monarch_dodra wrote: On Wednesday, 27 August 2014 at 21:43:40 UTC, bearophile wrote: rcor: It compiles if you use: @property auto feature() const pure nothrow { return _feature; } Otherwise I get strange errors like:

Re: How to cast to void*, while bypassing alias this or opCast

2014-08-28 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 28 August 2014 at 11:02:03 UTC, anonymous wrote: On Thursday, 28 August 2014 at 10:45:52 UTC, monarch_dodra wrote: I'm investigating a phobos regression. From doesPointTo: // static if (isPointer!S || is(S == class) || is(S == interface)) { const m = cast(void*)

Re: Issue with dmd 2.066, alias this, and sort

2014-08-28 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 28 August 2014 at 10:54:47 UTC, monarch_dodra wrote: Phobos issue: http://forum.dlang.org/thread/uignsankcumgmhwpo...@forum.dlang.org#post-uignsankcumgmhwpoead:40forum.dlang.org https://github.com/D-Programming-Language/phobos/pull/2472

Re: 'idiomatic' porting of c and or c++ code that does NULL checking

2014-08-23 Thread monarch_dodra via Digitalmars-d-learn
On Saturday, 23 August 2014 at 10:33:02 UTC, nikki wrote: A good to know! thanks. I'd still be interrested to see the idiomatic D version of that function, what would that depend on ? Honestly, I wouldn't change it much. If it didn't throw exceptions before, then it probably would have

Re: Acces Values in DList

2014-08-23 Thread monarch_dodra via Digitalmars-d-learn
On Saturday, 23 August 2014 at 15:18:15 UTC, axwro wrote: On Saturday, 23 August 2014 at 14:54:55 UTC, axwro wrote: How can i access values in DList? I save different objects of type Property in my DList, but if i want to access them this way: this.properties[0].value.start i get: Error:

Re: Module-level attributes and unit tests

2014-08-23 Thread monarch_dodra via Digitalmars-d-learn
On Saturday, 23 August 2014 at 15:26:02 UTC, Leandro Motta Barros via Digitalmars-d-learn wrote: Hello, I have a module which is completelly @nogc, and as such I'd like to just say @nogc: at the top of the file and be happy. However, my unit tests for this same module do some GC

Re: Generating a tree structure

2014-08-21 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 21 August 2014 at 14:09:24 UTC, Ricky C wrote: TileTree* self; Don't do that. D has banned internal pointers to implement its move semantics. branches[index] = tile_trees[index]; This will make a *value-copy* of your TileTree nodes. There are good chances it'll break your

Re: Variadic parameter of length 1

2014-08-20 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 20 August 2014 at 15:11:53 UTC, Dominikus Dittes Scherkl wrote: I have several times seen a construct template foo(T...) if(T.length == 1) { ... } What is that good for? Why using variadic parameter if anyway exactly one parameter is required?!? AFAIK, it's a historical

Re: Variadic parameter of length 1

2014-08-20 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 20 August 2014 at 17:02:59 UTC, Dicebot wrote: On Wednesday, 20 August 2014 at 15:34:30 UTC, Dominikus Dittes Scherkl wrote: And why historical? Is that not necessary anymore? What better solution is there today? Historical in a sense that distinct can be anything template

Re: Can you explain this?

2014-08-20 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 20 August 2014 at 20:39:42 UTC, Jonathan M Davis wrote: is(typeof(foo)) and __traits(compiles, foo) are not the same. The first tests for the existence of the symbol, whereas the second checks whether the code will actually compile. Is that even true? I mean, are you just

Re: new error message in 2.066, type bool (const)

2014-08-20 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 20 August 2014 at 20:46:20 UTC, Paul D Anderson wrote: Re-compiling existing code with version 2.066 generates a lot of errors complaining about implicit conversion to const. Typical is this call (inside a struct with properties 1 2): z.sign = x.sign ^ y.sign; Error:

Re: String Prefix Predicate

2014-08-19 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 18 August 2014 at 20:50:55 UTC, Nordlöw wrote: On Monday, 18 August 2014 at 12:42:25 UTC, monarch_dodra wrote: If you are using a string, the only thing helpful in there is `byCodeunit`. The rest is only useful if you have actual ranges. Actual ranges of...characters and strings?

Re: In the new D release why use free functions instead of properties?

2014-08-19 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 18 August 2014 at 21:17:11 UTC, Jonathan M Davis wrote: On Monday, 18 August 2014 at 21:02:09 UTC, Gary Willoughby wrote: In the new D release there have been some changes regarding built-in types. http://dlang.org/changelog.html?2.066#array_and_aa_changes I would like to learn

Re: goto skips declaration of variable

2014-08-19 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 18 August 2014 at 13:51:14 UTC, nrgyzer wrote: Hi all, I've the following code snipped: import std.bigint; void main(string[] args) { BigInt i = 12345; if (args.length 1) { goto Exit; } i = BigInt(67890); Exit:

Re: String Prefix Predicate

2014-08-18 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 18 August 2014 at 11:28:25 UTC, Nordlöw wrote: On Saturday, 16 August 2014 at 20:59:47 UTC, monarch_dodra wrote: I don't get it? If you use byDchar, you are *explicitly* decoding. How is that any better? If anything, you are *preventing* the (many) opportunities phobos has to

Re: Using std.container.BinaryHeap like C++

2014-08-18 Thread monarch_dodra via Digitalmars-d-learn
On Monday, 18 August 2014 at 06:50:08 UTC, Paulo Pinto wrote: On Sunday, 17 August 2014 at 21:09:04 UTC, monarch_dodra wrote: On Sunday, 17 August 2014 at 18:54:27 UTC, Paulo Pinto wrote: Hi, I was wondering if it is possible to use the BinaryHeap store like the C++'s

Re: Using std.container.BinaryHeap like C++

2014-08-17 Thread monarch_dodra via Digitalmars-d-learn
On Sunday, 17 August 2014 at 18:54:27 UTC, Paulo Pinto wrote: Hi, I was wondering if it is possible to use the BinaryHeap store like the C++'s make_heap/pop_heap/push_heap functions. I would like to port to D some A* C++ code I have which rearranges the priorities on the underlying store,

Re: @safe, pure and nothrow at the beginning of a module

2014-08-16 Thread monarch_dodra via Digitalmars-d-learn
On Saturday, 16 August 2014 at 19:30:16 UTC, Jonathan M Davis via Digitalmars-d-learn wrote: On Sat, 16 Aug 2014 14:39:00 +0200 Artur Skawina via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On 08/16/14 13:58, Philippe Sigaud via Digitalmars-d-learn wrote: On Sat, Aug 16,

Re: drop* and take* only for specific element values

2014-08-16 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 14 August 2014 at 07:30:59 UTC, Nordlöw wrote: On Thursday, 14 August 2014 at 00:56:47 UTC, Jonathan M Davis wrote: You forgot the !, making the predicate a function argument. It Great! My solution: Depending on your exact needs, don't forget too about findSkip (same as find,

Re: String Prefix Predicate

2014-08-16 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 14 August 2014 at 17:41:08 UTC, Nordlöw wrote: On Thursday, 14 August 2014 at 17:33:41 UTC, Justin Whear wrote: std.algorithm.startsWith? Should auto-decode, so it'll do a What about https://github.com/D-Programming-Language/phobos/pull/2043 Auto-decoding should be avoided

Re: String Prefix Predicate

2014-08-16 Thread monarch_dodra via Digitalmars-d-learn
On Saturday, 16 August 2014 at 20:59:47 UTC, monarch_dodra wrote: If anything, you are *preventing* the (many) opportunities phobos has to *avoid* decoding when it can... By that I want to stress what Jonathan M Davis said Unless the string types match, there's no way around it. You should

Re: Appender is ... slow

2014-08-15 Thread monarch_dodra via Digitalmars-d-learn
On Friday, 15 August 2014 at 11:57:30 UTC, Messenger wrote: T[size] beats all of those on dmd head, though it is inarguably a bit limiting. Hey guys, just a bit of background and my own understanding of Appender, having worked on it a fair bit. First of all, Appender was not designed as a

Re: Appender is ... slow

2014-08-15 Thread monarch_dodra via Digitalmars-d-learn
On Friday, 15 August 2014 at 12:08:58 UTC, Philippe Sigaud via Digitalmars-d-learn wrote: Hmm, what about a sort of linked list of static arrays, that allocates a new one when necessary? Appender is not a container, and has no freedom on the data it manipulates. It has to be able to accept

Re: Appender is ... slow

2014-08-15 Thread monarch_dodra via Digitalmars-d-learn
On Friday, 15 August 2014 at 14:40:36 UTC, Philippe Sigaud wrote: Well, I created a wrapper around a std.array.uninitializedArray call, to manage the interface I need Make sure you don't use that if your type has elaborate construction, or assumes a certain initial state (unless you are

  1   2   3   >