Exist in phobos something like Import template?
public import std.traits;
template Import(alias Module){
mixin(import ~ moduleName!Module ~ ;);
}
class C;
struct Test{
Import!(std.typecons).Rebindable!C test;//symbols
}
///Hello, i'm trying to implement d compiler and i've problems
with some template corner cases.
class Type{}
class Foo(T : const T){
alias X = T;
}
alias Bar(T : Foo!Ts, Ts...) = Ts[0];
pragma(msg, "Foo1: ", Foo!(immutable Type).X);//Foo1: Type
pragma(msg, "Foo2: ",
On Saturday, 21 May 2016 at 17:32:47 UTC, dan wrote:
Is it possible to have a class which has a variable which can
be seen from the outside, but which can only be modified from
the inside?
Something like:
class C {
int my_var = 3; // semi_const??
void do_something() { my_var = 4; }
}
On Saturday, 21 May 2016 at 18:10:55 UTC, captain_fid wrote:
Please forgive if asked before. My google skills seemed to fail
me and didn't see any result from search.
My problem is simple (though not my understanding LOL).
struct D {
int value;
bool opEquals()(bool value) const {
On Saturday, 24 September 2016 at 11:51:56 UTC, Basile B. wrote:
On Saturday, 24 September 2016 at 10:59:50 UTC, mikey wrote:
On Saturday, 24 September 2016 at 10:16:34 UTC, Basile B.
wrote:
You don't need to cast, from "mutable" to "const" is implicit:
On Thursday, 29 June 2017 at 06:40:04 UTC, Balagopal Komarath
wrote:
On Wednesday, 28 June 2017 at 12:19:31 UTC, vit wrote:
auto foo(alias F, T)(T x)
{
return x.foo();
}
With this definition foo!((x) => x+1)(3); doesn't work. Is
there a way to solve this?
You don´t need overload
On Monday, 3 July 2017 at 13:53:45 UTC, Paolo Invernizzi wrote:
I've struct like that:
struct Foo {
int a_1; float a_2; string a_3;
string b_1; double b_2;
}
I would like to transparently access that like:
foo.a.first
foo.b.second = "baz";
with an helper like:
auto a(...) { ... }
On Wednesday, 28 June 2017 at 11:49:57 UTC, Balagopal Komarath
wrote:
Shouldn't the compiler be able to resolve foo!g(3) to the first
template foo?
import std.stdio;
import std.algorithm;
import std.range;
auto foo(F, T)(T x)
{
return x.foo(F);
}
auto foo(F, T)(T x, F f)
{
return
Hello,
What's the difference between x = Nullable!Test.init and
x.nullify?
class Test{}
void test()pure nothrow{
Nullable!Test x;
x = Nullable!Test.init; //OK
x.nullify; //Error: function
'std.typecons.Nullable!(Test).Nullable.nullify!().nullify' is not
nothrow
On Saturday, 3 June 2017 at 06:19:29 UTC, Jonathan M Davis wrote:
[...]
thanks
On Sunday, 4 June 2017 at 09:04:14 UTC, Jonathan M Davis wrote:
[...]
Why Nullable!T call destroy for reference types?
On Saturday, 25 November 2017 at 09:52:01 UTC, Chirs Forest wrote:
I'd like to make a class that takes multiple template types (1
- several) which can hold an array/tuple of a second class that
are instantiated with those types.
class Bar(T) {
T bar;
}
class Foo(T[]){ // not sure how to
How to manualy declare constructor for struct Ptr which work like
Ptr.create?
struct Ptr{
int* ptr;
static Ptr create(scope return int* ptr)@safe{
Ptr x;
x.ptr = ptr;
return x;
}
/++ This doesn't work:
this(scope return int* ptr)scope @safe{
On Monday, 13 November 2017 at 12:15:26 UTC, Nathan S. wrote:
Unqual!Element seed = r.front;
alias MapType = Unqual!(typeof(mapFun(CommonElement.init)));
This looks like a job for std.typecons.Rebindable!(const A)
instead of Unqual!(const A) which is used currently. I am
surprised that
On Monday, 11 December 2017 at 20:44:06 UTC, Eugene Wissner wrote:
On Monday, 11 December 2017 at 20:40:09 UTC, vit wrote:
This code doesn't compile with -dip1000:
struct Foo{
int foo;
ref int bar(){
return foo;
}
}
Error: returning `this.foo` escapes a reference to
This code doesn't compile with -dip1000:
struct Foo{
int foo;
ref int bar(){
return foo;
}
}
Error: returning `this.foo` escapes a reference to parameter
`this`, perhaps annotate with `return`
How can be annotated this parameter with 'return ref' ?
Why is template param T != B but T == Rebindable!(const(B)) when
specialization is T : const(A)?
abstract class A{}
class B : A{}
string foo(T : const(A))(T x){
return T.stringof;
}
void main(){
import std.typecons : Rebindable;
import std.stdio : writeln;
Rebindable!(const
On Tuesday, 3 July 2018 at 02:13:21 UTC, Flaze07 wrote:
e.g A is a class that emits output during destruction
{
auto a = scoped!A();
}
how do I contain it in a container, in the Array struct ?
{
auto a = scoped!A();
Array!( typeof( a ) ) arr;
foreach( i ; 0..3 ) {
On Friday, 29 December 2017 at 21:43:25 UTC, Chris Paulson-Ellis
wrote:
On Friday, 29 December 2017 at 21:34:27 UTC, vit wrote:
use:
n = Nullable!Object.init; //doesn't call destroy
instead of:
n.nullify();
Only nullify() can make isNull return true again. I need that
semantic.
On Friday, 29 December 2017 at 20:52:51 UTC, Chris Paulson-Ellis
wrote:
I've been bitten by trying to use Nullable(T) on class types.
Minimal example...
[...]
use:
n = Nullable!Object.init; //doesn't call destroy
instead of:
n.nullify();
It's possible create something like this without errors?
void main()@nogc{ //Error: function `app.main` is `@nogc`
// yet allocates closures with the GC
import std.experimental.all;
const int j = 2;
int i = 0;
const int[3] tmp = [1, 2, 3];
tmp[]
On Sunday, 5 August 2018 at 10:57:32 UTC, Steven Schveighoffer
wrote:
On 8/5/18 5:20 AM, vit wrote:
It's possible create something like this without errors?
void main()@nogc{ //Error: function `app.main` is `@nogc`
// yet allocates closures with the GC
import
On Monday, 6 August 2018 at 19:17:58 UTC, nkm1 wrote:
On Monday, 6 August 2018 at 18:22:24 UTC, vit wrote:
Hello,
I have this struct:
struct S{
uint kind;
void[N] data_;
}
Instances of struct S are allocated by standard GC new and
S.data_ can contain pointers/ranges to GC allocated
On Monday, 6 August 2018 at 21:23:36 UTC, Paul Backus wrote:
On Monday, 6 August 2018 at 20:22:36 UTC, vit wrote:
On Monday, 6 August 2018 at 19:56:03 UTC, Steven Schveighoffer
wrote:
BTW, is there a reason you aren't just using Algebraic?
https://dlang.org/phobos/std_variant.html#.Algebraic
On Monday, 6 August 2018 at 19:56:03 UTC, Steven Schveighoffer
wrote:
BTW, is there a reason you aren't just using Algebraic?
https://dlang.org/phobos/std_variant.html#.Algebraic
-Steve
primarily visit for Algebraic isn't pure, @nogc, @safe, nothrow.
On Monday, 6 August 2018 at 20:29:29 UTC, Alexandru Ermicioi
wrote:
Hi Dlang community!
I've been playing with dip1000 and scope storage class and
stumbled upon a strange error that I can't to understand yet.
Here is minimized version of code that generates the error:
[...]
Parameter
Hello, is in phobos some function which convert float/double to
string and is pure @nogc and nothrow?
Hello,
I have this struct:
struct S{
uint kind;
void[N] data_;
}
Instances of struct S are allocated by standard GC new and
S.data_ can contain pointers/ranges to GC allocated data.
If is GC disabled then program run fine. But when is GC enabled
then it fail randomly.
If the
On Tuesday, 14 August 2018 at 14:37:33 UTC, Andrey wrote:
On Tuesday, 14 August 2018 at 14:07:23 UTC, Timoses wrote:
Here's one version:
template StringEnumValues(alias Enum)
{
import std.traits : EnumMembers;
string[] StringEnumValues()
{
string[] enumValues;
On Monday, 6 August 2018 at 18:28:11 UTC, Steven Schveighoffer
wrote:
On 8/6/18 2:22 PM, vit wrote:
Hello,
I have this struct:
struct S{
uint kind;
void[N] data_;
define "N"
}
Instances of struct S are allocated by standard GC new and
S.data_ can contain pointers/ranges to GC
On Wednesday, 8 August 2018 at 17:40:11 UTC, ketmar wrote:
vit wrote:
Hello, is in phobos some function which convert float/double
to string and is pure @nogc and nothrow?
i don't think that you can make it `pure`, but you certainly
can make it `nothrow`, `@nogc` and ctfe-able. it's
On Tuesday, 28 August 2018 at 12:28:19 UTC, Andrey wrote:
Hello,
Let we have two variadic templates:
template Qwerty(Values...) {}
template Qaz(alias type, Data...) {}
Now I want to add a constraint to "Qwerty" so that each type in
"Values" pack must be a "Qaz" template. I don't care about
On Tuesday, 28 August 2018 at 12:28:19 UTC, Andrey wrote:
Hello,
Let we have two variadic templates:
template Qwerty(Values...) {}
template Qaz(alias type, Data...) {}
Now I want to add a constraint to "Qwerty" so that each type in
"Values" pack must be a "Qaz" template. I don't care about
On Monday, 20 August 2018 at 13:22:02 UTC, Andrey wrote:
On Monday, 20 August 2018 at 13:14:14 UTC, Andrey wrote:
Mistake... this is:
static void log(bool newline = true)(string text)
{
alias print(T...) = newline ? :
_file.print(text);
text.print();
}
static void log(bool newline
On Monday, 27 August 2018 at 12:54:59 UTC, SG wrote:
On Monday, 27 August 2018 at 03:21:04 UTC, rikki cattermole
wrote:
Templates make it the easiest way, since common patterns, like
arrays, classes and pointers have the exact same null check
syntax.
I see.
That code is only for classes. C#
On Friday, 24 August 2018 at 15:18:13 UTC, Peter Alexander wrote:
Consider this code, which is used as an example only:
auto scaleAll(int[] xs, int m) {
return xs.map!(x => m * x);
}
As m is captured, the delegate for map will rightly allocate
the closure in the GC heap.
In C++, you would
On Friday, 13 July 2018 at 11:37:09 UTC, Michael wrote:
On Friday, 13 July 2018 at 11:17:32 UTC, Radu wrote:
On Friday, 13 July 2018 at 11:12:47 UTC, Michael wrote:
On Friday, 13 July 2018 at 10:52:54 UTC, Radu wrote:
On Friday, 13 July 2018 at 10:21:54 UTC, Michael wrote:
[...]
Do you try
On Wednesday, 29 August 2018 at 19:56:31 UTC, Everlast wrote:
On Tuesday, 28 August 2018 at 22:01:45 UTC, Paul Backus wrote:
[...]
One of the things that makes a good language is it's internal
syntactic consistency. This makes learning a language easier
and also makes remembering it easier.
On Thursday, 30 August 2018 at 10:41:58 UTC, Andrey wrote:
Hello,
This code doesn't print enum values:
import std.meta;
import std.traits;
import std.stdio;
enum MyEnum : string
{
First = "F_i_r_s_t",
Second = "S_e_c_o_n_d"
}
alias QW(alias arg) =
On Thursday, 5 July 2018 at 11:15:03 UTC, Timoses wrote:
Is this safe?
class A {}
immutable(A) getA()
{
A a;
// .. do stuff with a
// not leaking a to any functions
// is this safe
return cast(immutable A)a;
}
What if A is replaced with A[] or A[int]?
If it's not safe,
On Thursday, 5 July 2018 at 09:47:32 UTC, Andre Pany wrote:
Hi,
the purpose of this code is to generate CSV based on 3 double
arrays.
I wonder why map cannot directly use the result of the chunks
function.
import std.experimental.all;
void main()
{
double[] timestamps = [1.1];
On Wednesday, 4 July 2018 at 17:32:49 UTC, Robert M. Münch wrote:
I have the following C++ code and want to give the D/C++
integration a new try:
template class Array {...}
class myClass {...}
typedef Array myClassArray;
myClassArray classA::getArray() noexcept
Hello,
Is it possible to create scope wrapper initialized by non default
constructor with scope parameter?
something like this:
struct Wrapper{
int* p;
static Wrapper create(scope return int* p)@safe{
Wrapper w;
w.p = p;
return w;
}
/++ This doesn't
On Thursday, 30 August 2018 at 11:34:36 UTC, Andrey wrote:
On Thursday, 30 August 2018 at 11:09:40 UTC, vit wrote:
[...]
I want to create a reusable template for this purpose.
Why I can't use "staticMap" so that compiler it self would do
this:
[...]
Just wrap some some symbol "args" with
On Monday, 3 September 2018 at 09:09:44 UTC, Andrey wrote:
Hello,
Here is a code with comments: https://run.dlang.io/is/BNl2Up.
I don't understand how to pass lambda into template.
I get an error:
onlineapp.d(18): Error: template instance `qwerty!((i) => "arg"
~ i.to!string ~ "[0] == '?'",
On Friday, 11 December 2020 at 11:25:22 UTC, Andrey Zherikov
wrote:
Here is the example:
alias f1 = (string ) {}; f1(int .init);
alias f2 = (string s) {}; f2(int .init);
alias f3 = (int ) {}; f3(string.init);
alias f4 = (int i ) {}; f4(string.init);
"f1" case compiles
On Tuesday, 19 January 2021 at 06:49:06 UTC, Kyle Ingraham wrote:
I’m sorry that this isn’t a solution to your problem but your
code caught my attention. What is your snippet supposed to do?
This is more specific example:
https://run.dlang.io/is/W7rd2u
import std.traits : CopyTypeQualifiers;
On Sunday, 13 June 2021 at 17:18:46 UTC, ag0aep6g wrote:
On Sunday, 13 June 2021 at 16:27:18 UTC, vit wrote:
Why I can take address of Foo variable but not Bar?
```d
//-dip1000
struct Foo{
private double d;
}
struct Bar{
private void* ptr;
}
void main()@safe{
///this is OK:
Why I can take address of Foo variable but not Bar?
```d
//-dip1000
struct Foo{
private double d;
}
struct Bar{
private void* ptr;
}
void main()@safe{
///this is OK:
{
scope Foo x;
scope ptr =
}
///Error: cannot take address of `scope` local `x` in
Hello,
I am implementing @nogc string struct similar to c++
std::basic_string (link
https://code.dlang.org/packages/basic_string).
C++ string has methods front, back and pop_back
returning/deleting code units.
D strings has functions (std.range) front, back and popBack
returning/deleting
On Wednesday, 23 June 2021 at 15:48:57 UTC, Tejas wrote:
On Wednesday, 23 June 2021 at 15:31:04 UTC, vit wrote:
Hello,
I am implementing @nogc string struct similar to c++
std::basic_string (link
https://code.dlang.org/packages/basic_string).
C++ string has methods front, back and pop_back
Are asserts enough to make method @trusted or is something like
throw exception or return error code necessary? How it work in
phobos?
Example:
```d
struct Slice(T){
private T[] data;
this(T[] data){
this.data = data;
}
inout(T)[] opSlice()inout scope return
On Wednesday, 7 July 2021 at 19:14:52 UTC, Kevin Bailey wrote:
I'm trying to use some fairly simple template argument
deduction, but
maybe I'm not getting the syntax correct. C++ doesn't event
blink at
something like this, but D is giving me:
temptest.d(18): Error: template temptest.func
On Wednesday, 10 February 2021 at 12:17:43 UTC, rm wrote:
On 09/02/2021 5:05, frame wrote:
On Sunday, 7 February 2021 at 14:13:18 UTC, vitamin wrote:
Why using 'new' is allowed in pure functions but calling
GC.addRange or GC.removeRange isn't allowed?
Does 'new' violate the 'pure' paradigm?
On Thursday, 19 August 2021 at 08:25:23 UTC, Bienlein wrote:
On Thursday, 19 August 2021 at 07:30:38 UTC, Bienlein wrote:
Hello,
I allocate some instance of class C manually and then free the
memory again:
class C {
int num;
~this() {
writeln("~this");
}
On Wednesday, 14 July 2021 at 15:01:45 UTC, wjoe wrote:
On Wednesday, 14 July 2021 at 14:39:03 UTC, vit wrote:
On Wednesday, 14 July 2021 at 13:16:49 UTC, Tejas wrote:
[...]
This work:
```d
import std.stdio;
struct abc{
int[100] a;
ref int opIndex(int index)return{
On Wednesday, 14 July 2021 at 15:19:03 UTC, vit wrote:
```d
import std.stdio;
struct abc{
int[100] a;
struct Proxy{
abc* ptr;
const int index;
int opUnary(string op : "++")(){
return ++ptr.a[index]; //add missing ++
}
}
On Monday, 2 August 2021 at 11:28:46 UTC, Tejas wrote:
On Monday, 14 June 2021 at 13:31:51 UTC, baby_tiger wrote:
[...]
It seems to not work at runtime either. Maybe they've made this
behaviour illegal now? Hopefully someone answers.
```d
import std.traits;
import core.stdc.stdarg;
On Monday, 14 June 2021 at 13:31:51 UTC, baby_tiger wrote:
this used work for me, after upgrade I get this error. how to
fix it ?
import std.traits;
enum LogLevel : ubyte {
INFO = 0,
WARN,
ERROR,
Hello,
Why this doesn't work:
```d
template DestructorType(T){
alias Get(T) = T;
alias DestructorType = Get!(typeof((void*){
T tmp;
}));
}
struct Foo{
~this()@safe{}
}
```
```d
void main(){
//Error: static assert: `is(void function(void*) pure
nothrow
On Monday, 9 August 2021 at 02:47:40 UTC, Mathias LANG wrote:
On Sunday, 8 August 2021 at 18:36:02 UTC, vit wrote:
Hello, is there reason why elements of input range must be
copyable?
By design, not that I can think of. But it is assumed all over
the place, unfortunately. You can make your
Hello, is there reason why elements of input range must be
copyable?
For example this example works and copy ctor is never called:
```d
import std.algorithm : map;
import std.range;
struct Foo{
int i;
this(scope ref typeof(this) rhs)pure nothrow @safe @nogc{
//this.i =
Hello,
Why is copy ctor in this example not called?
```d
import std.stdio;
struct Foo {
int i;
this(int i){
this.i = i;
writeln("init: ", i);
}
this(ref typeof(this) rhs){
this.i = rhs.i;
writeln("copy: ", i);
}
~this() {
On Sunday, 19 December 2021 at 23:21:00 UTC, Stanislav Blinov
wrote:
On Sunday, 19 December 2021 at 22:29:21 UTC, vit wrote:
Hello,
Why is copy ctor in this example not called?
Because D runtime isn't properly married to copy constructors
yet. I.e. it's a bug, a variant of this one:
On Wednesday, 5 January 2022 at 08:40:15 UTC, rempas wrote:
I'm trying to use mixins and enums to "expand" code in place
but the results are not what I expected and I'm getting an
weird error. I have created the smallest possible example to
reproduce the error and it is the following:
[...]
On Wednesday, 5 January 2022 at 08:40:15 UTC, rempas wrote:
I'm trying to use mixins and enums to "expand" code in place
but the results are not what I expected and I'm getting an
weird error. I have created the smallest possible example to
reproduce the error and it is the following:
[...]
On Wednesday, 5 January 2022 at 09:17:54 UTC, rempas wrote:
On Wednesday, 5 January 2022 at 09:02:53 UTC, vit wrote:
Try this:
```d
pragma(msg, type_check!("static if", "i8", "true", "5", "4",
"10", "5"));
```
Result:
```d
static if(is_same!(num, i8)) {
mixin(base_digit!("5", "4", "10",
On Tuesday, 21 December 2021 at 08:26:17 UTC, rempas wrote:
On Tuesday, 21 December 2021 at 08:11:39 UTC, Anonymouse wrote:
I'm not certain I understand, but won't `foreach (i, a; args)
{ /* ... */ }` in his example do that?
As in, if you necessarily must index `args` instead of using a
Hi, why this code doesn't compile?
```d
struct Foo{
bool opCast(T : bool)()const{
assert(0);
}
~this(){}
}
struct Bar{
const Foo foo;
}
void main(){
}
```
Error: template instance `opCast!(Foo)` does not match template
declaration `opCast(T : bool)()`
On Wednesday, 29 December 2021 at 01:00:53 UTC, Tejas wrote:
On Tuesday, 28 December 2021 at 18:27:36 UTC, vit wrote:
[...]
Since a destructor ignores `const`, I think adding the `~this`
to Foo manually is somehow making the compiler have to actually
cast away const, which it is doing via
Hello, why does this code fail to compile?
```d
struct Foo(T){
this(Rhs, this This)(scope Rhs rhs){
}
this(ref scope typeof(this) rhs){
}
}
struct Bar{
Foo!int foo;
}
void main(){
}
```
error: Segmentation fault (core dumped)
On Sunday, 12 December 2021 at 18:32:28 UTC, Imperatorn wrote:
On Sunday, 12 December 2021 at 11:57:43 UTC, vit wrote:
Hello, why does this code fail to compile?
```d
struct Foo(T){
this(Rhs, this This)(scope Rhs rhs){
}
this(ref scope typeof(this) rhs){
}
}
struct Bar{
On Tuesday, 14 December 2021 at 14:40:00 UTC, RazvanN wrote:
On Sunday, 12 December 2021 at 11:57:43 UTC, vit wrote:
Hello, why does this code fail to compile?
```d
struct Foo(T){
this(Rhs, this This)(scope Rhs rhs){
}
this(ref scope typeof(this) rhs){
}
}
struct Bar{
On Wednesday, 21 July 2021 at 08:28:22 UTC, Mike Parker wrote:
On Wednesday, 21 July 2021 at 08:11:06 UTC, vit wrote:
Is it possible to call all shared static ctors in betterC?
```d
//-betterC
static immutable int i;
shared static this(){
i = 42;
}
extern(C) void main(){
assert(i
Is it possible to call all shared static ctors in betterC?
```d
//-betterC
static immutable int i;
shared static this(){
i = 42;
}
extern(C) void main(){
assert(i != 42);
}
```
On Tuesday, 20 July 2021 at 06:20:34 UTC, Tejas wrote:
...
Initially, I was trying to create the spaceship operator of
C++, but we aren't allowed to create new operators
...
D has spaceship operator: opCmp
(https://dlang.org/spec/operatoroverloading.html#compare).
On Friday, 23 July 2021 at 20:24:02 UTC, Jim wrote:
Hello,
I've been playing with D and trying to understand how to work
with @nogc. I must be doing something wrong, because even
though I tagged the destructor for my class `@nogc`, I'm
getting the following error: `.\min.d(27): Error:
On Wednesday, 14 July 2021 at 12:49:58 UTC, Tejas wrote:
On Wednesday, 14 July 2021 at 12:35:07 UTC, wjoe wrote:
On Wednesday, 14 July 2021 at 11:31:36 UTC, Tejas wrote:
``` {auto a = i[1] , ++i[1] , a} //note the , not the ;```
Sorry I can't provide something even more concrete.
Yes I saw
On Wednesday, 14 July 2021 at 13:16:49 UTC, Tejas wrote:
On Wednesday, 14 July 2021 at 13:09:56 UTC, vit wrote:
On Wednesday, 14 July 2021 at 12:49:58 UTC, Tejas wrote:
[...]
From doc: https://dlang.org/spec/operatoroverloading.html
Postincrement e++ and Postdecrement e-- Operators
These are
On Wednesday, 12 January 2022 at 05:27:08 UTC, forkit wrote:
I am familiar with the concept of a slice in D.
However, a slice is a consecutive slice, is in not? (e.g)
[4..$-1]
I would like a slice (or a view, or whatever name you wanna
call it), of particular elements within an array that
On Wednesday, 12 January 2022 at 06:43:40 UTC, forkit wrote:
On Wednesday, 12 January 2022 at 06:16:49 UTC, vit wrote:
Yes std.algorithm : filter.
```d
import std.stdio : writeln;
import std.algorithm : filter;
void main()@safe{
auto a = ["one", "one", "two", "one", "two", "one",
Hello, I have this code:
```d
import core.lifetime : move, forward;
import std.stdio : writeln;
struct Foo{
int i;
static auto make(int i){
Foo tmp;
tmp.i = i;
return move(tmp);
}
this(scope const ref typeof(this) rhs){
this.i = rhs.i;
On Wednesday, 12 January 2022 at 06:58:47 UTC, vit wrote:
On Wednesday, 12 January 2022 at 06:43:40 UTC, forkit wrote:
On Wednesday, 12 January 2022 at 06:16:49 UTC, vit wrote:
Yes std.algorithm : filter.
```d
import std.stdio : writeln;
import std.algorithm : filter;
void main()@safe{
On Wednesday, 12 January 2022 at 08:04:19 UTC, vit wrote:
Hello, I have this code:
```d
[...]
run.dlang.io has old version of dmd-beta/dmd-nightly with bug
Hello,
why this code compile without problems:
```d
struct Query{
public const SharedPtr!Builder builder;
}
interface Builder{
void build(ref Query query);
}
struct SharedPtr(T){
enum touch_T = __traits(hasMember, T, "touch");
//...
}
void main(){
}
```
but if `ref Query
On Tuesday, 1 March 2022 at 08:16:13 UTC, Mike Parker wrote:
On Tuesday, 1 March 2022 at 07:16:11 UTC, bauss wrote:
Right now if you want to add an additional cast then you have
to implement ALL the default behaviors and then add your
custom cast.
It's two template functions like the OP
On Tuesday, 1 March 2022 at 08:40:12 UTC, Vijay Nayar wrote:
I've randomly encountered a strange error, and I cannot find
any explanation for it in the official documentation of syntax.
Essentially, a class cannot call function overload in a
super-class if the class itself contains an
On Tuesday, 1 March 2022 at 08:40:12 UTC, Vijay Nayar wrote:
I've randomly encountered a strange error, and I cannot find
any explanation for it in the official documentation of syntax.
[...]
Here is more info (3.):
On Sunday, 27 March 2022 at 16:27:44 UTC, JN wrote:
I would like to have only one definition of getX if possible,
because they both are doing the same thing. I can't remove the
ref one, because without a ref it will pass the struct as a
temporary and compiler won't like that.
```d
import
On Wednesday, 30 March 2022 at 12:46:07 UTC, Vijay Nayar wrote:
Consider the following code example:
```d
import std.stdio;
void main()
{
alias DelegateT = string delegate();
// An array of delegates, each has their own scope.
DelegateT[] funcs;
foreach (i; ["ham", "cheese"]) {
//
On Wednesday, 30 March 2022 at 12:56:39 UTC, Vijay Nayar wrote:
On Wednesday, 30 March 2022 at 12:53:10 UTC, vit wrote:
use two delegates :)
```d
(){
// Deliberately create a copy to keep in delegate scope.
string myStr = i.dup;
// The
On Friday, 1 April 2022 at 22:22:21 UTC, Vijay Nayar wrote:
Consider the following program:
```d
void main()
{
import std.stdio;
import std.container.rbtree;
import std.variant;
[...]
Variant can contain any type => variant cannot assume attributes
like pure nothrow @safe @nogc
On Saturday, 2 April 2022 at 14:49:15 UTC, Vijay Nayar wrote:
On Saturday, 2 April 2022 at 14:35:10 UTC, Vijay Nayar wrote:
The `tryMatch` method fails to compile, and instead I get the
following error:
```d
/dlang/dmd/linux/bin64/../../src/phobos/std/sumtype.d(2004):
Error: static assert:
On Tuesday, 18 January 2022 at 12:05:38 UTC, Paul Backus wrote:
On Tuesday, 18 January 2022 at 04:42:45 UTC, frame wrote:
At the very top of my module I have this declaration:
```d
static if (__VERSION__ >= 2098)
{
alias Foo = TypeA;
}
else
{
alias Foo = TypeB;
}
```
No problem inside
On Tuesday, 18 January 2022 at 04:42:45 UTC, frame wrote:
At the very top of my module I have this declaration:
```d
static if (__VERSION__ >= 2098)
{
alias Foo = TypeA;
}
else
{
alias Foo = TypeB;
}
```
No problem inside the module itself but this doesn't work when
imported from
On Wednesday, 19 January 2022 at 04:15:54 UTC, Steven
Schveighoffer wrote:
On 1/18/22 7:19 AM, vit wrote:
On Tuesday, 18 January 2022 at 12:05:38 UTC, Paul Backus wrote:
On Tuesday, 18 January 2022 at 04:42:45 UTC, frame wrote:
At the very top of my module I have this declaration:
```d
On Wednesday, 19 January 2022 at 08:47:27 UTC, Enjoys Math wrote:
```
module expr;
import dots;
import operator;
import equation;
import var;
import var_expr;
import zz_const;
class Expr
{
public:
void opBinary(string op)(string s) const
{
static if (op == "+")
{
Hello,
Why is tuple variable `params` immediately destructed after its
construction?
Why is `check(-2)` after `dtor(2)`?
Code:
```d
import std.stdio : writeln;
import core.lifetime : forward, move;
struct Foo{
int i;
this(int i){
this.i = i;
writeln("ctor(", i,
On Saturday, 22 January 2022 at 17:23:12 UTC, Ali Çehreli wrote:
On 1/22/22 07:17, vit wrote:
> Why local variable of type tuple call destructors immediately
after
> initialization?
I don't even understand where the local variable comes from. If
you want a pair of Foo objects, I would use
On Saturday, 22 January 2022 at 14:23:32 UTC, Adam Ruppe wrote:
You can't forward to a local variable. Local variables will be
a copy of the tuple. forward only actually works if sent
*directly* to another function call.
There's a bunch of things in D that only work in function
parameter
1 - 100 of 124 matches
Mail list logo