On Wednesday, 15 March 2023 at 19:22:32 UTC, Paul Backus wrote:
On Tuesday, 14 March 2023 at 10:19:24 UTC, Elfstone wrote:
[...]
Currently the best workaround for this is to define `Vector` as
a `struct` with `alias this` instead of as an `alias`:
```d
struct Matrix(S, size_t M, size_t N)
{
On Tuesday, 14 March 2023 at 10:19:24 UTC, Elfstone wrote:
I went back to some of my old code and couldn't stand what I
had ended up with - If I already have a well-defined `Vector`,
why do I have to write extra code to implement `isVector`, and
use `isVector` instead of simply declaring the pa
eters, because D simply won't match template alias
parameters, and I could not find a way to create a constraint
based on an existing alias, which defeats the supposed meaning
and purpose of `alias`.
I hope some Samaritan in the community will actually "see the
value" in this, pic
On Tuesday, 14 March 2023 at 10:19:24 UTC, Elfstone wrote:
```D
struct Matrix(S, size_t M, size_t N)
{
}
alias Vector(S, size_t N) = Matrix!(S, N, 1);
enum isVector(V) = is(V == Vector!(S, N), S, size_t N); // it
doesn't work
enum isVectorCorrect(V) = is(V == Matrix!(U, N, 1), U, size_t
N);
```D
struct Matrix(S, size_t M, size_t N)
{
}
alias Vector(S, size_t N) = Matrix!(S, N, 1);
enum isVector(V) = is(V == Vector!(S, N), S, size_t N); // it
doesn't work
enum isVectorCorrect(V) = is(V == Matrix!(U, N, 1), U, size_t N);
// the "correct" way and how much I like to REPEAT myself!
On Friday, 24 February 2023 at 15:28:18 UTC, Steven Schveighoffer
wrote:
On 2/24/23 7:00 AM, Elfstone wrote:
Seems like the same bug is still there after ten years.
`static` should not affect module-level functions, but also,
this code should work without `static`.
Reported, not sure if t
On Friday, 24 February 2023 at 14:22:17 UTC, user1234 wrote:
you can break using `goto`, restore `static` everywhere, and
using local introspection determine whether the result exists.
```d
struct Bar
{
@("hello") int t;
}
static bool hasAttribute(alias F, T)()
{
static foreach
On 2/24/23 7:00 AM, Elfstone wrote:
Seems like the same bug is still there after ten years.
`static` should not affect module-level functions, but also, this code
should work without `static`.
Reported, not sure if there's a previous bug, it was hard to come up
with a good description:
On Friday, 24 February 2023 at 12:00:41 UTC, Elfstone wrote:
Seems like the same bug is still there after ten years.
```d
struct Bar
{
@("hello") int t;
}
static bool hasAttribute(alias F, T)()
{
bool result = false;
https://forum.dlang.org/post/imnannjdgtjnlzevh...@forum.dlang.org
On Saturday, 24 August 2013 at 11:47:43 UTC, Matej Nanut wrote:
On Friday, 23 August 2013 at 22:54:33 UTC, Jonathan M Davis
wrote:
Because without static it's a member variable, which means
that you have to
have a constructed obj
On Wednesday, 22 February 2023 at 20:20:46 UTC, Dark Hole wrote:
I'm trying to rewrite really old D code. There was fragment
like that:
```d
template Foo(T, T[] Array) {
// ...
}
// ...
Bar[] arr;
Foo!(Bar, arr);
```
This gives error `can't read arr in compile time`. Small
changes:
```d
t
On Wednesday, 22 February 2023 at 20:20:46 UTC, Dark Hole wrote:
```d
template Foo(T, alias T[] Array) {
// ...
}
// ...
Bar[] arr;
Foo!(Bar, arr);
```
This is valid D, but it doesn't work. It gives error "Error:
template instance `Foo!(Bar, arr)` does not match template
declaration `Foo(T
I'm trying to rewrite really old D code. There was fragment like
that:
```d
template Foo(T, T[] Array) {
// ...
}
// ...
Bar[] arr;
Foo!(Bar, arr);
```
This gives error `can't read arr in compile time`. Small changes:
```d
template Foo(T, alias T[] Array) {
// ...
}
// ...
Bar[] arr;
Foo
On Saturday, 16 January 2021 at 01:21:24 UTC, Paul wrote:
I'm having issues when trying to use a template alias as a
template specialisation.
When using the following:
alias Vec(uint size, Type) = Mat!(size, 1, Type);
void setUniform(V : Vec!(L, bool), int L)(string name, V
On Saturday, 16 January 2021 at 01:38:38 UTC, Paul Backus wrote:
You have encountered issue 1807:
https://issues.dlang.org/show_bug.cgi?id=1807
Ah I see, thank you, sad to see several DIP's I'd be interested
in are postponed :(
Thanks for the workaround hint, I'll probably be using that.
On Saturday, 16 January 2021 at 01:21:24 UTC, Paul wrote:
I'm having issues when trying to use a template alias as a
template specialisation.
When using the following:
alias Vec(uint size, Type) = Mat!(size, 1, Type);
void setUniform(V : Vec!(L, bool), int L)(string name, V
I'm having issues when trying to use a template alias as a
template specialisation.
When using the following:
alias Vec(uint size, Type) = Mat!(size, 1, Type);
void setUniform(V : Vec!(L, bool), int L)(string name, V value)
{...}
Vec!(4, bool) a;
setUniform("test",
On 23.02.19 23:30, Alexandru Ermicioi wrote:
According to
https://dlang.org/spec/template.html#TemplateAliasParameter, simple
types and arrays are excluded from the list of supported "alias X"
arguments. I'm wondering why do we have such limitation? Is there any
reasoning at limiting primitive
Perhaps I missed somewhere, but it seems that you can pass only
classes or interfaces to alias argument of a template. Trying to
pass another type (such as int, int[]) yields an error.
Example of issue:
void test(alias T)(int o) {
import std.stdio;
writeln("coo"
On Saturday, 4 August 2018 at 12:54:49 UTC, Steven Schveighoffer
wrote:
Once you have an alias, it's the original thing in all
respects. So there's no way to get the specific alias that was
used. That's not a bug, but a feature.
Aha. Thanks.
I've tried std.traits.TemplateOf and __traits
On 8/3/18 12:17 PM, aliak wrote:
Hi
Is there a way to tell if an alias is to a template?
I'm writing some algorithms and I need to distinguish between a binary
predicate that provides "less than" and one that provides "equal to"
semantics. So I have these two templates:
template eq(alias pr
On Friday, 3 August 2018 at 19:10:45 UTC, Hakan Aras wrote:
I don't think you can distinguish between entities evaluated
through different templates. TemplateOf will paradoxically not
work on pure templates of the form "template X() {}" only
things like template functions and template structs.
I don't think you can distinguish between entities evaluated
through different templates. TemplateOf will paradoxically not
work on pure templates of the form "template X() {}" only things
like template functions and template structs. isSame, is, and
isInstanceOf will only work on the fully eva
Hi
Is there a way to tell if an alias is to a template?
I'm writing some algorithms and I need to distinguish between a
binary predicate that provides "less than" and one that provides
"equal to" semantics. So I have these two templates:
template eq(alias pred) {
alias eq = pred;
}
temp
On Thursday, 19 July 2018 at 22:16:22 UTC, Ali Çehreli wrote:
On 07/19/2018 08:12 AM, Emma wrote:
> [...]
> If I try to compile it, dmd complains, which I guess makes
sense:
>
> ---
> Error: need this for bar of type void()
> Error: need this for baz of type void()
> ---
>
> [...]
I think it's a
On 07/19/2018 08:12 AM, Emma wrote:
> void test(alias fn1, alias fn2)()
> {
> fn1();
> fn2();
> }
>
> struct Foo
> {
> void foo()
> {
> test!(bar, baz);
> }
>
> void bar()
> {}
>
> void baz()
> {}
> }
> ---
>
> If I try to compile it, dmd comp
Hello,
I’ve got this piece of code:
---
import std.stdio;
void test(alias fn1, alias fn2)()
{
fn1();
fn2();
}
struct Foo
{
void foo()
{
test!(bar, baz);
}
void bar()
{}
void baz()
{}
}
---
If I try to compile it, dmd complains, which I guess makes
On Sunday, 1 July 2018 at 13:01:20 UTC, Timoses wrote:
Aw, okay, then that won't work.
Still, this looks like it should work:
void foo(F, T)(T param) { writeln("Called with type: ",
T.stringof); }
alias tfoo = ApplyLeft!(foo, int);
tfoo!string("hi");
// tfoo("hi"); // Error
On Sunday, 1 July 2018 at 11:55:15 UTC, Simen Kjærås wrote:
On Sunday, 1 July 2018 at 09:46:55 UTC, Timoses wrote:
Would be nice if std.meta.ApplyLeft did the job here.. Is
there no way of achieving that?
[snip]
Would have to find a way to determine whether Template would
resolve to a function
On Sunday, 1 July 2018 at 09:46:55 UTC, Timoses wrote:
Would be nice if std.meta.ApplyLeft did the job here.. Is there
no way of achieving that?
[snip]
Would have to find a way to determine whether Template would
resolve to a function or not. Can't find anything in Traits[1]
or std.traits[2].
On Sunday, 1 July 2018 at 01:48:15 UTC, Simen Kjærås wrote:
I'd send you straight to std.meta.ApplyLeft, but it seems to do
the wrong thing here, in that it doesn't handle IFTI. This
thing does:
void fooImpl(int n, T)(const T line) { }
unittest {
alias fun = applyLeft!(fooImpl, 3);
On Saturday, 30 June 2018 at 21:11:54 UTC, Anonymouse wrote:
I have a template that I want to provide easy aliases for,
where the aliases includes (partially applies?) a template
parameter.
void fooImpl(char token, T)(const T line)
{
// ...
}
alias quoteFoo(T) = fooImpl!('"', T);
alias s
;fooImpl!('"', string);
auto singlequoteFooString = &fooImpl!('\'', string);
void main()
{
quoteFooString("test quote");
singlequoteFooString("test single quote");
import std.meta;
// std/meta.d(1232): Error: template instance
`Template!'"'` does not match template
//alias quoteFoo = ApplyLeft!(fooImpl, '"');
//quoteFoo(3);
}
I have a template that I want to provide easy aliases for, where
the aliases includes (partially applies?) a template parameter.
void fooImpl(char token, T)(const T line)
{
// ...
}
alias quoteFoo(T) = fooImpl!('"', T);
alias singlequoteFoo(T) = fooImpl!('\'', T);
void main()
{
quoteF
Thanks to both, I got it. Type templates for generic types, and
alias for other things knowing that the instantiation is by
symbol.
Yes, the "alias this" in my message was a (double) brainfart, I
actually wanted to write "alias template".
In this case both functions had the same assembler b
nd the only diffence is that the call to writevalue1
does a "mov -0x8(%rdi),%edi" just before the callq instruction.
(As noted by Mike the examples you present are actually template
alias parameters, not alias this which affects name lookup.)
There are three kinds of template p
On Wednesday, 12 April 2017 at 11:06:13 UTC, Juanjo Alvarez wrote:
Hi!
With "alias this" accepting runtime variables I'm struggling to
FYI, you are not talking about "alias this", but "alias template
parameters", two very different concepts.
understand the difference between a generic funct
Hi!
With "alias this" accepting runtime variables I'm struggling to
understand the difference between a generic function with an
"alias this" parameter and another one with a "runtime" parameter
of template type.
Example:
// example code
import std.stdio: writeln;
void writevalue
On Wednesday, 22 March 2017 at 18:12:31 UTC, Yuxuan Shui wrote:
Hi,
Is there any difference, when a type is passed into an alias
parameter vs into a type parameter?
alias parameters fail with builtin types, ex. 'int'.
hopefully this will be corrected one day.
Hi,
Is there any difference, when a type is passed into an alias
parameter vs into a type parameter?
main.d:
--
struct A(T, int D) {
this(string ignore){}
}
alias B(T)=A!(T, 1);
void fun1(T)(A!(T,1) a) { }
void fun2(T)(B!T a) { }
unittest{
auto a=A!(double,1)("a");
assert(is(typeof(a) == B!double));
fun1(a);//ok
fun2!double(a);//ok
// no IFTI here:
//fun2(a);//not ok:
> functions. The grammar does not allow this syntax:
>>>
>>> ```
>>> template (alias Modules ...) {
>>> ...
>>> ```
>>
>> The grammar allows omitting the 'alias' keyword.
>>
>> artur
>
> alias parameters are diffe
On Friday, 8 May 2015 at 22:29:28 UTC, Biotronic wrote:
Sadly, the ... syntax precludes the use of __LINE__ and
__FILE__. :(
You can put them in the runtime parameters:
void traceVars(alias T, U...)(size_t line = __LINE__, string file
= __FILE__) {
import std.stdio : writeln;
wr
On Friday, 8 May 2015 at 21:56:56 UTC, Brian Schott wrote:
Allowing "template Tem(alias Args ...)" syntax would let me
trace multiple variables at once.
Actually, this already works:
void traceVars(alias T, U...)() {
import std.stdio : writeln;
writeln(T.stringof, ": ", T);
static
On Friday, 8 May 2015 at 12:44:31 UTC, Artur Skawina wrote:
On 05/08/15 03:53, Brian Schott via Digitalmars-d-learn wrote:
The problem occurs when I want to register multiple modules to
scan for functions. The grammar does not allow this syntax:
```
template (alias Modules
On Friday, 8 May 2015 at 02:03:17 UTC, Rikki Cattermole wrote:
Can you not use something like this?
Yes. I was getting confused by another problem that I had just
worked on before this one.
On 05/08/15 03:53, Brian Schott via Digitalmars-d-learn wrote:
> The problem occurs when I want to register multiple modules to scan for
> functions. The grammar does not allow this syntax:
>
> ```
> template (alias Modules ...) {
> ...
> ```
The grammar allows omittin
his syntax:
```
template (alias Modules ...) {
...
```
Any ideas (besides "STRING MIXINS EVERYWHERE")?
Can you not use something like this?
import std.stdio;
import std.traits;
void main() {
func!(std.stdio, std.traits)();
}
void func(T...)() {
pr
the
implementation, which is ugly because Phobos is missing a lot of
functionality, but that's not the topic I'm discussing here).
The problem occurs when I want to register multiple modules to
scan for functions. The grammar does not allow this syntax:
```
template (ali
Baz:
Is this a normal behaviour ?
Try to move the definition of "poly" to module-level scope.
This is a design decision to avoid other troubles.
Bye,
bearophile
Is this a normal behaviour ?
---
void main()
{
import std.algorithm;
auto list = [0,1,2,3];
alias poly = map;
list.poly!(a => a + a);
}
---
outputs:
"Error: no property 'poly' for type 'int[]'"
On Saturday, 13 September 2014 at 11:34:01 UTC, Marc Schütz wrote:
Consider the following code:
alias Sink = scope void delegate(const(char)[]);
private template generateAliases(int __i, __vars...) {
import std.conv : to;
static if(__i < __vars.length)
On Sunday, 14 September 2014 at 09:29:16 UTC, Kagamin wrote:
Doesn't this cause infinite recursion?
No, because the inner templates are instantiated with different
first template parameters. Even if all template parameters were
the same, it would only be a runtime recursion.
Doesn't this cause infinite recursion?
Consider the following code:
alias Sink = scope void delegate(const(char)[]);
private template generateAliases(int __i, __vars...) {
import std.conv : to;
static if(__i < __vars.length)
enum generateAliases = "alias " ~
__vars[__i].stringof ~ " =
On Friday, 23 August 2013 at 22:54:33 UTC, Jonathan M Davis wrote:
Because without static it's a member variable, which means that
you have to
have a constructed object to access it (since it's part of the
object). When
you declare a variable in a class or struct static, then
there's only one f
On Friday, August 23, 2013 23:28:46 Matej Nanut wrote:
> Hello!
>
> I've run into this issue that I don't understand, maybe someone
> can enlighten me. :)
>
> This code:
> ---
> struct Thing
> {
> int i;
> }
>
> void main()
> {
> t!(Thing.i)();
> }
>
> void t(alias a)()
> {
> return;
> }
> ---
Hello!
I've run into this issue that I don't understand, maybe someone
can enlighten me. :)
This code:
---
struct Thing
{
int i;
}
void main()
{
t!(Thing.i)();
}
void t(alias a)()
{
return;
}
---
fails to compile with: ‘Error: need 'this' for 't' of type 'pure
nothrow @safe voi
On Thu, 09 May 2013 10:00:45 -0400, Dicebot wrote:
Feels like I am the only one who wants to restrict rules, not relax them
=/
But, erm, you don't need alias accepting literals for old syntax!
Strings are valid as template value parameters:
http://dpaste.1azy.net/54e5d3f2
Hm.. maybe it
Feels like I am the only one who wants to restrict rules, not
relax them =/
But, erm, you don't need alias accepting literals for old syntax!
Strings are valid as template value parameters:
http://dpaste.1azy.net/54e5d3f2
ing it for template alias parameters does is enable the whole
std.algorithm acceptance of a string literal for function lambdas.
Arguably, this is no longer needed due to the new lambda syntax (but I
think we have found other uses for it). It has also caused some headaches:
map!"a.x"(
Kenji Hara:
AFAIK, there is no plan for fix. The behavior is currently a
part of language design.
Considering matters of D semantic uniformity, and the code shown
by Dicebot:
template Hello(T...)
if (T.length == 1)
{
static if (is(T[0]))
// ...
else
// ...
}
The
On Thursday, 9 May 2013 at 13:27:35 UTC, Steven Schveighoffer
wrote:
template GetString(T) if (is(T == int) || is(T == float) || ...)
{
enum string GetString = T.stringof;
}
Current idiomatic D way to handle both built-in types and symbols
looks like this:
template Hello(T...)
if (T.l
On Thursday, 9 May 2013 at 12:09:03 UTC, Dicebot wrote:
On Thursday, 9 May 2013 at 11:19:38 UTC, bearophile wrote:
It will be fixed.
Ugh, proof-link? I have always thought it is by design and that
actually makes sense.
AFAIK, there is no plan for fix. The behavior is currently a part
of la
Steven Schveighoffer:
Do you have evidence of an official statement to the contrary?
Here I don't have evidence, just faith :-)
Bye,
bearophile
;
}
There may even already be a template for detecting a builtin type, not
sure.
On Thu, 09 May 2013 07:19:37 -0400, bearophile
wrote:
Template alias arguments don't yet accept built-in types as int. It will
be fixed.
I don't think this is true, alias strictly accepts symb
On Thursday, 9 May 2013 at 11:19:38 UTC, bearophile wrote:
It will be fixed.
Ugh, proof-link? I have always thought it is by design and that
actually makes sense.
On Thursday, 9 May 2013 at 10:59:02 UTC, ref2401 wrote:
Version D 2.062
http://dlang.org/template.html#TemplateAliasParameter
Is is said in the documentation that is's possible but i get
compile time error.
template GetString(alias Arg)
{
enum string GetString = Arg.stringof;
}
void m
ref2401:
template GetString(alias Arg)
{
enum string GetString = Arg.stringof;
}
...
writeln(GetString!int); // Error: template instance
Template alias arguments don't yet accept built-in types as int.
It will be fixed.
Bye,
bearophile
Version D 2.062
http://dlang.org/template.html#TemplateAliasParameter
Is is said in the documentation that is's possible but i get
compile time error.
template GetString(alias Arg)
{
enum string GetString = Arg.stringof;
}
void main(string[] argv)
{
writeln(GetString!"1234");
i'm using VisualD.
this assertion fails assert(msg == "Null reference message");
in my actual code instead of variable _message an exception is
thrown if (obj is null) == true.
i'm using the unittest block to test exception throwing.
...
this(T obj)
{
if (obj is
On Tue, 07 May 2013 10:58:09 -0400, ref2401 wrote:
Version D 2.062
class MyClass
{}
struct MyStruct(T)
if (is(T == class))
{
string _message = "nothing";
this(T obj)
{
if (obj is null){
_message = "Null reference message";
Version D 2.062
class MyClass
{}
struct MyStruct(T)
if (is(T == class))
{
string _message = "nothing";
this(T obj)
{
if (obj is null){
_message = "Null reference message";
}
else{
On 27/02/2013 18:06, Dicebot wrote:
Ye, lambda litteral issue is different one.
OK.
My code example: http://dpaste.1azy.net/b06370ea
The problem may be related to optional parentheses and stringof, and may
be a compiler bug.
You can pass function names as a template alias parameter
Fuck. Optional. Parens.
Thank you. I have tried some other code than .stringof but guess
it invoked Symbols somewhere silently, too.
Ye, lambda litteral issue is different one.
My code example: http://dpaste.1azy.net/b06370ea
On 27/02/2013 17:38, Nick Treleaven wrote:
On 27/02/2013 15:20, Dicebot wrote:
Looking here: http://dlang.org/template.html#TemplateAliasParameter
There are no function symbols in the list. And quick check that it won't
compile.
Two questions arise:
a) Why so?
b) Is there a workaround?
Actua
On 27/02/2013 15:20, Dicebot wrote:
Looking here: http://dlang.org/template.html#TemplateAliasParameter
There are no function symbols in the list. And quick check that it won't
compile.
Two questions arise:
a) Why so?
b) Is there a workaround?
This has sometimes come up in the NG, with some s
Actually it looks like a somewhat broken behavior as it works for
parameter-less functions.
On Sunday, 25 November 2012 at 16:42:03 UTC, Maxim Fomin wrote:
Recently I saw a major pull affecting this behavior, so in
2.061 the situation may be changed (I haven't bother to figure
yet). In practice this makes a tricky thing to understand what
S() is and creates a problem when you e.x. hea
On Sunday, 25 November 2012 at 16:01:39 UTC, Ali Çehreli wrote:
Could you please create a bug report:
http://d.puremagic.com/issues/
Ali
Filed an issue 9078.
On Sunday, 25 November 2012 at 15:27:53 UTC, comco wrote:
A!B(...) defines a struct A with B typed in as Method, so call
to method(s); is the same as B(string)
Why is that? Here method is an instance of the type Method, not
the type Method itself, so by saying `method(s)` we can't mean
a cons
On 11/25/2012 07:27 AM, comco wrote:
>
>> A!B(...) defines a struct A with B typed in as Method, so call to
>> method(s); is the same as B(string)
> Why is that? Here method is an instance of the type Method, not the type
> Method itself,
That could be case but you original code did use a type na
A!B(...) defines a struct A with B typed in as Method, so call
to method(s); is the same as B(string)
Why is that? Here method is an instance of the type Method, not
the type Method itself, so by saying `method(s)` we can't mean a
constructor. Something very strange happens...
I have a simple
On Saturday, 24 November 2012 at 20:34:39 UTC, comco wrote:
I have the following snippet:
struct A(alias Method)
{
string s;
this(Method method) {
method(s); // 5
}
}
struct B
{
this(int i) { }
void opCall(string s) { }
}
void main() {
A!B(B(0));
}
This code
I have the following snippet:
struct A(alias Method)
{
string s;
this(Method method) {
method(s); // 5
}
}
struct B
{
this(int i) { }
void opCall(string s) { }
}
void main() {
A!B(B(0));
}
This code fails to compile with the following errors:
test.d(5): Error:
On 2012-05-18 17:11, Maxim Fomin wrote:
Changing template parameter to Bar.f or bar.f affects value of
bar.f.data. Seems to be a bug.
It's a bug. Further reduction:
import std.stdio;
mixin template Foo() {
string data = "default";
}
struct Bar {
mixin Foo f;
}
string get_data(alias u
Reduced:
import std.stdio;
mixin template Foo() {
string data = "default";
}
class Bar {
string data;
mixin Foo f;
}
void check_data(alias M, T)(T obj) {
writeln(M.stringof);
writeln(obj.data);
writeln(obj.f.data);
}
void main() {
Bar bar = new Bar;
bar.data = "Bar";
bar.f.d
On Sunday, 11 November 2012 at 10:36:42 UTC, Jacob Carlborg wrote:
This won't work. The "node" template doesn't evaluate to a type
and you wouldn't use it as a mixin if it did.
You _can_ actually use an identifier for mixin templates, it is
used to disambiguate in case of name collisions.
As
On Sunday, 11 November 2012 at 10:36:42 UTC, Jacob Carlborg wrote:
This won't work. The "node" template doesn't evaluate to a type
and you wouldn't use it as a mixin if it did.
But this is works! Why?
mixin template node() {
alias int E;
E prev, next;
}
struct list(alias N) {
N.E head;
On 2012-11-11 10:04, Jack Applegame wrote:
I'm trying creating template for intrusive double-linked list:
mixin template node() {
static if(is(this == struct))
alias typeof(this)* E;
else
alias typeof(this) E;
E prev, next;
}
class A {
mixin node L1;
mixin node L2;
}
T
I'm trying creating template for intrusive double-linked list:
mixin template node() {
static if(is(this == struct))
alias typeof(this)* E;
else
alias typeof(this) E;
E prev, next;
}
struct list(alias N) {
N.E head;
N.E tail;
}
class A {
mixin node;
}
list!A l;
All works g
On 12/24/2011 11:23 AM, André Stein wrote:
Hi,
I'm trying to write a template function which takes a templated alias to
another type:
struct test(T)
{
}
template aliasT(T)
{
alias test!(T) aliasT;
}
void foo(T)(test!T t) { // works
}
void foo2(T)(aliasT!T t) { // doesn't work
}
int main(str
Hi,
I'm trying to write a template function which takes a templated alias to
another type:
struct test(T)
{
}
template aliasT(T)
{
alias test!(T) aliasT;
}
void foo(T)(test!T t) { // works
}
void foo2(T)(aliasT!T t) { // doesn't work
}
int main(string[] args)
{
test!(int) t;
al
enuhtac Wrote:
> Hi,
>
> I'm playing around with template alias parameters. At the moment I'm
> considering the following simple code:
>
> struct A
> {};
>
> struct B( T )
> {
> T t;
> };
>
> struct C( alias T )
> {
>
Hi,
I'm playing around with template alias parameters. At the moment I'm
considering the following simple code:
struct A
{};
struct B( T )
{
T t;
};
struct C( alias T )
{
T t;
};
void main()
{
B!A a;
C!A b;
}
What exactly is the difference between a and b? Both seem
simendsjo Wrote:
> Are these pages written using DDoc? Is it possible to extract and compile the
> examples to
> ensure they are correct? And perhaps use asserts instead of/in addition to
> comments where
> possible (Asserts are used many places already)?
> Executable and verifiable examples cou
This example comes from http://digitalmars.com/d/2.0/template.html
int x;
template Foo(alias X)
{
static int* p = &X;
}
void test()
{
alias Foo!(x) bar;
*bar.p = 3; // set x to 3
static int y;
alias Foo!(y) abc;
*abc.p = 3; // set y to 3
}
Compiling this
Luke J. West wrote:
Hi,
I don't want to keep typing isNumeric!T | isSomeChar!T. I want to type
isBuiltIn!T instead, but am trying to work out how to implement it.
Something like
template isBuiltInT(T) {const bool t=isNumeric!T | isSomeChar!T};}
alias isBuiltInT.t isBuiltIn;
But that doesn
Use the eponymous trick:
import std.stdio;
import std.traits;
template isBuiltInT(T)
{
enum isBuiltInT = isNumeric!T || isSomeChar!T;
}
void main()
{
assert(isBuiltInT!(int));
assert(isBuiltInT!(char));
}
1 - 100 of 104 matches
Mail list logo