Re: How get struct value by member name string ?

2023-06-01 Thread John Xu via Digitalmars-d-learn

A correction:

 string getTMember(T t, string columnName) {
 foreach(member; __traits(allMembers, T)){
 if (member == columnName) {
 return __traits(getMember, t, member).to!string;
 }
 }
 return "";
 }




Re: How get struct value by member name string ?

2023-06-01 Thread John Xu via Digitalmars-d-learn
On Thursday, 1 June 2023 at 15:38:08 UTC, Steven Schveighoffer 
wrote:

On 5/31/23 12:08 AM, John Xu wrote:



When render vibe.d diet template,

     string[] allMembers = __traits(allMembers, t);


enum allMembers = __traits(allMembers, t);


     res.render!("index.dt", t, allMembers)

if I don't want write memberName one by one in diet template:

     table
     - foreach(memberName; allMembers)
     tr
     td #{memberName}
     td #{getTMember!memberName(t)}

Problem: memberName is not known at compile time.


The problem is that you stored the member name list as a 
runtime variable, and that is not known at compile time. Try 
the enum.


Or really, just `foreach(memberName; __traits(allMembers, t))` 
right in the diet template.


-Steve


Ok, thanks for all you gentlemen's help. I tried following 
function,

now it works like C/C++/Python way:

string getTMember(T t, string columnName) {
foreach(member; __traits(allMembers, T)){
if (member == columnName) {
return __traits(getMember, mcu, member).to!string;
}
}
return "";
}



Re: How static link dll msvcr120.dll?

2023-06-01 Thread novice2 via Digitalmars-d-learn

On Thursday, 1 June 2023 at 15:05:40 UTC, Marcone wrote:
I linked msvcr120.lib, but the executable still ask for 
msvcr120.dll not found.



i am sorry.
my words was sourced from common sence, usual practice.
it seems, msvcr120 is special case, and have only one version of 
.lib - for link to .dll

