On Sunday, 7 July 2024 at 14:49:52 UTC, Anonymouse wrote:
On Sunday, 7 July 2024 at 14:41:31 UTC, Andrey Zherikov wrote:
```d
import std.path;
// Error: no property `asNormaliedPath` for
`dirName("/sandbox/onlineapp.d")` of type `string`
auto p = __FILE_FULL_PATH__.dirName.asNormaliedPath;
``
On Friday, 26 April 2024 at 13:25:34 UTC, Salih Dincer wrote:
You have a 5-item data tuples as Tuple(1, 2, 3, [1, 3], 5) and
implement the sum (total = 15) with the least codes using the
sum() function of the language you are coding...
Let's start with D:
```d
import std.typecons : tuple;
im
On Sunday, 5 November 2023 at 18:36:40 UTC, Ctn-Dev wrote:
Is there a more concise way of getting the same result?
Try this:
```d
switch(range.map!(_ => (_== "Two" ? 2 : _=="One" ? 1 :
0)).fold!((a,b) => a | b)(0)) {
case 3: writeln("both"); break;
case 2: writein("only two"); break;
case 1:
On Friday, 3 November 2023 at 19:21:42 UTC, BoQsc wrote:
However I would want to try to enforce this behaviour from the
`dub.json` or `dub.sdl` file.
IMHO this is not something that should be enforced from package
build configuration, however there can be a way to configure it
on system level
On Friday, 3 November 2023 at 18:04:58 UTC, Jonathan M Davis
wrote:
- Jonathan M Davis
Thanks a lot for detailed explanation!
On Friday, 3 November 2023 at 00:52:18 UTC, H. S. Teoh wrote:
Supposedly you can do this:
/* Original: */
// pkg/mymodule.d
module mymodule;
... // code here
// main.d
import mymodule;
void main() { ... }
/* Split */
//
On Thursday, 2 November 2023 at 19:43:01 UTC, Adam D Ruppe wrote:
On Thursday, 2 November 2023 at 19:30:58 UTC, Jonathan M Davis
wrote:
The entire reason that it was added to the language was to be
able to split up existing modules without breaking code. And
it does that well.
No, it doesn't
On Tuesday, 3 October 2023 at 19:57:06 UTC, christian.koestlin
wrote:
On Tuesday, 3 October 2023 at 01:55:43 UTC, Andrey Zherikov
wrote:
On Monday, 2 October 2023 at 18:46:14 UTC, christian.koestlin
wrote:
[...]
Slightly improved:
```d
import std;
[...]
Thanks .. the thing with ref result
On Monday, 2 October 2023 at 18:46:14 UTC, christian.koestlin
wrote:
On Monday, 2 October 2023 at 02:47:37 UTC, Joel wrote:
How can I improve this code? Like avoiding using foreach.
You could fold into a hash that counts the occurrences like
that:
```d
import std.uni : toLower;
import std.a
On Sunday, 11 December 2022 at 16:24:30 UTC, Ali Çehreli wrote:
On 12/11/22 05:54, Salih Dincer wrote:
> On Sunday, 11 December 2022 at 09:43:34 UTC, Andrey Zherikov
wrote:
>> Note that callback parameter must be compile-time parameter
as it
>> represents a member of a type during introspection d
I have this (very simplified) code:
```d
void foo(alias callback)()
{
callback!5;
}
static void print(int i)() { writeln(i); }
foo!print;
```
Is there a way to merge two last lines into one of a form like
`foo!(...something...)`?
Note that callback parameter must be compile-time parameter
On Saturday, 19 November 2022 at 10:17:19 UTC, []() {}() wrote:
On Saturday, 19 November 2022 at 09:51:09 UTC, []() {}() wrote:
...
no. in C# it breaks ABI. that is why its not acceptable in my
team.
of course that's not the reason we don't use public member
variables in classes.
the rea
On Saturday, 19 November 2022 at 09:49:18 UTC, thebluepandabear
wrote:
I am too dumb to know what ABI is
https://en.wikipedia.org/wiki/Application_binary_interface
On Saturday, 19 November 2022 at 09:51:09 UTC, []() {}() wrote:
no. in C# it breaks ABI. that is why its not acceptable in my
team.
Every company works differently. Yours are using .net and (I
guess) ships dlls so you must care about ABI with existing
software. In my company we use static lin
On Saturday, 19 November 2022 at 09:12:26 UTC, thebluepandabear
wrote:
That's the point many people have given here which is not
convincing him, even though it is quite great.
I think we all know the answer here 😂
IMHO you are both right :)
You are speaking about API compatibility, `[]() {}()
On Saturday, 19 November 2022 at 09:12:26 UTC, thebluepandabear
wrote:
That's the point many people have given here which is not
convincing him, even though it is quite great.
I think we all know the answer here 😂
IMHO you are both right :)
You are speaking about API compatibility, `[]() {}()
On Saturday, 19 November 2022 at 09:05:42 UTC, []() {}() wrote:
Once you refactor your class (creating actual private member
variables and creating getter/setter methods, you are almost
certainly going to break binary compatability, and when you
send your update compiler library to your custome
On Saturday, 19 November 2022 at 04:13:33 UTC, []() {}() wrote:
oh. so i get it now. you have to refactor your class (change
member variable names and also do it in all places where they
are used througout the class. then add new methods, overloading
them in this way and that way, all because y
On Saturday, 12 November 2022 at 10:02:12 UTC, confuzzled wrote:
Why would I have to search for libcrypto, libminizip, libexpat,
and more that I haven't even figured out what library they are?
I thought those dependencies would already be linked into
libxlsxio_read.a which is a statically linke
On Wednesday, 26 October 2022 at 04:40:17 UTC, Salih Dincer wrote:
On Tuesday, 25 October 2022 at 13:51:30 UTC, Andrey Zherikov
wrote:
Does the second piece of code shows a bug or my expectation is
not correct (and why if so)?
As a result, if this is a bug, Andrey has the right to report
it.
On Tuesday, 25 October 2022 at 14:53:50 UTC, Adam D Ruppe wrote:
On Tuesday, 25 October 2022 at 13:51:30 UTC, Andrey Zherikov
wrote:
A[] a = [A.init];
This is a problem - this is referring to a static array
instance, shared across all copies of B. You almost certainly
don't want this.
On Tuesday, 25 October 2022 at 14:53:50 UTC, Adam D Ruppe wrote:
But just don't do this. Only basic values and immutable strings
are good to initialize this way. With the array or class
objects, you're liable to get some shared thing.
If you change this to be initialized in a constructor (whic
I have the following types (simplified version of my code):
```d
struct A
{
int[] i;
}
struct B
{
A[] a = [A.init];
}
```
This code:
```d
auto b1 = B.init;
b1.a[0].i ~= 1;
b1.a ~= A.init;
b1.a[0].i ~= 11;
b1.a[1].i ~= 12;
b1.writeln;
auto b2 = B();
b2.writ
On Sunday, 23 October 2022 at 20:12:46 UTC, Hipreme wrote:
This will greatly reduce the number of import and dependencies
you need if you ever need to distribute a library.
Could you elaborate more on the benefit? Does it reduce
compilation time for dependency? If so then how much?
On Monday, 3 October 2022 at 18:09:05 UTC, Fausto wrote:
Hello all,
I am trying to rotate left an array.
I found a very basic way, and I am not sure if there is
something clever than this :) maybe using slices...
the external for represents how many times you are rotating (in
this case 2).
I
On Saturday, 10 September 2022 at 10:39:12 UTC, Injeckt wrote:
server.d(29): Error: function `server.WndProc(void* hwnd, uint
message, uint wParam, int lParam)` is not callable using
argument types `()`
I think you need to get address of a function:
```d
wndclass.lpfnWndProc = &WndProc;
```
On Friday, 9 September 2022 at 15:22:30 UTC, Ali Çehreli wrote:
I added and removed '&& false' to every 'static assert'
condition manually one by one. :/
It's not CI-friendly :(
Perhaps a new compiler switch can compile every 'static assert'
with an automatic 'false' and dump all their text t
I have bunch of `static assert(, )` in my
code and would like to validate that specific code triggers
specific assert by checking what `` is thrown.
Right now I do `static assert(!__traits(compiles, {
}));` but since `` might not compile due to many
different reasons, I might not be testing
On Monday, 22 August 2022 at 17:40:59 UTC, Andrey Zherikov wrote:
I'm providing a struct (`U` in examples above) with some API
and I'm looking for this struct as an UDA (through
`hasUDA`/`getUDAs`). And actually I already have a mix of
member-functions and free-functions in my API so it's gonna
On Monday, 22 August 2022 at 16:42:50 UTC, Paul Backus wrote:
It's probably not worth completely changing your API design
just to work around this issue. Also, even if you do this, it
is still possible for a user to run into a same problem with a
member function of one of their own types; for e
On Monday, 22 August 2022 at 15:20:46 UTC, Paul Backus wrote:
On Monday, 22 August 2022 at 14:43:24 UTC, Andrey Zherikov
wrote:
But the question is still opened: why is `typeof(U().func!0)`
not the same as `typeof(U().func!0())`?
Probably because if it were the same, it would be completely
im
On Monday, 22 August 2022 at 15:15:22 UTC, Paul Backus wrote:
My first instinct is to say that this is the user's mistake.
UDAs are not evaluated like normal expressions, and anyone
using UDAs is going to have to learn that sooner or later.
My feeling was that UDA expression is just an express
But the question is still opened: why is `typeof(U().func!0)` not
the same as `typeof(U().func!0())`?
There is also inconsistency within UFCS - type depends on whether
function is a member or standalone (even if I replace `auto ref`
with `ref U`):
```d
struct U
{
ref U func(int i)() { ret
On Monday, 22 August 2022 at 12:04:09 UTC, Paul Backus wrote:
On Monday, 22 August 2022 at 11:24:59 UTC, Andrey Zherikov
wrote:
On Monday, 22 August 2022 at 06:01:11 UTC, JG wrote:
Why not just change to:
alias type = typeof(U().func!0());
This is user's code and `U().func!0` is legit syntax.
On Monday, 22 August 2022 at 06:01:11 UTC, JG wrote:
Why not just change to:
alias type = typeof(U().func!0());
This is user's code and `U().func!0` is legit syntax.
On Monday, 22 August 2022 at 05:25:50 UTC, Ali Çehreli wrote:
This is where the @property keyword makes a difference:
@property auto ref func(int i)() { return this; }
Now U().func!0 will be a call in your expression.
Is original `U().func!0` not a call?
But I think std.traits.ReturnType
I have this simple code:
```d
struct U
{
auto ref func(int i)() { return this; }
}
void main()
{
{
alias type = typeof(U().func!0);
pragma(msg, type); // pure nothrow @nogc ref @safe U()
return
pragma(msg, is(type : U)); // false
auto u = U().func!0;
On Wednesday, 10 August 2022 at 14:08:59 UTC, pascal111 wrote:
This version has modern features, it's 1) functional 2)
goto-less.
There is nothing modern ;-D
On Wednesday, 10 August 2022 at 13:34:53 UTC, pascal111 wrote:
So, the program will be like this:
Is this clearer?
```d
import std.stdio;
import std.algorithm;
import std.range;
double getNumber()
{
double x;
write("Enter a number: ");
readf(" %s\n", &x);
writeln;
retur
On Monday, 1 August 2022 at 23:35:13 UTC, pascal111 wrote:
I think this line needs explanation:
'''D
return FilterResult!(unaryFun!predicate, Range)(range);
'''
Create an object of type `FilterResult!(unaryFun!predicate,
Range)` by passing `range` to its ctor, then return that object.
On Monday, 1 August 2022 at 14:15:31 UTC, pascal111 wrote:
We all know the strange syntax of lambda function within filter
algorithm like "auto r = chain(a, b).filter!(a => a > 0);".
TBH I don't find lambda syntax strange - it's pretty nice and
there are two forms (unlike in C++): short one (`
On Friday, 29 July 2022 at 22:16:26 UTC, H. S. Teoh wrote:
This totally makes sense. Thanks for explanation!
On Friday, 29 July 2022 at 22:09:47 UTC, pascal111 wrote:
I next code, we have a data type problem
"54.among(to!uint[10](y)).writeln;":
module main;
import std.stdio;
import std.string;
import std.conv;
import dcollect;
import std.math;
import std.algorithm;
int main(string[] args)
{
In the example below `func` changes its `const*` argument. Does
this violates D's constness?
```d
import std;
struct S
{
string s;
void delegate(string s) update;
}
void func(const S* s)
{
writeln(*s);
s.update("func");
writeln(*s);
}
void main()
{
auto s = S("test");
On Wednesday, 15 June 2022 at 16:53:13 UTC, mw wrote:
Create a simple test case, file bug at:
https://issues.dlang.org/
I tried. No luck.
On Wednesday, 15 June 2022 at 09:24:35 UTC, Dukc wrote:
Now when I think of it, perhaps the fact that private
`printHelp` has the same name as the public `printHelp` is
somehow confusing dmd. If you try to rename the private
`printHelp` and it's call in the public one to something else,
you mi
On Wednesday, 15 June 2022 at 09:21:28 UTC, user1234 wrote:
On Tuesday, 14 June 2022 at 13:39:12 UTC, Andrey Zherikov wrote:
I have [pretty simple code in my
library](https://github.com/andrey-
[Line (2)
produces](https://github.com/andrey-zherikov/argparse/runs/6880350900?check_suite_focus=tru
On Wednesday, 15 June 2022 at 07:38:36 UTC, JG wrote:
I tried to reproduce it but wasn't able (I guess it is some
interplay with the rest of your code):
I tried this first but got the same result as you. I think my
small library overheats DMD's template engine.
On Tuesday, 14 June 2022 at 21:44:48 UTC, Dukc wrote:
No idea. The functions seems indeed to be exactly the same, so
I assume this is a DMD bug. It cannot be a bug in
`std.sumtype`, since that would trigger in both of the
templates.
This definitely triggers some bug in DMD because this `priva
I have [pretty simple code in my
library](https://github.com/andrey-zherikov/argparse/blob/bug/source/argparse/help.d#L27-L47):
```d
alias CC = SumType!(AA,BB);
struct AA {}
struct BB
{
CC[] c;
}
private void ppp(T, Output)(auto ref Output output, in
CommandArguments!T cmd, in Config config
On Tuesday, 31 May 2022 at 23:15:24 UTC, Andrey Zherikov wrote:
On Tuesday, 31 May 2022 at 21:53:17 UTC, Paul Backus wrote:
If you want compile-time polymorphism, three's no other way.
Yes, I want compile-time polymorphism.
In case if `S.doSomething` is NOT template function then the
proble
On Tuesday, 31 May 2022 at 22:34:41 UTC, Christian Köstlin wrote:
Would it help to not create the delegate in R's constructor,
but feed
the delegate into it (and create the delegate outside). This
would also resemble your description (R is a delegate holder)
more.
That's possible but the prob
On Tuesday, 31 May 2022 at 21:53:17 UTC, Paul Backus wrote:
If you want compile-time polymorphism, three's no other way.
Yes, I want compile-time polymorphism.
```d
import std.stdio;
struct S
{
// function that should be called from delegate
void doSomething(T)(T value) { value.write
I have tightly coupled code which I'd like to decouple but I'm a
bit stuck.
For simplicity, I reduced the amount of code to something simple
to understand. So I have a struct `S` that has templated member
function that does something. On the other side I have delegate
holder `R` - this delegate
On Tuesday, 24 May 2022 at 22:51:50 UTC, Adam Ruppe wrote:
On Tuesday, 24 May 2022 at 22:46:55 UTC, Andrey Zherikov wrote:
return S(s);
return S(s.dup);
The variadic lives in a temporary array that expires at the end
of the function. So copying it out to the GC lets it live on.
Yo
How to fix this?
```d
struct S
{
string[] s;
}
auto foo(string[] s...) // Error: typesafe variadic function
parameter `s` of type `string[]` cannot be marked `return`
{
return S(s);
}
void main()
{
import std.stdio: writeln;
writeln(foo("Hello D"));
}
```
Th
On Friday, 29 April 2022 at 12:05:35 UTC, Dennis wrote:
On Friday, 29 April 2022 at 11:30:49 UTC, Andrey Zherikov wrote:
Is it a compiler issue so this shouldn't be allowed?
Members called `init` are in the process of being deprecated,
see:
https://github.com/dlang/dmd/pull/12512
That's n
Seems compiler allows custom nested type with `init` name:
```d
struct T
{
struct init {}
int b = 2;
}
void main()
{
T t;
writeln(t);// T(2)
//writeln(T.init); // Error: cannot pass type `init` as a
function argument
}
```
Is it a compiler issue so this shouldn't
On Tuesday, 19 April 2022 at 20:29:01 UTC, Steven Schveighoffer
wrote:
You can work around the dual context, if you are OK with
passing the second context explicitly.
The easiest way is to move the member function to a UFCS
function. an example:
```d
struct X
{
int x;
void applyToX(ali
On Tuesday, 19 April 2022 at 19:07:37 UTC, Ali Çehreli wrote:
On 4/19/22 11:18, Andrey Zherikov wrote:
> Is there a way/workaround to achieve the desired behavior?
Can you describe the goal a little more. For example, I assume
you really need a more useful lambda although the example you
show
I get the same error even with just `struct`:
```d
struct S
{
static void f_new(alias func)()
{
func();
}
}
void f_new(alias func)()
{
func();
}
void f(FUNC)(FUNC func)
{
f_new!(() => func()); // works
// S.f_new!(() => func()); // doesn't work
}
```
On Tuesday, 19 April 2022 at 18:18:26 UTC, Andrey Zherikov wrote:
Is there a way/workaround to achieve the desired behavior?
Those two bugs pointed above were reported in 2017 and 2011 (!)
which makes me think that they won't be fixed any time soon
(I'm not sure that they are actually the same
On Tuesday, 19 April 2022 at 16:38:42 UTC, Steven Schveighoffer
wrote:
On 4/19/22 11:46 AM, Paul Backus wrote:
If you remove `static` from `f_new`, you get an error message
talking about this explicitly:
Interesting that `static` does anything there, since it's a
no-op.
-Steve
I put `stat
I want to migrate my library API from standalone function that
takes delegate as argument to a template member function that
takes delegate as a template parameter but compiler errors out.
Here is code example:
```d
import std.stdio;
template T(P)
{
static void f_new(alias func)()
{
On Wednesday, 30 March 2022 at 04:15:24 UTC, Paul Backus wrote:
Probably the easiest way is to split it into two functions
```d
void f()
{
version (foo)
fVersionFoo();
else
fDefault();
}
void fVersionFoo()
{
/* ... */
}
void fDefault()
{
/* ... */
}
```
Then yo
On Tuesday, 29 March 2022 at 20:20:46 UTC, Steven Schveighoffer
wrote:
So keep in mind that versions are *module-wide*, and usually
*compilation-wide*. Which means that you won't be testing
multiple version configurations in the same build.
...
In the case where version is going to *affect th
I have a function below (just an example). What's the recommended
way to unit-test it for all `version` cases?
```d
void f()
{
import std.stdio: writeln;
version(foo)
writeln("foo");
else
writeln("no foo");
}
```
On Friday, 11 March 2022 at 12:53:56 UTC, Adam D Ruppe wrote:
On Friday, 11 March 2022 at 12:01:27 UTC, Andrey Zherikov wrote:
There is some inconsistency between templates and template
functions as this works as I want to:
Yeah, functions have the special feature of implicit
instantiation fr
There is some inconsistency between templates and template
functions as this works as I want to:
```d
import std.stdio;
void f(int i=3)()
{
writeln(i);
}
void main()
{
f!1; // 1
f!(); // 3
f;// 3
}
```
On Friday, 11 March 2022 at 07:06:15 UTC, bauss wrote:
Create an alias for T!() is the best you can do.
Ex.
```
alias t = T!();
```
There isn't really any better method as far as I know.
I'd like to preserve the name (`t` != `T`) but `alias T = T!()`
gives me `Error: declaration `T` is alre
I have simple template:
```d
template T(int i=3)
{
mixin template M(int m)
{
enum t = i;
}
}
{
mixin T!1.M!1;
pragma(msg, t); // 1
}
{
mixin T!().M!1;
pragma(msg, t); // 3
}
{
mixin T.M!1; // Error: identifier `M` of `T.M` is not
On Friday, 25 February 2022 at 16:24:46 UTC, Paul Backus wrote:
On Friday, 25 February 2022 at 14:25:22 UTC, Andrey Zherikov
wrote:
Another interesting observation - is there any explanation why
`typeof` returns different results for generated `opAssign`?
[...]
If I move `foreach` loop into
On Friday, 25 February 2022 at 05:25:14 UTC, Ali Çehreli wrote:
On 2/24/22 20:44, Andrey Zherikov wrote:
How can I check that `opAssign` is generated by compiler and
doesn't exist in the original code?
I think this one:
https://dlang.org/phobos/std_traits.html#hasElaborateAssign
Ali
Thi
This code
```d
import std.sumtype: SumType;
struct A
{
SumType!int b;
}
static foreach(sym; __traits(allMembers, A))
pragma(msg,sym);
```
prints
```
b
opAssign
```
How can I check that `opAssign` is generated by compiler and
doesn't exist in the original code?
On Sunday, 20 February 2022 at 11:08:55 UTC, partypooper wrote:
Hello, I'm new to D.
Title is self described, is it possible to use keyword as
struct field?
Maybe it is XYproblem, so here I will describe a little what I
need.
I'm parsing some json currently with
[mir-ion](https://code.dlang
On Thursday, 17 February 2022 at 20:59:43 UTC, Andrey Zherikov
wrote:
Another question: does `auto foo(ARGS...)(ARGS args) { return
a.foo(args); }` correctly forward `ref`, `const` etc. arguments?
Actually the answer is `NO`. I have to do `auto foo(ARGS...)(auto
ref ARGS args) { return
a.foo(a
I have a struct that has struct data member and I'd like to
forward some (not all) functions from internal data member. Some
thing like this:
```d
struct A {
void foo() const { writeln("A.foo"); }
}
struct B {
A a;
auto foo(ARGS...)(ARGS args) { return a.foo(args); }
// alias f
On Thursday, 27 January 2022 at 03:19:59 UTC, Jaime wrote:
You can accomplish this by heading off the template sequence
parameter with several default template parameters. If you need
them all under one name, you can recombine them in the function
body with std.meta.AliasSeq, the effective "kin
What is the best way to emulate a default value for template
sequence parameter of a function?
I want something like this:
```d
void foo(MODULES... = __MODULE__)() {}
// these should work:
foo!(module1, module2);
foo!(module1);
foo(); // this should use current module (__MODULE__)
acc
On Wednesday, 8 December 2021 at 17:05:49 UTC, Timon Gehr wrote:
```d
import std.stdio, std.traits, core.lifetime;
auto partiallyApply(alias fun,C...)(C context){
return &new class(move(context)){
C context;
this(C context) { foreach(i,ref c;this.context)
c=move(context[i]);
On Tuesday, 7 December 2021 at 18:50:04 UTC, Ali Çehreli wrote:
I don't know whether the workaround works with your program but
that delegate is the equivalent of the following struct (the
struct should be faster because there is no dynamic context
allocation). Note the type of 'dg' is changed
I have a struct `A` that stores delegates. The problem is that
I'm getting "`Error: closures are not yet supported in CTFE`" if
I create an compile-time constant value of type `A`:
```d
struct A
{
void delegate()[] dg;
}
auto createDelegate(string s)
{
return { s.writeln; }; // E
On Sunday, 14 November 2021 at 16:55:24 UTC, Alexey wrote:
Remove "!"
On Sunday, 14 November 2021 at 14:41:21 UTC, Alexey wrote:
On Sunday, 14 November 2021 at 14:24:00 UTC, Andrey Zherikov
wrote:
On Sunday, 14 November 2021 at 12:01:36 UTC, Alexey wrote:
You just need two changes:
- make `threadFunc` function static: `static void threadFunc()`
- use `task` in
On Sunday, 14 November 2021 at 12:01:36 UTC, Alexey wrote:
You just need two changes:
- make `threadFunc` function static: `static void threadFunc()`
- use `task` instead of `Task`: `auto t1 = task!threadFunc;`
On Sunday, 14 November 2021 at 07:06:25 UTC, user1234 wrote:
On Sunday, 14 November 2021 at 05:12:58 UTC, Andrey Zherikov
wrote:
Here is my code:
[...]
`W()` (2) works as expected but is it possible to achieve the
same without parenthesis so `getAttributes` trait returns
`tuple(L("app.d", 16LU
Here is my code:
```d
struct L
{
string file;
size_t line;
}
auto W(string f = __FILE__,size_t l= __LINE__)()
{
return L(f,l);
}
struct A
{
@W // (1): line# 16
{
int a;
int b;
}
@W() // (2): line# 21
{
int c;
int d;
}
}
void main()
{
pragma(
On Saturday, 6 November 2021 at 13:57:47 UTC, Ali Çehreli wrote:
Have you considered std.range.indexed, which should at least
cover the case of accessing:
https://dlang.org/phobos/std_range.html#indexed
I don't need to iterate over whole collection, but subset of it.
Can you give a little
On Saturday, 6 November 2021 at 04:28:05 UTC, Ali Çehreli wrote:
On 11/5/21 5:43 PM, Andrey Zherikov wrote:
In case others want to work, here are the modules that need to
be imported:
import std.algorithm;
import std.range;
import std.stdio;
> struct A {}
> struct B
> {
> A[] ar = [A.in
On Friday, 5 November 2021 at 20:13:02 UTC, Andrey Zherikov wrote:
On Friday, 5 November 2021 at 19:49:50 UTC, Ali Çehreli wrote:
Indexes are typed as size_t, which is ulong for 64-bit and
uint for 32-bit. If idx elements were indeed indexes, it
should have been typed as size_t:
size_t[] idx
On Friday, 5 November 2021 at 19:49:50 UTC, Ali Çehreli wrote:
Indexes are typed as size_t, which is ulong for 64-bit and uint
for 32-bit. If idx elements were indeed indexes, it should have
been typed as size_t:
size_t[] idx = [1,3,4]; // <-- Here
Ah, good point. Thanks!
On Thursday, 4 November 2021 at 13:03:54 UTC, Paul Backus wrote:
On Thursday, 4 November 2021 at 11:26:30 UTC, Andrey Zherikov
wrote:
I have the following code example:
```d
struct A{}
A[5] a;
ulong[] idx = [1,3,4];
auto get()
{
return idx.map!(_ => a[_]);
}
foreach(i; 0 .. a.length)
On Thursday, 4 November 2021 at 17:09:31 UTC, Steven
Schveighoffer wrote:
D doesn't have any equivalent for this.
Is it possible to add this feature having `-C VERSION="1.2.3"`
(`-D` is already used) to be equal to `enum VERSION="1.2.3"` in
global namespace?
The closest you can get is to t
I want to embed some info from build system - version info, for
example. I can easily do this with C++ compiler by
`-DVERSION="1.2.3"` but there is no such an option in dmd. So I'm
wondering how do people workaround this?
I see only one way: generate a file and add it to the build (file
might b
On Thursday, 4 November 2021 at 13:03:54 UTC, Paul Backus wrote:
Have the lambda return by reference:
```d
auto get()
{
return idx.map!(ref (i) => a[i]);
}
```
That works, thanks!
I have the following code example:
```d
struct A{}
A[5] a;
ulong[] idx = [1,3,4];
auto get()
{
return idx.map!(_ => a[_]);
}
foreach(i; 0 .. a.length)
write(&a[i], " ");
writeln;
foreach(ref b; get())
write(&b, " ");
writeln;
```
How can I change `get` function so it returns the
On Saturday, 30 October 2021 at 00:52:23 UTC, Imperatorn wrote:
On Saturday, 30 October 2021 at 00:49:04 UTC, Stanislav Blinov
wrote:
On Friday, 29 October 2021 at 21:00:48 UTC, Steven
Schveighoffer wrote:
This is incorrect, the buckets are each heap allocated. Just
the array of bucket pointe
On Friday, 29 October 2021 at 17:58:24 UTC, Paul Backus wrote:
No, the AA does not guarantee that the value will remain in the
same location. Inserting or removing *any* keys could cause the
AA to resize, which may change the locations of all of its
values.
However, you do not have to worry a
I want to have a pointer to a value in an associative array. Does
AA guarantee that the value will remain at the same address all
the time unless I remove the corresponding key? I couldn't find
any guarantees similar to C++ iterator invalidation in D Language
Reference.
On Sunday, 9 May 2021 at 17:53:07 UTC, SealabJaster wrote:
On Sunday, 9 May 2021 at 17:37:40 UTC, Andrey Zherikov wrote:
Is this a bug?
My best guess is that, since the struct doesn't have any member
functions the compiler has decided that the struct doesn't need
any access to the main funct
1 - 100 of 160 matches
Mail list logo