How to compile Windows exe files from this source

2020-08-09 Thread Marc via Digitalmars-d-learn
I don't know much more about D than creating a 'hello world' exe file with the DMD Compiler but I'm interested in using the eBay/tsv-utils binaries. Unfortunately, the author didn't create any MS Windows binaries: https://github.com/eBay/tsv-utils/releases Does anyone know how to compile this

How do I make only the array itself immutable?

2018-03-14 Thread Marc via Digitalmars-d-learn
Can I make it work? struct S { int[] l; } then auto s = S(); s.l ~= 1; // ok s.l = []; // error

Why does file order matters when using -run option?

2018-03-14 Thread Marc via Digitalmars-d-learn
assume the files: app.d void main() { import myModule : foo; writeln(foo(...)); } myModule.d module myModule; int foo(int n) { } the following fail: dmd -run app.d mymodule.d give error like this: Error: module `myModule` is in file 'myModule.d' which cannot be read

Re: overload binary + operator to work with different types

2018-03-13 Thread Marc via Digitalmars-d-learn
On Tuesday, 13 March 2018 at 19:05:00 UTC, Jonathan M Davis wrote: On Tuesday, March 13, 2018 18:55:35 Marc via Digitalmars-d-learn wrote: I want to basically make this work: >[...] I managed to do this: > [...] } Note the ref in the fucntion return, I also want to return a ref

overload binary + operator to work with different types

2018-03-13 Thread Marc via Digitalmars-d-learn
I want to basically make this work: auto l = new List(); l += 5; I managed to do this: class List { int[] items; ref List opBinary(string op)(int rhs) if(op == "+") { items ~= rhs; return *this; } } Note the ref in the

Re: how do I pass this callback?

2018-03-08 Thread Marc via Digitalmars-d-learn
On Thursday, 8 March 2018 at 17:06:05 UTC, Marc wrote: How do I define the callback so that it can be used in RegisterWaitForSingleObject()? I've tried pass as argument: myFunc myFunc.ptr none worked. Here's my code: [...] Function call: [...] Error: [...] Solved! I shall rather

how do I pass this callback?

