const of AliasSeq is silently ignored

2019-04-08 Thread Yuxuan Shui via Digitalmars-d-learn
In this example: const(AliasSeq!(int, int)) a; pragma(msg, typeof(a)); // (int, int) This kind of make sense, since AliasSeq is not a "single" type. But silently dropping const seems bad, the compiler should probably report an error/warning in this case?

ElementType of MapResult is a delegate??

2018-12-08 Thread Yuxuan Shui via Digitalmars-d-learn
This surprised me A LOT: https://d.godbolt.org/z/82a_GZ So if I call something.map!().array, I get an array of delegates? That makes no sense to me.

Re: Circular reference error gone after inspecting members

2018-08-25 Thread Yuxuan Shui via Digitalmars-d-learn
Issue filed: https://issues.dlang.org/show_bug.cgi?id=19190

Suggestion: Bug fix releases (Re: Dicebot on leaving D: It is anarchy driven development in all its glory.)

2018-08-25 Thread Yuxuan Shui via Digitalmars-d
On Wednesday, 22 August 2018 at 11:59:37 UTC, Paolo Invernizzi wrote: Just found by chance, if someone is interested [1] [2]. /Paolo [1] https://gitlab.com/mihails.strasuns/blog/blob/master/articles/on_leaving_d.md [2]

Re: Circular reference error gone after inspecting members

2018-08-25 Thread Yuxuan Shui via Digitalmars-d-learn
On Saturday, 25 August 2018 at 14:13:18 UTC, rikki cattermole wrote: On 26/08/2018 2:10 AM, Yuxuan Shui wrote: The offending code base is a little big and hard to reduce. I'll try if code is required, but here is the gist of the problem: This snippet of code in my project:     ...    

Circular reference error gone after inspecting members

2018-08-25 Thread Yuxuan Shui via Digitalmars-d-learn
The offending code base is a little big and hard to reduce. I'll try if code is required, but here is the gist of the problem: This snippet of code in my project: ... alias tmp = genCode!T; enum str = tmp.str; // This line here ... Generate a circular reference error.

Re: Alignment of symbol is not kept during linking

2018-08-10 Thread Yuxuan Shui via Digitalmars-d
On Friday, 10 August 2018 at 08:46:46 UTC, Kagamin wrote: On Thursday, 9 August 2018 at 14:15:31 UTC, Yuxuan Shui wrote: The alignment is specified for the section, and it apparently kept. problem is individual symbols in the section don't have a alignment. If the section is aligned at 16

Re: Alignment of symbol is not kept during linking

2018-08-09 Thread Yuxuan Shui via Digitalmars-d
On Thursday, 9 August 2018 at 13:50:00 UTC, Kagamin wrote: On Thursday, 9 August 2018 at 13:30:38 UTC, Yuxuan Shui wrote: I searched around, and there seems to be no way to specify alignment on symbol, so I don't think the linker is in the wrong here. The alignment should be specified for

Re: Alignment of symbol is not kept during linking

2018-08-09 Thread Yuxuan Shui via Digitalmars-d
Clarifications: On Thursday, 9 August 2018 at 13:30:38 UTC, Yuxuan Shui wrote: I'm trying to build LDC with dmd and Musl, but the result ldc will always crash. I track that down to an unalignment SIMD access to a global variable. Apparently C++ compiler thinks the variable should be aligned

Alignment of symbol is not kept during linking

2018-08-09 Thread Yuxuan Shui via Digitalmars-d
I'm trying to build LDC with dmd and Musl, but the result ldc will always crash. I track that down to an unalignment SIMD access to a global variable. Apparently C++ compiler thinks the variable should be aligned to 16 bytes, but it's only aligned to 8 bytes. After some more digging, I find

getProtection gives different result when member is accessed via getMember

2018-08-04 Thread Yuxuan Shui via Digitalmars-d-learn
file1.d: import std.stdio; file2.d: import file1; pragma(msg, __traits(getProtection, __traits(getMember, m1, "std"))); // public pragma(msg, __traits(getProtection, m1.std)); // private Bug? Intended?

Re: Eponymous template member from a template mixin

2018-08-04 Thread Yuxuan Shui via Digitalmars-d-learn
On Saturday, 4 August 2018 at 21:10:32 UTC, Steven Schveighoffer wrote: On 8/4/18 4:10 PM, Yuxuan Shui wrote: This doesn't work: template A() { void B() {}; } template B() { mixin A!(); } void main() { B!()(); } Is this intentional? I believe mixin templates introduce a new

Eponymous template member from a template mixin

2018-08-04 Thread Yuxuan Shui via Digitalmars-d-learn
This doesn't work: template A() { void B() {}; } template B() { mixin A!(); } void main() { B!()(); } Is this intentional?

Re: A struct with a tuple as alias this, is kind of confusing

2018-07-27 Thread Yuxuan Shui via Digitalmars-d
On Friday, 27 July 2018 at 10:48:08 UTC, ag0aep6g wrote: On 07/27/2018 12:19 PM, Yuxuan Shui wrote: On Friday, 27 July 2018 at 10:17:21 UTC, Yuxuan Shui wrote: [...] Oh no, is it just defining arrays in the is() statement, though? Yup. But wait, this works: alias C = A!(1,2,3); static

