Re: Is old style compile-time foreach redundant?

2018-01-09 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 10, 2018 at 12:18:46AM +0100, Timon Gehr via Digitalmars-d-learn wrote: > On 09.01.2018 22:04, H. S. Teoh wrote: > > if (0 == 3) {} > > // all subsequent iterations deleted > > > > because the static break is unconditionally compiled (it has nothing > > to do with the runtime

Re: Is old style compile-time foreach redundant?

2018-01-09 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 09, 2018 at 03:26:32PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 1/9/18 2:31 PM, H. S. Teoh wrote: [...] > > If there were a hypothetical `static continue` or `static break` > > that's recognized by the static foreach unroller, we could in theory > > automate

Re: Is old style compile-time foreach redundant?

2018-01-09 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 09, 2018 at 02:24:11PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: [...] > A break or continue is simply a goto underneath. A goto in an unrolled > loop isn't much different than a goto in a um... rolled loop :) It's > just that there are copies of each loop body, and

Re: Is old style compile-time foreach redundant?

2018-01-09 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 09, 2018 at 10:57:03AM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 1/8/18 9:27 AM, H. S. Teoh wrote: > > On Sun, Jan 07, 2018 at 10:39:19PM -0500, Steven Schveighoffer via > > Digitalmars-d-learn wrote: > > > On 1/6/18 6:25 PM, Ali Çehreli wrote: > > > > Is

Re: __traits(isSame, TemplateOf ...) errors and some Idiomatic D questions

2018-01-08 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jan 08, 2018 at 10:59:44PM +, aliak via Digitalmars-d-learn wrote: [...] > onlineapp.d(61): Error: template std.traits.TemplateOf does not match > any template declaration. And I use it like this: > > enum r1Sorted = __traits(isSame, TemplateOf!(R1), SortedRange); This seems

Re: Is old style compile-time foreach redundant?

2018-01-08 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Jan 07, 2018 at 10:39:19PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 1/6/18 6:25 PM, Ali Çehreli wrote: > > Is 'static foreach' sufficient for all needs or is there any value > > for regular foreach over compile-time sequences? > > If you use continues or breaks,

Re: Is old style compile-time foreach redundant?

2018-01-06 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Jan 07, 2018 at 12:55:27AM +, Stefan Koch via Digitalmars-d-learn wrote: > On Saturday, 6 January 2018 at 23:25:58 UTC, Ali Çehreli wrote: > > Is 'static foreach' sufficient for all needs or is there any value > > for regular foreach over compile-time sequences? [...] > No it's not. >

Re: Upcasting slice of class elements

2018-01-05 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 05, 2018 at 10:16:04PM +, Nordlöw via Digitalmars-d-learn wrote: > Why isn't > > class X {} > class Y : X {} > X[] xs = cast(X[])(Y[].init); > > compilable in safe D? > > What's unsafe about such a cast? Your original code snippet seems redundant. If you wanted an

Re: Consequences of casting away immutable from pointers

2018-01-05 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 05, 2018 at 05:50:34PM +, jmh530 via Digitalmars-d-learn wrote: > On Friday, 5 January 2018 at 04:10:54 UTC, Steven Schveighoffer wrote: > > > > Yes, this is undefined behavior. > > > > https://dlang.org/spec/const3.html#removing_with_cast > > > > The compiler assumes x is going

Re: Array is already defined

