On Thursday, 5 October 2023 at 22:24:06 UTC, mw wrote:
On Thursday, 5 October 2023 at 21:41:38 UTC, cc wrote:
If you have `T info`, T.tupleof[n] will always match up with
info.tupleof[n]. You can think of `info.tupleof[n]` as being
rewritten by the compiler in-place as
info.whateverFieldTha
On Thursday, 5 October 2023 at 21:41:38 UTC, cc wrote:
If you have `T info`, T.tupleof[n] will always match up with
info.tupleof[n]. You can think of `info.tupleof[n]` as being
rewritten by the compiler in-place as info.whateverFieldThatIs.
You might try this version (note the double {{ }}
ame, mixin( "info." ~
attribName ));
}
}
Is there is some other way to evaluate info.attribName without
using string mixins?
Cheers, PP
If you have `T info`, T.tupleof[n] will always match up with
info.tupleof[n]. You can think of `info.tupleof[n]` as being
rewritten by the
On Sunday, 1 May 2016 at 10:13:47 UTC, H. S. Teoh wrote:
Using typeof(T.tupleof) seems a bit circuitous. Here's how I'd
do it:
void printStructInfo( T )( T info ) {
import std.stdio : writefln;
foreach (memb; __traits(allMembers, T)) {
situation to use template mixins instead of
potentially having to include a lot of information in the base
class? Or should I go with the traditional "everything is
derived from the base class"?
I understand if this is light on details, I'll try and provide
more if necessary, but
I am (still) writing a 3D graphics engine, and was considering my
choices for a scene graph.
Originally, I was going to use classes derived from my base
SceneNode class for the nodes of the graph, but would this
instead be a better situation to use template mixins instead of
potentially
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 Monday, 20 December 2021 at 18:58:39 UTC, bachmeier wrote:
You can see the ["String mixins" section
here](http://ddili.org/ders/d.en/mixin.html) for more details.
Mixins are generated at compile time, so if you're referring to
a string mixin inside a runtime loop, the c
ou can see the ["String mixins" section
here](http://ddili.org/ders/d.en/mixin.html) for more details.
Mixins are generated at compile time, so if you're referring to a
string mixin inside a runtime loop, the code will not be
generated every time the loop runs.
On Monday, 20 December 2021 at 18:12:35 UTC, Stanislav Blinov
wrote:
https://dlang.org/spec/traits.html#identifier
Thanks!!! Finally I was able to do it! The code is the following
(well not in my final project but it's a demonstration):
```
enum add_char(string c) =
`if (stdout_index < ST
On Monday, 20 December 2021 at 18:06:32 UTC, rempas wrote:
On Monday, 20 December 2021 at 11:58:58 UTC, Tejas wrote:
Ehh, it still fails; should've explicitly put the length of
the array and the `extern (C)` in `main`
```d
module demo;
[ ... ]
extern(C) /+added this because you used -bette
On Monday, 20 December 2021 at 18:03:09 UTC, rempas wrote:
> Now the problem is that I want it to get the name of so
> symbol and add it to a string literal.
Let's check this example: enum state(alias name) = `name` ~ ` =
10;`;
https://dlang.org/spec/traits.html#identifier
On Monday, 20 December 2021 at 11:58:58 UTC, Tejas wrote:
Ehh, it still fails; should've explicitly put the length of the
array and the `extern (C)` in `main`
```d
module demo;
[ ... ]
extern(C) /+added this because you used -betterC+/ void main() {
while (true) {
mixin
On Monday, 20 December 2021 at 11:30:09 UTC, rumbu wrote:
Enums (that's why the string is declarated as enum) are
evaluated at compile time, the concatenation op will not end in
your code as instruction, so you can do anything outside
betterC rules as long you do it at compile time. You are j
On Monday, 20 December 2021 at 11:30:09 UTC, rumbu wrote:
On Monday, 20 December 2021 at 10:49:20 UTC, rempas wrote:
On Monday, 20 December 2021 at 09:30:30 UTC, rumbu wrote:
Thanks a lot for the info. When I try to use this code, I'm
getting the following error:
```
Error: expression expect
On Monday, 20 December 2021 at 10:49:20 UTC, rempas wrote:
On Monday, 20 December 2021 at 09:30:30 UTC, rumbu wrote:
Thanks a lot for the info. When I try to use this code, I'm
getting the following error:
```
Error: expression expected, not `%`
Error: expression expected, not `%`
```
My fa
On Monday, 20 December 2021 at 09:30:30 UTC, rumbu wrote:
because you cannot have statements directly in a template (the
fact that is a mixin template is irelevant), only declarations.
If you want to just insert some random code, use strings. You
can create a templated enum to store your par
On Monday, 20 December 2021 at 08:45:50 UTC, rempas wrote:
Here I am having a problem with templates again. No matter how
much I read, I can't seem to understand how templates/mixins
work.
So any ideas why this doesn't work?
because you cannot have statements directly in a tem
Here I am having a problem with templates again. No matter how
much I read, I can't seem to understand how templates/mixins
work. So I'm having the following code (just a snippet of the
real code):
```
if (c != '%') {
if (stdout_index < STDOUT_BUF_LEN)
On Wednesday, 17 November 2021 at 14:51:58 UTC, Abby wrote:
Hello I would like to create validation mixin or mixin template
which would return on error.
Something like this:
```
mixin template Validate(a, b)
{
if(a > b)
{
writeln("invalid input");
return false;
}
}
On Wednesday, 17 November 2021 at 14:51:58 UTC, Abby wrote:
Hello I would like to create validation mixin or mixin template
which would return on error.
Something like this:
```
mixin template Validate(a, b)
{
if(a > b)
{
writeln("invalid input");
return false;
}
}
On Wednesday, 17 November 2021 at 15:12:50 UTC, Tejas wrote:
On Wednesday, 17 November 2021 at 14:51:58 UTC, Abby wrote:
Hello I would like to create validation mixin or mixin
template which would return on error.
Something like this:
```
mixin template Validate(a, b)
{
if(a > b)
{
On Wednesday, 17 November 2021 at 14:51:58 UTC, Abby wrote:
Hello I would like to create validation mixin or mixin template
which would return on error.
Something like this:
```
mixin template Validate(a, b)
{
if(a > b)
{
writeln("invalid input");
return false;
}
}
Hello I would like to create validation mixin or mixin template
which would return on error.
Something like this:
```
mixin template Validate(a, b)
{
if(a > b)
{
writeln("invalid input");
return false;
}
}
bool test(a,b)
{
mixin Validate!(a,b);
on v
On Thursday, 26 August 2021 at 19:31:54 UTC, DLearner wrote:
if (typeof(v).stringof == "int" ) {
Tip: you can instead of string of do
if (is(typeof(v) == int))
That is operator lets you compare types directly.
(stringof is something you will almost never use as you learn
more of the lan
On Thursday, 26 August 2021 at 16:28:22 UTC, Adam D Ruppe wrote:
On Thursday, 26 August 2021 at 16:16:55 UTC, DLearner wrote:
Please confirm that mixins of format:
You really shouldn't use string mixins like this at all. If you
want to work with a variable, pass the variable itself
On Thursday, 26 August 2021 at 18:07:48 UTC, Ali Çehreli wrote:
In some cases it's more useful to have a 'static if' inside a
single function template instead of two separate function
templates.
In most cases that's better. A template constraint is really a
way to say "this template cannot ac
On 8/26/21 10:45 AM, Adam D Ruppe wrote:
On Thursday, 26 August 2021 at 17:39:16 UTC, Ali Çehreli wrote:
String mixins are appealing because they can inject code like C macros
do. It's not trivially possible to do the same with template mixins.
Template mixins are great, but obviously to
On Thursday, 26 August 2021 at 17:39:16 UTC, Ali Çehreli wrote:
String mixins are appealing because they can inject code like C
macros do. It's not trivially possible to do the same with
template mixins.
Template mixins are great, but obviously totally inappropriate
here. I'm ju
alias. You can just check `typeof(v)`
in there.
String mixins are appealing because they can inject code like C macros
do. It's not trivially possible to do the same with template mixins.
import std.traits : isPointer;
import std.stdio : writeln;
mixin template valueFrom(alias var)
if (isPoin
On Thursday, 26 August 2021 at 17:01:06 UTC, DLearner wrote:
The object was to take a variable, and do alternative things
with it depending on (say) whether it was an 'int' or an 'int*'.
That's *very* easy to do with the alias. You can just check
`typeof(v)` in there.
On Thursday, 26 August 2021 at 16:28:22 UTC, Adam D Ruppe wrote:
On Thursday, 26 August 2021 at 16:16:55 UTC, DLearner wrote:
Please confirm that mixins of format:
You really shouldn't use string mixins like this at all. If you
want to work with a variable, pass the variable itself
On Thursday, 26 August 2021 at 16:16:55 UTC, DLearner wrote:
Please confirm that mixins of format:
You really shouldn't use string mixins like this at all. If you
want to work with a variable, pass the variable itself as an
argument to the function and use it with regular code inste
On Thursday, 26 August 2021 at 16:16:55 UTC, DLearner wrote:
Please confirm that mixins of format:
```
string mxn1(string VarName) {
...
}
```
Invoked like:
```
mixin(mxn1("Var1"));
```
Have a wider scope than mixins like:
```
string mxn2(string VarName)() {
...
}
```
In
Please confirm that mixins of format:
```
string mxn1(string VarName) {
...
}
```
Invoked like:
```
mixin(mxn1("Var1"));
```
Have a wider scope than mixins like:
```
string mxn2(string VarName)() {
...
}
```
Invoked like:
```
mixin(mxn2!"Var2");
```
I tried direct r
On Friday, 24 January 2020 at 16:21:48 UTC, Jan Hönig wrote:
I am looking for a detailed explanation or showcase regarding
CTFE and string mixins.
I want to play with D a little bit regarding code generation.
I would like to have a pseudo-AST, consisting of a few classes,
to represent some
;enum', but there are
limitations (enums cannot take AA's or class objects as values,
also, once assigned they are immutable).
As long as you can produce a string (via CTFE or otherwise)
whose value is known at compile-time and represents valid D
code, it's fair game for string
On Fri, Jan 24, 2020 at 08:26:50PM +0100, Jacob Carlborg via
Digitalmars-d-learn wrote:
> On 2020-01-24 19:43, H. S. Teoh wrote:
>
> > (enums cannot take AA's or class objects as values, also, once
> > assigned they are immutable).
>
> AA enums work.
Ah you're right, it's statically-constructed
On 2020-01-24 19:43, H. S. Teoh wrote:
(enums cannot take AA's or
class objects as values, also, once assigned they are immutable).
AA enums work. Class objects kind of work. One can use static
const/immutable instead. The following snippet compiles:
class A
{
int a = 3;
}
const bar =
On Fri, Jan 24, 2020 at 04:21:48PM +, Jan Hönig via Digitalmars-d-learn
wrote:
> I am looking for a detailed explanation or showcase regarding CTFE and
> string mixins.
> I want to play with D a little bit regarding code generation.
> I would like to have a pseudo-AST, consist
exity when using the
`new` keyword.
https://dlang.org/spec/function.html#interpretation
Basically the only limitation of string mixins is that a single
string should evaluate to valid D code, opposed to C macros. So
int y mixin("= 6");
doesn't compile, while
int y = mixin("
On Friday, 24 January 2020 at 16:21:48 UTC, Jan Hönig wrote:
I am looking for a detailed explanation or showcase regarding
CTFE and string mixins.
I want to play with D a little bit regarding code generation.
I would like to have a pseudo-AST, consisting of a few classes,
to represent some
I am looking for a detailed explanation or showcase regarding
CTFE and string mixins.
I want to play with D a little bit regarding code generation.
I would like to have a pseudo-AST, consisting of a few classes,
to represent some calculation. Think of a loop, some statements,
and expressions
There's a template mixin in my dimage project's new version in
base.d, and when I try to access it from another file I get two
errors:
undefined identifier `ChunkyAccess4bit`, did you mean template
`ChunkyAccess4Bit()`?
and
mixin `dimage.tga.TGA.ChunkyAccess4bit!()` is not defined
Should I
On Tuesday, 26 February 2019 at 00:07:54 UTC, Victor Porton wrote:
I want to create a string mixin based on a supplementary
variable (name2 below):
Let we have something like:
mixin template X(string name) {
immutable string name2 = '_' ~ name;
mixin("struct " ~ name2 ~ "{ int i; }");
}
B
On Monday, February 25, 2019 5:07:54 PM MST Victor Porton via Digitalmars-d-
learn wrote:
> I want to create a string mixin based on a supplementary variable
> (name2 below):
>
> Let we have something like:
>
> mixin template X(string name) {
>immutable string name2 = '_' ~ name;
>mixin("st
On Tuesday, 26 February 2019 at 00:07:54 UTC, Victor Porton wrote:
I want to create a string mixin based on a supplementary
variable (name2 below):
Let we have something like:
mixin template X(string name) {
immutable string name2 = '_' ~ name;
mixin("struct " ~ name2 ~ "{ int i; }");
}
B
I want to create a string mixin based on a supplementary variable
(name2 below):
Let we have something like:
mixin template X(string name) {
immutable string name2 = '_' ~ name;
mixin("struct " ~ name2 ~ "{ int i; }");
}
But it would create variable name2 inside X, which should not be
cre
On Wednesday, 12 December 2018 at 16:33:02 UTC, H. S. Teoh wrote:
On Wed, Dec 12, 2018 at 01:35:00PM +, AlCaponeJr via
Digitalmars-d-learn wrote:
On Tuesday, 11 December 2018 at 21:17:46 UTC, H. S. Teoh wrote:
> Whoa. That looks like a compiler bug. File a bug here:
> ...
Genuinely asking
On 12/12/18 10:22 AM, Kagamin wrote:
On Tuesday, 11 December 2018 at 21:19:59 UTC, Steven Schveighoffer wrote:
If I add an int using a regular declaration or a straight mixin("int
i0 = 5;"); then the variable shows up.
mixin template genInts()
{
enum arr = [0];
static foreach (t; arr
On Wed, Dec 12, 2018 at 01:35:00PM +, AlCaponeJr via Digitalmars-d-learn
wrote:
> On Tuesday, 11 December 2018 at 21:17:46 UTC, H. S. Teoh wrote:
> > Whoa. That looks like a compiler bug. File a bug here:
> > ...
>
> Genuinely asking if this is a case of lacking of unit test for the
> Compil
On Tuesday, 11 December 2018 at 21:19:59 UTC, Steven
Schveighoffer wrote:
If I add an int using a regular declaration or a straight
mixin("int i0 = 5;"); then the variable shows up.
mixin template genInts()
{
enum arr = [0];
static foreach (t; arr)
{
mixin("int i0 = 5;");
On Tuesday, 11 December 2018 at 21:17:46 UTC, H. S. Teoh wrote:
Whoa. That looks like a compiler bug. File a bug here:
...
Genuinely asking if this is a case of lacking of unit test for
the Compiler or this is a case that where is hard to test or
prevent?
Al.
On Tuesday, 11 December 2018 at 21:09:55 UTC, Johannes Riecken
wrote:
Code:
import std.conv;
import std.stdio;
mixin template genInts()
{
enum arr = [0,1];
static foreach (t; arr) {
mixin("int i" ~ to!string(t) ~ " = 5;");
}
}
void main() {
mixin genInts!();
writeln(i0);
writel
P.S. Just looked at the disassembly. Seems to be a codegen bug -- the
code appears to be trying to lookup local variables (presumably i0 and
i1), but somehow the initialization code is missing.
--T
On Tue, Dec 11, 2018 at 09:09:55PM +, Johannes Riecken via
Digitalmars-d-learn wrote:
> Cod
On 12/11/18 4:09 PM, Johannes Riecken wrote:
Code:
import std.conv;
import std.stdio;
mixin template genInts()
{
enum arr = [0,1];
static foreach (t; arr) {
mixin("int i" ~ to!string(t) ~ " = 5;");
}
}
void main() {
mixin genInts!();
writeln(i0);
writeln(i1);
}
Expecte
On Tue, Dec 11, 2018 at 09:09:55PM +, Johannes Riecken via
Digitalmars-d-learn wrote:
> Code:
>
> import std.conv;
> import std.stdio;
>
> mixin template genInts()
> {
> enum arr = [0,1];
> static foreach (t; arr) {
> mixin("int i" ~ to!string(t) ~ " = 5;");
> }
> }
>
> void main(
Code:
import std.conv;
import std.stdio;
mixin template genInts()
{
enum arr = [0,1];
static foreach (t; arr) {
mixin("int i" ~ to!string(t) ~ " = 5;");
}
}
void main() {
mixin genInts!();
writeln(i0);
writeln(i1);
}
Expected output:
5
5
Actual output is two garbage integer v
On Friday, 23 November 2018 at 21:49:55 UTC, Kagamin wrote:
Well, just have all factories in one module and import it, then
they will be visible.
They're part of another library over which I have no control, but
yes, I could still import them all and make life easier.
import allfactories;
a
On Saturday, 17 November 2018 at 17:58:54 UTC, John Chapman wrote:
The following code doesn't compile because the generated type
name needs to be available inside the mixin's scope, whereas
it's actually in another module.
auto makeWith(string className, Args…)(auto ref Args args) {
mixin("r
On Thursday, 22 November 2018 at 16:27:08 UTC, Eduard Staniloiu
wrote:
So I had a go at this and I have a working solution.
https://run.dlang.io/is/oaH6Ib
At first, I tried to do everything in the mixin, as you can see
with the `failedAttempt` function. The idea was that this
should have worke
On Saturday, 17 November 2018 at 17:58:54 UTC, John Chapman wrote:
The following code doesn't compile because the generated type
name needs to be available inside the mixin's scope, whereas
it's actually in another module.
auto makeWith(string className, Args…)(auto ref Args args) {
mixin("r
On Sunday, 18 November 2018 at 11:29:51 UTC, John Chapman wrote:
On Saturday, 17 November 2018 at 21:11:38 UTC, Adam D. Ruppe
wrote:
On Saturday, 17 November 2018 at 17:58:54 UTC, John Chapman
wrote:
Has anyone had a similar need and come up with a solution?
You might be able to just pass it
On Saturday, 17 November 2018 at 21:11:38 UTC, Adam D. Ruppe
wrote:
On Saturday, 17 November 2018 at 17:58:54 UTC, John Chapman
wrote:
Has anyone had a similar need and come up with a solution?
You might be able to just pass it the Calendar type, and then
fetch its parent module and get the I
On Saturday, 17 November 2018 at 17:58:54 UTC, John Chapman wrote:
Has anyone had a similar need and come up with a solution?
You might be able to just pass it the Calendar type, and then
fetch its parent module and get the ICalendarFactory from there
(assuming they are defined in the same mo
On Sat, 17 Nov 2018 17:58:54 +, John Chapman wrote:
> The idea is that users could type (for example) makeWith!`Calendar`(…)
> instead of the longer makeWith!ICalendarFactory(…).
Your project might define a hundred types named ICalendarFactory; the
compiler can't figure out which one you're t
The following code doesn't compile because the generated type
name needs to be available inside the mixin's scope, whereas it's
actually in another module.
auto makeWith(string className, Args…)(auto ref Args args) {
mixin("return makeWith!(I", className, "Factory)(args);"); //
Fowarded to i
On Sunday, October 01, 2017 06:32:53 Nicholas Wilson via Digitalmars-d-learn
wrote:
> On Sunday, 1 October 2017 at 06:27:21 UTC, Nicholas Wilson wrote:
> > And am getting
> > util.d(72,12): Error: template instance helper!(foo) cannot use
> > local 'foo' as parameter to non-global template
> > hel
On Sunday, 1 October 2017 at 06:27:21 UTC, Nicholas Wilson wrote:
And am getting
util.d(72,12): Error: template instance helper!(foo) cannot use
local 'foo' as parameter to non-global template
helper(Fields...)
Fixed by making helper a global template.
Thanks Jonathan!
On Sunday, 1 October 2017 at 04:44:16 UTC, Jonathan M Davis wrote:
I don't see any reason why the compiler would be complaining
about 'this' being required.
Neither do I.
I would think that that would imply that the compiler thinks
that you're accessing the member rather than introspecting on
On Sunday, October 01, 2017 03:11:15 Nicholas Wilson via Digitalmars-d-learn
wrote:
> On Sunday, 1 October 2017 at 02:29:57 UTC, Jonathan M Davis wrote:
> > I would have thought that it would be pretty straightforward to
> > just write a recursive, eponymous template to solve the problem
> > and h
On Sunday, 1 October 2017 at 02:29:57 UTC, Jonathan M Davis wrote:
I would have thought that it would be pretty straightforward to
just write a recursive, eponymous template to solve the problem
and have it recursively build a single string to mix in for
everything.
In general though, without
On Sunday, October 01, 2017 02:07:26 Nicholas Wilson via Digitalmars-d-learn
wrote:
> On Sunday, 1 October 2017 at 01:05:56 UTC, Nicholas Wilson wrote:
> > struct MyType
> > {
> >
> > void* raw;
> > static struct Info
> > {
> >
> > @(42) int foo;
> >
> > }
> > mixin gen
On Sunday, 1 October 2017 at 01:05:56 UTC, Nicholas Wilson wrote:
struct MyType
{
void* raw;
static struct Info
{
@(42) int foo;
}
mixin generateGetInfo!MyTypeGetInfo;
}
extern(C) void MyTypeGetInfo(void*,int,size_t,void*size_t*);
mixin template generateGetInfo(alias
struct MyType
{
void* raw;
static struct Info
{
@(42) int foo;
}
mixin generateGetInfo!MyTypeGetInfo;
}
extern(C) void MyTypeGetInfo(void*,int,size_t,void*size_t*);
mixin template generateGetInfo(alias func)
{
foreach(field; typeof(this).Info.tupleof)
{
On Wednesday, 27 September 2017 at 18:24:04 UTC, Nordlöw wrote:
At ...
Thanks Adam for your advice at
https://stackoverflow.com/questions/46454887/inter-module-symbol-resolution-error-of-template-type-parameter-when-using-mixin?noredirect=1#comment79867792_46454887
I made things work in this
uses `.mangleof` together with mixins to automatically infer
the definition (including its name) of each array store for each
element type in `Types`. The element types are passed in the
template parameter `Types` to the two templated structs mentioned
above.
Everything works except for when I t
you simply have not learned how to think
about mixins correctly. Stop whining about it and focus that
energy on working with them.
[...]
Thank you. You have rejuvenated my quest for mixin mastery :)
Just stick with it ;) Things will click. The more you trudge
through them and just try to i
On 08/21/2017 12:29 AM, WhatMeForget wrote:
> Thanks. Don't know if you noticed, but i used some code from your book.
> Hope you take that as a complement.
I did notice that and thank you. Every time I see people struggle with
code that originated from my half-witted examples, I actually feel
On 8/21/17 3:29 AM, WhatMeForget wrote:
On Sunday, 20 August 2017 at 19:41:14 UTC, Ali Çehreli wrote:
On 08/20/2017 12:27 PM, WhatMeWorry wrote:
> // Mixins are for mixing in generated code into the
source code.
> // The mixed in code may be generated as a template
instance
>
On Sunday, 20 August 2017 at 22:50:40 UTC, Johnson Jones wrote:
On Sunday, 20 August 2017 at 19:27:43 UTC, WhatMeWorry wrote:
[...]
It's not difficult, it's just new. It's not that you are a poor
programmer, but you simply have not learned how to think about
mixins correctl
On Sunday, 20 August 2017 at 19:41:14 UTC, Ali Çehreli wrote:
On 08/20/2017 12:27 PM, WhatMeWorry wrote:
> // Mixins are for mixing in generated code into the
source code.
> // The mixed in code may be generated as a template
instance
> // or a string.
Yes, it means that t
`;
}
void main()
{
// Mixins are for mixing in generated code into the source
code.
// The mixed in code may be generated as a template instance
// or a string.
mixin(printStatement("hello world"));
mixin(`writeln(` ~ `Hello` ~ `);` );
mixin("writeln(`World`);"
On 08/20/2017 12:27 PM, WhatMeWorry wrote:
> // Mixins are for mixing in generated code into the source code.
> // The mixed in code may be generated as a template instance
> // or a string.
Yes, it means that the string must be legal D code.
> mixin(`writel
It's stuff like this which makes me very frustrated. Or depressed
because it demonstrates just how poor a programmer I am:
string printStatement(string message) {
return `writeln("` ~ message ~ `");`;
}
void main()
{
// Mixins are for mixing in generated code into t
On Thursday, 3 August 2017 at 19:05:47 UTC, Meta wrote:
On Thursday, 3 August 2017 at 19:03:55 UTC, Meta wrote:
`mixin vectorize!sin vsin; alias sin = vsin;` and see if it
Should be `alias sin = vsin.sin;`
Thanks, this pointed me in the right direction. I got the line
below working.
m
On Thursday, 3 August 2017 at 19:03:55 UTC, Meta wrote:
`mixin vectorize!sin vsin; alias sin = vsin;` and see if it
Should be `alias sin = vsin.sin;`
On Thursday, 3 August 2017 at 15:29:47 UTC, jmh530 wrote:
I am trying to create a vectorize function that mixes in a new
version of function with the same name that applies the
function (to an ndslice).
The code below compiles without error and has the behavior I
would expect.
However, when
I am trying to create a vectorize function that mixes in a new
version of function with the same name that applies the function
(to an ndslice).
The code below compiles without error and has the behavior I
would expect.
However, when I change the function import to a selective import
(e.g.
On Sunday, 18 June 2017 at 16:02:38 UTC, Seb wrote:
On Saturday, 17 June 2017 at 11:27:40 UTC, Igor Shirkalin wrote:
On Saturday, 17 June 2017 at 11:23:52 UTC, Cym13 wrote:
On Saturday, 17 June 2017 at 11:20:53 UTC, Igor Shirkalin
wrote:
[...]
I'm sure others will have cleaner solutions as a
1 - 100 of 300 matches
Mail list logo