Re: A struct with a tuple as alias this, is kind of confusing

2018-07-27 Thread Yuxuan Shui via Digitalmars-d
On Friday, 27 July 2018 at 10:17:21 UTC, Yuxuan Shui wrote: First, it surprised me that I can't index a struct like that. So: struct A(T...) { alias S = T; alias S this; } alias B = A!(int, double); B[0] x; // Actually an array Then, it surprised me again, that I actually can index

A struct with a tuple as alias this, is kind of confusing

2018-07-27 Thread Yuxuan Shui via Digitalmars-d
First, it surprised me that I can't index a struct like that. So: struct A(T...) { alias S = T; alias S this; } alias B = A!(int, double); B[0] x; // Actually an array Then, it surprised me again, that I actually can index it, sometimes static if (!is(B[0] == B[1])) pragma(msg,

Re: I have a plan.. I really DO

2018-07-10 Thread Yuxuan Shui via Digitalmars-d-announce
On Friday, 6 July 2018 at 21:15:46 UTC, H. S. Teoh wrote: On Fri, Jul 06, 2018 at 08:16:36PM +, Ecstatic Coder via Digitalmars-d-announce wrote: [...] I've never said that this is something smart to do. I'm just saying that this code can perfectly be executed once in a C++ game frame

Re: Normalize void

2018-07-10 Thread Yuxuan Shui via Digitalmars-d
On Tuesday, 10 July 2018 at 11:37:25 UTC, ag0aep6g wrote: On 07/10/2018 11:56 AM, Yuxuan Shui wrote: Possible alternatives: * struct Void {}. Takes 1 byte, not as ideal * alias Void = AliasSeq!(). Doesn't work as template argument. i.e.   SomeTemplate!Void; // actually become

Re: Normalize void

2018-07-10 Thread Yuxuan Shui via Digitalmars-d
On Tuesday, 10 July 2018 at 09:50:45 UTC, Yuxuan Shui wrote: Suppose I want to create a type to contain either a return value or an error, I could probably do something like this: [...] Breaking changes: void[] x; pragma(msg, x[0].sizeof); // now 0?

Re: Normalize void

2018-07-10 Thread Yuxuan Shui via Digitalmars-d
On Tuesday, 10 July 2018 at 09:50:45 UTC, Yuxuan Shui wrote: Suppose I want to create a type to contain either a return value or an error, I could probably do something like this: [...] Possible alternatives: * struct Void {}. Takes 1 byte, not as ideal * alias Void = AliasSeq!(). Doesn't

Normalize void

2018-07-10 Thread Yuxuan Shui via Digitalmars-d
Suppose I want to create a type to contain either a return value or an error, I could probably do something like this: struct Result(T, E) { bool is_err; union { T result; E error; } } This will probably work fine, unless I don't need an

Re: Is package.d a good idea?

2018-07-01 Thread Yuxuan Shui via Digitalmars-d
On Sunday, 1 July 2018 at 18:03:41 UTC, Adam D. Ruppe wrote: On Sunday, 1 July 2018 at 14:23:36 UTC, Yuxuan Shui wrote: I was suggesting we do what Rust did. i.e. 'import foo', imports foo.d, which can in turn do 'import foo.bar', which will import foo/bar.d. Yeah, that's the way it should

Re: Is package.d a good idea?

2018-07-01 Thread Yuxuan Shui via Digitalmars-d
On Sunday, 1 July 2018 at 11:55:17 UTC, Jonathan M Davis wrote: On Sunday, July 01, 2018 11:36:51 Yuxuan Shui via Digitalmars-d wrote: [...] The entire reason that package.d was added as a feature was so that modules could be split into packages without breaking code, and it's still

Is package.d a good idea?

2018-07-01 Thread Yuxuan Shui via Digitalmars-d
In Rust, they have something call mod.rs, which is very similar to package.d. When you use a module 'foo' in Rust, it can either be 'foo.rs' or 'foo/mod.rs'. If 'foo' has sub-modules, it has to be 'foo/mod.rs'. Now in the Rust 2018 edition, they are getting rid of mod.rs. So when you import

Re: Why are we not using libbacktrace for backtrace?

2018-06-14 Thread Yuxuan Shui via Digitalmars-d
On Thursday, 14 June 2018 at 17:26:50 UTC, Johannes Pfau wrote: Am Thu, 14 Jun 2018 01:19:30 + schrieb Yuxuan Shui: Just ran into a problem where program will crash during stack trace. Turns out not only does druntime not support compressed debug info, it cannot handle it at all. So I

Why are we not using libbacktrace for backtrace?

2018-06-13 Thread Yuxuan Shui via Digitalmars-d
Just ran into a problem where program will crash during stack trace. Turns out not only does druntime not support compressed debug info, it cannot handle it at all. So I was thinking why don't we use a existing and proven library for this, instead of roll our own?

Re: What's happening with the `in` storage class

