On Sunday, 15 June 2025 at 16:14:28 UTC, Manfred Nowak wrote:
On Sunday, 15 June 2025 at 10:51:37 UTC, Nick Treleaven wrote:
An untyped parameter does make the literal an actual template:
```d
pragma(msg, __traits(isTemplate, (x) {})); // true
```
It can be instantiated with a type parameter.
On Sunday, 15 June 2025 at 10:51:37 UTC, Nick Treleaven wrote:
An untyped parameter does make the literal an actual template:
```d
pragma(msg, __traits(isTemplate, (x) {})); // true
```
It can be instantiated with a type parameter.
Therefore in the case discussed, the code `(_){}' declares a
On Sunday, 15 June 2025 at 10:51:37 UTC, Nick Treleaven wrote:
So I think there must be another reason why your unary literals
work.
Given it's specifically void return, and top level and it acts
like it matches the first return, I expect that void is
incorrectly being considered a invalid
On Saturday, 14 June 2025 at 23:49:19 UTC, Steven Schveighoffer
wrote:
A lambda is a shortened syntax for a function literal or
delegate literal.
HOWEVER, when you do not give the parameters types, the lambda
becomes a template! Well, not actually a template, but a
quasi-template.
An untype
On Saturday, 14 June 2025 at 23:49:19 UTC, Steven Schveighoffer
wrote:
If I had to guess, I think the compiler is not able to exactly
deduce what form your lambda should be instantiated with. I
think it's picking the first form it sees.
I think if anything, the error message is really weird.
On Saturday, 14 June 2025 at 00:02:32 UTC, Andrey Zherikov wrote:
The simplest code that shows the issue:
```d
struct S{}
template f(void function(S) F) {}
template f(int function(S) F) {}
mixin f!((_) {});
mixin f!((_) => 0); // Error: cannot return non-void from
`void` function
On Saturday, 14 June 2025 at 03:17:09 UTC, monkyyy wrote:
```d
import std;
mixin template f(int function(int) F){}
mixin template f(void function(int)
F){unittest{"void".writeln;}}
//mixin f!((_){}); //FAILS
mixin template g(void function(int)
F){unittest{"void&quo
oid f(void function(int) F)(){"void".writeln;}
unittest{
f!((_) {});
f!((_) => 0);
}
mixin template g(int function(int) F){string s1="int";}
mixin template g(void function(int) F){string s2="void";}
unittest{
mixin g!((_) {});
mixin
f!((_) {});
f!((_) => 0);
}
mixin template g(int function(int) F){string s1="int";}
mixin template g(void function(int) F){string s2="void";}
unittest{
mixin g!((_) {});
mixin g!((_) => 0);
s1.writeln;
s2.writeln;
}
``
hile the
latter can't.
In my case mixin template generates top-level `main()` function
but the content of the template is not important here.
Also using `alias F` as template parameter doesn't allow me to
introspect the actual type.
our still mixing syntax; mixin templates are suppose to be a
separate system according to the spec.
```d
import std;
void f(int function(int) F)(){"int".writeln;}
void f(void function(int) F)(){"void".writeln;}
unittest{
f!((_) {});
f!((_) => 0);
}
mixin templa
On Saturday, 14 June 2025 at 00:02:32 UTC, Andrey Zherikov wrote:
Simplified test case a bit more.
This works:
```d
template f(void function(int) F) {}
template f(int function(int) F) {}
mixin f!((int _) {});
mixin f!((int _) => 0);
mixin f!((int) {});
mixin f!((int) => 0);
mixin f!((_) {});
mi
On Saturday, 14 June 2025 at 00:02:32 UTC, Andrey Zherikov wrote:
The simplest code that shows the issue:
```d
struct S{}
template f(void function(S) F) {}
template f(int function(S) F) {}
mixin f!((_) {});
mixin f!((_) => 0); // Error: cannot return non-void from
`void` function
The simplest code that shows the issue:
```d
struct S{}
template f(void function(S) F) {}
template f(int function(S) F) {}
mixin f!((_) {});
mixin f!((_) => 0); // Error: cannot return non-void from `void`
function
// mixin f!((_) => 0);
//
On Wednesday, 30 April 2025 at 06:08:23 UTC, cc wrote:
On Friday, 25 April 2025 at 16:14:49 UTC, Andy Valencia wrote:
I have a code pattern, and would like to generate rather than
copy/paste. It _seems_ like mixin templates apply, but I'm
not having much luck. I saw one comment that templates
On Friday, 25 April 2025 at 16:14:49 UTC, Andy Valencia wrote:
I have a code pattern, and would like to generate rather than
copy/paste. It _seems_ like mixin templates apply, but I'm not
having much luck. I saw one comment that templates always
expand in their own context, so perhaps they're
On Friday, 25 April 2025 at 17:24:18 UTC, Andy Valencia wrote:
On Friday, 25 April 2025 at 16:59:16 UTC, monkyyy wrote:
its extremely unclear what your trying to do my best geuss:
I want to use a mixin template to generate a top-level
function. Like, is there a variant of the following
On 4/25/25 10:24 AM, Andy Valencia wrote:
On Friday, 25 April 2025 at 16:59:16 UTC, monkyyy wrote:
its extremely unclear what your trying to do my best geuss:
I want to use a mixin template to generate a top-level function. Like,
is there a variant of the following which makes a function
On Fri, Apr 25, 2025 at 05:24:18PM +, Andy Valencia via Digitalmars-d-learn
wrote:
> On Friday, 25 April 2025 at 16:59:16 UTC, monkyyy wrote:
> > its extremely unclear what your trying to do my best geuss:
>
> I want to use a mixin template to generate a top-level function.
On Friday, 25 April 2025 at 16:59:16 UTC, monkyyy wrote:
its extremely unclear what your trying to do my best geuss:
I want to use a mixin template to generate a top-level function.
Like, is there a variant of the following which makes a function
named "foo1" available?
Andy
rhaps they're not useful for
generating a top-level function?
Andy
its extremely unclear what your trying to do my best geuss:
```d
int func1()=>3;
int func2()=>4;
mixin template makenewfunction(alias F,int reference){
int newfunction(int i:reference)(){
return F(
Andy
```d
bool bigtest(in string s) {
return true;
}
bool test1(in char c) {
return false;
}
bool test2(in char c) {
return true;
}
mixin template MyFunc(alias fn) {
bool fn(in string s) {
if (!bigtest(s)) {
return false;
}
foreach(c; s) {
On Sunday, 2 March 2025 at 23:28:09 UTC, Inkrementator wrote:
On Sunday, 2 March 2025 at 19:31:06 UTC, realhet wrote:
Anyone have an idea?
While template mixins have access to the caller scope, the
default values for parameters apparently don't.
Thank you, both of you!
That was the key to
On Sunday, 2 March 2025 at 19:31:06 UTC, realhet wrote:
Anyone have an idea?
While template mixins have access to the caller scope, the
default values for parameters apparently don't. If you `inline`
the default value, it will work
```
import std.traits;
mixin template T(strin
On Sunday, 2 March 2025 at 19:31:06 UTC, realhet wrote:
Anyone have an idea?
Such things are extremely discouraged and I could suggest maybe 3
hacks
But I unable to find a way to parse this declaration in the
scope where my types are.
```d
--- foo.d
import std;
public import bar;
myint fi
Hello,
```d
mixin template T(string def, alias C = typeof(mixin("new
class{"~def~"}")))
{
enum generatedStr = FieldTypeTuple!C.stringof;
}
void main()
{
{
mixin T!"int a, b;";
pragma(msg, generatedStr); //works
}
{
So, I've came to a situation where I must use mixin template for
defining members overloads, like:
```d
mixin template OverloadGen()
{
static if(hasMethod!(typeof(this), "add", int, int))
{
float add(float x, float y){return x+y;}
}
static if(hasMethod!(typ
On Friday, 22 July 2022 at 12:33:37 UTC, Anthony Quizon wrote:
I get:
```
foo.d(16): Error: mixin `foo.B.opBi!(B, ["+":function (B a, B
b) pure nothrow @nogc @safe => a])` does not match template
declaration `opBi(A, A function(A, A)[string] f0)`
```
Is this a bug or am I doing something wron
On Friday, 22 July 2022 at 12:56:44 UTC, Adam D Ruppe wrote:
```
mixin template opBi(
alias f0
) {
static foreach (k, f; f0) { typeof(this) opBinary(string op:
k)(typeof(this) r) { return f(this, r); } }
}
```
Thanks, this seems to do the trick.
On 7/22/22 8:33 AM, Anthony Quizon wrote:
Hello,
I'm trying to create a mixin for quick binary operator overloads by
passing in types with a corresponding associative array of strings to
functions. However,
the code I currently have:
```
module foo;
mixin template opBi(
A, A fun
if it
is supposed to change.
I vaguely recall seeing this before but yeah smells buggy
anyway.
An alternative you might consider is dropping some of the type
and using typeof(this):
```
module foo;
mixin template opBi(
alias f0
) {
static foreach (k, f; f0) { typeof(this
Hello,
I'm trying to create a mixin for quick binary operator overloads
by passing in types with a corresponding associative array of
strings to functions. However,
the code I currently have:
```
module foo;
mixin template opBi(
A, A function(A, A)[string] f0,
) {
static forea
On 5/23/22 08:14, Vindex wrote:
> Why? Why can't I have two constructors when I use mixin?
And there is an example in Phobos:
https://dlang.org/library/std/exception/basic_exception_ctors.html
The documentation there mentions the following bug:
https://issues.dlang.org/show_bug.cgi?id=115
On Monday, 23 May 2022 at 15:14:53 UTC, Vindex wrote:
I have this code:
```
import std.array, std.exception, std.stdio;
mixin template RealizeException() {
this(string msg, string file = __FILE__, size_t line =
__LINE__) {
super(msg, file, line);
}
}
class WrongUsage
I have this code:
```
import std.array, std.exception, std.stdio;
mixin template RealizeException() {
this(string msg, string file = __FILE__, size_t line =
__LINE__) {
super(msg, file, line);
}
}
class WrongUsage : Exception {
mixin RealizeException;
this(string
On Friday, 20 May 2022 at 14:54:31 UTC, Christopher Katko wrote:
If the declarations are at module scope, `static` has no
effect, and CTFE will be used for initialization.
It won't use CTFE? Why is there a local module requirement?
"module scope" just means at the top level in a module. so n
On Friday, 20 May 2022 at 14:54:31 UTC, Christopher Katko wrote:
So wait, that means if I have a module with extra stuff like
D
colors.d
auto red =
// grey
and then in my other file
D
auto white = grey(1.0);
It won't use CTFE? Why is there a local module requirement?
I'm
On Friday, 20 May 2022 at 02:30:10 UTC, Mike Parker wrote:
On Friday, 20 May 2022 at 00:12:44 UTC, Chris Katko wrote:
Yeah that occurred to me as I was falling asleep. Though, do I
have to a specify
```D
static auto myColor = grey(0.5);
```
to ensure it's done at compile time? It's not the en
On Friday, 20 May 2022 at 00:12:44 UTC, Chris Katko wrote:
Yeah that occurred to me as I was falling asleep. Though, do I
have to a specify
```D
static auto myColor = grey(0.5);
```
to ensure it's done at compile time? It's not the end of the
world, but ideally, these are static / hardcoded v
On 5/19/22 8:29 PM, Steven Schveighoffer wrote:
Given a CTFE function it's very easy to wrap for ensuring compile-time
usage:
```d
enum ctGrey(float f) = grey(f);
auto myColor = ctGrey!(0.5);
```
That being said, if it's calculatable at compile time, chances are the
compiler is already goi
On 5/19/22 8:12 PM, Chris Katko wrote:
On Thursday, 19 May 2022 at 10:35:30 UTC, ag0aep6g wrote:
On 19.05.22 12:15, Chris Katko wrote:
given
```D
struct COLOR
{
float r, g, b, a; // a is alpha (opposite of transparency)
}
auto red = COLOR(1,0,0,1);
auto green = COLOR(0,1,0,1);
auto blue = C
On Thursday, 19 May 2022 at 10:35:30 UTC, ag0aep6g wrote:
On 19.05.22 12:15, Chris Katko wrote:
given
```D
struct COLOR
{
float r, g, b, a; // a is alpha (opposite of transparency)
}
auto red = COLOR(1,0,0,1);
auto green = COLOR(0,1,0,1);
auto blue = COLOR(0,0,1,1);
auto white = COLOR(1,1,1,
On 19.05.22 12:15, Chris Katko wrote:
given
```D
struct COLOR
{
float r, g, b, a; // a is alpha (opposite of transparency)
}
auto red = COLOR(1,0,0,1);
auto green = COLOR(0,1,0,1);
auto blue = COLOR(0,0,1,1);
auto white = COLOR(1,1,1,1);
//etc
```
is there a way to do:
```D
auto myColor = GR
On Thursday, 19 May 2022 at 10:18:38 UTC, user1234 wrote:
On Thursday, 19 May 2022 at 10:15:32 UTC, Chris Katko wrote:
given
```D
struct COLOR
{
float r, g, b, a; // a is alpha (opposite of transparency)
}
auto red = COLOR(1,0,0,1);
auto green = COLOR(0,1,0,1);
auto blue = COLOR(0,0,1,1);
au
On Thursday, 19 May 2022 at 10:15:32 UTC, Chris Katko wrote:
given
```D
struct COLOR
{
float r, g, b, a; // a is alpha (opposite of transparency)
}
auto red = COLOR(1,0,0,1);
auto green = COLOR(0,1,0,1);
auto blue = COLOR(0,0,1,1);
auto white = COLOR(1,1,1,1);
//etc
```
is there a way to do:
given
```D
struct COLOR
{
float r, g, b, a; // a is alpha (opposite of transparency)
}
auto red = COLOR(1,0,0,1);
auto green = COLOR(0,1,0,1);
auto blue = COLOR(0,0,1,1);
auto white = COLOR(1,1,1,1);
//etc
```
is there a way to do:
```D
auto myColor = GREY!(0.5);
// where GREY!(0.5) becomes C
On 12/7/21 1:03 PM, Q. Schroll wrote:
On Tuesday, 7 December 2021 at 12:43:40 UTC, Rumbu wrote:
Bug or feature?
Feature. It even has a name: "overload set". It keeps you from
accidentally calling a function you had no idea existed, for example
because of a name clash.
Not in this case. See
On Tuesday, 7 December 2021 at 12:43:40 UTC, Rumbu wrote:
Bug or feature?
Feature. It even has a name: "overload set". It keeps you from
accidentally calling a function you had no idea existed, for
example because of a name clash.
Is there any workaround?
Yes, the error message is very c
On 12/7/21 7:43 AM, Rumbu wrote:
On Friday, 3 December 2021 at 10:57:34 UTC, Stanislav Blinov wrote:
On Friday, 3 December 2021 at 10:42:37 UTC, Rumbu wrote:
Bug or feature? Is there any workaround?
The error message explains what to do :)
Error: class `mixinover.AnotherVisitor` use of
`mi
On Friday, 3 December 2021 at 10:57:34 UTC, Stanislav Blinov
wrote:
On Friday, 3 December 2021 at 10:42:37 UTC, Rumbu wrote:
Bug or feature? Is there any workaround?
The error message explains what to do :)
Error: class `mixinover.AnotherVisitor` use of
`mixinover.Visitor.visit(S s)` is hid
On Friday, 3 December 2021 at 10:42:37 UTC, Rumbu wrote:
Bug or feature? Is there any workaround?
The error message explains what to do :)
Error: class `mixinover.AnotherVisitor` use of
`mixinover.Visitor.visit(S s)` is hidden by `AnotherVisitor`;
use `alias visit = Visitor.visit;` to intro
```d
class S {}
class A:S {}
class B:S {}
mixin template vmix(T)
{
void visit(T t) {}
}
class Visitor
{
void visit(S s) {}
mixin vmix!A;
mixin vmix!B;
}
class AnotherVisitor: Visitor
{
override void visit(A a) {}
}
```
This will result in error when I try to override mixin
On Wednesday, 16 June 2021 at 05:48:21 UTC, VitaliiY wrote:
On Tuesday, 15 June 2021 at 12:39:40 UTC, Dennis wrote:
On Tuesday, 15 June 2021 at 12:18:26 UTC, VitaliiY wrote:
[...]
```D
enum string ADDBITS(string a, string b) = `
{
bitbuffer = (bitbuffer<<(`~a~`))|((`~b~`)&((1<<`~a~`)-1));
On Tuesday, 15 June 2021 at 12:39:40 UTC, Dennis wrote:
On Tuesday, 15 June 2021 at 12:18:26 UTC, VitaliiY wrote:
[...]
```D
enum string ADDBITS(string a, string b) = `
{
bitbuffer = (bitbuffer<<(`~a~`))|((`~b~`)&((1<<`~a~`)-1));
numbits += (`~a~`);
mixin(STOREBITS);
}`;
// on use:
On Tuesday, 15 June 2021 at 12:38:15 UTC, Ali Çehreli wrote:
On 6/15/21 5:18 AM, VitaliiY wrote:
> STOREBITS and ADDBITS use variables defined in STARTDATA
If possible in your use case, I would put those variables in a
struct type and make add() a member function. However, a
similar type alre
On Tuesday, 15 June 2021 at 12:18:26 UTC, VitaliiY wrote:
It's simple with STARTDATA as mixin, but STOREBITS and ADDBITS
use variables defined in STARTDATA scope, so I can't understand
how to do mixin template with it.
If the code duplication isn't too bad, consider just e
On 6/15/21 5:18 AM, VitaliiY wrote:
> STOREBITS and ADDBITS use variables defined in STARTDATA
If possible in your use case, I would put those variables in a struct
type and make add() a member function. However, a similar type already
exists as std.bitmanip.BitArray.
Ali
Could anybody help with translation of this C macro to D
mixin/mixin template? Here a - unsigned char, b - int. It's
simple with STARTDATA as mixin, but STOREBITS and ADDBITS use
variables defined in STARTDATA scope, so I can't understand how
to do mixin template with it.
On Saturday, 27 June 2020 at 21:23:10 UTC, Adam D. Ruppe wrote:
On Saturday, 27 June 2020 at 21:10:59 UTC, NonNull wrote:
Is it possible to use a template to declare something whose
name is computed at compile time?
You'd have to string mixin the contents inside the mixin
template.
W
On Saturday, 27 June 2020 at 21:10:59 UTC, NonNull wrote:
Is it possible to use a template to declare something whose
name is computed at compile time?
You'd have to string mixin the contents inside the mixin template.
Want
mixin mytemplate!("foo", .);
to be able to declare names dependent upon the text foo in the
context it is used.
For example declaring
enum x_foo = ;
blah foo_value = ;
.
.
.
.
Is it po
On Thursday, 10 October 2019 at 15:56:36 UTC, Just Dave wrote:
I'm trying to get my head around mixing templates. I'm using it
as kind of a replacement for class inheritance as it seems to
fit better composition over inheritance. So I do something like:
mixin template Numb
I'm trying to get my head around mixing templates. I'm using it
as kind of a replacement for class inheritance as it seems to fit
better composition over inheritance. So I do something like:
mixin template NumberTemplate()
{
private:
int number = 0;
public:
d then you can add it as part
of the template.
mixin template UnitTest(string filename = __FILE__)
{
private static this()
{
testClasses ~= TestClass(this.classinfo.name, filename
);
}
}
Thanks a lot. That looks great.
Kind regards
Andre
On Wednesday, 29 May 2019 at 08:45:45 UTC, Andre Pany wrote:
Hi,
I have a module a.d
---
struct TestClass
{
string name;
string fileName;
}
TestClass[] testClasses;
mixin template UnitTest()
{
private static string getFileName(string fileName =
__FILE__
Hi,
I have a module a.d
---
struct TestClass
{
string name;
string fileName;
}
TestClass[] testClasses;
mixin template UnitTest()
{
private static string getFileName(string fileName = __FILE__)
{
return fileName;
}
private static this
On Monday, 10 December 2018 at 21:16:23 UTC, aliak wrote:
Does this fix your issue?
struct S {
mixin operators ops;
S opBinary(string op, T)(T a) {
alias opBinary = ops.opBinary; // explicitly alias
opBinary in this scope
return opBinary!op(a);
}
}
It does, thanks
On Sunday, 9 December 2018 at 18:36:50 UTC, Dennis wrote:
I'm using Adam's workaround from
https://issues.dlang.org/show_bug.cgi?id=19365, but now I have
endless recursion. Reduced code:
```
mixin template operators() {
S opBinary(string op: "+")(S rhs)
On Sunday, 9 December 2018 at 18:36:50 UTC, Dennis wrote:
Does anyone know how to get this working?
I added this to the mixin template:
```
alias mixinOpBinary = opBinary;
```
And called mixinOpBinary instead in the forwarded function. I
think that solved it. I think I'll just file an
I'm using Adam's workaround from
https://issues.dlang.org/show_bug.cgi?id=19365, but now I have
endless recursion. Reduced code:
```
mixin template operators() {
S opBinary(string op: "+")(S rhs) {
return rhs;
}
// (A)
auto opBinary(string op,
On Tuesday, 28 August 2018 at 20:58:23 UTC, Alex wrote:
Isn't the problem, that inside a template a declaration is
expected, and not a foreach?
Boh, you're right. I guess I misunderstood mixin templates. Found
a way with a normap function though :p
void mapSelf(alias self, alias aa)() {
y map
}
So I'm trying to do something similar in D:
mixin template MapMembers(alias aa) {
foreach (name; typeof(this).tupleof) {
// if name is in aa, then mixin(m = aa[" ~ m ~ "]) ... ish
}
}
struct User {
this(Variant[string] aa) {
mixin MapMembers!aa;
}
}
Seems I
Hi,
I'm trying to do something similar to what Kotlin allows with
assigning to member variables from a map. The syntax is very
readable and looks like:
class User(val map: Map) {
val name: String by map
val age: Int by map
}
So I'm trying to do something similar in
try this:
mixin template test(A...){
__gshared int a = A[0];
int dummy = (){
a++;
return 0;
}();
}
import core.stdc.stdio;
int main(){
mixin test!1;
printf("a=%d\n", a);
return 0;
}
On Friday, 10 August 2018 at 13:17:13 UTC, learnfirst1 wrote:
this work, it report no error but give a link problem. (this
could be a bug ?)
mixin template test(A...){
__gshared int a = A[0];
pragma(inline, true) // remove this will work
static extern(C) int test
On Friday, 10 August 2018 at 13:10:57 UTC, Kagamin wrote:
On Friday, 10 August 2018 at 13:01:21 UTC, learnfirst1 wrote:
Looks like some problem with tuple, try __gshared a = A[0];
this work, it report no error but give a link problem. (this
could be a bug ?)
On Friday, 10 August 2018 at 13:05:24 UTC, Kagamin wrote:
Mixim template can only introduce declarations, not statements,
a workaround is a lambda called in place.
mixin template test(A...){
__gshared a = A;
int dummy = (){ a++; return 0; }();
}
extern(C) void main
On Friday, 10 August 2018 at 13:05:24 UTC, Kagamin wrote:
Mixim template can only introduce declarations, not statements,
a workaround is a lambda called in place.
mixin template test(A...){
__gshared a = A;
int dummy = (){ a++; return 0; }();
}
extern(C) void main
On Friday, 10 August 2018 at 13:01:21 UTC, learnfirst1 wrote:
duplicate symbol __D4test4mainUZ8__mixin111__a_field_0i in:
test.o
ld: 1 duplicate symbol for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to
see invocation)
Error: linker exited with status 1
Mixim template can only introduce declarations, not statements, a
workaround is a lambda called in place.
mixin template test(A...){
__gshared a = A;
int dummy = (){ a++; return 0; }();
}
extern(C) void main(){
mixin test!123;
}
On Friday, 10 August 2018 at 12:38:55 UTC, learnfirst1 wrote:
mixin template test(A...){
mixin template test(A...){
__gshared a = A;
}
extern(C) void main(){
mixin test!123;
}
---
duplicate symbol __D4test4mainUZ8__mixin111__a_field_0i in:
test.o
ld: 1
mixin template test(A...){
__gshared a = A;
a++;
}
extern(C) void main(){
mixin test!123;
}
-
I dont want to use string mixin to intro a lot un want symbol,
try with mixin template find this not work.
I know if mixin test on global it should not working
On Friday, 10 August 2018 at 12:05:52 UTC, Simen Kjærås wrote:
On Friday, 10 August 2018 at 11:17:10 UTC, learnfirst1 wrote:
If you try the same without the mixin template, you'll see that
it doesn't work:
struct Test {
extern(C) pragma(crt_constructor) static void init(
(){}
}
void main(){
mixin G!(); // Line 5
init();
}
If you try the same without the mixin template, you'll see that
it doesn't work:
void main() {
static extern(C) pragma(crt_constructor) void init();
init();
}
Depending on the order of static, extern(C) a
On Friday, 10 August 2018 at 10:24:55 UTC, Simen Kjærås wrote:
On Friday, 10 August 2018 at 08:31:21 UTC, learnfirst1 wrote:
Filed a bug:
https://issues.dlang.org/show_bug.cgi?id=19153
template G(){
pragma(crt_constructor) static extern(C) void init(){}
}
void main(){
mixin G!(); // Li
On Friday, 10 August 2018 at 10:24:55 UTC, Simen Kjærås wrote:
On Friday, 10 August 2018 at 08:31:21 UTC, learnfirst1 wrote:
The correct behavior would be for the compiler to show the
latter error message for a mixin'd function as well.
Filed a bug:
https://issues.dlang.org/show_bug.cgi?id=191
On Friday, 10 August 2018 at 08:31:21 UTC, learnfirst1 wrote:
#!/usr/bin/env rdmd
import core.stdc.stdio;
template G(size_t line = __LINE__, A...){
int i = 3;
static extern(C) pragma(crt_constructor) void init2(){
printf("init: %d\n", line);
}
}
pragma(c
#!/usr/bin/env rdmd
import core.stdc.stdio;
template G(size_t line = __LINE__, A...){
int i = 3;
static extern(C) pragma(crt_constructor) void init2(){
printf("init: %d\n", line);
}
}
pragma(crt_constructor) extern(C) void init1(){
printf("init fro
On Tuesday, 3 April 2018 at 18:49:00 UTC, Carlos Navarro wrote:
QUESTION:
Obviously I'm no geting mixins/templates nor traits and I'm
failing miserably to find/identify the right examples or
documentation to help me tackle this thing. What is wrong in
this code? is this pattern sintactically
mixin template.
A mixin template is basically expected to be mixin-able in
global scope or in a class/struct so it can't have any things
like function calls because that would be the same as writing
`foo();` at global level instead of in the main function.
static foreach on the other h
tactically possible? what I'm
getting wrong?
CONTEXT:
I'm a newbie trying to extend a struct using a mixin template
like this one:
struct World {
floatrotation;
bool active;
mixin BuildStuff;
}
mixin template BuildStuff() {
foreach(elem;
T:
I'm a newbie trying to extend a struct using a mixin template
like this one:
struct World {
floatrotation;
bool active;
mixin BuildStuff;
}
mixin template BuildStuff() {
foreach(elem; __traits(allMembers, typeof(this))) {
On Thursday, 11 January 2018 at 21:30:43 UTC, aliak wrote:
On Thursday, 11 January 2018 at 08:56:11 UTC, ChangLong wrote:
When I try add some sub type for struct with mixin template,
seems there is no way to hidden the private type.
Is there a way to hidden type from mix template like
On Thursday, 11 January 2018 at 08:56:11 UTC, ChangLong wrote:
When I try add some sub type for struct with mixin template,
seems there is no way to hidden the private type.
Is there a way to hidden type from mix template like Voldemort
type ?
fake code:
mix template TypeX () {
alias
When I try add some sub type for struct with mixin template,
seems there is no way to hidden the private type.
Is there a way to hidden type from mix template like Voldemort
type ?
fake code:
mix template TypeX () {
alias This = typeof(this);
static struct Unique {
This
On Saturday, 25 November 2017 at 10:08:36 UTC, vit wrote:
On Saturday, 25 November 2017 at 09:52:01 UTC, Chirs Forest
wrote:
[...]
import std.meta : staticMap;
class Bar(T) {
T bar;
}
class Foo(Ts...){
staticMap!(Bar, Ts) bars;
this(){
static foreach(i, alias T; Ts) bars
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 t
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 take variadic types here?
Bar!(?)[] bars; //not sure how I'd defi
Clear explanation, thanks!
I think it would avoid a lot of confusion to disallow the alias f
= c1.field notation and only allow the alias f = C.field
notation. If necessary one could use alias f = typeof(c1).field
On 09/03/2017 08:54 PM, Eric_DD wrote:
*** This works:
struct Array {
void foo() { writeln("foo"); }
}
mixin template arrayOperations(arrays...) {
void foo() {
foreach(ref a; arrays) a.foo();
}
}
class Thing {
Array data1;
Array data2;
1 - 100 of 266 matches
Mail list logo