Re: how to properly compare this type?

2021-02-09 Thread frame via Digitalmars-d-learn

On Tuesday, 9 February 2021 at 23:12:57 UTC, Jack wrote:


arr is empty


You need to check for __traits(getOverloads,...), isCallable!, 
ReturnType!.




how to properly compare this type?

2021-02-09 Thread Jack via Digitalmars-d-learn

I have a class like this:

struct S { }

class A
{
@(S)
{
int a;
string b() { return ib; }
string b(string s) { return ib = s;}
}

int x;
int y;

string ib = "lol";
}

where I want to list the members that have S UDA but it failing 
to compare string b() { ... }. How do I do this?


current code:


import std.traits : hasUDA;
string[] arr;
static foreach(member; __traits(allMembers, A))
{
static if(hasUDA!(__traits(getMember, A, member), S))
{
pragma(msg, typeof(__traits(getMember, A, member)));
			static if(is(typeof(__traits(getMember, A, member)) == string 
function(string)))

{
arr ~= member;
}
}   
}
writeln(arr);


arr is empty


Re: GC.addRange in pure function

2021-02-09 Thread Paul Backus via Digitalmars-d-learn

On Tuesday, 9 February 2021 at 20:50:12 UTC, Max Haughton wrote:

On Tuesday, 9 February 2021 at 19:53:27 UTC, Temtaime wrote:

On Sunday, 7 February 2021 at 14:13:18 UTC, vitamin wrote:
Why using 'new' is allowed in pure functions but calling 
GC.addRange or GC.removeRange isn't allowed?


pure is broken. Just don't [use it]



[Citation needed]


Allowing memory allocation in pure code in a language that can 
distinguish between pointer equality and value equality is, let's 
say, "unprincipled."


Re: GC.addRange in pure function

2021-02-09 Thread Max Haughton via Digitalmars-d-learn

On Tuesday, 9 February 2021 at 19:53:27 UTC, Temtaime wrote:

On Sunday, 7 February 2021 at 14:13:18 UTC, vitamin wrote:
Why using 'new' is allowed in pure functions but calling 
GC.addRange or GC.removeRange isn't allowed?


pure is broken. Just don't [use it]



[Citation needed]


Re: GC.addRange in pure function

2021-02-09 Thread Temtaime via Digitalmars-d-learn

On Sunday, 7 February 2021 at 14:13:18 UTC, vitamin wrote:
Why using 'new' is allowed in pure functions but calling 
GC.addRange or GC.removeRange isn't allowed?


pure is broken. Just don't [use it]


Real simple unresolved external symbols question...

2021-02-09 Thread WhatMeWorry via Digitalmars-d-learn



I'm trying to create a super simple dynamic library consisting of 
two files:



  file2.d --
extern(D):
double addEight(double d) { return (d + 8.0); }

 fileB.d --
extern(D)
{
string concatSuffix(string s) { return (s ~ ".ext"); }
}



dmd -m64 -c file2.d
dmd -m64 -c fileB.d

creates file2.obj and fileB.obj files

link.exe /DLL /NOENTRY file2.obj fileB.obj msvcrt.lib

fileB.obj : error LNK2019: unresolved external symbol 
_D12TypeInfo_Aya6__initZ referenced in function 
_D5fileB12concatPrefixFAyaZQe
fileB.obj : error LNK2019: unresolved external symbol 
_d_arraycatT referenced in function _D5fileB12concatPrefixFAyaZQe


Ok. I find _d_arraycatT in the D website at:

https://dlang.org/library/rt/lifetime/_d_arraycat_t.html

So I thought, this symbol will be in phobos64.lib.  But when I 
add it to the command, all hell breaks loose:



link.exe /DLL /NOENTRY file2.obj fileB.obj msvcrt.lib 
phobos64.lib


phobos64.lib(bits_23fa_21c.obj) : error LNK2001: unresolved 
external symbol memcpy

 o  o  o
file2.dll : fatal error LNK1120: 57 unresolved externals


So I'm stuck and don't have a clue as to how to continue.

I thought Phobos64.lib was self-contained.  Do I need to add 
other libraries?  And how do I know which ones?







Re: Profiling

2021-02-09 Thread drug via Digitalmars-d-learn

