On Wednesday, 6 October 2021 at 18:29:34 UTC, Steven
Schveighoffer wrote:
```d
struct GCWrapped(T)
{
private T *_val;
this(T* val) { _val = val; }
ref T get() { return *_val; }
alias get this; // automatically unwrap
~this() { free(_val); _val = null; }
@disable this(this); // d
On Thursday, 7 October 2021 at 11:55:35 UTC, Steven Schveighoffer
wrote:
The GC is technically not required to free any blocks ever. But
in general, it does.
When it does free a struct, as long as you allocated with
`new`, it should call the dtor.
In practice when I played around with it, de
I found https://dlang.org/library/std/typecons/unique.html ,
which I think solves my problem by disabling copying. Thanks for
the help.
Sorry for messed up post, fixed it.
On Wednesday, 6 October 2021 at 18:29:34 UTC, Steven
Schveighoffer wrote:
You can return this thing and pass it around, and the GC will
keep it alive until it's not needed. Then on collection, the
value is freed.
Is the gc required to call ~this() on the s
Thanks for the help.
On Wednesday, 6 October 2021 at 18:29:34 UTC, Steven
Schveighoffer wrote:
You can return this thing and pass it around, and the GC will
keep it alive until it's not needed. Then on collection, the
value is freed.
Is the gc required to call ~this() on the struct? I remember
I interface to a C library that gives me a malloced object. How
can I manage that pointer so that it gets freed automatically.
What I've thought of so far:
* scope(exit): not an option because I want to return that memory
* struct wrapper: Doesn't work because if I pass it to another
function, t
To implement your option A you could simply use
std.range.enumerate.
Would something like this work?
import std.algorithm.iteration : map;
import std.algorithm.searching : until;
import std.range : tee;
size_t bytesConsumed;
auto result = input.map!(a => a.yourTransformation )
On Monday, 28 March 2016 at 23:06:49 UTC, Anon wrote:
Any because you're using ranges,
*And because you're using ranges,
On Monday, 28 March 2016 at 22:49:28 UTC, Jack Stouffer wrote:
On Monday, 28 March 2016 at 22:43:26 UTC, Anon wrote:
On Monday, 28 March 2016 at 22:34:31 UTC, Jack Stouffer wrote:
void main () {
import std.range.primitives;
char[] val = ['1', '0', 'h', '3', '6', 'm', '2', '8',
's'];
On Monday, 28 March 2016 at 22:34:31 UTC, Jack Stouffer wrote:
void main () {
import std.range.primitives;
char[] val = ['1', '0', 'h', '3', '6', 'm', '2', '8', 's'];
pragma(msg, ElementEncodingType!(typeof(val)));
pragma(msg, typeof(val.front));
}
prints
char
dchar
Why
On Tuesday, 8 March 2016 at 20:26:04 UTC, Yuxuan Shui wrote:
On Monday, 7 March 2016 at 16:13:45 UTC, Steven Schveighoffer
wrote:
On 3/4/16 4:30 PM, Yuxuan Shui wrote:
On Friday, 4 March 2016 at 15:18:55 UTC, Steven Schveighoffer
wrote:
[...]
Thanks for answering. But I still don't understan
On Saturday, 5 March 2016 at 14:18:31 UTC, Atila Neves wrote:
With a small number of threads, things work as intended in the
code below. But with 1000, on my machine it either crashes or
throws an exception:
import std.stdio;
import std.parallelism;
import std.range;
void main() {
stdou
On Friday, 15 January 2016 at 14:04:50 UTC, Nordlöw wrote:
What have I missed?
In line 126, `static struct Result()` is a template. Either drop
the parens there, or change the call on line 187 to
`Result!()(haystack, needles)`.
On Wednesday, 25 November 2015 at 21:26:09 UTC, Meta wrote:
On Wednesday, 25 November 2015 at 20:47:35 UTC, anonymous wrote:
Use `final switch`. Ordinary `switch`es need an explicit
default case. `final switch`es have to cover all possibilities
individually. Implicit default cases are not allow
On Friday, 3 July 2015 at 02:37:00 UTC, Paul D Anderson wrote:
The following code fails to compile and responds with the given
error message. Varying the "plusTwo" function doesn't work; as
long as there is an arithmetic operation the error occurs.
This works for me on OSX 10.10 (Yosemite) usi
On Wednesday, 29 April 2015 at 19:43:44 UTC, Laeeth Isharc wrote:
I get the following errors under LDC (this is LDC beta, but
same problem under master) although the code compiles fine
under DMD.
Am I doing something wrong?
The help generating feature of std.getopt is new in 2.067. Use
bran
On Friday, 6 March 2015 at 16:04:33 UTC, Benjamin Thaut wrote:
On Friday, 6 March 2015 at 15:36:47 UTC, anon wrote:
Hi,
I can't figure this out.
struct Pair(T)
{
T x;
T y;
alias x c;
alias y r;
}
What would like is that the x and y to be initialized to
different values depending on
Hi,
I can't figure this out.
struct Pair(T)
{
T x;
T y;
alias x c;
alias y r;
}
What would like is that the x and y to be initialized to
different values depending on type eg:
struct Container
{
Pair!double sample1; // This will initialize sample1 with 0 for
both x and y
Pa
On Thursday, 22 January 2015 at 00:16:23 UTC, bearophile wrote:
anon:
I have the following C code, how can I do the same in D.
Info **info;
info = new Info*[hl + 2];
int r;
for(r = 0; r < hl; r++)
{
info[r] = new Info[vl + 2];
}
info[r] = NULL;
I suggest you to ignore ketmar, he's n
On Wednesday, 21 January 2015 at 23:59:34 UTC, ketmar via
Digitalmars-d-learn wrote:
On Wed, 21 Jan 2015 23:50:59 +
anon via Digitalmars-d-learn
wrote:
On Wednesday, 21 January 2015 at 23:47:46 UTC, ketmar via
Digitalmars-d-learn wrote:
> On Wed, 21 Jan 2015 23:44:49 +
> an
On Wednesday, 21 January 2015 at 23:47:46 UTC, ketmar via
Digitalmars-d-learn wrote:
On Wed, 21 Jan 2015 23:44:49 +
anon via Digitalmars-d-learn
wrote:
I have the following C code, how can I do the same in D.
Info **info;
info = new Info*[hl + 2];
int r;
for(r = 0; r < hl
I have the following C code, how can I do the same in D.
Info **info;
info = new Info*[hl + 2];
int r;
for(r = 0; r < hl; r++)
{
info[r] = new Info[vl + 2];
}
info[r] = NULL;
anon
On Wednesday, 25 September 2013 at 04:35:57 UTC, lomereiter wrote:
I thought about it once but quickly abandoned the idea. The
primary reason was that D doesn't have REPL and is thus not
suitable for interactive data exploration.
https://github.com/MartinNowak/drepl
https://drepl.dawg.eu/
On Friday, 19 December 2014 at 10:41:04 UTC, bearophile wrote:
A case where the usage of ranges (UFCS chains) leads to very
bad performance:
import std.stdio: writeln;
import std.algorithm: map, join;
uint count1, count2;
const(int)[] foo1(in int[] data, in int i, in int max) {
count1++;
24 matches
Mail list logo