2018-01-05 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 05, 2018 at 03:56:30PM +, Vino via Digitalmars-d-learn wrote: [...] > Hi Jonathan, > > Sorry , not able to get you, can you please point our as to where we > need to added the braces in the below example. Try this: void main () { Array!int Keycol;

Re: No modification of pointer values in safe functions?

2018-01-03 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 03, 2018 at 03:42:07PM -0700, Jonathan M Davis via Digitalmars-d-learn wrote: > On Wednesday, January 03, 2018 22:25:16 Mark via Digitalmars-d-learn wrote: [...] > > https://dlang.org/spec/function.html#safe-functions > > > > "The following operations are not allowed in safe

Re: No modification of pointer values in safe functions?

2018-01-03 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 03, 2018 at 10:02:22PM +, Mark via Digitalmars-d-learn wrote: > The documentation says the modification of pointer values is not > allowed in safe functions. Yet the following compiles fine on dmd: > > void main() @safe > { > int* x = new int; > int* y = new int; >

Re: How do I use ncurses library with D? are there any wrapper?

2018-01-03 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 03, 2018 at 09:04:00PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: > On Wednesday, 3 January 2018 at 19:15:18 UTC, H. S. Teoh wrote: > > https://github.com/adamdruppe/arsd/blob/master/terminal.d [...] > > Depending on what you want, you could also tack on eventloop.d from

Re: How do I use ncurses library with D? are there any wrapper?

2018-01-03 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 03, 2018 at 03:47:58PM +, Marc via Digitalmars-d-learn wrote: > Long time ago, IIRC, I read somewhere there was a ncurses for D but > now I can't find it are there any wrapper or am I mistaken? anyway, > I'm doing it from scratch and not porting anything so even a library > with

Re: Is it bad form to put code in package.d other than imports?

2018-01-03 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 03, 2018 at 12:43:52AM -0700, Jonathan M Davis via Digitalmars-d-learn wrote: > On Wednesday, January 03, 2018 06:10:10 Soulsbane via Digitalmars-d-learn > wrote: > > I've only understood that imports should go in package.d. I'm seeing > > more and more packages on code.dlang.org

Re: Efficient way to pass struct as parameter

2018-01-03 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 03, 2018 at 07:02:28AM +, Tim Hsu via Digitalmars-d-learn wrote: > On Tuesday, 2 January 2018 at 22:49:20 UTC, Adam D. Ruppe wrote: > > On Tuesday, 2 January 2018 at 22:17:14 UTC, Johan Engelen wrote: > > > Pass the Vector3f by value. > > > > This is very frequently the correct

Re: Efficient way to pass struct as parameter

2018-01-02 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 02, 2018 at 10:17:14PM +, Johan Engelen via Digitalmars-d-learn wrote: [...] > Passing by pointer (ref is the same) has large downsides and is > certainly not always fastest. For small structs and if copying is not > semantically wrong, just pass by value. +1. > More important:

Re: how to localize console and GUI apps in Windows

2017-12-29 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Dec 29, 2017 at 10:35:53AM +, Andrei via Digitalmars-d-learn wrote: > On Thursday, 28 December 2017 at 18:45:39 UTC, H. S. Teoh wrote: > > On Thu, Dec 28, 2017 at 05:56:32PM +, Andrei via Digitalmars-d-learn > > wrote: > > ... > > The string / wstring / dstring types in D are

Re: how to localize console and GUI apps in Windows

2017-12-28 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Dec 28, 2017 at 05:56:32PM +, Andrei via Digitalmars-d-learn wrote: > There is one everlasting problem writing Cyrillic programs in Windows: > Microsoft consequently invented two much different code pages for > Russia and other Cyrillic-alphabet countries: first was MSDOS-866 (and >

Re: Don't expect class destructors to be called at all by the GC

2017-12-28 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Dec 24, 2017 at 02:07:26PM -0700, Jonathan M Davis via Digitalmars-d-learn wrote: [...] > Regardless, even if it were the case that it were guaranteed that all > finalizers were run when the program exited, it would still be > terrible practice to rely on it. It's trivial to end up in a

Re: Converting member variables to strings with using reflection from base class

2017-12-22 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Dec 22, 2017 at 09:13:31PM +, kerdemdemir via Digitalmars-d-learn wrote: > I want to make a logging function for member variables by using reflection. [...] > class B > { > void Log() > { > auto a = [__traits(derivedMembers, D)]; > foreach(memberName; a) { >

Re: Don't expect class destructors to be called at all by the GC

2017-12-21 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Dec 21, 2017 at 06:45:27PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: > On Thursday, 21 December 2017 at 18:20:19 UTC, H. S. Teoh wrote: > > When the scoped destruction of structs isn't an option, RefCounted!T > > seems to be a less evil alternative than an unreliable class dtor.

Re: Don't expect class destructors to be called at all by the GC

2017-12-21 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Dec 21, 2017 at 06:50:44AM +, Mike Parker via Digitalmars-d-learn wrote: [...] > I just don't even bother with class destructors. Without a guarantee > that they can run and without any sort of deterministic behavior, it's > really not appropriate to refer to them as destructors and

Re: Array Template

2017-12-15 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Dec 15, 2017 at 05:21:55PM +, Vino via Digitalmars-d-learn wrote: > Hi All, > > Request your help, Is it possible to an template array something > similar as below so that we can insert any type of value(string, int > etc). If possible can you provide me a example of how to define

Re: Static array as immutable

2017-12-12 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Dec 12, 2017 at 06:06:48PM +, Ivan Trombley via Digitalmars-d-learn wrote: > On Tuesday, 12 December 2017 at 15:30:01 UTC, Nathan S. wrote: > > While what you're saying is true, exponentiation not being runnable > > at compile-time is a defect and I would assume a regression. [...] >

OT (Was: Re: What's the proper way to use std.getopt?)

2017-12-11 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Dec 11, 2017 at 11:35:53PM +, Seb via Digitalmars-d-learn wrote: [...] > D style would be to use sth. like this (instead of try/catch): > > ``` > scope(failure) { > e.msg.writeln; > 1.exit; > } > ``` Frankly, much as I love UFCS syntax, I think this is taking it a little too far.

Re: Sort characters in string

2017-12-06 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Dec 06, 2017 at 10:32:03AM -0800, Ali Çehreli via Digitalmars-d-learn wrote: > On 12/06/2017 04:43 AM, Fredrik Boulund wrote: > > On Wednesday, 6 December 2017 at 10:42:31 UTC, Dgame wrote: > > > >> > >> Or you simply do > >> > >> writeln("longword".array.sort); > >> > > > >

Re: git workflow for D

2017-12-05 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Dec 04, 2017 at 12:02:37PM -0800, Ali Çehreli via Digitalmars-d-learn wrote: [...] > Paraphrasing someone I trust very much, "Never 'pull', always 'fetch > -p' and then rebase." I always use `git pull --ff-only`. Lets me pull when it's "safe", aborts if it will end up in a mess (i.e.,

Re: git workflow for D

2017-12-05 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Dec 04, 2017 at 06:51:42AM -0500, Nick Sabalausky (Abscissa) via Digitalmars-d-learn wrote: > On 12/03/2017 03:05 PM, bitwise wrote: > > I've finally started learning git, due to our team expanding beyond > > one person - awesome, right? > > PROTIP: Version control systems (no matter

Re: scope(exit) and Ctrl-C

2017-12-02 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Dec 02, 2017 at 11:32:17AM +, Patrick Schluter via Digitalmars-d-learn wrote: > On Saturday, 2 December 2017 at 04:49:26 UTC, H. S. Teoh wrote: > > On Sat, Dec 02, 2017 at 04:38:29AM +, Adam D. Ruppe via > > Digitalmars-d-learn wrote: > > > [...] > > > > Signal handlers can

Re: scope(exit) and Ctrl-C

2017-12-01 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Dec 02, 2017 at 04:38:29AM +, Adam D. Ruppe via Digitalmars-d-learn wrote: > On Saturday, 2 December 2017 at 04:28:57 UTC, Wanderer wrote: > > Thanks! This works. But it seems a little bit suspicions that D's > > type for handler function has `nothrow` `@nogc` and `@system`. I > >

Re: associative array: unexpected results after static initialization

2017-12-01 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Dec 01, 2017 at 01:14:14PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 12/1/17 12:02 PM, H. S. Teoh wrote: > > On Fri, Dec 01, 2017 at 11:59:08AM -0500, Steven Schveighoffer via > > Digitalmars-d-learn wrote: > > > So I would say we should define that the last

Re: associative array: unexpected results after static initialization

2017-12-01 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Dec 01, 2017 at 11:59:08AM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 12/1/17 11:23 AM, H. S. Teoh wrote: > > On Fri, Dec 01, 2017 at 04:06:50PM +, kdevel via Digitalmars-d-learn > > wrote: > > > On Friday, 1 December 2017 at 00:42:00 UTC, H. S. Teoh wrote: > > >

Re: associative array: unexpected results after static initialization

2017-12-01 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Dec 01, 2017 at 04:06:50PM +, kdevel via Digitalmars-d-learn wrote: > On Friday, 1 December 2017 at 00:42:00 UTC, H. S. Teoh wrote: > > Here's the fix: > > > > https://github.com/dlang/druntime/pull/1980 > > And wouldn't it be reasonable to add > >assert(aa.values == [ "b"

Re: associative array: unexpected results after static initialization

2017-11-30 Thread H. S. Teoh via Digitalmars-d-learn
Seems like this problem is already known: https://issues.dlang.org/show_bug.cgi?id=15290 Here's the fix: https://github.com/dlang/druntime/pull/1980 --T

Re: associative array: unexpected results after static initialization

2017-11-30 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Nov 30, 2017 at 03:57:37PM -0800, H. S. Teoh via Digitalmars-d-learn wrote: > Hmm, which compiler are you using, and which version? I cannot > reproduce this bug with DMD git head. It may be have fixed since the > release you're using? [...] Sorry, I was testing the w

Re: associative array: unexpected results after static initialization

2017-11-30 Thread H. S. Teoh via Digitalmars-d-learn
Hmm, which compiler are you using, and which version? I cannot reproduce this bug with DMD git head. It may be have fixed since the release you're using? --T

Re: associative array: unexpected results after static initialization

2017-11-30 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Nov 30, 2017 at 11:50:13PM +, kdevel via Digitalmars-d-learn wrote: > This program > > ``` void aa_stat(T, U) (T[U] aa) { import std.stdio; writefln ("aa > : %s", aa); writefln ("aa.length : %d", aa.length); writefln ("aa.keys > : %s", aa.keys); writefln ("aa.values : %s", aa.values);

Re: On Attributes

2017-11-27 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Nov 27, 2017 at 07:10:04PM +, A Guy With a Question via Digitalmars-d-learn wrote: > Hi again! > > I've been trying to do my best to write idiomatically. One thing that > is bugging me is having to mark up all of my declarations with > attributes. Which means I'm having to remember

Re: String copying fails when output from assert

2017-11-21 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Nov 21, 2017 at 12:05:21PM -0700, Jonathan M Davis via Digitalmars-d-learn wrote: > On Tuesday, November 21, 2017 18:49:40 David Zhang via Digitalmars-d-learn > wrote: [...] > > char[64] chars; > > chars[0..str.length] = str; > > assert(false, chars[0..str.length]); [...] > Well,

Re: User defined type and foreach

2017-11-18 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Nov 17, 2017 at 02:50:59AM -0700, Jonathan M Davis via Digitalmars-d-learn wrote: [...] > Personally, I'm inclined to think that we should never have had save > and should have required that reference type ranges which are forward > ranges be wrapped in a struct where copying it does the

Re: User defined type and foreach

2017-11-16 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Nov 17, 2017 at 01:06:31AM +, Tony via Digitalmars-d-learn wrote: [...] > But I do have a complaint about the methods empty(), popFront() and > pop(). I think they should have a special syntax or name to reflect > that they are not general purpose methods. __empty() or preferably >

Re: private keyword dont appear to do anything

2017-11-03 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Nov 03, 2017 at 05:59:20PM -0600, Jonathan M Davis via Digitalmars-d-learn wrote: > On Friday, November 03, 2017 16:32:52 H. S. Teoh via Digitalmars-d-learn > wrote: > > Perhaps the solution is to go the > > one-overload-set-per-file route, with std/algorithm/packa

Re: private keyword dont appear to do anything

2017-11-03 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Nov 03, 2017 at 04:30:21PM -0600, Jonathan M Davis via Digitalmars-d-learn wrote: > On Friday, November 03, 2017 14:52:22 H. S. Teoh via Digitalmars-d-learn > wrote: [...] > > Arguably, many of these large flat files ought to be split up into > > smaller f

Re: private keyword dont appear to do anything

2017-11-03 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Nov 03, 2017 at 05:43:55PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 11/3/17 5:08 PM, Nathan S. wrote: > > On Friday, 3 November 2017 at 20:01:27 UTC, Jonathan M Davis wrote: > > > Most folks are surprised by this behavior > > > > I found it surprising at first but

Re: private keyword dont appear to do anything

2017-11-03 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Nov 03, 2017 at 09:08:56PM +, Nathan S. via Digitalmars-d-learn wrote: > On Friday, 3 November 2017 at 20:01:27 UTC, Jonathan M Davis wrote: > > Most folks are surprised by this behavior > > I found it surprising at first but now any other way seems absurd to > me. None of the

Re: writeln double precision

2017-10-24 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Oct 24, 2017 at 04:59:04PM +, jmh530 via Digitalmars-d-learn wrote: > On Tuesday, 24 October 2017 at 16:18:03 UTC, H. S. Teoh wrote: > > > > I have never seen a programming language in which dividing two > > integers yields a float or double. Either numbers default to a > > floating

Re: writeln double precision

2017-10-24 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Oct 24, 2017 at 10:02:11AM +, Arun Chandrasekaran via Digitalmars-d-learn wrote: > On Monday, 23 October 2017 at 18:08:43 UTC, Ali Çehreli wrote: > > On 10/23/2017 07:22 AM, Arun Chandrasekaran wrote: > > > [...] > > The rule is that every expression has a type and 22/7 is int. > >

Re: Should this Compile?

2017-10-03 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Oct 03, 2017 at 10:37:17PM +, SamwiseFilmore via Digitalmars-d-learn wrote: [...] > string toString() { > return > this.value.toString() ~ > " of " ~ > this.suit.toString() ~ > this.suit == CardSuit.diamonds ? "" : "\t" ~ >

Re: problem with opIndex

2017-09-29 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Sep 29, 2017 at 07:31:14PM +, Joseph via Digitalmars-d-learn wrote: > I am trying to have a multi-dimensional array and opIndex has to have > both an arbitrary number of parameters and allow for slicing. > > The problem is if I create opIndex for non-slicing, it looks like > > ref

Re: Real beginner traits question

2017-09-25 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Sep 25, 2017 at 03:41:14PM +, WhatMeWorry via Digitalmars-d-learn wrote: > On Monday, 25 September 2017 at 06:07:58 UTC, H. S. Teoh wrote: > > On Mon, Sep 25, 2017 at 05:28:13AM +, WhatMeForget via > > Digitalmars-d-learn wrote: > > > [...] > > > > You're not the only one. I

Re: Real beginner traits question

2017-09-25 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Sep 25, 2017 at 05:28:13AM +, WhatMeForget via Digitalmars-d-learn wrote: > > This is taken exactly from the traits documentation. > > > > 25 Traits > > 25.21 identifier > > Takes one argument, a symbol. Returns the identifier for

Re: Getting the size of a type tuple

2017-09-21 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Sep 21, 2017 at 09:49:14PM +0200, ag0aep6g via Digitalmars-d-learn wrote: [...] > 3) Declaring a packed struct in a function literal that gets > immediately called: > > enum size_so_very_clever(Types ...) = () { > struct S { align(1) Types fields; } > return S.sizeof; > } ();

Re: std.algorithm.joiner unexpected behavior

2017-08-31 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 31, 2017 at 05:37:20PM -0600, Jonathan M Davis via Digitalmars-d-learn wrote: > On Thursday, August 31, 2017 14:09:55 H. S. Teoh via Digitalmars-d-learn [...] > I know. We've had this argument before. I know. Let's not rehash that. :-) [...] > Even copying ranges in gen

Re: std.algorithm.joiner unexpected behavior

2017-08-31 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 31, 2017 at 01:34:39PM -0600, Jonathan M Davis via Digitalmars-d-learn wrote: [...] > In general, byLine does not work with other range-based algorithms > precisely because it reuses the buffer. I think that it does manage to > work for some, but IMHO, it should have just supported

Re: std.algorithm.joiner unexpected behavior

2017-08-31 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 31, 2017 at 06:26:33PM +, Sergei Degtiarev via Digitalmars-d-learn wrote: [...] > File[] files; > > foreach(ln; joiner(files.map!(a => a.byLine))) > writeln(ln); You probably want to use byLineCopy instead. The problem here is that .byLine

Re: DIPs - question about mores, etiquette and DIP1009 in particular

2017-08-30 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 30, 2017 at 05:16:11PM +, Cecil Ward via Digitalmars-d-learn wrote: > Is there a way I can simply register my vote eg about DIP 1009? My > vote is 'no thanks'. Like the existing system, don't care about the > alleged verbosity / room thing, and please whatever do not deprecate >

Re: Formated Output and file creation time

2017-08-16 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 16, 2017 at 03:30:18PM +, Vino.B via Digitalmars-d-learn wrote: [...] > Current Output > C:\Test1\Test2\T.txt 1234 2017-Aug-16 19:10:54.0618385 > C:\Test1\Test2\TX.txt 1234 2017-Aug-16 19:10:54.0618385 > C:\Test1\Test2\TXXX.txt 1234 2017-Aug-16

Re: Bug in D?!

2017-08-11 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Aug 11, 2017 at 11:34:04PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: > On Friday, 11 August 2017 at 22:43:02 UTC, Mr. Pib wrote: > > int and I should be able to append an int without having to worry > > about the value of the int. > > Appending an int to a string really ought

Re: BigInt foreach loop

2017-08-09 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 09, 2017 at 09:34:26PM +, Q. Schroll via Digitalmars-d-learn wrote: > On Friday, 4 August 2017 at 16:40:08 UTC, Stefan Koch wrote: > > [..] > > > > foreach(x;A .. B) > > it's lowerd to > > auto limit = B; > > auto key = A; > > for(auto x = key;key < limit;++key) > > { > > // use

Re: why won't byPair work with a const AA?

2017-08-02 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 02, 2017 at 11:06:03AM -0700, H. S. Teoh via Digitalmars-d-learn wrote: [...] > auto byPair(AA)(inout(AA) aa) > { > alias Modifiers = std.traits.getModifiers!AA; > struct Result { > std.traits.Apply

Re: why won't byPair work with a const AA?

2017-08-02 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 02, 2017 at 01:15:44PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: [...] > It's not currently legal, you can't have inout members of a struct. > This could be added, but it still wouldn't work, because you can't > "strip off" the inout part upon return. > > The real

Re: why won't byPair work with a const AA?

2017-08-02 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 02, 2017 at 08:20:23AM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 8/1/17 7:44 PM, H. S. Teoh via Digitalmars-d-learn wrote: [...] > You can iterate a const AA, but if you want to iterate a non-const AA, > you need a different type. > > For insta

Re: why won't byPair work with a const AA?

2017-08-01 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Aug 01, 2017 at 07:31:41PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 8/1/17 7:15 PM, H. S. Teoh via Digitalmars-d-learn wrote: > > On Tue, Aug 01, 2017 at 07:09:45PM -0400, Steven Schveighoffer via > > Digitalmars-d-learn wrote: > >

Re: why won't byPair work with a const AA?

2017-08-01 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Aug 01, 2017 at 07:09:45PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 8/1/17 6:50 PM, H. S. Teoh via Digitalmars-d-learn wrote: [...] > > Actually, there's nothing about the implementation of both > > byKeyValue (the underlying implementation in drunt

Re: why won't byPair work with a const AA?

2017-08-01 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Aug 01, 2017 at 10:04:18AM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 7/30/17 12:19 AM, Matthew Gamble wrote: [...] > > import std.array; > > import std.algorithm; > > > > class A > > { > > this() { aa = ["a":1, "b" : 2, "c" : 3]; } > > auto pairs()

Re: How do I cast to from byte[] <-> double for making a small assembler language VM to work?

2017-07-18 Thread H. S. Teoh via Digitalmars-d-learn
Maybe use a union? union U { double d; byte[double.sizeof] bytes; } U u; u.bytes = ...; double d = u.d; ... // do something with d // or: U u; u.d = 3.14159; byte[] b = u.bytes[];

Re: Appending static arrays

2017-07-17 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jul 17, 2017 at 10:32:14PM +, Nordlöw via Digitalmars-d-learn wrote: > On Monday, 17 July 2017 at 20:01:41 UTC, H. S. Teoh wrote: [...] > > result[offset .. offset + a.length] = a[]; > > This slice assignment doesn't support conversion between different >

Re: Appending static arrays

2017-07-17 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jul 17, 2017 at 08:28:12PM +, Nordlöw via Digitalmars-d-learn wrote: [...] > I had to special-case foreach body for `i == 0` since `sumOfLengths` > couldn't instantiate with empty tuple `()`. > > Further, should `concat` support `CommonType`? That is, should > > int[2] x = [1,

Re: Appending static arrays

2017-07-17 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jul 17, 2017 at 08:11:03PM +, Nordlöw via Digitalmars-d-learn wrote: [...] > Does this have a place in Phobos? Never know till you try. :-D > If so, > > - under what name: append, concat or cat? I'd vote for concat. > - where: std.algorithm or std.array? std.array, IMO, since

Re: Appending static arrays

2017-07-17 Thread H. S. Teoh via Digitalmars-d-learn
OK, here's an actual, compilable, runnable version: import std.algorithm : sum; import std.meta : allSatisfy, staticMap; import std.range : only; import std.traits : CommonType, isStaticArray; alias Elem(A : E[n], E, size_t n) = E; enum Length(A) =

Re: Appending static arrays

2017-07-17 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jul 17, 2017 at 12:01:48PM -0700, H. S. Teoh via Digitalmars-d-learn wrote: [...] > template sumOfLengths(A...) > if (A.length > 0) > { > static if (A.length == 1) > enum sumOfLengths = A[0].length; &g

Re: Appending static arrays

2017-07-17 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jul 17, 2017 at 12:01:48PM -0700, H. S. Teoh via Digitalmars-d-learn wrote: [...] > T[sumOfLengths!StaticArrays] append(StaticArrays...)(StaticArrays > arrays) > if (/* insert static array constraints here */) > { > typeof(return

Re: Appending static arrays

2017-07-17 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jul 17, 2017 at 05:38:23PM +, Nordlöw via Digitalmars-d-learn wrote: > I'm want to define a specialization of `append()` that takes only > static arrays as inputs and returns a static array being the sum of > the lengths of the inputs. > > Have anybody already implemented this? > >

Re: Exception handling

2017-07-14 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jul 14, 2017 at 11:09:23PM +, Stefan Koch via Digitalmars-d-learn wrote: > On Friday, 14 July 2017 at 23:02:24 UTC, Moritz Maxeiner wrote: > > On Friday, 14 July 2017 at 21:20:29 UTC, Jonathan M Davis wrote: > > > Basically, the compiler _never_ looks at the bodies of other > > >

Re: Silly struct behaviour

2017-07-13 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 13, 2017 at 06:48:27PM +, JN via Digitalmars-d-learn wrote: > On Thursday, 13 July 2017 at 18:09:46 UTC, H. S. Teoh wrote: > > > > It's not quite so simple. Consider for example: > > > > struct Foo { int bar; } > > struct Oof { int bar; } > > > > void process(Foo

Re: Silly struct behaviour

2017-07-13 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 13, 2017 at 06:07:31PM +, JN via Digitalmars-d-learn wrote: > Consider: > > struct Foo > { > int bar; > } > > void processFoo(Foo foo) > { > } > > void main() > { > Foo f = {bar: 5}; > processFoo(f);// ok > processFoo(Foo(5)); //

Re: CTFE output is kind of weired

2017-07-08 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jul 08, 2017 at 03:09:09PM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > On 07/08/2017 02:29 PM, Andre Pany wrote: > > > I use assert(false, tmp) to see the content of variable tmp as it > > seems there is no other way in CTFE. > > A more natural way is pragma(msg), which you can

Re: Undefined symbol for, apparently, valid code?

2017-07-06 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 06, 2017 at 06:49:51PM +, unleashy via Digitalmars-d-learn wrote: > On Thursday, 6 July 2017 at 16:16:17 UTC, H. S. Teoh wrote: > > Which version of the compiler are you using? I just tested on the > > latest dmd git HEAD, and it (correctly) tells me that it's illegal > > to

Re: Undefined symbol for, apparently, valid code?

2017-07-06 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 06, 2017 at 06:28:11AM +, unleashy via Digitalmars-d-learn wrote: > Hello. I am trying to compile this: > > --- > module asd.asd; > > abstract class Asd > { > void opCall(Args...)(Args args); > } > > @system unittest > { > class Foo : Asd > { > override void

Re: Remove instance from array

2017-07-05 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jul 05, 2017 at 05:07:14PM +, Jolly James via Digitalmars-d-learn wrote: > On Wednesday, 5 July 2017 at 16:55:43 UTC, bachmeier wrote: > > On Wednesday, 5 July 2017 at 16:04:16 UTC, Jolly James wrote: > > > > > Here in D everything looks like climbing mount everest. When you > > >

Re: Append to 'map' result

2017-07-04 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jul 04, 2017 at 11:27:25PM +, Jean-Louis Leroy via Digitalmars-d-learn wrote: > I want to create a range that consists of the result of a map() > followed by a value, e.g.: > > int[] x = [ 1, 2, 3]; > auto y = map!(x => x * x)(x); > auto z = y ~ 99; // how??? > > I have tried

Re: Funny issue with casting double to ulong

2017-07-03 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jul 03, 2017 at 07:13:45AM +, Era Scarecrow via Digitalmars-d-learn wrote: > On Monday, 3 July 2017 at 06:20:22 UTC, H. S. Teoh wrote: [...] > > I don't think there's a way to change how the FPU works -- the > > hardware is coded that way and can't be changed. You'd have to > > build

Re: Funny issue with casting double to ulong

2017-07-03 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jul 03, 2017 at 05:38:56AM +, Era Scarecrow via Digitalmars-d-learn wrote: > On Monday, 3 July 2017 at 03:57:25 UTC, Basile B wrote: > > 6.251 has no perfect double representation. It's real value is: > > I almost wonder if a BCD, fixed length or alternative for floating > point

Re: std.string.format call from varyargs

2017-07-02 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Jul 02, 2017 at 11:38:34AM +0300, drug via Digitalmars-d-learn wrote: > 02.07.2017 09:52, H. S. Teoh via Digitalmars-d-learn пишет: [...] > > Take a look at the docs that describe the "%(...%)" nested format > > specifiers. For example: > >

Re: std.string.format call from varyargs

2017-07-02 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Jul 02, 2017 at 12:49:30AM +, LeqxLeqx via Digitalmars-d-learn wrote: > Hello! > > How does one go about invoking a templated-variatic function such as > std.string.format with an array of objects? > > For example: > > string stringMyThing (string formatForMyThings, MyThing[]

Re: ReadProcessMemory + address from ollydbg

2017-06-30 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jul 01, 2017 at 02:23:36AM +0200, ag0aep6g via Digitalmars-d-learn wrote: > On 07/01/2017 01:41 AM, bauss wrote: [...] > > stringSize, )) { > > return defaultValue; > >} > > > >auto s = cast(string)data[0 .. stringSize]; > > > >return s ? s : defaultValue; > >

Re: Strange Bug in LDC vs DMD

2017-06-30 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 30, 2017 at 07:57:22PM +, FoxyBrown via Digitalmars-d-learn wrote: [...] > The only way this can happen is if the rename command is somehow > feeding back in to the algorithm. Since the problem goes away when I > pre-compute dirEntries, it suggests that dirEntries is being lazily

Re: Strange Bug in LDC vs DMD

2017-06-30 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 30, 2017 at 12:50:24PM +, FoxyBrown via Digitalmars-d-learn wrote: > I am using dirEntries to iterate over files to rename them. > > I am renaming them in a loop(will change but added code for testing). > > > In DMD the renaming works but in LDC the renaming fails. It fails in

Re: Converting a ubyte[] to a struct with respect to endianness?

2017-06-23 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 23, 2017 at 10:10:22PM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > On 06/23/2017 09:26 PM, Felix wrote: > > That works, thanks! > > I've just tried this, which seems cleaner: > > import std.stdio; > import std.system; > import std.bitmanip; > > void ensureBigEndian(T)(ref T

Re: Is there s.th. like enforceSuffix for arrays (string)?

2017-06-22 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jun 22, 2017 at 06:18:22PM +, Andre Pany via Digitalmars-d-learn wrote: > Hi, > > i often need to check whether an array(string) ends with a specific > text and if not I need to add this text. > > For example I have a variable url and / has to be added to the end in > case it is

Re: Dealing with the interior pointers bug

2017-06-21 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jun 21, 2017 at 05:11:41PM +, TheGag96 via Digitalmars-d-learn wrote: > On Wednesday, 21 June 2017 at 15:42:22 UTC, Adam D. Ruppe wrote: > > This comes from the fact that D's GC is conservative - if it sees > > something that *might* be a pointer, it assumes it *is* a pointer > > and

Re: libc dependency

2017-06-19 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jun 19, 2017 at 07:29:46PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 6/19/17 5:45 PM, Moritz Maxeiner wrote: > > On Monday, 19 June 2017 at 21:35:56 UTC, Steven Schveighoffer wrote: > > > IIRC, Tango did not depend on libc at all. It only used system > > > calls. So

Re: AliasSeq of AliasSeq, or meta-functions that take multiple lists

2017-06-19 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jun 19, 2017 at 01:59:33PM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > On 06/19/2017 12:54 PM, Jean-Louis Leroy wrote: > > I need to process two sequences in parallel (select some elements of > > sequence A depending of the corresponding element of sequence B). > > How can I pass

Re: How to implement opCmp?

2017-06-13 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jun 13, 2017 at 10:51:40AM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: [...] > I think Andrei has a nice way to do opCmp for integers that's a simple > subtraction and negation or something like that. [...] In theory, cmp(int x, int y) can be implemented simply as (x - y).

Re: Generic operator overloading for immutable types?

2017-06-12 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jun 12, 2017 at 01:08:13PM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > On 06/12/2017 01:03 PM, Gary Willoughby wrote: > > On Monday, 12 June 2017 at 19:36:52 UTC, H. S. Teoh wrote: > > >> public inout Rational opBinary(string op)(inout Rational rhs) > > > Quick question

Re: Generic operator overloading for immutable types?

2017-06-12 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jun 12, 2017 at 07:38:44PM +, Gary Willoughby via Digitalmars-d-learn wrote: > In the following code is there any way to make the `opBinary` method > generic to be able to accept immutable as well as a standard type? The > code currently passes the unit test but I wonder if I could

Re: O(1) sum

2017-06-12 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jun 12, 2017 at 06:16:06PM +, Stefan Koch via Digitalmars-d-learn wrote: > On Monday, 12 June 2017 at 06:15:07 UTC, Biotronic wrote: [...] > > On a multi-core system we can do better: > > > > auto nums = iota(10_000_000.0f); > > auto sum = taskPool.reduce!"a + b"(nums); > > > >

Re: Can I speed up this log parsing script further?

2017-06-09 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 09, 2017 at 04:28:08PM +, uncorroded via Digitalmars-d-learn wrote: [...] > Is there a good resource to read about the good stuff in std.algorithm > and range? I tried going through the library docs but they are too > exhaustive! [...] Try these:

Re: [Solved] Confusing error message

2017-06-07 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jun 07, 2017 at 11:16:14PM +0300, drug via Digitalmars-d-learn wrote: > 07.06.2017 22:40, bachmeier пишет: [...] > > In any event, I made a second suggestion that would always work. If > > it can't find a match, it asks if you're missing an import > > statement, as a way to provide the new

<    6   7   8   9   10   11   12   13   14   15   >