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, member)
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.
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, 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: a
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
recentl
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, Endian.bigEn
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 : En
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 require
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 ret
On Friday, 1 September 2017 at 18:06:04 UTC, Jonathan M Davis
wrote:
[...]
You can use std.meta.Filter if you need to filter anything out
of an AliasSeq like this, and whether you should be filtering
out those functions is highly dependent on what you're doing -
e.g. sometimes, you really wan
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 y
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:
"Identifi
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 wit
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
---
modul
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: import
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 bar;
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
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
functio
correct link:
https://issues.dlang.org/show_bug.cgi?id=14448
On Tuesday, 14 April 2015 at 10:43:16 UTC, anonymous wrote:
On Tuesday, 14 April 2015 at 09:24:04 UTC, Filippo Fantini
wrote:
Hello everyone!
I'm new to D.
While playing with around with traits,
I ended up writing this short example:
module test;
class Foo
{
private int _value = 21;
v
On Tuesday, 14 April 2015 at 09:24:04 UTC, Filippo Fantini wrote:
Hello everyone!
I'm new to D.
While playing with around with traits,
I ended up writing this short example:
module test;
class Foo
{
private int _value = 21;
void foo()
{
import std.traits;
alias f
On Saturday, 10 January 2015 at 23:23:52 UTC, Ali Çehreli wrote:
On 01/10/2015 08:21 AM, Bauss wrote:
Is there a way to get all functions within a module using
traits? I
tried "allMembers" and it seem to work, but I can't use
"getFunctionAttributes" with it and if I use "getAttributes"
then it
On 01/10/2015 08:21 AM, Bauss wrote:
Is there a way to get all functions within a module using traits? I
tried "allMembers" and it seem to work, but I can't use
"getFunctionAttributes" with it and if I use "getAttributes" then it
won't find any applied attributes.
What I do is having a package m
On 10/13/13 02:25, luminousone wrote:
> On Saturday, 12 October 2013 at 23:48:56 UTC, Artur Skawina wrote:
>>template isBaseOf(BASE, C) {
>> enum isBaseOf = {
>> static if (is(C S == super))
>> foreach (A; S)
>>static if (isBaseOf!(BASE, A))
>>
On Saturday, 12 October 2013 at 23:48:56 UTC, Artur Skawina wrote:
On 10/12/13 21:42, luminousone wrote:
On Saturday, 12 October 2013 at 11:50:05 UTC, Artur Skawina
wrote:
template isBaseOf(BASE, C) {
enum isBaseOf = {
static if (is(C S == super))
foreach (A; S)
On 10/12/13 21:42, luminousone wrote:
> On Saturday, 12 October 2013 at 11:50:05 UTC, Artur Skawina wrote:
>>template isBaseOf(BASE, C) {
>> enum isBaseOf = {
>> static if (is(C S == super))
>> foreach (A; S)
>>static if (is(A==BASE))
>>
On Saturday, 12 October 2013 at 11:50:05 UTC, Artur Skawina wrote:
On 10/12/13 13:42, Artur Skawina wrote:
template isBaseOf(BASE, C) {
static if (is(C S == super))
enum isBaseOf = {
foreach (A; S)
static if (is(A==BASE))
return true
On 10/12/13 13:42, Artur Skawina wrote:
>template isBaseOf(BASE, C) {
> static if (is(C S == super))
> enum isBaseOf = {
> foreach (A; S)
>static if (is(A==BASE))
> return true;
> return is(C==BASE);
> }();
>
On 10/11/13 06:13, Agustin wrote:
> I have a function that needs to check if the template provided inherit a
> class.
>
> For example:
>
> public void function(T, A...)(auto ref A values)
> {
> // static assert(IsBaseOf(L, T));
> }
>
> Check if T inherit class "L". Same result that std::is_ba
On Saturday, October 12, 2013 11:50:27 luminousone wrote:
> On Saturday, 12 October 2013 at 08:40:42 UTC, Jonathan M Davis
>
> wrote:
> > On Saturday, October 12, 2013 10:24:13 luminousone wrote:
> >> 1.
> >>
> >> opCast, and alias can break the cast approach. You pointed this
> >> out yourself.
On Saturday, 12 October 2013 at 08:40:42 UTC, Jonathan M Davis
wrote:
On Saturday, October 12, 2013 10:24:13 luminousone wrote:
1.
opCast, and alias can break the cast approach. You pointed this
out yourself.
And as I pointed out, that's perfectly acceptable in most
cases, because what
you c
On Saturday, October 12, 2013 10:24:13 luminousone wrote:
> 1.
>
> opCast, and alias can break the cast approach. You pointed this
> out yourself.
And as I pointed out, that's perfectly acceptable in most cases, because what
you care about is the conversion. alias this is specifically designed w
On Saturday, 12 October 2013 at 07:47:18 UTC, Jonathan M Davis
wrote:
On Saturday, October 12, 2013 09:32:09 luminousone wrote:
And again, the casting solution is a bloody hack, it is loaded
with corner cases that will break things if you are not aware
of
them. It also requires an allocated in
On Saturday, October 12, 2013 09:32:09 luminousone wrote:
> And again, the casting solution is a bloody hack, it is loaded
> with corner cases that will break things if you are not aware of
> them. It also requires an allocated instance of that object
Of course, it requires an instance of the obje
On Saturday, 12 October 2013 at 05:38:16 UTC, Jonathan M Davis
wrote:
On Friday, October 11, 2013 22:31:25 Jonathan M Davis wrote:
On Saturday, October 12, 2013 00:54:48 luminousone wrote:
> The inability to handle null is pretty big, specially
> considering
> that at not point is the class in
On Friday, October 11, 2013 22:31:25 Jonathan M Davis wrote:
> On Saturday, October 12, 2013 00:54:48 luminousone wrote:
> > The inability to handle null is pretty big, specially considering
> > that at not point is the class instance itself cared about!,
>
> No. It's expected. When you are castin
On Saturday, October 12, 2013 00:54:48 luminousone wrote:
> The inability to handle null is pretty big, specially considering
> that at not point is the class instance itself cared about!,
No. It's expected. When you are casting to a particular object to test whether
the object is of that type, y
On Friday, 11 October 2013 at 21:49:50 UTC, Jonathan M Davis
wrote:
On Friday, October 11, 2013 23:06:53 luminousone wrote:
On Friday, 11 October 2013 at 19:54:39 UTC, Jonathan M Davis
wrote:
> On Friday, October 11, 2013 21:19:29 luminousone wrote:
>> Using casts that way won't always be corre
On Friday, October 11, 2013 23:06:53 luminousone wrote:
> On Friday, 11 October 2013 at 19:54:39 UTC, Jonathan M Davis
>
> wrote:
> > On Friday, October 11, 2013 21:19:29 luminousone wrote:
> >> Using casts that way won't always be correct, it would be
> >> better
> >> to use reflection in some wa
On Friday, 11 October 2013 at 19:54:39 UTC, Jonathan M Davis
wrote:
On Friday, October 11, 2013 21:19:29 luminousone wrote:
Using casts that way won't always be correct, it would be
better
to use reflection in some way if possible.
The only reason that the casts wouldn't be correct would be i
On Friday, 11 October 2013 at 19:19:31 UTC, luminousone wrote:
On Friday, 11 October 2013 at 14:09:09 UTC, Gary Willoughby
wrote:
On Friday, 11 October 2013 at 05:49:38 UTC, luminousone wrote:
On Friday, 11 October 2013 at 04:13:55 UTC, Agustin wrote:
I have a function that needs to check if th
On Friday, October 11, 2013 21:19:29 luminousone wrote:
> Using casts that way won't always be correct, it would be better
> to use reflection in some way if possible.
The only reason that the casts wouldn't be correct would be if the class
overrode opCast for the type that you're casting to or h
On Friday, 11 October 2013 at 14:09:09 UTC, Gary Willoughby wrote:
On Friday, 11 October 2013 at 05:49:38 UTC, luminousone wrote:
On Friday, 11 October 2013 at 04:13:55 UTC, Agustin wrote:
I have a function that needs to check if the template
provided inherit a class.
For example:
public voi
On Friday, October 11, 2013 15:34:28 Jacob Carlborg wrote:
> On 2013-10-11 11:49, luminousone wrote:
> > Is is just the typeid call that makes it unable to be ran at compile
> > time or is their something else wrong in their?,
> >
> > Would a string compare with type.classInfo.name fix that, or is
On Friday, 11 October 2013 at 04:35:38 UTC, Ali Çehreli wrote:
On 10/10/2013 09:13 PM, Agustin wrote:
> I have a function that needs to check if the template
provided inherit a
> class.
>
> For example:
>
> public void function(T, A...)(auto ref A values)
function happens to be a keyword. :)
>
On Friday, 11 October 2013 at 05:49:38 UTC, luminousone wrote:
On Friday, 11 October 2013 at 04:13:55 UTC, Agustin wrote:
I have a function that needs to check if the template provided
inherit a class.
For example:
public void function(T, A...)(auto ref A values)
{
// static assert(IsBaseOf(
On 2013-10-11 11:49, luminousone wrote:
Is is just the typeid call that makes it unable to be ran at compile
time or is their something else wrong in their?,
Would a string compare with type.classInfo.name fix that, or is their
not a tool yet in place for that?
Hmm, it may actually be possibl
On Friday, 11 October 2013 at 09:37:33 UTC, Jacob Carlborg wrote:
On 2013-10-11 07:49, luminousone wrote:
import std.traits;
bool ChildInheritsFromParent( parent, child )( ) {
foreach ( k, t; BaseClassesTuple!child ) {
if( typeid(t) == typeid(parent) )
return true;
On 2013-10-11 07:49, luminousone wrote:
import std.traits;
bool ChildInheritsFromParent( parent, child )( ) {
foreach ( k, t; BaseClassesTuple!child ) {
if( typeid(t) == typeid(parent) )
return true;
}
return false;
}
That will perform a runtime check and
On Friday, 11 October 2013 at 04:13:55 UTC, Agustin wrote:
I have a function that needs to check if the template provided
inherit a class.
For example:
public void function(T, A...)(auto ref A values)
{
// static assert(IsBaseOf(L, T));
}
Check if T inherit class "L". Same result that
std:
On Thursday, October 10, 2013 21:35:37 Ali Çehreli wrote:
> One of the uses of the is expression determines "whether implicitly
> convertible to". It may work for you:
>
> public void foo(T, A...)(auto ref A values)
> {
> static assert(is (T : L));
> }
Actually, checking for implicit convers
On 10/10/2013 09:13 PM, Agustin wrote:
> I have a function that needs to check if the template provided inherit a
> class.
>
> For example:
>
> public void function(T, A...)(auto ref A values)
function happens to be a keyword. :)
> {
>// static assert(IsBaseOf(L, T));
> }
>
> Check if T inh
On Saturday, 8 June 2013 at 14:06:32 UTC, Andrej Mitrovic wrote:
On Saturday, 8 June 2013 at 13:57:13 UTC, Q wrote:
Hi there, I want to iterate over all the public members of a
class.
It is a known problem. The workaround is to use is(typeof()):
void main() {
foreach (mem; __traits(allMem
You could probably throw in a traits(compiles) right above.
foreach(...) {
// or maybe compiles, getProtection(getMember))
static if(__traits(compiles, __traits(getMember,Foo.init, mem)) {
enum prot = __traits(getProtection, __traits(getMember,
Foo.init, mem));
// and so on
}
}
I haven't
On Saturday, 8 June 2013 at 13:57:13 UTC, Q wrote:
Hi there, I want to iterate over all the public members of a
class.
It is a known problem. The workaround is to use is(typeof()):
void main() {
foreach (mem; __traits(allMembers, Foo))
{
static if (is(typeof(
__trai
On Thursday, 6 June 2013 at 17:50:08 UTC, Chris Williams wrote:
...
It will work if use "enum" instead of "auto" for storing
attribute tuple. If compile-time value is needed you almost
always want to store it in enum.
Here's how I do it:
enum Dump; // just a type, no value here
template Dumper(T) {
void dump() {
foreach (mem; __traits(allMembers, T)) {
// loop over the attrs instead of try to store them in a
var
foreach(attr; __traits(getAttributes, __traits(getMember,
T, mem)))
On 3/12/13, Andrej Mitrovic wrote:
> On 3/12/13, cal wrote:
>> if i remove the parenthesis around 'other'.
>
> Ah yes, I can recreate it now. Can you file this as a bug?
>
Ok I filed it: http://d.puremagic.com/issues/show_bug.cgi?id=9692
On Monday, 11 March 2013 at 23:38:20 UTC, Andrej Mitrovic wrote:
On 3/12/13, cal wrote:
if i remove the parenthesis around 'other'.
Ah yes, I can recreate it now. Can you file this as a bug?
Sure thanks for checking it
On 3/12/13, cal wrote:
> if i remove the parenthesis around 'other'.
Ah yes, I can recreate it now. Can you file this as a bug?
On Monday, 11 March 2013 at 23:22:42 UTC, cal wrote:
On Monday, 11 March 2013 at 23:19:18 UTC, cal wrote:
On Monday, 11 March 2013 at 23:10:58 UTC, Andrej Mitrovic
I can't reproduce this. How are you compiling the modules?
Specifically:
dmd main.d other.d dir/other.d
produces:
Error: impor
On Monday, 11 March 2013 at 23:19:18 UTC, cal wrote:
On Monday, 11 March 2013 at 23:10:58 UTC, Andrej Mitrovic wrote:
On 3/11/13, cal wrote:
When the module name I use inside __traits is in the same dir
as
the main module, I need the extra parenthesis to satisfy the
compiler. Is this a bug, o
On Monday, 11 March 2013 at 23:10:58 UTC, Andrej Mitrovic wrote:
On 3/11/13, cal wrote:
When the module name I use inside __traits is in the same dir
as
the main module, I need the extra parenthesis to satisfy the
compiler. Is this a bug, or unavoidable?
I can't reproduce this. How are you c
On 3/11/13, cal wrote:
> When the module name I use inside __traits is in the same dir as
> the main module, I need the extra parenthesis to satisfy the
> compiler. Is this a bug, or unavoidable?
I can't reproduce this. How are you compiling the modules?
Adam D. Ruppe wrote:
> Is there a way in today's D to exclude members marked private and
> protected from processing in the __traits(allMembers) family of
> functions?
>
> I thought if I at least put it in a separate module, trying to get
> a private member would fail to compile, but I tried it
On Mon, Feb 14, 2011 at 22:09, Martin Kinkelin wrote:
> So from the outside, components are accessed either via indexing or
> via x,y,z and w (analog to HLSL/GLSL). I also added some downcasting
> shortcuts via properties, e.g.:
>
> auto f4 = float4(1,2,3,4);
> auto r = f4.xyz + 2.0; // downcast
> Did you try without the cast? Since we know that _data components can
> be cast to r._data elements, the compiler should take care of that for
> you.
Nope, I didn't try that because, for instance, floats shouldn't be
implicitly castable to ints.
> You can also use cast(float2) f3 to get rid of
On Mon, Feb 14, 2011 at 13:09, Martin Kinkelin wrote:
> Hi Philippe,
>
> thank you very much!
You're welcome.
> I added your isVector!T template as well as the two aliases.
> opCast!NewType is implemented like this:
>
> V opCast(V)() if (isVector!V)
> // parameters {d2,T2} of V are checked when
Hi Philippe,
thank you very much! I added your isVector!T template as well as the two
aliases.
opCast!NewType is implemented like this:
V opCast(V)() if (isVector!V)
// parameters {d2,T2} of V are checked when instantiating V: d2 >= 1 &&
isNumeric!T2
{
V r;
foreach (i; 0 .. (d < V.dim ?
Hi Martin,
> I'm implementing a generic Vector!(uint d, T) struct (wrapping a T[d] array).
> For readability:
> alias Vector!(4u,float) float4;
> alias Vector!(4u,int) int4;
>
> I'd like to be able to cast a float4 variable explicitly to an int4
> (component-wise casting):
> auto f4 = float4(1,2
I realize a parametrized constructor would be a better option:
this(T2)(const(Vector!(d,T2)) rhs) if (isNumeric!T2) { ... }
// e.g., auto i4 = int4(f4);
but I'd still prefer the casting syntax if possible.
75 matches
Mail list logo