i cant find static lib for msvcr120 :(


Re: How get struct value by member name string ?

2023-06-01 Thread Steven Schveighoffer via Digitalmars-d-learn

On 5/31/23 12:08 AM, John Xu wrote:



When render vibe.d diet template,

     string[] allMembers = __traits(allMembers, t);


enum allMembers = __traits(allMembers, t);


     res.render!("index.dt", t, allMembers)

if I don't want write memberName one by one in diet template:

     table
     - foreach(memberName; allMembers)
     tr
     td #{memberName}
     td #{getTMember!memberName(t)}

Problem: memberName is not known at compile time.


The problem is that you stored the member name list as a runtime 
variable, and that is not known at compile time. Try the enum.


Or really, just `foreach(memberName; __traits(allMembers, t))` right in 
the diet template.


-Steve


Re: How static link dll msvcr120.dll?

2023-06-01 Thread Mike Parker via Digitalmars-d-learn

On Thursday, 1 June 2023 at 15:05:40 UTC, Marcone wrote:



I linked msvcr120.lib, but the executable still ask for 
msvcr120.dll not found.


msvcr120.lib is a "link library", not a static library. On other 
systems, you pass shared libraries directly to the linker and it 
will pull the information it needs from there to set up the 
exectuable with what it needs for the system loader to load the 
shared library at runtime. Windows works differently. The 
compiler puts all that information in a link library when it 
creates the DLL, and you pass that to the linker instead of the 
DLL.


Windows system libraries are not distributed as static libraries 
as far as I know.


Re: How static link dll msvcr120.dll?

2023-06-01 Thread Marcone via Digitalmars-d-learn

On Tuesday, 30 May 2023 at 05:18:11 UTC, novice2 wrote:

you cannot "static link dll", "d" in "dll" is "dynamic".
you can implicity or explicity load dll.

https://learn.microsoft.com/en-us/cpp/build/linking-an-executable-to-a-dll?view=msvc-170

may be you mean static link msvcr120.lib?
i am not windows guru, but you need msvcr120.lib (there is 2 
version of .lib - one small for use .dll and contain only 
reference to code in dll, other large, for static linking, 
contains all code).


to link mylib.lib you can use pragma(lib, "mylib.lib") in D 
code.


I linked msvcr120.lib, but the executable still ask for 
msvcr120.dll not found.


Re: Indenting standards religions K, whitesmiths etc

2023-06-01 Thread Cecil Ward via Digitalmars-d-learn

On Thursday, 1 June 2023 at 09:37:43 UTC, Dukc wrote:

On Wednesday, 31 May 2023 at 16:24:38 UTC, Cecil Ward wrote:
I wanted to ask how some of the leaders of our group feel 
about D indentation standards. `i realise that this causes 
some religious fervour in C. I could be in trouble here 
because in all my years at work, we never used K & R ‘one true 
brace style’ indenting, with the house style I’m used to being 
more like whitesmiths. Wikipedia explains this better. 
Something like the following below.


So my question: would I get lynched for the following? (below)


Check out this module from me: 
https://github.com/dukc/nuklearbrowser/blob/master/source/nuklearbrowser.d


Plus similar style in most of my posts and bug reports. I'm 
still alive :D.


Your code is your code. There, you may do as you wish. You have 
to aknowledge that an esoteric style may make it more difficult 
to read for some, but we're not lynching people for other 
factors of code readability either. Brace style is no different.


Plus, what brace style is considered readable by the majority 
is a culture issue. There has to be some way to challege the 
established culture. If you don't exercise your power to code 
as you wish, someone will make your choice for you. Coding 
culture, or even culture in general, cannot develop if people 
never challege the present status quo.


When you're coding with others, though, then you should obey 
the style guideline of that project if there is one. Even there 
you're as entitled as anyone for an opinion what the style 
policy should be (and to whether there should be style policy 
at all), but you then should (usually) obey the decision 
regardless whether it's the one you were advocating for.


I wonder how much work it would be to write a D pretty printer / 
beautifier. Doing things such as lining up parameters or comments 
and breaking and re-wrapping comments etc if necessary because of 
the changes in whitespace.


I’ve no idea what the ‘official story’ is with nested functions. 
I have some experience with that because I used to write Pascal 
(on a Z80 box and on a VAX), and that feature is like the return 
of an old friend, I love it so much and for me it’s quite a 
serious advantage over C.


I’m always guilty of overcommenting, for various reasons although 
I’m not guilt of the likes of /* add 1 to x */!  ;-) It’s partly 
because I have a shocking memory and maintenance becomes 
literally impossible for me, for me just as important I want the 
comments to spell out original intent, not the implementation 
choices, so if you see later that the two don’t match then you’ve 
spotted the bug.


Many people comment in a very minimal way which makes the code 
look neat.


I did sort of find an /* add 1 to x */ though as it was 
explaining and giving a caveat about GCC in-line asm constraints, 
and the comment saved me having to go and look things up in the 
bible.


Re: Indenting standards religions K, whitesmiths etc

2023-06-01 Thread Cecil Ward via Digitalmars-d-learn

On Thursday, 1 June 2023 at 09:37:43 UTC, Dukc wrote:

On Wednesday, 31 May 2023 at 16:24:38 UTC, Cecil Ward wrote:
I wanted to ask how some of the leaders of our group feel 
about D indentation standards. `i realise that this causes 
some religious fervour in C. I could be in trouble here 
because in all my years at work, we never used K & R ‘one true 
brace style’ indenting, with the house style I’m used to being 
more like whitesmiths. Wikipedia explains this better. 
Something like the following below.


So my question: would I get lynched for the following? (below)


Check out this module from me: 
https://github.com/dukc/nuklearbrowser/blob/master/source/nuklearbrowser.d


Plus similar style in most of my posts and bug reports. I'm 
still alive :D.


Your code is your code. There, you may do as you wish. You have 
to aknowledge that an esoteric style may make it more difficult 
to read for some, but we're not lynching people for other 
factors of code readability either. Brace style is no different.


Plus, what brace style is considered readable by the majority 
is a culture issue. There has to be some way to challege the 
established culture. If you don't exercise your power to code 
as you wish, someone will make your choice for you. Coding 
culture, or even culture in general, cannot develop if people 
never challege the present status quo.


When you're coding with others, though, then you should obey 
the style guideline of that project if there is one. Even there 
you're as entitled as anyone for an opinion what the style 
policy should be (and to whether there should be style policy 
at all), but you then should (usually) obey the decision 
regardless whether it's the one you were advocating for.


Agree completely. You are not a criminal though because your 
closing braces are not indented out with the block they’re 
closing as I do.


I find K hard to read even though we see it everywhere, or 
variants of it. I do wonder if my style in that earlier post 
hurts normal people’s eyeballs a lot. ;-)


I’m told that Irish speakers can’t understand Scottish Gaelic on 
the radio a native speaker said to me that ‘it’s just a noise’. 
But as a ScG learner myself I can understand some spoken Irish 
even though I’ve never really studied the modern language (only 
the stuff of more that 1100 yrs ago.) So the pain isn’t 
symmetrical.


Re: Indenting standards religions K, whitesmiths etc

2023-06-01 Thread Dukc via Digitalmars-d-learn

On Wednesday, 31 May 2023 at 16:24:38 UTC, Cecil Ward wrote:
I wanted to ask how some of the leaders of our group feel about 
D indentation standards. `i realise that this causes some 
religious fervour in C. I could be in trouble here because in 
all my years at work, we never used K & R ‘one true brace 
style’ indenting, with the house style I’m used to being more 
like whitesmiths. Wikipedia explains this better. Something 
like the following below.


So my question: would I get lynched for the following? (below)


Check out this module from me: 
https://github.com/dukc/nuklearbrowser/blob/master/source/nuklearbrowser.d


Plus similar style in most of my posts and bug reports. I'm still 
alive :D.


Your code is your code. There, you may do as you wish. You have 
to aknowledge that an esoteric style may make it more difficult 
to read for some, but we're not lynching people for other factors 
of code readability either. Brace style is no different.


Plus, what brace style is considered readable by the majority is 
a culture issue. There has to be some way to challege the 
established culture. If you don't exercise your power to code as 
you wish, someone will make your choice for you. Coding culture, 
or even culture in general, cannot develop if people never 
challege the present status quo.


When you're coding with others, though, then you should obey the 
style guideline of that project if there is one. Even there 
you're as entitled as anyone for an opinion what the style policy 
should be (and to whether there should be style policy at all), 
but you then should (usually) obey the decision regardless 
whether it's the one you were advocating for.