2018-06-09 Thread Yuxuan Shui via Digitalmars-d
On Saturday, 9 June 2018 at 07:56:08 UTC, Jonathan M Davis wrote: Now that it is defined with DIP 1000, it seems like pretty much everyone trying to use it has a hard time understanding it at first (at least beyond the really simple cases). It might have been because that the DIP is written

Re: DIP Draft Review News

2018-06-04 Thread Yuxuan Shui via Digitalmars-d-announce
On Monday, 4 June 2018 at 11:28:26 UTC, rikki cattermole wrote: Thought: Couldn't we have alternative names in the parameter instead? E.g. ```D void foo(int x/x0/width, int y/y0/height){} ``` This intuitively means that any combination of the parameter names would work (e.g. (x, y0),

Re: DIP Draft Review News

2018-06-04 Thread Yuxuan Shui via Digitalmars-d-announce
On Monday, 4 June 2018 at 10:30:18 UTC, rikki cattermole wrote: On 04/06/2018 10:05 PM, Yuxuan Shui wrote: On Monday, 4 June 2018 at 05:46:04 UTC, rikki cattermole wrote: [...] Not sure what you meant? This definitely does not error out: https://godbolt.org/g/PAiFPw ```D @named: int

Re: DIP Draft Review News

2018-06-04 Thread Yuxuan Shui via Digitalmars-d-announce
On Monday, 4 June 2018 at 05:46:04 UTC, rikki cattermole wrote: On 04/06/2018 5:01 PM, Mike Parker wrote: Named arguments lite I'm concerned about this DIP (keep in mind I wrote a referenced WIP DIP). 1. Reordering of parameters that match (with overloads) ```D int add(int a, int b); int

Re: Clash When Using Function as Template Value-Parameters?

2018-05-29 Thread Yuxuan Shui via Digitalmars-d
On Tuesday, 29 May 2018 at 12:37:04 UTC, Vijay Nayar wrote: On Tuesday, 29 May 2018 at 11:36:11 UTC, Yuxuan Shui wrote: No, wait a second. (a)=>a is in default argument list, so it is in the global scope. And it was instantiated when you instantiate BTree with char. Could you explain that

Re: Clash When Using Function as Template Value-Parameters?

2018-05-29 Thread Yuxuan Shui via Digitalmars-d
On Tuesday, 29 May 2018 at 11:34:03 UTC, Yuxuan Shui wrote: On Saturday, 26 May 2018 at 11:56:30 UTC, Vijay Nayar wrote: I've been experimenting with code that uses std.functional : binaryFun and unaryFun, but I have found that using these methods makes it impossible to add function attributes

Re: Clash When Using Function as Template Value-Parameters?

2018-05-29 Thread Yuxuan Shui via Digitalmars-d
On Saturday, 26 May 2018 at 11:56:30 UTC, Vijay Nayar wrote: I've been experimenting with code that uses std.functional : binaryFun and unaryFun, but I have found that using these methods makes it impossible to add function attributes like @safe, @nogc, pure, and nothrow, because no guarantee

Re: Error about constructor calls in loops/labels, but there are no loops and labels?

2018-05-21 Thread Yuxuan Shui via Digitalmars-d
I've been using Swift in the past few years quite a bit, and it always amuses me when it can't figure out some kind of inference that seems trivial, but it just gives up because the compiler takes too long to determine: "This [one line] statement is too difficult, please split into multiple

Re: Error about constructor calls in loops/labels, but there are no loops and labels?

2018-05-21 Thread Yuxuan Shui via Digitalmars-d
My response below might be a little off-topic. On Monday, 21 May 2018 at 13:06:14 UTC, Steven Schveighoffer wrote: [snip] There is something to be said for keeping the compiler dumb: 1. Dumb is easy to implement, explain, and understand -- if you set the bar low then more compilers will be

Re: Error about constructor calls in loops/labels, but there are no loops and labels?

2018-05-20 Thread Yuxuan Shui via Digitalmars-d
On Sunday, 20 May 2018 at 14:39:28 UTC, Jonathan M Davis wrote: Well, constructors are one of the few places that the compiler attempts flow analysis for stuff other than optimization, because it pretty much has to in order to do what the language needs. And no, it's not very sophisticated

Re: Error about constructor calls in loops/labels, but there are no loops and labels?

2018-05-20 Thread Yuxuan Shui via Digitalmars-d
On Sunday, 20 May 2018 at 00:05:39 UTC, Jonathan M Davis wrote: because it tends to become very difficult to get right in all cases and results in situations where the programmer is forced to do something in order to make the compiler shut up Well, doesn't this post show exactly this problem,

Re: Error about constructor calls in loops/labels, but there are no loops and labels?

2018-05-19 Thread Yuxuan Shui via Digitalmars-d
On Thursday, 17 May 2018 at 20:32:23 UTC, Steven Schveighoffer wrote: On 5/17/18 4:25 PM, DarkHole wrote: On Thursday, 17 May 2018 at 20:02:19 UTC, Steven Schveighoffer wrote: On 5/17/18 3:55 PM, DarkHole wrote: This strange code - https://run.dlang.io/is/BKgv49 - fails with error "Error:

