Re: Is defining get/set methods for every field overkill?

2022-11-23 Thread surlymoor via Digitalmars-d-learn
On Wednesday, 23 November 2022 at 13:24:37 UTC, Tejas wrote: Please let's not repeat previous topics `private` will be enforced at module scope, for better or for worse, there has already been a [1000 post thread](https://forum.dlang.org/post/lqlllioynzfmpaozw...@forum.dlang.org) that

Re: Example for multi level template composition

2022-10-10 Thread surlymoor via Digitalmars-d-learn
On Monday, 10 October 2022 at 06:30:05 UTC, Arun wrote: Stumbled upon this question on HN https://news.ycombinator.com/item?id=33142751#33147401 This guy could have read std.meta's documentation or source, but instead makes assumptions and lazes around.

Re: Regular Templates May Be `mixin`d?

2021-10-02 Thread surlymoor via Digitalmars-d-learn
On Sunday, 3 October 2021 at 03:04:29 UTC, Paul Backus wrote: On Sunday, 3 October 2021 at 02:52:20 UTC, surlymoor wrote: This compiles and works. I checked the spec, and I don't see anything; probably missed it, however; mentioning the fact that regular templates may be used with `mixin`. Is

Regular Templates May Be `mixin`d?

2021-10-02 Thread surlymoor via Digitalmars-d-learn
```d // Modified sixth example from https://dlang.org/spec/template-mixin.html int y = 3; template Foo() { int abc() { return y; } } void main() { int y = 8; mixin Foo; // local y is picked up, not global y assert(abc() == 8); } ``` This compiles and works. I checked the

Re: Cannot Instantiate SumType

2021-09-20 Thread surlymoor via Digitalmars-d-learn
On Monday, 20 September 2021 at 15:33:23 UTC, Paul Backus wrote: On Monday, 20 September 2021 at 11:21:28 UTC, surlymoor wrote: The error in question... ``` Error: variable `std.typecons.ReplaceTypeUnless!(isSumTypeInstance, This, SumType!(Foo!(bar)), Foo!(bar)).F!(bar).replaceTemplateArgs`

Cannot Instantiate SumType

2021-09-20 Thread surlymoor via Digitalmars-d-learn
I'm experiencing an error when instantiating `SumType` with an aggregate template that itself is instantiated with a void function. In other words... ```d struct Foo(alias f) {} // As the error implies, altering it to be non-void makes everything copacetic~ void bar() {} alias S =

Re: In general, who should do more work: popFront or front?

2021-06-14 Thread surlymoor via Digitalmars-d-learn
On Tuesday, 15 June 2021 at 05:17:06 UTC, mw wrote: I think there is another convention (although it's not formally enforced, but should be) is: -- `obj.front() [should be] const`, i.e. it shouldn't modify `obj`, so can be called multiple times at any given state, and produce the same result

Re: In general, who should do more work: popFront or front?

2021-06-14 Thread surlymoor via Digitalmars-d-learn
On Tuesday, 15 June 2021 at 04:57:45 UTC, mw wrote: In English, `front` is a noun, `popFront` have a verb in it, so you know who should do more work :-) Sure, but, for example, the front method of Phobos' MapResult is the one applying the predicate to the source's front. There's a clear

Re: In general, who should do more work: popFront or front?

2021-06-14 Thread surlymoor via Digitalmars-d-learn
On Tuesday, 15 June 2021 at 04:43:38 UTC, jfondren wrote: Well, consider this program: ```d import std; struct Noisy { int[] source; int pops, fronts; bool empty() { return source.empty; } void popFront() { writeln("popFront #", ++pops); source.popFront; } int front() {

In general, who should do more work: popFront or front?

2021-06-14 Thread surlymoor via Digitalmars-d-learn
All my custom range types perform all their meaningful work in their respective popFront methods, in addition to its expected source data iteration duties. The reason I do this is because I swear I read in a github discussion that front is expected to be O(1), and the only way I can think to

Re: Can You Expand Arrays into an Argument List?

2020-05-15 Thread surlymoor via Digitalmars-d-learn
On Friday, 15 May 2020 at 19:19:59 UTC, H. S. Teoh wrote: It's possible to do it, but the called function has to support it. If that's not an option, then you're out of luck and probably have to use metaprogramming instead. Here's how to do it: int add(int[] args...) {

Can You Expand Arrays into an Argument List?

2020-05-15 Thread surlymoor via Digitalmars-d-learn
Hello, I don't often miss JS, but one particular feature that I enjoyed is the ability to expand arrays into argument lists using a unary operator. Example: add(...[1, 1]) === add(1, 1) // IIRC I've been looking in Phobos and the spec, but nothing's popped out to me. Is there a fairly