2018-03-08 Thread Marc via Digitalmars-d-learn
How do I define the callback so that it can be used in RegisterWaitForSingleObject()? I've tried pass as argument: myFunc myFunc.ptr none worked. Here's my code: extern (C) void OnExited(void* context, BOOLEAN isTimeOut); extern(Windows): BOOL RegisterWaitForSingleObject(

Re: issue with inf from exp function

2018-03-07 Thread Marc via Digitalmars-d-learn
On Wednesday, 7 March 2018 at 16:12:28 UTC, Matt Gamble wrote: On Wednesday, 7 March 2018 at 16:10:15 UTC, Marc wrote: On Wednesday, 7 March 2018 at 16:00:39 UTC, Alex wrote: On Wednesday, 7 March 2018 at 15:44:28 UTC, Matt Gamble wrote: [...] works for me as expected. ln(largest double) =

Re: issue with inf from exp function

2018-03-07 Thread Marc via Digitalmars-d-learn
On Wednesday, 7 March 2018 at 16:00:39 UTC, Alex wrote: On Wednesday, 7 March 2018 at 15:44:28 UTC, Matt Gamble wrote: I don't understand why I'm getting an 'inf' by raising E to a real number, e^^710.0L. See below. import std.stdio; import std.math; unittest { writefln("ln(largest double)

Re: issue with inf from exp function

2018-03-07 Thread Marc via Digitalmars-d-learn
On Wednesday, 7 March 2018 at 16:06:26 UTC, Matt Gamble wrote: On Wednesday, 7 March 2018 at 16:00:39 UTC, Alex wrote: On Wednesday, 7 March 2018 at 15:44:28 UTC, Matt Gamble wrote: [...] works for me as expected. ln(largest double) = 709.783 e^710 = inf ln(largest real) = 11356.5 e^710 =

How can I get notified when an process created by spawnShell() has exit?

2018-03-07 Thread Marc via Digitalmars-d-learn
I do need to start (up to 4 a time) processes in parallel but I'd like to get notified (similar to C#'s Process.Exited Event) when the process exits. How can I do that in D?

Setting executable's information by resources

2018-03-06 Thread Marc via Digitalmars-d-learn
I'm trying to use this resource to set executable's information/metadata but it fail to set anything but the icon, without any error message. Could anyone point out if there's anything wrong with my approach? (if anyone use a different approach/toolset to set those data, your suggestion is

dub preBuildCommand not working

2018-03-06 Thread Marc via Digitalmars-d-learn
I added the followiing to my dub.json: "preBuildCommand": [ "C:\\Users\\user003\\Desktop\\Nova pasta\\a.exe", "C:\\dm\\bin\\rcc.exe -32 -D__NT__ res.rc -o sources\\res.res" ] But neither command is executed. "C:\\Users\\user003\\Desktop\\Nova

Are files in dub's "copyFiles" copied every time dub is run?

2018-03-05 Thread Marc via Digitalmars-d-learn
if so, can I somehow make it copy only if newest?

Re: How to use globals correctly?

2018-03-05 Thread Marc via Digitalmars-d-learn
On Monday, 5 March 2018 at 18:57:01 UTC, Steven Schveighoffer wrote: On 3/5/18 1:35 PM, Robert M. Münch wrote: If I use VisualD and add a watch on myObj, I don't see anything just a "identifier myObj is undefined". Not sure if this is because of some threads running (using the D RX

Re: Speed of math function atan: comparison D and C++

2018-03-05 Thread Marc via Digitalmars-d-learn
On Monday, 5 March 2018 at 05:35:28 UTC, J-S Caux wrote: I'm considering shifting a large existing C++ codebase into D (it's a scientific code making much use of functions like atan, log etc). I've compared the raw speed of atan between C++ (Apple LLVM version 7.3.0 (clang-703.0.29)) and D

Any crash reporter for D?

2018-03-04 Thread Marc via Digitalmars-d-learn
Does anyone knows about any crash repórter library for D? there's nothing I couldn't find at code packages. Something as simple and easy to use like this C#'s https://archive.codeplex.com/?p=crashreporterdotnet

What's the proper way to add a local file dependence to dub?

2018-03-04 Thread Marc via Digitalmars-d-learn
then copy it to sources folder? let's say I have a small library folder at C:\mylibrary\D where I want to use dir.d from it. How do I add that file dependence to dub? But I do not want to that file be passed directly to dmd, I want to that file be copied to application's source folder (so

Re: How do I trace that memory error?

2018-02-27 Thread Marc via Digitalmars-d-learn
On Tuesday, 27 February 2018 at 16:55:27 UTC, Marc wrote: [...] So deep down the error is in that method which I call from deserializeLine() function: void setValue(T, V)(auto ref T aggregate, string field, V value) { writeln("setting {", field, "} to {",

Re: How do I trace that memory error?

2018-02-27 Thread Marc via Digitalmars-d-learn
On Tuesday, 27 February 2018 at 15:08:23 UTC, Stefan Koch wrote: On Monday, 26 February 2018 at 18:01:07 UTC, Marc wrote: I've tried both gdb and windbg debugger both it either get a "received signal ?" from gdb or crash the GUI application (windbg). The error is:

Re: How do I trace that memory error?

2018-02-27 Thread Marc via Digitalmars-d-learn
On Tuesday, 27 February 2018 at 15:08:23 UTC, Stefan Koch wrote: On Monday, 26 February 2018 at 18:01:07 UTC, Marc wrote: I've tried both gdb and windbg debugger both it either get a "received signal ?" from gdb or crash the GUI application (windbg). The error is:

Re: How do I trace that memory error?

2018-02-27 Thread Marc via Digitalmars-d-learn
On Tuesday, 27 February 2018 at 14:06:19 UTC, Nicholas Wilson wrote: On Monday, 26 February 2018 at 18:01:07 UTC, Marc wrote: I've tried both gdb and windbg debugger both it either get a "received signal ?" from gdb or crash the GUI application (windbg). The error is:

Re: How do I trace that memory error?

2018-02-26 Thread Marc via Digitalmars-d-learn
On Monday, 26 February 2018 at 18:01:07 UTC, Marc wrote: I've tried both gdb and windbg debugger both it either get a "received signal ?" from gdb or crash the GUI application (windbg). The error is: core.exception.OutOfMemoryError@src\core\exception.d(696): Memory allocation failed How do

How do I trace that memory error?

2018-02-26 Thread Marc via Digitalmars-d-learn
I've tried both gdb and windbg debugger both it either get a "received signal ?" from gdb or crash the GUI application (windbg). The error is: core.exception.OutOfMemoryError@src\core\exception.d(696): Memory allocation failed How do I find out the source of the error?

Could that bug be catch using D's way?

2018-02-19 Thread Marc via Digitalmars-d-learn
I'm pretty sure something could be done with Ada's type range but what we could do using D?

Re: print enum value rather name from enum X : string

2018-02-12 Thread Marc via Digitalmars-d-learn
On Monday, 12 February 2018 at 17:29:47 UTC, Jonathan M Davis wrote: On Monday, February 12, 2018 17:07:50 Marc via Digitalmars-d-learn wrote: [...] If you actually use the enum values anywhere other than with anything from std.conv, std.format, or std.stdio, then when they get converted

What should I use for concat string into array in loop?

2018-02-12 Thread Marc via Digitalmars-d-learn
appender doesn't support string[] so in such case: string[] output; for(...) { if(...) { output ~= str; } } Looking for avoid as many immediate allocations as possible, what should I use?

print enum value rather name from enum X : string

2018-02-12 Thread Marc via Digitalmars-d-learn
If I have an enum like this: enum S : string { foo = "a", baa = "b" } when I printed it, to my surprise I get the enum field name rather value: writefln("%s v%s", S.foo, S.baa); output: foo vbaa instead of a vb a cast solves it but without cast everywhere I

Re: How does this error from dub mean "dlang Non-selected Y package is available with version X"?

2018-02-12 Thread Marc via Digitalmars-d-learn
On Monday, 12 February 2018 at 15:51:58 UTC, Marc wrote: the warning is: Non-selected package lnk is available with version ~>0.2.1. What does it mean by *Non-selected* package lnk is available? from what I could tell from the page, it's highest version. But I've tried low versions anyway to

How does this error from dub mean "dlang Non-selected Y package is available with version X"?

2018-02-12 Thread Marc via Digitalmars-d-learn
the warning is: Non-selected package lnk is available with version ~>0.2.1. What does it mean by *Non-selected* package lnk is available? from what I could tell from the page, it's highest version. But I've tried low versions anyway to see if it Works 0.2.0, 0.1.1 etc and none did. I

How can I get the new stdout which changes periodically from a process?

2018-02-10 Thread Marc via Digitalmars-d-learn
I do call a program from my application which changes its stdout perdiodically (with ncurses library, I guess), where I'd to get somehow "notified" when some change happen (I need to new data from that changes and change my application accordingly). Currently, I do use spawnProcess() which

Re: String to binary conversation

2018-02-08 Thread Marc via Digitalmars-d-learn
On Monday, 5 February 2018 at 18:40:40 UTC, Steven Schveighoffer wrote: On 2/5/18 1:27 PM, Vino wrote: Hi All, Request your help on how to convert a string to binary,eg "test" to 01110100 01100101 01110011 01110100. import std.stdio, std.string; writefln("%(%b %)", "test".representation);

Re: what's the point of function template declarations if they can't be defined?

2018-02-08 Thread Marc via Digitalmars-d-learn
On Thursday, 8 February 2018 at 07:21:05 UTC, Jonathan M Davis wrote: On Wednesday, February 07, 2018 13:39:55 Timothee Cour via Digitalmars-d- learn wrote: [...] It's useful with stuff like version(Ddoc). [...] What's a di file? (sorry google didn't help with that) It's been my

How do I solve this kind of conflict?

2018-01-21 Thread Marc via Digitalmars-d-learn
I was using a Sqlite3 library then I included another library that started the conflict. From what I could tell, it seems it's another Sqlite3 engine that the included library uses. The link error is:

Any sample how to use Sqlite-d?

2018-01-17 Thread Marc via Digitalmars-d-learn
I was looking for a library to use SQLite with D, found this (https://code.dlang.org/packages/sqlite-d) but it has no documentation or code example. I looked into files in the source code and wrote this: Database db = Database(name); auto table = db.table(tableName); auto rows =

Web Browser

2018-01-16 Thread Marc via Digitalmars-d-learn
I'm used to use Qt's QWebView when I need an application to show a HTML page and change some elements on it. This time, if possible, I'd like to use D instead. Are there any web browsers ports in D?

class initialization

2018-01-15 Thread Marc via Digitalmars-d-learn
in C# you can initilizate the class members like this: var foo = new Foo { a = 1, b = 2 }; I found something similar to structs in D: myStruct S = {a:1, b:2}; But can't figure out if D does have that for classes.

Re: What's equivalent to C#'s select?

2018-01-15 Thread Marc via Digitalmars-d-learn
On Monday, 15 January 2018 at 07:37:42 UTC, Simen Kjærås wrote: On Sunday, 14 January 2018 at 22:07:22 UTC, Marc wrote: thanks, can i use it at compile time as well? enum isMutableString(string field) = is(typeof(__traits(getMember, >C, field)) == string); static foreach(field;

How do I get the value cache()?

2018-01-14 Thread Marc via Digitalmars-d-learn
let's assume I have class C { static string foo() { writeln("got called!"); // } } then I want to cache foo at some point: import std.algorithm; auto v = cache(c.foo); I call do: for(int i = 0; i <10; i++) { writeln(v); } then it'll print "got called" only once, which is what I

Re: What's equivalent to C#'s select?

2018-01-14 Thread Marc via Digitalmars-d-learn
On Sunday, 14 January 2018 at 21:59:26 UTC, Seb wrote: On Sunday, 14 January 2018 at 21:21:52 UTC, Marc wrote: give a list, how can I select only the elements of a range according to a condition give by a lamba function? something like this: auto l = myList.select(e => e.id < 300); it

Re: What's equivalent to C#'s select?

2018-01-14 Thread Marc via Digitalmars-d-learn
On Sunday, 14 January 2018 at 21:38:39 UTC, drug wrote: 15.01.2018 00:21, Marc пишет: give a list, how can I select only the elements of a range according to a condition give by a lamba function? something like this: auto l = myList.select(e => e.id < 300); it would return a range.

What's equivalent to C#'s select?

2018-01-14 Thread Marc via Digitalmars-d-learn
give a list, how can I select only the elements of a range according to a condition give by a lamba function? something like this: auto l = myList.select(e => e.id < 300); it would return a range. Similar to C#'s select: https://msdn.microsoft.com/en-us/library/bb548891(v=vs.110).aspx

Re: How do I get class member type?

2018-01-14 Thread Marc via Digitalmars-d-learn
On Sunday, 14 January 2018 at 19:08:44 UTC, Marc wrote: On Sunday, 14 January 2018 at 18:18:50 UTC, Marc wrote: I didn't find how using traits I could get a class member type? I need to test if give class member is not immutable, I find isMutable but not how get a type from give class member

Re: How do I get class member type?

2018-01-14 Thread Marc via Digitalmars-d-learn
On Sunday, 14 January 2018 at 18:18:50 UTC, Marc wrote: I didn't find how using traits I could get a class member type? I need to test if give class member is not immutable, I find isMutable but not how get a type from give class member to pass to it. for clarify, I want all this at compile

How do I get class member type?

2018-01-14 Thread Marc via Digitalmars-d-learn
I didn't find how using traits I could get a class member type? I need to test if give class member is not immutable, I find isMutable but not how get a type from give class member to pass to it.

Re: continue in static foreach

2018-01-12 Thread Marc via Digitalmars-d-learn
On Friday, 12 January 2018 at 22:03:53 UTC, H. S. Teoh wrote: On Fri, Jan 12, 2018 at 10:03:40PM +, Marc via Digitalmars-d-learn wrote: How do I use? > static foreach(enum string member; members) { >static if(isFunction!(__traits(getMember, C,

continue in static foreach

2018-01-12 Thread Marc via Digitalmars-d-learn
How do I use? static foreach(enum string member; members) { static if(isFunction!(__traits(getMember, C, m ember))) { continue; } give error: must use labeled continue within static foreach then I tried:

Re: Why is this valued zeroed?

2018-01-12 Thread Marc via Digitalmars-d-learn
On Friday, 12 January 2018 at 05:14:12 UTC, Jonathan M Davis wrote: On Thursday, January 11, 2018 14:07:18 Ali Çehreli via Digitalmars-d-learn wrote: [...] And if all what you're doing is printing the value out, you might as well just print the Duration directly rather than calling total.

Why is this valued zeroed?

2018-01-11 Thread Marc via Digitalmars-d-learn
I stuck at this and can't figure out the reason why the value of the variable ds is 0 when I do this: startTime = MonoTime.currTime; if I remove that statement, the value of ds isn't zeroed, it has the actual number of seconds. But I can't figure out, ds is of integer type and such, it is

what's the scope of a static variable inside a local function?

2018-01-05 Thread Marc via Digitalmars-d-learn
void foo() { void baa() { static int n; writeln(n++); } } void main() { static int x; foo(); doSomething(x); } does x and n has same lifetime, i.e, program's execution or n is longer available onde foo() call reach out of scope?

Re: how do I get only static member of a class?

2018-01-04 Thread Marc via Digitalmars-d-learn
On Thursday, 4 January 2018 at 00:02:24 UTC, Ali Çehreli wrote: On 01/03/2018 03:48 PM, Marc wrote: I found no way with __traits() on std.traits. I found isStaticFunction and isStaticArray but nothing about a member. Is this by desgin? Give a class like: class C { static int a, b, c; int

Passing a type as paramter to super

2018-01-04 Thread Marc via Digitalmars-d-learn
For code generation purposes, I'd like to pass a type name to base class. I'm not sure if it's supported, I didn't find anything at documentation for class constructor but it does compile: class A { static { int a, b; } this(T)() { } } then

Re: Passing a type as paramter to super

2018-01-04 Thread Marc via Digitalmars-d-learn
On Thursday, 4 January 2018 at 19:16:03 UTC, Marc wrote: For code generation purposes, I'd like to pass a type name to base class. I'm not sure if it's supported, I didn't find anything at documentation for class constructor but it does compile: class A { static {

how do I get only static member of a class?

2018-01-03 Thread Marc via Digitalmars-d-learn
I found no way with __traits() on std.traits. I found isStaticFunction and isStaticArray but nothing about a member. Is this by desgin? Give a class like: class C { static int a, b, c; int d; } I'd like to get a, b and c. I'm using this: __traits(allMembers, C)

Re: what's the proper way to convert wchar[] to string?

2018-01-03 Thread Marc via Digitalmars-d-learn
On Wednesday, 3 January 2018 at 18:59:39 UTC, Ali Çehreli wrote: On 01/03/2018 10:50 AM, Marc wrote: when calling winapi functions, usually you to deal with the result in wchar[]. How do I convert it to string in D to be usable by the application? does D have a native for this? std.conv has

what's the proper way to convert wchar[] to string?

2018-01-03 Thread Marc via Digitalmars-d-learn
when calling winapi functions, usually you to deal with the result in wchar[]. How do I convert it to string in D to be usable by the application? does D have a native for this?

How do you do "const nazi" in D?

2018-01-03 Thread Marc via Digitalmars-d-learn
for a safe programming, since C/C++ times I try to make thing const as possible. locals, parameters etc anything which isn't going to change. How do you do that in D? immutable everywhere? for example: foreach(Field field; fields) { immutable string htmlOutputfile =

How do I use ncurses library with D? are there any wrapper?

2018-01-03 Thread Marc via Digitalmars-d-learn
Long time ago, IIRC, I read somewhere there was a ncurses for D but now I can't find it are there any wrapper or am I mistaken? anyway, I'm doing it from scratch and not porting anything so even a library with same functionality as ncurses for D is welcome.

Does UDA not work for enums?

2018-01-01 Thread Marc via Digitalmars-d-learn
I got compilers errors from this: enum E { @("foo") A, @("baa") B } I got: Error: basic type expected, not @ Error: no identifier for declarator _error_ Error: type only allowed if anonymous enum and no enum type Error: if type, there must be an initializer

Re: take symbol as parameter

2017-12-31 Thread Marc via Digitalmars-d-learn
On Saturday, 30 December 2017 at 23:30:02 UTC, rjframe wrote: On Sat, 30 Dec 2017 13:07:49 +, Marc wrote: how do I take a symbol as parameter? for example: template nameof(alias S) { import std.array : split; enum nameof = S.stringof.split(".")[$-1]; } Works fine for

Re: take symbol as parameter

2017-12-31 Thread Marc via Digitalmars-d-learn
On Sunday, 31 December 2017 at 22:50:12 UTC, Marc wrote: On Saturday, 30 December 2017 at 23:30:02 UTC, rjframe wrote: On Sat, 30 Dec 2017 13:07:49 +, Marc wrote: how do I take a symbol as parameter? for example: [...] Works fine for say a enum member such nameof!(myEnum.X) but

Re: take symbol as parameter

2017-12-31 Thread Marc via Digitalmars-d-learn
On Saturday, 30 December 2017 at 23:30:02 UTC, rjframe wrote: On Sat, 30 Dec 2017 13:07:49 +, Marc wrote: how do I take a symbol as parameter? for example: template nameof(alias S) { import std.array : split; enum nameof = S.stringof.split(".")[$-1]; } Works fine for

take symbol as parameter

2017-12-30 Thread Marc via Digitalmars-d-learn
how do I take a symbol as parameter? for example: template nameof(alias S) { import std.array : split; enum nameof = S.stringof.split(".")[$-1]; } Works fine for say a enum member such nameof!(myEnum.X) but this: struct S { int v; } S s;

Re: How do I set a class member value by its name in a string?

2017-12-28 Thread Marc via Digitalmars-d-learn
Always helpful. Thank you very much guys.

How do I set a class member value by its name in a string?

2017-12-27 Thread Marc via Digitalmars-d-learn
I'd like to set the members of a class by its name at runtime, I would do something like this: __traits(getMember, myClass, name) = value; but since name is only know at runtime, I can't use __traits(). What's a workaround for this?

copy only reference rather duplicate a string in appender!string

2017-12-26 Thread Marc via Digitalmars-d-learn
I do build a string by coping large parts of diffrent buffers, all those buffers live after the functional call, so rather than duplicate those string I'd like to copy only references to those parts rather duplicate every string. I combined appender!string, assumeUnique() and array slices.

Re: copy only reference rather duplicate a string in appender!string

2017-12-26 Thread Marc via Digitalmars-d-learn
of course a totally different approach to solve this is welcome, I came from C/C++/C# worlds so I'm in the process of slowly converting my thinking to the D way (which is new for me, since I'm even unifamiliar with python and such, which got such friendly syntax)

Can I use memoize with a non-static struct method?

2017-12-25 Thread Marc via Digitalmars-d-learn
something like this: struct S { // variables... string doGen(int n) { return ""; } alias gen = memoize!doGen; } The error I got is: Error: need 'this' for 'doGen' of type 'string(int n)' I can't make doGen static because it access non-static struct members... can I workaround this?

Does to!(string)(char[]) do any memory allocation on conversion?

2017-12-25 Thread Marc via Digitalmars-d-learn
Does to!(string)(char[]) do any memory allocation on conversion or is this similar to a cast or what else?

What does scope do as storage class?

2017-12-23 Thread Marc via Digitalmars-d-learn
for example: scope struct S { int x; } What does scope do here?

alias to struct method

2017-12-22 Thread Marc via Digitalmars-d-learn
How can I create a alias to a struct method? struct S { string doSomething(int n) { return ""; } } I'd like to do something like this (imaginary code): alias doSomething = S.doSomething; then call it by doSomething(3) I got the following error from this code: Error: need 'this' for

It's possible to declare a variable inside a static foreach()?

2017-12-21 Thread Marc via Digitalmars-d-learn
For example, I'd like to declare a variable inside a static foreach like in below code, just for better organization, otherwise, I have to use the value directly instead of the variable. If the value is used more than once, it might be inviable. enum allMembers =

Re: Can I run this at compile time?

2017-12-20 Thread Marc via Digitalmars-d-learn
On Wednesday, 20 December 2017 at 17:16:50 UTC, Mengu wrote: On Wednesday, 20 December 2017 at 16:54:35 UTC, Marc wrote: Give this function I'd like to run it at compile time: import std.concurrency : Generator, yield; [...] but when I do: [...] I get the following erros:

Can I run this at compile time?

2017-12-20 Thread Marc via Digitalmars-d-learn
Give this function I'd like to run it at compile time: import std.concurrency : Generator, yield; Generator!string getNonIntegralMembers() { return new Generator!string({ enum allMembers = __traits(derivedMembers, C);

Re: How do I pass a type as parameter in this method?

2017-12-19 Thread Marc via Digitalmars-d-learn
On Tuesday, 19 December 2017 at 15:52:57 UTC, Dgame wrote: On Tuesday, 19 December 2017 at 15:19:53 UTC, Marc wrote: [...] template FirstOf(T...) { template otherwise(D) { static if (T.length == 0) { enum otherwise = D.init; } else { enum otherwise

Re: How do I pass a type as parameter in this method?

2017-12-19 Thread Marc via Digitalmars-d-learn
On Tuesday, 19 December 2017 at 00:01:00 UTC, Ali Çehreli wrote: On 12/18/2017 03:54 PM, Ali Çehreli wrote: On 12/18/2017 02:58 PM, Marc wrote: Here's another experiment: template FirstOf(T...) { template otherwise(D) { static if (T.length == 0) { enum otherwise =

How do I pass a type as parameter in this method?

2017-12-18 Thread Marc via Digitalmars-d-learn
Imaginary code: int index = FirstOrDefault!(int)(__traits(getAttributes, C.a)); In that case, if the tuple is empty, the value is the int's type default value. The method is defined as following: template FirstOrDefault(X)(T...) { static if(T.length > 0) { enum

Re: Does D have class' attributes like C#'s?

2017-12-16 Thread Marc via Digitalmars-d-learn
On Saturday, 16 December 2017 at 20:05:15 UTC, Anonymouse wrote: On Saturday, 16 December 2017 at 19:57:30 UTC, Marc wrote: C# has a quite nice way to store metadata about a property by a feature called atributes[1]. For example, I can write something like this: class A { [TextSize(256)]

Does D have class' attributes like C#'s?

2017-12-16 Thread Marc via Digitalmars-d-learn
C# has a quite nice way to store metadata about a property by a feature called atributes[1]. For example, I can write something like this: class A { [TextSize(256)] string Name { get; set; } } So using runtime/reflection I can retrieve the TextSize value associated to A.name

Re: how do I read a class member's value using traits?

2017-12-16 Thread Marc via Digitalmars-d-learn
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 >[...]

Re: get only user-defined members

2017-12-16 Thread Marc via Digitalmars-d-learn
On Saturday, 16 December 2017 at 07:23:38 UTC, Jonathan M Davis wrote: On Saturday, December 16, 2017 04:01:10 Marc via Digitalmars-d-learn wrote: how do I from class: > class Person { > > string name; > int age; > > } do: > auto c = [__traits(allMembers, Person)]; th

get only user-defined members

2017-12-15 Thread Marc via Digitalmars-d-learn
how do I from class: class Person { string name; int age; } do: auto c = [__traits(allMembers, Person)]; then return only ["name", "age"] rather ["name, "age", "ctor", "toString" ... ]?

how do I read a class member's value using traits?

2017-12-15 Thread Marc via Digitalmars-d-learn
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) {

Re: lower case only first letter of word

2017-12-05 Thread Marc via Digitalmars-d-learn
Kozak <kozz...@gmail.com> wrote: Something like this: https://dlang.org/phobos/std_uni.html#asCapitalized On Tue, Dec 5, 2017 at 2:31 PM, Marc via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: Does D have a native function to capitalize only the first letter

lower case only first letter of word

2017-12-05 Thread Marc via Digitalmars-d-learn
Does D have a native function to capitalize only the first letter of the word? (I'm asking that so I might avoid reinvent the wheel, which I did sometimes in D)

Re: Can I count the of enum's fields at compile time?

2017-11-22 Thread Marc via Digitalmars-d-learn
On Thursday, 23 November 2017 at 01:34:54 UTC, Ali Çehreli wrote: On 11/22/2017 05:21 PM, Marc wrote: On Thursday, 23 November 2017 at 01:04:29 UTC, Jonathan M Davis wrote: On Thursday, November 23, 2017 00:58:21 Marc via Digitalmars-d-learn wrote: [...] import std.traits; enum countOfA

Re: Can I count the of enum's fields at compile time?

2017-11-22 Thread Marc via Digitalmars-d-learn
On Thursday, 23 November 2017 at 01:04:29 UTC, Jonathan M Davis wrote: On Thursday, November 23, 2017 00:58:21 Marc via Digitalmars-d-learn wrote: for example: enum A { a = -10, b = -11, c = -12, d = -13, e = -34} enum int countOfA = coutOfFields(A); // 5 fields import std.traits; enum

Re: Can I count the of enum's fields at compile time?

2017-11-22 Thread Marc via Digitalmars-d-learn
On Thursday, 23 November 2017 at 01:01:42 UTC, Michael V. Franklin wrote: On Thursday, 23 November 2017 at 00:58:21 UTC, Marc wrote: for example: enum A { a = -10, b = -11, c = -12, d = -13, e = -34} enum int countOfA = coutOfFields(A); // 5 fields

Can I count the of enum's fields at compile time?

2017-11-22 Thread Marc via Digitalmars-d-learn
for example: enum A { a = -10, b = -11, c = -12, d = -13, e = -34} enum int countOfA = coutOfFields(A); // 5 fields