Re: Extend the call site default argument expansion mechanism?

2018-05-15 Thread Yuxuan Shui via Digitalmars-d
On Tuesday, 15 May 2018 at 13:59:37 UTC, jmh530 wrote: On Tuesday, 15 May 2018 at 13:16:21 UTC, Steven Schveighoffer wrote: [snip] Hm... neat idea. Somehow, opDispatch can probably be used to make this work even more generically (untested): struct WithAlloc(alias alloc) { auto

Re: Extend the call site default argument expansion mechanism?

2018-05-15 Thread Yuxuan Shui via Digitalmars-d
On Friday, 11 May 2018 at 18:55:03 UTC, Meta wrote: On Friday, 11 May 2018 at 15:03:41 UTC, Uknown wrote: [...] It's not as pretty, and I don't know if it works outside this toy example yet, but you can do: import std.stdio; struct Allocator { auto call(alias F, Args...)(Args args)

Re: Extend the call site default argument expansion mechanism?

2018-05-11 Thread Yuxuan Shui via Digitalmars-d
On Thursday, 10 May 2018 at 15:15:03 UTC, Paul Backus wrote: On Thursday, 10 May 2018 at 14:37:00 UTC, rikki cattermole wrote: On 11/05/2018 2:33 AM, Yuxuan Shui wrote: On Thursday, 10 May 2018 at 14:28:39 UTC, JN wrote: But doing it with default argument expansion saves you 1 allocation,

Re: Extend the call site default argument expansion mechanism?

2018-05-10 Thread Yuxuan Shui via Digitalmars-d
On Thursday, 10 May 2018 at 14:30:49 UTC, Seb wrote: On Thursday, 10 May 2018 at 14:15:18 UTC, Yuxuan Shui wrote: So in D I can use default argument like this: int f(int line=__LINE__) {} [...] Why not define a TLS or global variable like theAllocator? Or if you know it at compile-time as

Re: Extend the call site default argument expansion mechanism?

2018-05-10 Thread Yuxuan Shui via Digitalmars-d
On Thursday, 10 May 2018 at 14:28:39 UTC, JN wrote: On Thursday, 10 May 2018 at 14:15:18 UTC, Yuxuan Shui wrote: [...] For things like this you can use the OOP Factory pattern, pseudocode: class DataStructureFactory { this(Allocator alloc) { this.alloc = alloc; } Allocator

Re: Extend the call site default argument expansion mechanism?

2018-05-10 Thread Yuxuan Shui via Digitalmars-d
On Thursday, 10 May 2018 at 14:17:50 UTC, rikki cattermole wrote: On 11/05/2018 2:15 AM, Yuxuan Shui wrote: [...] Bad idea, too much magic. This magic is already there in D. I just want to use it in a different way.

Extend the call site default argument expansion mechanism?

2018-05-10 Thread Yuxuan Shui via Digitalmars-d
So in D I can use default argument like this: int f(int line=__LINE__) {} And because default argument is expanded at call site, f() will be called with the line number of the call site. This is a really clever feature, and I think a similar feature can be useful in other ways. Say I need

Re: partially mutable immutable type problem, crazy idea

2018-05-08 Thread Yuxuan Shui via Digitalmars-d
On Wednesday, 9 May 2018 at 00:58:51 UTC, jmh530 wrote: On Tuesday, 8 May 2018 at 22:31:10 UTC, Yuxuan Shui wrote: snip] This doesn't compile for me on run.dlang.io: onlineapp.d(22): Error: template onlineapp.f cannot deduce function from argument types !()(B), candidates are:

Re: partially mutable immutable type problem, crazy idea

2018-05-08 Thread Yuxuan Shui via Digitalmars-d
After watching the DConf 2018 video, I came up with this wild idea: auto f(T)(immutable T a) { // If T is a aggregate type, and I only use (directly // or indirectly) the immutable fields of T, // Then it should be OK to call f() with a partially mutable type return a.x+1; }

Re: Unreachable warning is annoying

2018-03-13 Thread Yuxuan Shui via Digitalmars-d
On Tuesday, 13 March 2018 at 14:40:21 UTC, Steven Schveighoffer wrote: On 3/13/18 10:25 AM, Yuxuan Shui wrote: [...] This has been discussed before. There are a few ways around this. One is to do what you did. Another is to append a sentinel, or use id to terminate the loop: foreach(id,

Unreachable warning is annoying

2018-03-13 Thread Yuxuan Shui via Digitalmars-d
See this simple example: int staticFind(T, S...)() { foreach(id, R; S) { if (is(T == R)) return id; } } return -1; } staticFind!(int, int, double) will generate a 'statement is unreachable' warning, and staticFind!(int, double) won't. This behaviour is

Re: How to stringify a template instantiation expression?

2018-03-02 Thread Yuxuan Shui via Digitalmars-d
On Thursday, 1 March 2018 at 17:48:02 UTC, Simen Kjærås wrote: On Thursday, 1 March 2018 at 16:46:30 UTC, Yuxuan Shui wrote: [...] string TemplateStringOf(T...)() if (T.length == 1) { import std.traits : TemplateOf, TemplateArgsOf; import std.meta : AliasSeq, staticMap; import

Re: How to stringify a template instantiation expression?

2018-03-01 Thread Yuxuan Shui via Digitalmars-d
On Thursday, 1 March 2018 at 16:46:30 UTC, Yuxuan Shui wrote: On Wednesday, 28 February 2018 at 15:49:25 UTC, aliak wrote: On Wednesday, 28 February 2018 at 15:09:56 UTC, Yuxuan Shui wrote: For a template instantiation expression like A!(B, C!(D, E)), I want to get a string "A!(B, C!(D, E))",

Re: How to stringify a template instantiation expression?

2018-03-01 Thread Yuxuan Shui via Digitalmars-d
On Wednesday, 28 February 2018 at 15:49:25 UTC, aliak wrote: On Wednesday, 28 February 2018 at 15:09:56 UTC, Yuxuan Shui wrote: For a template instantiation expression like A!(B, C!(D, E)), I want to get a string "A!(B, C!(D, E))", better if A, B, C, D, E is replaced by fully qualified name.

How to stringify a template instantiation expression?

2018-02-28 Thread Yuxuan Shui via Digitalmars-d
For a template instantiation expression like A!(B, C!(D, E)), I want to get a string "A!(B, C!(D, E))", better if A, B, C, D, E is replaced by fully qualified name. Is this possible?

Re: What does rt/sections_elf_shared.d do? (Porting dmd to musl)

2017-12-17 Thread Yuxuan Shui via Digitalmars-d
On Sunday, 17 December 2017 at 12:45:58 UTC, Yuxuan Shui wrote: However, going through sections_elf_shared.d, it makes me feel it's doing some magic tricks with dl functions, but I don't know what for? Looks like it's also repeating some work that is already done by the dynamic linker...

What does rt/sections_elf_shared.d do? (Porting dmd to musl)

2017-12-17 Thread Yuxuan Shui via Digitalmars-d
I'm trying to get dmd and phobos working with musl. Right now I have a bootstrapped compiler built with musl, which seems to work fine. However user applications will segmentation fault before even reaches main. I investigated a bit. Looks like musl is not happy with how druntime uses dlopen

Re: Supporting musl libc

2017-12-11 Thread Yuxuan Shui via Digitalmars-d
On Tuesday, 17 May 2016 at 08:51:01 UTC, Jacob Carlborg wrote: As an alternative to glibc there's a C standard library called musl [1]. This is the C standard library used by ELLCC [2], a cross-compiler based on Clang. This cross-compiler makes it very easy to target other platforms and can be

Re: Proposal: Support for objects in switch statements

2017-10-31 Thread Yuxuan Shui via Digitalmars-d
On Wednesday, 1 November 2017 at 01:16:32 UTC, solidstate1991 wrote: After I started to alter my graphics engine to use the multiple kinds of bitmaps (now using multiple language features, like templates and aliases) on one layer, I noticed that type detection of bitmap objects would be easier

Re: -betterC and extern(C++) classes

2017-09-10 Thread Yuxuan Shui via Digitalmars-d
On Sunday, 10 September 2017 at 14:42:42 UTC, Moritz Maxeiner wrote: On Sunday, 10 September 2017 at 14:04:20 UTC, rikki cattermole wrote: On 10/09/2017 2:19 PM, Moritz Maxeiner wrote: If TypeInfo for extern(C++) classes is removed, couldn't final extern(C++) classes without base class and

Re: -betterC and extern(C++) classes

2017-09-10 Thread Yuxuan Shui via Digitalmars-d
By the way, can we dynamic_cast extern(C++) classes in C++? If not, what are we generating these TypeInfo_Class for?

Re: -betterC and extern(C++) classes

2017-09-10 Thread Yuxuan Shui via Digitalmars-d
On Sunday, 10 September 2017 at 09:31:55 UTC, Walter Bright wrote: On 9/10/2017 1:40 AM, Yuxuan Shui wrote: I was experimenting with -betterC and found out that C++ classes doesn't work. Because the resulting object file needs a symbol "_D14TypeInfo_Class6__vtblZ" which is in druntime. I

-betterC and extern(C++) classes

2017-09-10 Thread Yuxuan Shui via Digitalmars-d
I was experimenting with -betterC and found out that C++ classes doesn't work. Because the resulting object file needs a symbol "_D14TypeInfo_Class6__vtblZ" which is in druntime. I suppose this is to support T.classinfo? Could we remove T.classinfo and make classes work under -betterC? Or is

Re: Release D 2.076.0

2017-09-01 Thread Yuxuan Shui via Digitalmars-d-announce
On Friday, 1 September 2017 at 14:03:26 UTC, Martin Nowak wrote: Glad to announce D 2.076.0. This release comes with static foreach, many -betterC enhancements, various phobos additions, an -mcpu=avx2 switch, and lots of bugfixes. Thanks to everyone involved in this .

Re: Dynamic array leak?

2017-08-11 Thread Yuxuan Shui via Digitalmars-d
On Friday, 11 August 2017 at 18:44:56 UTC, bitwise wrote: struct S { static int count = 0; this(int x) { ++count; } this(this) { ++count; } ~this() { --count; } } int main(string[] argv) { S[] x = [S(1), S(1)]; writeln("GC allocated: ", (GC.addrOf(x.ptr) !is null));

Re: [OT] Generative C++

2017-08-03 Thread Yuxuan Shui via Digitalmars-d
On Tuesday, 1 August 2017 at 22:06:28 UTC, Walter Bright wrote: On 7/31/2017 5:41 AM, Joakim wrote: If he's right that C++ use is so balkanized, this will simplify some code but further balkanize the language. That might be worth it for them, but rather than simplifying the language, it

[OT] Generative C++

2017-07-28 Thread Yuxuan Shui via Digitalmars-d
Someone made an interesting proposal to C++: https://herbsutter.files.wordpress.com/2017/07/p0707r1.pdf Thoughts?

Re: proposed @noreturn attribute

2017-07-20 Thread Yuxuan Shui via Digitalmars-d
On Wednesday, 19 July 2017 at 10:35:37 UTC, Stefan Koch wrote: On Wednesday, 19 July 2017 at 10:24:35 UTC, Marc Schütz wrote: On Sunday, 16 July 2017 at 20:44:13 UTC, Andrei Alexandrescu wrote: Perhaps we go the inverse route and define the bottom type as typeof(*null). Would that simplify

Re: proposed @noreturn attribute

2017-07-18 Thread Yuxuan Shui via Digitalmars-d
On Tuesday, 18 July 2017 at 15:26:59 UTC, Timon Gehr wrote: On 18.07.2017 14:19, Stefan Koch wrote: [...] D has a C-inspired first-order type system, so it is not necessarily crucial to have it in D. (The reason I got involved in this thread is that it was proposed to add Bottom as a type

Re: Question on @nothrow

2017-07-05 Thread Yuxuan Shui via Digitalmars-d-learn
On Wednesday, 31 May 2017 at 09:31:48 UTC, Jonathan M Davis wrote: On Wednesday, May 31, 2017 08:18:07 Vasileios Anagnostopoulos via Digitalmars-d-learn wrote: [...] Well, if you're not doing checked exceptions, the interesting question is really what _doesn't_ throw rather than what

Re: Question on @nothrow

2017-07-05 Thread Yuxuan Shui via Digitalmars-d-learn
On Wednesday, 31 May 2017 at 08:18:07 UTC, Vasileios Anagnostopoulos wrote: Hi, after reading various articles bout the "supposed" drawbacks of checked exceptions I started to have questions on @nothrow. Why there exists and not a @throws annotation enforced by the compiler? I understand

Re: C++17 cannot beat D surely

2017-06-06 Thread Yuxuan Shui via Digitalmars-d
On Sunday, 4 June 2017 at 04:39:21 UTC, Adam D. Ruppe wrote: On Sunday, 4 June 2017 at 04:34:44 UTC, Mike Parker wrote: I would not have expected enum b = sort(a) to trigger an allocation. auto b, yes, of course (and the disassembly from that is not much different). So I'd love to see a blog

Re: How to move append to an array?

2017-05-15 Thread Yuxuan Shui via Digitalmars-d-learn
On Tuesday, 16 May 2017 at 01:34:50 UTC, Stanislav Blinov wrote: On Tuesday, 16 May 2017 at 01:22:49 UTC, Yuxuan Shui wrote: Can I expand an array with uninitialized object? Or can I rely on the compiler to optimize the initialization away? Built-in arrays always default-initialize their

Re: How to move append to an array?

2017-05-15 Thread Yuxuan Shui via Digitalmars-d-learn
On Monday, 15 May 2017 at 23:36:06 UTC, Stanislav Blinov wrote: On Monday, 15 May 2017 at 21:38:52 UTC, Yuxuan Shui wrote: Suppose I have a struct A { @disable this(this); } x; How do I append it into an array? Do I have to do array.length++; moveEmplace(x, array[$-1]); ? moveEmplace

How to move append to an array?

2017-05-15 Thread Yuxuan Shui via Digitalmars-d-learn
Suppose I have a struct A { @disable this(this); } x; How do I append it into an array? Do I have to do array.length++; moveEmplace(x, array[$-1]); ?

code.demangle can't demangle a type.

2017-05-13 Thread Yuxuan Shui via Digitalmars-d-learn
So in this document: http://yshui.gitlab.io/sdpc/sdpc/parsers/whitespace.html Part of the type name is still mangled. I found ddox use core.demangle.demangleType internally. So I guess code.demangle is following behind dmd? Is there a better way to demangle a name?

Re: weird empty string

2017-05-12 Thread Yuxuan Shui via Digitalmars-d
On Saturday, 13 May 2017 at 00:59:14 UTC, Stanislav Blinov wrote: On Saturday, 13 May 2017 at 00:36:55 UTC, mogu wrote: ```d if (null) "1".writeln; if ("") "2".writeln; if ("" == null) "3".writeln; ``` Output: 2 3 How to understand this? Boolean conversion on an array works on

Turn .opApply into ranges

2017-05-09 Thread Yuxuan Shui via Digitalmars-d
I wondered if I can turn struct that defines opApply into ranges. And it turns out to be surprisingly easy: https://gist.github.com/yshui/716cfe987c89997760cabc2c951ca430 Maybe we can phase out opApply support in foreach? ;) BTW, is there a way to get the "element type" from .opApply?

Re: Working code in an upcoming PR by Timon Gehr

2017-05-09 Thread Yuxuan Shui via Digitalmars-d-announce
On Tuesday, 9 May 2017 at 13:19:09 UTC, Timon Gehr wrote: On 07.05.2017 19:03, Stanislav Blinov wrote: On Sunday, 7 May 2017 at 16:57:58 UTC, Andrei Alexandrescu wrote: [...] I see only unsurprising Jpeg artifacts and not much more :) It's too low resolution to make anything out. It's

Local pointer escape under current DIP1000 implementation

2017-05-05 Thread Yuxuan Shui via Digitalmars-d
Code: @safe auto id(scope int *p) { int*[] a; a ~= p; return a; } @safe int *bar() { int i; return id()[0]; //pointer to local escaped } Compiles with -dip1000

Re: Function names and lambdas

2017-04-07 Thread Yuxuan Shui via Digitalmars-d-learn
On Thursday, 6 April 2017 at 18:45:26 UTC, Ali Çehreli wrote: On 04/06/2017 11:37 AM, Russel Winder via Digitalmars-d-learn wrote: [...] I think it's just a design choice. C implicitly converts the name of the function to a pointer to that function. D requires the explicit & operator:

Re: CTFE Status 2

2017-04-05 Thread Yuxuan Shui via Digitalmars-d
On Wednesday, 5 April 2017 at 16:06:39 UTC, H. S. Teoh wrote: On Wed, Apr 05, 2017 at 11:20:28AM +, Yuxuan Shui via Digitalmars-d wrote: [...] Did you read the entire article? There is an entire section dedicated to interleaving of CTFE and templates. And no, you still cannot run CTFE

Re: CTFE Status 2

2017-04-05 Thread Yuxuan Shui via Digitalmars-d
On Sunday, 2 April 2017 at 04:34:34 UTC, H. S. Teoh wrote: On Sat, Apr 01, 2017 at 05:06:14PM +, Inquie via Digitalmars-d wrote: [...] How far off until newCTFE is usable to compile the majority of templates out there? CTFE and templates are two separate things. You may want to read this

Re: Of the use of unpredictableSeed

2017-03-26 Thread Yuxuan Shui via Digitalmars-d
On Sunday, 26 March 2017 at 17:55:20 UTC, Nick Sabalausky (Abscissa) wrote: 2. Maybe the std.random docs need to be more clear, right up top, that it's not for anything security-related. Agreed. Like what Python did here: https://docs.python.org/3/library/random.html

Re: Comparing two AliasSeq

2017-03-24 Thread Yuxuan Shui via Digitalmars-d-learn
On Saturday, 25 March 2017 at 05:20:44 UTC, Jonathan M Davis wrote: On Saturday, March 25, 2017 04:57:26 Yuxuan Shui via Digitalmars-d-learn wrote: [...] An AliasSeq isn't really ever a type. AliasSeq!(int, float) is a list of types, not a type itself, and is expressions supports comparing

Re: Comparing two AliasSeq

2017-03-24 Thread Yuxuan Shui via Digitalmars-d-learn
On Saturday, 25 March 2017 at 04:23:31 UTC, Jonathan M Davis wrote: On Saturday, March 25, 2017 03:25:27 Yuxuan Shui via Digitalmars-d-learn wrote: In this example: import std.range; template expandRange(alias R) if (isInputRange!(typeof(R))) { static if (R.empty

Comparing two AliasSeq

2017-03-24 Thread Yuxuan Shui via Digitalmars-d-learn
In this example: import std.range; template expandRange(alias R) if (isInputRange!(typeof(R))) { static if (R.empty) alias expandRange = AliasSeq!(); else alias expandRange = AliasSeq!(R.front(), expandRange!(R.drop(1))); } /// unittest {

Re: Parameterized template value parameter

2017-03-24 Thread Yuxuan Shui via Digitalmars-d
On Friday, 24 March 2017 at 20:43:18 UTC, Dmitry Olshansky wrote: On 3/24/17 12:24 AM, Yuxuan Shui wrote: So I was trying to make my template take a value parameter, whose type is also a parameter to the template. e.g.: template A(Char[] str, Char); But dmd complains about 'Char' being

Re: sdpc - Simple/Stupid D parser combinator

2017-03-24 Thread Yuxuan Shui via Digitalmars-d-announce
On Friday, 24 March 2017 at 17:53:14 UTC, Basile B. wrote: On Thursday, 23 March 2017 at 22:55:10 UTC, Yuxuan Shui wrote: [...] Thanks for sharing this but your project is not visible! Gitlab is a bit confusing because by default repositories are private. Go to your project setting(should

Parameterized template value parameter

2017-03-23 Thread Yuxuan Shui via Digitalmars-d
So I was trying to make my template take a value parameter, whose type is also a parameter to the template. e.g.: template A(Char[] str, Char); But dmd complains about 'Char' being undefined. I have to write: template A(Char, Char[] str); Which is inconvenient, because now 'Char'

Re: sdpc - Simple/Stupid D parser combinator

2017-03-23 Thread Yuxuan Shui via Digitalmars-d-announce
BTW, ddox cleanly has some problem with this symbol: https://yshui.gitlab.io/sdpc/sdpc/parsers/skip_whitespace.html

sdpc - Simple/Stupid D parser combinator

2017-03-23 Thread Yuxuan Shui via Digitalmars-d-announce
GitLab: https://gitlab.com/yshui/sdpc Documents: https://yshui.gitlab.io/sdpc Dub: http://code.dlang.org/packages/sdpc I started this project ~1.8 years ago. It only took me a couple of weeks to write, and I learned a lot about D's template system (and its limitations) by writing it. But back

template alias parameter vs type parameter.

2017-03-22 Thread Yuxuan Shui via Digitalmars-d-learn
Hi, Is there any difference, when a type is passed into an alias parameter vs into a type parameter?

Re: Annoying thing about auto ref function template

2017-03-21 Thread Yuxuan Shui via Digitalmars-d
On Tuesday, 21 March 2017 at 01:10:38 UTC, Jonathan M Davis wrote: On Monday, March 20, 2017 22:14:37 Yuxuan Shui via Digitalmars-d wrote: On Monday, 20 March 2017 at 21:53:47 UTC, Jonathan M Davis wrote: > [...] Makes sense... OK, attempt 2: how about support implicit partial applicat

Re: Annoying thing about auto ref function template

2017-03-20 Thread Yuxuan Shui via Digitalmars-d
On Monday, 20 March 2017 at 21:53:47 UTC, Jonathan M Davis wrote: On Monday, March 20, 2017 21:37:26 Yuxuan Shui via Digitalmars-d wrote: [...] auto ref for non-templates would not be quite the same thing, and regardless, it wouldn't help any with explictly instantiating a template that had

Re: Annoying thing about auto ref function template

2017-03-20 Thread Yuxuan Shui via Digitalmars-d
On Monday, 20 March 2017 at 21:34:14 UTC, Yuxuan Shui wrote: On Monday, 20 March 2017 at 21:08:40 UTC, Jonathan M Davis wrote: [...] This is a bit tedious because it requires you creating a new function. Maybe we can create a template for that. But still, auto ref requires us to do things

Re: Annoying thing about auto ref function template

2017-03-20 Thread Yuxuan Shui via Digitalmars-d
On Monday, 20 March 2017 at 21:08:40 UTC, Jonathan M Davis wrote: On Monday, March 20, 2017 13:20:52 Jonathan M Davis via Digitalmars-d wrote: So, yes, this particular restriction can be annoying, but there is a good reason for the restriction (though the error message _is_ pretty bad), and I

Re: Annoying thing about auto ref function template

2017-03-20 Thread Yuxuan Shui via Digitalmars-d
On Monday, 20 March 2017 at 19:49:03 UTC, Yuxuan Shui wrote: And you can't do that with an auto ref template, which makes them quite annoying. BTW, the error message you get when you try to do this, is not very helpful: 'auto' can only be used as part of 'auto ref' for template function

Annoying thing about auto ref function template

2017-03-20 Thread Yuxuan Shui via Digitalmars-d
An auto ref function template should behave like a normal function template, but it doesn't. You can fully instantiate a function template by specifying all of its template parameters, but you can't do that with auto ref templates. The only way to instantiate an auto ref template is to call

We can't have alias of instantiated auto ref functions?

2017-03-18 Thread Yuxuan Shui via Digitalmars-d-learn
auto a(T)(auto ref T t) { return t; } void main() { alias tmp = a!int; import std.stdio; writeln(tmp(10)); } This gives this error message: test.d(1): Error: 'auto' can only be used as part of 'auto ref' for template function parameters Which is rather useless,

Re: DConf 2017 Schedule

2017-03-16 Thread Yuxuan Shui via Digitalmars-d-announce
On Wednesday, 15 March 2017 at 22:07:26 UTC, Bastiaan Veelo wrote: On Wednesday, 15 March 2017 at 14:06:23 UTC, Yuxuan Shui wrote: So someone already wrote a parser combinator for D? I searched code.dlang.org (1.5 years ago?), and there was none, so I wasted couple weeks writing my own

Re: DConf 2017 Schedule

2017-03-15 Thread Yuxuan Shui via Digitalmars-d-announce
On Tuesday, 14 March 2017 at 20:16:34 UTC, Ali Çehreli wrote: On 03/14/2017 09:35 AM, Moritz Maxeiner wrote: On Tuesday, 14 March 2017 at 16:12:56 UTC, Mike Parker wrote: Fresh from the D Foundation HQ, the DConf 2017 schedule [1] is now available for your perusal. If you haven't registered

  1   2   3   >