import std;
import std.range;
void main()
{
int[] a = [3, 5, 7];
foreach (i, ref ae; a.enumerate)
{
writeln(i, " ", ae);
ae = 6;
}
writeln(a);
assert(a[].equal([6, 6, 6])); // fails, a is in initial state
}
Why does the compiler allow such 'ref ae' loop,
On Tuesday, 21 May 2019 at 17:16:05 UTC, Russel Winder wrote:
Hi,
Has anyone used D to work with arbitrary length bitfields with
multiple occurences of a sub-bitfield. I am working with DVB
Sections and EIT packets are defined as bitfields with loops in
them and the header is 112 bits. The lo
On Sunday, 19 May 2019 at 23:54:27 UTC, Anonymouse wrote:
What makes it decide to collect? What triggers it?
You can try setting heapSizeFactor option to something lower than
2 to increase collection frequency:
https://github.com/dlang/druntime/blob/47b03c14a1097d28afcf22f645628ba4046377bd/sr
On Sunday, 19 May 2019 at 22:20:48 UTC, Josh wrote:
This is just more curiosity, but do you happen to know why I
have to use DList.linearRemove() instead of DList.remove()?
These two functions are separate because they differ in
complexity. remove is O(1), linearRemove on the other hand
eager
On Friday, 14 December 2018 at 21:22:05 UTC, unDEFER wrote:
So it looks like a bug, and I have reported about it:
https://issues.dlang.org/show_bug.cgi?id=19487
Not an expert, but you may wish to try GC.minimize()
(https://dlang.org/phobos/core_memory.html#.GC.minimize).
On Thursday, 13 December 2018 at 09:51:42 UTC, aliak wrote:
Ie:
struct S {
@disable this(this);
this(int i) {}
}
struct Container(T) {
T value;
this(T value) {
this.value = value;
}
}
void main() {
auto a = Container!S(S(3)); // can't do this.
}
I can build a c
On Tuesday, 20 November 2018 at 13:20:08 UTC, Stanislav Blinov
wrote:
https://dlang.org/changelog/2.083.0.html#reboot14246
Wording "object" means both classes and structs?
On Tuesday, 20 November 2018 at 13:20:08 UTC, Stanislav Blinov
wrote:
https://dlang.org/changelog/2.083.0.html#reboot14246
Nvm, found the info in the issue tracker, thank you for the link.
https://run.dlang.io/is/LdylJX
Notice no "B destructor" line in stdout.
Just got bitten by the assumption that my Buffer struct that
transactionally aquires multiple external resources in
constructor will rollback via member destructors that were
successfully completed before the throw.
Can
On Sunday, 14 October 2018 at 01:31:26 UTC, Jonathan M Davis
wrote:
Unless there's something about the implementation that's tied
to the list itself, I would think that it would make more sense
to make it a generic algorithm, then it will work with any
non-random-access range, and it avoids nee
On Monday, 1 October 2018 at 23:07:29 UTC, spikespaz wrote:
The problem with the code you have is that the callback needs
to be extern (Windows). I don't know how to do that with a
"lambda".
Neither do I actually. Apparently it is impossible.
Best I could squeeze out was this:
https://run.dlan
On Monday, 1 October 2018 at 20:27:43 UTC, spikespaz wrote:
I was hoping I could use something more akin to JavaScript's
syntax: (void* hWnd, long) => {}.
I tried this but I'm getting errors with the signature, it says
the function is a delegate and apparently Windows API can't
accept a deleg
On Monday, 16 April 2018 at 06:46:36 UTC, WhatMeForget wrote:
Another thing that had me wondering is the use of put() down
below; doesn't the append syntax (~=) give you the same exact
functionality; so why bother?
Appender also performs unicode-related conversions, so you can
append dstring
On Sunday, 1 April 2018 at 22:44:45 UTC, Jonathan M Davis wrote:
Which doesn't work in @safe code and doesn't work when you have
an rvalue as you would when passing 42. Ultimately, using
pointers ultimately either requires explicitly allocating stuff
on the heap to be able to pass rvalues, or i
On Sunday, 1 April 2018 at 22:25:45 UTC, Jonathan M Davis wrote:
How would a pointer help? Instead of doing
foo(nullable(42))
he'd have to do
foo(new int(42))
which is just one character shorter and ends up allocating on
the heap, unlike with Nullable.
- Jonathan M Davis
foo(&x);
On Sunday, 1 April 2018 at 15:54:16 UTC, Steven Schveighoffer
wrote:
I currently have a situation where I want to have a function
that accepts a parameter optionally.
I would simply use a pointer for this. Fighting D grammar seems
too much of a hassle for such simple task.
On Friday, 30 March 2018 at 20:31:35 UTC, Per Nordlöw wrote:
Is there a faster way of allocating many small class objects
such as...
maybe something like this:
import std.conv: to;
import std.stdio;
class Node {}
class StrNode : Node
{
string value;
}
void main()
{
writeln(StrNode.c
On Tuesday, 27 March 2018 at 09:27:07 UTC, Jonathan M Davis wrote:
On Tuesday, March 27, 2018 09:15:43 Boris-Barboris via Now that
DIP 1000 is being implemented, and scope is actually going to
do something for more than just delegates, it was deemed too
dangerous to have in suddenly really mean
Hello! Can someone point me to the changelong entry or maybe a
pull request, wich changed the "in" from "scope const" to
"const"? I thought the previous matter of things was pretty
natural, and current "in" is now redundant. Would be glad to read
up on this design decision.
https://docarchive
On Saturday, 10 February 2018 at 06:32:43 UTC, German Diago wrote:
The mixin line does not work. I want to generate the access to
the field. How could I achieve that?
struct Outer
{
struct Inner
{
int a;
float b;
}
Inner i;
On Saturday, 13 January 2018 at 17:58:14 UTC, Joe wrote:
...ddb. The latter perhaps has the distinction that it doesn't
use libpq, but rather implements the Postgres FE/BE protocol.
That's a bit *too* native for my taste. It means the library
maintainer has to keep up with changes to the intern
On Thursday, 22 June 2017 at 21:16:40 UTC, Ali Çehreli wrote:
And yes, there should be one destructor, which may be a no-op
if you grab its resource and set it to null.
On all compilers...
That's a relief, thank you for your help.
On Thursday, 22 June 2017 at 20:05:46 UTC, Ali Çehreli wrote:
To be complete, 'auto ref' passes lvalues by reference and
rvalues by value, which you can detect with __traits(isRef):
struct S{
}
void foo()(auto ref S s) {
static if (__traits(isRef, s)) {
pragma(msg, "lvalue");
}
On Thursday, 22 June 2017 at 19:17:13 UTC, Ali Çehreli wrote:
No time to think about the rest of the design but just to get
the code compiled, replace 'ref' with 'auto ref' like so:
Ok, looks like this indeed passes rhs by reference, thank you.
destcalls - number of times UniquePtr destructor
On Thursday, 22 June 2017 at 19:17:13 UTC, Ali Çehreli wrote:
No time to think about the rest of the design but just to get
the code compiled, replace 'ref' with 'auto ref' like so:
this(DT)(scope auto ref UniquePtr!DT rhs)
{
// ...
}
Ali
i added this static variable:
st
On Thursday, 22 June 2017 at 19:11:19 UTC, Cym13 wrote:
Here it's the programmer's fault really. You should never use
casts in normal code, cast is the ultimate switch to say "Look,
I know what I'm doing, so disable all safety, don't try to make
sense of it, and let me do my thing. If I'm telli
Hi
https://dpaste.dzfl.pl/0def4e286564
Is there a cleaner way to go than the one on the line 26? And why
is the constructor
/d475/f781.d(37): f781.UniquePtr!(A).UniquePtr.__ctor(DT)(ref
scope UniquePtr!DT rhs)
unfit for line 51?
Is it because the expression " = UniquePtr!B.make()" cannot b
On Thursday, 22 June 2017 at 13:56:29 UTC, ag0aep6g wrote:
For example, the type system guarantees that immutable data
never changes. But the compiler allows you to cast from
immutable to mutable and change the data. It's an invalid
operation, but the compiler is not expected to catch that for
On Thursday, 22 June 2017 at 09:45:09 UTC, Russel Winder wrote:
I think the term "systems programming language" contains no
actual data, so needs to be retired. In this situation it
provides no reason for conservative garbage collection.
It means the intent of language designer to let you writ
On Monday, 19 June 2017 at 06:34:49 UTC, Ali Çehreli wrote:
It's unreliable because structs are value types in D, which
means that they can be moved around freely. This is why
self-referencing structs are illegal in D.
I guess it's more like the spec states, that they can be moved
vithout not
Hello, I was trying to write some templated unique pointers.
Idea was simple: struct UniquePointer that handles underlying
pointer in RAII-style and WeakPointer struct that is spawned by
UniquePointer. Weak pointer is handled differently in my
collections, wich subscribe to the event of UniqueP
On Thursday, 8 June 2017 at 22:42:14 UTC, Boris-Barboris wrote:
1). Do I understand correctly, that there is currently no way
(aside from editing the sources of course) to efficiently
(using one underlying iteration) remove all\first element(s)
from DList based on a predicate?
Oh, sorry, I gu
Good day to you reader! I have a couple questions about Phobos:
1). Do I understand correctly, that there is currently no way
(aside from editing the sources of course) to efficiently (using
one underlying iteration) remove all\first element(s) from DList
based on a predicate? Can such operatio
Ok, sorry, look's like that was always the case in C++, so it's
too late to question it. I'll just elevate it to package, I guess.
Hi!
I have a base class in module A:
module A;
...
class GuiElement: GuiComponent
{
protected
{
GuiElement _parent;
...
}
template isGuiElement(T)
{
enum isGuiElement = is(T: GuiElement);
}
...
and derived class in module B:
module B;
...
class Div(uint dim, uint odim): G
On Sunday, 9 April 2017 at 16:44:41 UTC, ag0aep6g wrote:
Or you can make it a template value parameter [2] with type
`string[]`:
string[] sfilter(T, string[] fields)()
{
string[] result;
foreach (f; aliasSeqOf!fields)
{
/* ... loop body as you have it ... */
}
On Wednesday, 15 March 2017 at 17:27:35 UTC, ag0aep6g wrote:
Phobos has it: std.meta.aliasSeqOf "converts an input range
[...] to an
alias sequence." [1]
Woops, forgot to give the URL for that "[1]". Here it is:
http://dlang.org/phobos/std_meta.html#aliasSeqOf
Hello, I have a similar proble
37 matches
Mail list logo