On Tuesday, 9 February 2021 at 07:45:13 UTC, JG wrote:
I was trying to profile a d program. So I ran: dub build 
--build=profile. I then ran the program and it produced 
trace.log and trace.def. I then ran d-profile-viewer and got 
the following error:


std.conv.ConvException@/home/jg/dlang/ldc-1.24.0/bin/../import/std/conv.d(2382):
 Unexpected '-' when converting from type char[] to type ulong


I'm guessing only but it looks like slurp is used to read text 
output but the format used does not correspond to the real data 
format.


Re: Profiling

2021-02-09 Thread Dukc via Digitalmars-d-learn

On Tuesday, 9 February 2021 at 16:39:25 UTC, Dukc wrote:
You may have or may not have done it wrong, but in any case 
this is a bug. If you do something wrong, the program should 
tell you what you did wrong, instead of telling you that 
character '-' does not belong to middle of a long int.


Oh wait a bit. The stack trace shows calling some function of 
'app.d' - that's presumably your program.


I wonder why it's being called - aren't you supposed to be 
viewing the profiling results instead of profiling? I'm not sure 
what's happening.


Re: Profiling

2021-02-09 Thread Dukc via Digitalmars-d-learn

On Tuesday, 9 February 2021 at 07:45:13 UTC, JG wrote:
Is d-profile-viewer no longer working? Or did I do something 
wrong?


You may have or may not have done it wrong, but in any case this 
is a bug. If you do something wrong, the program should tell you 
what you did wrong, instead of telling you that character '-' 
does not belong to middle of a long int.


You can try older d-profile-viewers as a workaround. Or you can 
try different ways to invoke the profile viewer or to profile 
different programs and see if you can pinpoint the cause.


Re: Traits of variadic templates

2021-02-09 Thread Jeff via Digitalmars-d-learn

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 => isIntegral!t || isSomeString!t)

Thanks!


import std.meta: allSatisfy, Or = templateOr;
allSatisfy!(Or!(isIntegral, isSomeString), T);

http://phobos.dpldocs.info/std.meta.allSatisfy.html
http://phobos.dpldocs.info/std.meta.templateOr.html


Thanks so much!



Re: Traits of variadic templates

2021-02-09 Thread Paul Backus via Digitalmars-d-learn

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: allSatisfy, Or = templateOr;
allSatisfy!(Or!(isIntegral, isSomeString), T);

http://phobos.dpldocs.info/std.meta.allSatisfy.html
http://phobos.dpldocs.info/std.meta.templateOr.html


Traits of variadic templates

2021-02-09 Thread Jeff via Digitalmars-d-learn

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 check would be done at 
compile-time.


Obviously, I could modify foo to something like:

void foo(Algebraic!(int, string)[] xs)

I could also put checks in the body at runtime. But, for the sake 
of this thread, let's not. ;-)


What would be ideal (IMO) would be something along the lines of:

void foo(T...)(T xs) if (isIntegral!T || isSomeString!T)

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!


Re: Are there any containers that go with allocators?

2021-02-09 Thread John Burton via Digitalmars-d-learn
On Tuesday, 9 February 2021 at 12:23:52 UTC, rikki cattermole 
wrote:

https://github.com/dlang-community/containers

It uses the older design for allocators (dependency).


Looks good, thank you


Re: Are there any containers that go with allocators?

2021-02-09 Thread rikki cattermole via Digitalmars-d-learn

https://github.com/dlang-community/containers

It uses the older design for allocators (dependency).


Are there any containers that go with allocators?

2021-02-09 Thread John Burton via Digitalmars-d-learn
Normally I'm happy with the GC containers in D, they work well 
and suit my use.


I have a few uses that would benefit from allocation in memory 
arenas or local stack based allocation. Looks like 
std.experimental has allocators for those use cases.


But I can't find any containers to make use of those allocators. 
The built in ones use GC managed memory, there are std.container 
but they appear to use malloc/free which again is useful but not 
what I'm looking for.


I'd like resizeable arrays, hashmaps and strings that I can 
allocate using an allocator?
Am I missing something in the standard library, or a way to use 
the existing ones, or is it just that nobody has implemented this 
kind of thing yet?