On Saturday, 18 March 2023 at 20:42:50 UTC, Nick Treleaven wrote:
On Saturday, 18 March 2023 at 19:22:07 UTC, Chris Katko wrote:
...
So there's multiple sub-problems to solve. I asked this years
ago, and got 90% of the way done and then lost the code and
cannot find the original forum post.
On Saturday, 18 March 2023 at 19:22:07 UTC, Chris Katko wrote:
...
So there's multiple sub-problems to solve. I asked this years
ago, and got 90% of the way done and then lost the code and
cannot find the original forum post.
Maybe it was this?:
Given:
```D
struct pos {float x, y;}
draw(myBitmap, pos(320, 240), centered);
draw(pos(320, 240), myBitmap);
draw("text", myFont, pos(320, 240));
```
I'm writing a general "draw" template function that through
compile-time, calls an associated DAllegro/Allegro 5 function:
```
draw(myBitmap,
On Sunday, 10 October 2021 at 12:56:30 UTC, Some Guy wrote:
But I did not understand what you meant by "enums hold values,
not types". Aren't types values at compile time?
Types can be template arguments, if that's what you mean, but
they aren't values.
On Sunday, 10 October 2021 at 12:48:49 UTC, Adam D Ruppe wrote:
On Sunday, 10 October 2021 at 12:39:17 UTC, Some Guy wrote:
I have this enum to get the type
enums hold values, not types.
try alias instead
Thanks! `alias typeOfMember(T, string member) =
typeof(__traits(getMember, T,
On Sunday, 10 October 2021 at 12:39:17 UTC, Some Guy wrote:
I have this enum to get the type
enums hold values, not types.
try alias instead
It actually looks like I'm having problems wherever I try to pass
that enum as a template parameter.
I have this enum to get the type of a member field in a struct:
`enum typeOfMember(T, string member) = typeof(__traits(getMember,
T, member));`
I'm having problems when I try to used it though. For example:
```D
writeln(typeOfMember!(T, member).stringof); // Doesn't work:
Error: initializer
On Thursday, 9 September 2021 at 05:37:35 UTC, Tejas wrote:
On Thursday, 9 September 2021 at 05:32:29 UTC, Tejas wrote:
On Tuesday, 7 September 2021 at 17:47:15 UTC, james.p.leblanc
wrote:
[...]
writeln([0]);
scope(exit) AlignedMallocator.instance.deallocate(buffer);
//...
}
```
On Thursday, 9 September 2021 at 05:32:29 UTC, Tejas wrote:
On Tuesday, 7 September 2021 at 17:47:15 UTC, james.p.leblanc
wrote:
[...]
from what I understand you want to change the aligned data that
you're referring to at runtime.
```d
void main()
{
import
On Tuesday, 7 September 2021 at 17:47:15 UTC, james.p.leblanc
wrote:
On Tuesday, 7 September 2021 at 17:33:31 UTC, Adam D Ruppe
wrote:
On Tuesday, 7 September 2021 at 17:24:34 UTC, james.p.leblanc
wrote:
If you want to do a runtime lookup, you need to separate the
two pieces. This pattern
On Tuesday, 7 September 2021 at 17:24:34 UTC, james.p.leblanc
wrote:
```d
/*…*/
// this is fine (notice that 'val' is never used
foreach( i, val ; u.tupleof ){
ptr = u.tupleof[i].x.ptr;
writeln("ptr: ", ptr);
}
// this fails with: "Error: variable 'i' cannot be read at
On Tuesday, 7 September 2021 at 17:47:15 UTC, james.p.leblanc
wrote:
What I mean by "dig out" the needed "x" is: if I could
alias/enum/
or someother trick be then able just to use that "x" as a
simple static array.
You might be able to just cast the struct to a static array of
the same
On Tuesday, 7 September 2021 at 17:33:31 UTC, Adam D Ruppe wrote:
On Tuesday, 7 September 2021 at 17:24:34 UTC, james.p.leblanc
wrote:
If you want to do a runtime lookup, you need to separate the
two pieces. This pattern works:
switch(runtime_index) {
foreach(i, val; item.tupleof)
On Tuesday, 7 September 2021 at 17:24:34 UTC, james.p.leblanc
wrote:
// this fails with: "Error: variable 'i' cannot be read at
compile time
//
// foreach( i ; 0 .. 3 ){
//ptr = u.tupleof[i].x.ptr;
tuples only exist at compile time, so you'd have to make sure the
indexing is
Dear All,
In playing with some reflection and meta programming, this
curiosity
appeared.
Does someone understand what is happening? I would appreciate
learning
about it if possible. Enclosed code snippet tells the story:
```d
import std.stdio;
import std.traits;
import std.meta;
struct
On Tuesday, 9 February 2021 at 16:25:46 UTC, Paul Backus wrote:
On Tuesday, 9 February 2021 at 16:22:16 UTC, Jeff wrote:
But, those don't work because T is a Tuple of the types. Is
there some trait combination I can use to do this? Something
like (obviously made up)...
all(TemplateArgsOf!T,
On Tuesday, 9 February 2021 at 16:22:16 UTC, Jeff wrote:
But, those don't work because T is a Tuple of the types. Is
there some trait combination I can use to do this? Something
like (obviously made up)...
all(TemplateArgsOf!T, t => isIntegral!t || isSomeString!t)
Thanks!
import std.meta:
Let's say I have...
void foo(T...)(T xs)
{
foreach(x; xs)
{
if (typeid(x) == typeid(int))
writeln("int: ", x);
else
writeln("str: ", x);
}
}
From the body, it's obvious I really only want int or string to
be passed in to foo. Ideally, this
On Wednesday, 30 September 2020 at 18:18:48 UTC, Basile B. wrote:
On Tuesday, 29 September 2020 at 17:08:40 UTC, Frak wrote:
Hi folks,
I've this:
/Users/frak/dlang/ldc-1.23.0/bin/../import/std/traits.d(3711):
Deprecation: function
`std.typecons.Nullable!long.Nullable.get_` is deprecated -
On Tuesday, 29 September 2020 at 17:08:40 UTC, Frak wrote:
Hi folks,
I've this:
/Users/frak/dlang/ldc-1.23.0/bin/../import/std/traits.d(3711):
Deprecation: function
`std.typecons.Nullable!long.Nullable.get_` is deprecated -
Implicit conversion with `alias Nullable.get this` will be
removed
, you probably
can't figure out the exact usage. What's more annoying is
that likely it is a spurious warning. A lot of traits "try
something", and then alias to false or true depending on what
works. But it's not going to make a difference in your code.
It's one of the most annoy
is that
likely it is a spurious warning. A lot of traits "try
something", and then alias to false or true depending on what
works. But it's not going to make a difference in your code.
It's one of the most annoying things in the library. If you
see this warning coming from *your* code
usage. What's more annoying is that
likely it is a spurious warning. A lot of traits "try
something", and then alias to false or true depending on what
works. But it's not going to make a difference in your code.
It's one of the most annoying things in the library. If you see
this warn
On 9/29/20 10:08 AM, Frak wrote:
Hi folks,
I've this:
/Users/frak/dlang/ldc-1.23.0/bin/../import/std/traits.d(3711):
Deprecation: function `std.typecons.Nullable!long.Nullable.get_` is
deprecated - Implicit conversion with `alias Nullable.get this` will be
removed after 2.096. Please use
of traits "try something", and then alias to
false or true depending on what works. But it's not going to make a
difference in your code.
It's one of the most annoying things in the library. If you see this
warning coming from *your* code, then you should fix it. But it will
tell you th
Hi folks,
I've this:
/Users/frak/dlang/ldc-1.23.0/bin/../import/std/traits.d(3711):
Deprecation: function `std.typecons.Nullable!long.Nullable.get_`
is deprecated - Implicit conversion with `alias Nullable.get
this` will be removed after 2.096. Please use `.get` explicitly.
I'm trying to
On Thursday, 6 February 2014 at 23:06:03 UTC, QAston wrote:
How do i get aliases to overloads of a template method like
Class A
{
int a(T)(T tq,T tw);
int a(T)(T tq);
}
__traits(getOverloads, A, "a(int)")doesnt work
Support for template in the getOverloads trait has been added
On Monday, 10 September 2018 at 13:46:08 UTC, aliak wrote:
On Monday, 10 September 2018 at 12:57:25 UTC, Timoses wrote:
How to "select" one?
Can you either:
alias myPeek = () => peek!(int, Endian.bigEndian,
immutable(ubyte)[])();
Or
alias myPeek = (size_t *index) => peek!(int,
On Monday, 10 September 2018 at 12:57:25 UTC, Timoses wrote:
On Thursday, 6 February 2014 at 23:06:03 UTC, QAston wrote:
[...]
Is there any way to "select" overloaded template functions?
I require to select one of `std.bitmanip.peek`
import std.bitmanip : peek;
import std.system :
On Thursday, 6 February 2014 at 23:06:03 UTC, QAston wrote:
How do i get aliases to overloads of a template method like
Class A
{
int a(T)(T tq,T tw);
int a(T)(T tq);
}
__traits(getOverloads, A, "a(int)")doesnt work
Is there any way to "select" overloaded template functions?
I
On Wednesday, 21 March 2018 at 15:36:01 UTC, Márcio Martins wrote:
Hi!
How do I get past this?
static struct X {
int x;
private enum T = 1;
private alias M = string;
}
foreach (Member; __traits(allMembers, X)) {
pragma(msg, __traits(getProtection, __traits(getMember,
On Wednesday, 21 March 2018 at 15:36:01 UTC, Márcio Martins wrote:
Hi!
How do I get past this?
static struct X {
int x;
private enum T = 1;
private alias M = string;
}
foreach (Member; __traits(allMembers, X)) {
pragma(msg, __traits(getProtection, __traits(getMember,
Hi!
How do I get past this?
static struct X {
int x;
private enum T = 1;
private alias M = string;
}
foreach (Member; __traits(allMembers, X)) {
pragma(msg, __traits(getProtection, __traits(getMember, X,
Member)));
}
Output:
public
private
c.d(1084): Error:
On Saturday, 3 March 2018 at 16:20:57 UTC, JN wrote:
https://run.dlang.io/gist/ec7008372d60ac52460dd58068f1ca6d?compiler=dmd
Why only listUDA2 works and listUDA doesn't? Why do I need to
use __traits(getMember again, if I use what I saved in a
variable, it doesn't work :(
because getUDAs
https://run.dlang.io/gist/ec7008372d60ac52460dd58068f1ca6d?compiler=dmd
Why only listUDA2 works and listUDA doesn't? Why do I need to use
__traits(getMember again, if I use what I saved in a variable, it
doesn't work :(
On Thursday, 25 January 2018 at 19:49:05 UTC, JN wrote:
if (!hasUDA!(member, "noserialize"))
Nevermind, I get it now, member is only the field name, not a
'reference', changed it to:
if (!hasUDA!(mixin(T.stringof ~ "." ~ member), "noserialize"))
and works now
On 01/25/2018 11:49 AM, JN wrote:
foreach (i, member; FieldNameTuple!T)
{
if (!hasUDA!(member, "noserialize"))
{
writeln(member);
}
'member' is a string local variable, which does not have that UDA. You
need to get the
I decided it's time to learn how std traits work. I still find
the whole compile time business a bit weird to deal with, so I
decided to write a simple JSON serializer for struct that loops
over member fields and outputs them.
import std.stdio;
import std.json;
import std.traits;
struct
On Saturday, 16 December 2017 at 03:48:01 UTC, Jonathan M Davis
wrote:
On Saturday, December 16, 2017 03:34:43 Marc via
Digitalmars-d-learn wrote:
I need to give a class C, read all user-defined members of it,
both name and value dynamically. for example:
> [...]
then
>[...]
I get this
On Saturday, December 16, 2017 03:34:43 Marc via Digitalmars-d-learn wrote:
> I need to give a class C, read all user-defined members of it,
>
> both name and value dynamically. for example:
> > class C {
> >
> > string a;
> > string b;
> > string c;
> >
> > }
>
> then
>
> > Class c = new
I need to give a class C, read all user-defined members of it,
both name and value dynamically. for example:
class C {
string a;
string b;
string c;
}
then
Class c = new C();
// set c members...
enum string[] members = [__traits(allMembers, C)];
foreach(string member; members) {
04.10.2017 12:54, Biotronic пишет:
template isTemplate(T...) if (T.length == 1) {
enum isTemplate = __traits(isTemplate, T[0]);
}
--
Biotronic
Thank you!
, so
it works, but I think it's dirty hack instead of dry and clean
way...
}
}
```
May be phobos has such traits somewhere?
template isTemplate(T...) if (T.length == 1) {
enum isTemplate = __traits(isTemplate, T[0]);
}
--
Biotronic
dry and clean way...
}
}
```
May be phobos has such traits somewhere?
On Mon, Sep 25, 2017 at 03:41:14PM +, WhatMeWorry via Digitalmars-d-learn
wrote:
> On Monday, 25 September 2017 at 06:07:58 UTC, H. S. Teoh wrote:
> > On Mon, Sep 25, 2017 at 05:28:13AM +, WhatMeForget via
> > Digitalmars-d-learn wrote:
> > > [...]
> >
> > You're not the only one. I
On Monday, 25 September 2017 at 06:07:58 UTC, H. S. Teoh wrote:
On Mon, Sep 25, 2017 at 05:28:13AM +, WhatMeForget via
Digitalmars-d-learn wrote:
[...]
You're not the only one. I stared at this same piece of
documentation for a long time before I figured out what it
meant. This is
On Monday, September 25, 2017 05:28:13 WhatMeForget via Digitalmars-d-learn
wrote:
> This is taken exactly from the traits documentation.
>
> ----
>
> 25 Traits
>
> 25.21 identifier
>
> Takes one argument, a sym
On Mon, Sep 25, 2017 at 05:28:13AM +, WhatMeForget via Digitalmars-d-learn
wrote:
>
> This is taken exactly from the traits documentation.
>
> ----
>
> 25 Traits
>
> 25.21 identifier
>
> Takes one argument, a
On 25/09/2017 6:28 AM, WhatMeForget wrote:
This is taken exactly from the traits documentation.
25 Traits
25.21 identifier
Takes one argument, a symbol. Returns the identifier for that symbol as
a string literal
This is taken exactly from the traits documentation.
25 Traits
25.21 identifier
Takes one argument, a symbol. Returns the identifier for that
symbol as a string literal
On Friday, September 01, 2017 14:38:38 bitwise via Digitalmars-d-learn
wrote:
> When I'm using __traits(allMembers), I get a all the invisible
> functions added by the compiler as well "__ctor", "__xdtor",
> "__cpctor", etc..
>
> Is there a way to filter them out?
You can use std.meta.Filter if
On Friday, 1 September 2017 at 17:26:11 UTC, ketmar wrote:
[...]
they *should* listen. anyone who doesn't just aksing for
troubles, and i see no reason to guard 'em further.
Yeah...eventually came to the same conclusion ;)
Thanks
bitwise wrote:
On Friday, 1 September 2017 at 14:38:38 UTC, bitwise wrote:
When I'm using __traits(allMembers), I get a all the invisible functions
added by the compiler as well "__ctor", "__xdtor", "__cpctor", etc..
Is there a way to filter them out?
dlang's "Lexical" page says:
On Friday, 1 September 2017 at 14:38:38 UTC, bitwise wrote:
When I'm using __traits(allMembers), I get a all the invisible
functions added by the compiler as well "__ctor", "__xdtor",
"__cpctor", etc..
Is there a way to filter them out?
dlang's "Lexical" page says:
"Identifiers starting
When I'm using __traits(allMembers), I get a all the invisible
functions added by the compiler as well "__ctor", "__xdtor",
"__cpctor", etc..
Is there a way to filter them out?
On Tuesday, 25 July 2017 at 11:34:23 UTC, Andre Pany wrote:
On Tuesday, 25 July 2017 at 08:30:43 UTC, ag0aep6g wrote:
Works for me. What compiler are you using?
I reduced the example too lot. The issue is occuring if there
is also a package.d is involved.
m1.d
---
On Tuesday, 25 July 2017 at 08:30:43 UTC, ag0aep6g wrote:
Works for me. What compiler are you using?
I reduced the example too lot. The issue is occuring if there is
also a package.d is involved.
m1.d
---
module m1;
import sub; // Does not throw if replaced with:
On 07/24/2017 11:40 PM, Andre Pany wrote:
m1.d
-
module m1;
import m2;
class Foo
{
int foo;
}
void main()
{
static assert(__traits(compiles, m1.Foo.foo));
static assert(__traits(compiles, m2.Bar.bar));
}
m2.d
---
module m2;
class Bar
{
int
Hi,
I want to validate whether a class contains a specific attribute.
I have the attribute name as compile time string. This string
could either be a direct attribute of the class or a hierarchy
(TextSettings.Font.Size).
As example T is the class Label and p.name contains the text
Known issue:
https://issues.dlang.org/buglist.cgi?quicksearch=getSymbolsByUDA
Ali
I'm reworking my code to use UDAs, and I'm running into a wall of
text of deprecation warnings when compiling.
import std.traits;
private:
struct SomeUDA {}
@SomeUDA
void foo() {}
@SomeUDA
void bar() {}
@SomeUDA
void etc() {}
public:
void main()
{
mixin("static import thisModule = "
On Monday, 27 March 2017 at 21:18:31 UTC, XavierAP wrote:
When I first read about inout as a device to obviate code
duplication typical in C++ const ref overloads, I liked it but
I assumed it was implemented by lowering it into the actual
duplicate overloads. Though I'm not even sure right now
On Monday, 27 March 2017 at 16:28:13 UTC, Gary Willoughby wrote:
Even Andrei was baffled:
http://forum.dlang.org/thread/nepm2k$311l$1...@digitalmars.com
I see... And Walter went further and reported it as a DMD bug
(still open clearly).
It's what I mean. This strange behavior is more
On Sunday, 26 March 2017 at 23:25:49 UTC, XavierAP wrote:
I've looked into Phobos to emulate it when defining my own
trait template, and when I see this:
module std.range.primitives;
// ...
template isInputRange(R)
{
enum bool isInputRange = is(typeof(
(inout int = 0)
{
R r
On Monday, 27 March 2017 at 00:49:14 UTC, Moritz Maxeiner wrote:
Have you tried it without the dummy parameter on the example
given in the bug report [2]?
I see, thanks for finding it! Looks a bit hacky but I can live
with it.
Indeed if I remove the argument from Phobos, Martin's example
On Sunday, 26 March 2017 at 23:25:49 UTC, XavierAP wrote:
I've looked into Phobos to emulate it when defining my own
trait template, and when I see this:
module std.range.primitives;
// ...
template isInputRange(R)
{
enum bool isInputRange = is(typeof(
(inout int = 0)
{
R r
I've looked into Phobos to emulate it when defining my own trait
template, and when I see this:
module std.range.primitives;
// ...
template isInputRange(R)
{
enum bool isInputRange = is(typeof(
(inout int = 0)
{
R r = R.init; // can define a range object
if
On Thursday, 23 February 2017 at 18:35:29 UTC, Profile Anaysis
wrote:
[...]
option 1 is the one I was shooting for. does the static if
(audio) just check for the existence of audio, or does it also
check to see if audio is true as well?
Yes, but it checks at compile time. So the code
There are a few options:
1. static if(audio)
2. version(audio)
3. if (audio)
It looks like you are trying to create the version(audio)
semantic(if exists then use, else don't).
Ultimately, though, if you are trying to make a binary that
can either use audio or not depending on where it is
On Wednesday, 22 February 2017 at 22:37:25 UTC, Profile Anaysis
wrote:
On Wednesday, 22 February 2017 at 21:27:47 UTC, WhatMeWorry
wrote:
I'm doing conditional compilation using static ifs like so:
enum bool audio = true;
// if audio flag is present and set to true, add to code
On Wednesday, 22 February 2017 at 21:27:47 UTC, WhatMeWorry wrote:
I'm doing conditional compilation using static ifs like so:
enum bool audio = true;
// if audio flag is present and set to true, add to code build
static if ( (__traits(compiles, audio)) && audio)
On Wednesday, 22 February 2017 at 21:27:47 UTC, WhatMeWorry wrote:
I'm doing conditional compilation using static ifs like so:
enum bool audio = true;
// if audio flag is present and set to true, add to code build
static if ( (__traits(compiles, audio)) && audio)
I'm doing conditional compilation using static ifs like so:
enum bool audio = true;
// if audio flag is present and set to true, add to code build
static if ( (__traits(compiles, audio)) && audio)
playSound(soundSys, BLEEP );
This works,
and isType traits.
And I am curious about of what is the Monitor.
The whole thing you do to initialize could be replaced by a copy of the
initializer, which is what emplace does:
static T nogcNew(T, Args...)(Args args) @nogc
{
import core.stdc.stdlib : malloc;
import std.traits, std.meta
Monitor is not an
expression
..\src\core\nogc_memory.d(64): Error: template instance
core.nogc_memory.__unittestL39_3.MyClass.NogcAllocator!(MyClass).nogcNew!(MyClass, int) error instantiating
I don't understand my mistake with the getMember and isType
traits.
And I am curious about of what
\nogc_memory.d(64): Error: template instance
core.nogc_memory.__unittestL39_3.MyClass.NogcAllocator!(MyClass).nogcNew!(MyClass,
int) error instantiating
I don't understand my mistake with the getMember and isType traits.
And I am curious about of what is the Monitor.
On 2016-09-20 21:45, Ram_B wrote:
I'm trying to set fields of object from JSON with traits library. How i
can to it properly?
import std.stdio;
import std.json;
import std.traits;
import std.meta: Alias;
class Obj{
void fromJSON(this T)(JSONValue j){
foreach(field; FieldNameTuple
I'm trying to set fields of object from JSON with traits library.
How i can to it properly?
import std.stdio;
import std.json;
import std.traits;
import std.meta: Alias;
class Obj{
void fromJSON(this T)(JSONValue j){
foreach(field; FieldNameTuple!T
On Sunday, 18 September 2016 at 13:28:15 UTC, ketmar wrote:
https://issues.dlang.org/show_bug.cgi?id=11595
https://issues.dlang.org/show_bug.cgi?id=16044
Thanks that clarifies my issues...
Do you if there are any statuses on that?
https://issues.dlang.org/show_bug.cgi?id=11595
https://issues.dlang.org/show_bug.cgi?id=16044
I'm trying to retrieve all functions with a certain attribute.
I know how to go about it and I can get it working with functions
in the same module as the traits expression, but as soon as I
nest modules in packages and import those packages then I don't
get any functions.
Is there a way
On Friday, 16 September 2016 at 08:01:18 UTC, Gary Willoughby
wrote:
On Thursday, 15 September 2016 at 22:05:55 UTC, Ram_B wrote:
test.d(33): Error: variable f cannot be read at compile time
test.d(33): Error: string expected as second argument of
__traits hasMember instead of __error
On Thursday, 15 September 2016 at 22:05:55 UTC, Ram_B wrote:
test.d(33): Error: variable f cannot be read at compile time
test.d(33): Error: string expected as second argument of
__traits hasMember instead of __error
test.d(46): Error: template instance test.A.t!(B) error
instantiating
Maybe
On Thursday, 15 September 2016 at 15:56:56 UTC, Gary Willoughby
wrote:
On Thursday, 15 September 2016 at 15:07:09 UTC, Ram_B wrote:
How i can get fields of derived classes in runtime? This not
works
What about something like this:
import std.traits;
import std.stdio;
class A {
int
On Thursday, 15 September 2016 at 15:56:56 UTC, Gary Willoughby
wrote:
On Thursday, 15 September 2016 at 15:07:09 UTC, Ram_B wrote:
How i can get fields of derived classes in runtime? This not
works
What about something like this:
import std.traits;
import std.stdio;
class A {
int
On Thursday, 15 September 2016 at 15:07:09 UTC, Ram_B wrote:
How i can get fields of derived classes in runtime? This not
works
What about something like this:
import std.traits;
import std.stdio;
class A {
int a,b;
this(){}
void fields(this T)(){
On 16/09/2016 3:07 AM, Ram_B wrote:
How i can get fields of derived classes in runtime? This not works
import std.traits;
import std.experimental.logger;
class A {
int a,b;
this(){}
void fields(){
log(FieldNameTuple!this);
}
}
class B : A{
int c;
this(){}
}
How i can get fields of derived classes in runtime? This not works
import std.traits;
import std.experimental.logger;
class A {
int a,b;
this(){}
void fields(){
log(FieldNameTuple!this);
}
}
class B : A{
int c;
this(){}
}
I'm using DMD 2.071 and am getting this new deprecation error:
source/screener/lib/syntax/semantics.d(42): Deprecation:
screener.lib.virtualmachine.functions.object is not visible from
module semantics
source/screener/lib/syntax/semantics.d(42): Deprecation:
On Thursday, 6 February 2014 at 23:06:03 UTC, QAston wrote:
How do i get aliases to overloads of a template method like
Class A
{
int a(T)(T tq,T tw);
int a(T)(T tq);
}
__traits(getOverloads, A, "a(int)")doesnt work
Bump. I also have a similar problem. I have a module with two
Thanks all for your replies. One question:
Jonathan M Davis wrote:
> Alternatively, you can use static if, though you're only dealing
> with one template in that case. e.g.
But if we wanted to deprecate one of the alternatives, then we necessary
need to declare two templates with the same name
Hello. I want to define a template specialization using traits:
import std.stdio, std.traits;
void func(T)(T t) { writeln(1); }
void func(T)(T t) if(isIntegral!T) { writeln(2); }
void main()
{
func(1);
}
But I'm getting an error saying that the called function matches both. If it
were
On Monday, 21 December 2015 at 11:12:10 UTC, Jonathan M Davis
wrote:
On Monday, 21 December 2015 at 11:07:16 UTC, Jonathan M Davis
wrote:
For your example to work with template constraints, the most
straightforward solution would be
void func(T)(T t)
if(!isIntegral!T)
{
writeln(1);
}
On Monday, December 21, 2015 15:14:20 Shriramana Sharma via Digitalmars-d-learn
wrote:
> Hello. I want to define a template specialization using traits:
>
> import std.stdio, std.traits;
> void func(T)(T t) { writeln(1); }
> void func(T)(T t) if(isIntegral!T) { writeln(2)
On Monday, 21 December 2015 at 11:07:16 UTC, Jonathan M Davis
wrote:
For your example to work with template constraints, the most
straightforward solution would be
void func(T)(T t)
if(!isIntegral!T)
{
writeln(1);
}
void func(T)(T t)
if(isIntegral!T)
{
writeln(2);
}
On Monday, 21 December 2015 at 09:44:20 UTC, Shriramana Sharma
wrote:
Hello. I want to define a template specialization using traits:
import std.stdio, std.traits;
void func(T)(T t) { writeln(1); }
void func(T)(T t) if(isIntegral!T) { writeln(2); }
void main()
{
func(1);
}
But I'm getting
On Monday, December 21, 2015 19:54:53 Shriramana Sharma via Digitalmars-d-learn
wrote:
> Thanks all for your replies. One question:
>
> Jonathan M Davis wrote:
> > Alternatively, you can use static if, though you're only dealing
> > with one template in that case. e.g.
>
> But if we wanted to
is like in the stack
overflow answer: statically check if the mixin methods are
already there and remix the mixin in each descendant, so that the
getOverloads traits works on the right 'this'.
What do you think ? is it a bug ?
Alternatively, you can use a static method and pass in the
instance.
Note that `new B` will print A's members twice, because A's
constructor is always called and `__traits(allMembers, B)`
includes A's members.
---
import std.stdio;
mixin template Bug()
{
import std.traits;
static
1 - 100 of 228 matches
Mail list logo