Re: It won't run in gdb...

2020-04-27 Thread Adam D. Ruppe via Digitalmars-d-learn
On Mon, Apr 27, 2020 at 10:56:09AM +, mark via Digitalmars-d-learn wrote: > Thread 1 "DebFind" received signal SIGUSR1, User defined signal 1. The GC sends that signal to pause other threads when it is about to collect. You can tell gdb to just ignore it. handle SIGUSR1 noprint handle SIGUSR2

Re: Help, what is the code mean?

2020-04-27 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 27 April 2020 at 13:29:08 UTC, lilijreey wrote: Hi: In dlang core.thread.osthread has below code, the 654 line code i can understand why write () first, and {m_fn = fn;}() do what? The stdlib uses that pattern from time to time to indicate an unsafe block in an otherwise safe

Re: Help, what is the code mean?

2020-04-27 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 27 April 2020 at 15:24:09 UTC, lilijreey wrote: Thanks your help. where is unsafe in above code? It depends on the context but I assume it is because it is storing a reference to the function across thread boundaries, something normally banned, but since it is (I believe) a private

Re: Building Win32 application via dub

2020-04-28 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 28 April 2020 at 19:25:06 UTC, Sam E. wrote: I'm a bit surprised to see a linking error given that building directly from `dmd` seems to work fine without any flag. dmd directly uses -m32 whereas dub by default uses -m32mscoff to dmd. The mscoff linker (also used for -m64 btw) do

Re: in vs inout

2020-04-30 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 30 April 2020 at 14:00:40 UTC, Arredondo wrote: I had been using inout for some time now for "purely input function parameters". `inout` is more specifically for things you take in, look at, then pass back out. So it forms part of your return value. `const` is for when you are j

Re: Aliasing current function template instance

2020-05-01 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 1 May 2020 at 20:28:58 UTC, Jean-Louis Leroy wrote: Something I have overlooked? Any ideas? There's an old rule, that I can't find in the spec anymore but I'm still pretty sure it is there, where taking the address of a template inside a template yields the current instantiation.

Re: Hided Subprocess in Dlang

2020-05-02 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 2 May 2020 at 14:06:55 UTC, Baby Beaker wrote: open the command prompt console running this other process. when calling the functions pass Config.suppressConsole to it. like in the doc example here http://dpldocs.info/experimental-docs/std.process.Config.html#suppressConsole

Re: Hided Subprocess in Dlang

2020-05-02 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 2 May 2020 at 15:37:09 UTC, Baby Beaker wrote: Error: none of the overloads of `spawnProcess` are callable using argument types `(string, File, File, File, Config)`, candidates are: The example is prolly out of date try spawnProcess(program, null, Config.suppressConsole)

Re: Variable assignment in “if” condition in Dlang

2020-05-03 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 3 May 2020 at 14:53:21 UTC, Baby Beaker wrote: How can I assign a variable in “if” condition in Dlang? depends on exactly what there's also if ( (a = 10) ) with extra parens for special purposes

Re: How can I check if an element is iterable?

2020-05-03 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 3 May 2020 at 20:02:09 UTC, Marcone wrote: How can I check if an element is iterable in Dlang? http://dpldocs.info/experimental-docs/std.traits.isIterable.html

Re: How can I check if an element is iterable?

2020-05-03 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 3 May 2020 at 20:21:24 UTC, Marcone wrote: How can I check if a variable is iterable? Every variable has a type. You can get it with typeof(varaiable)

Re: Retrieve the return type of the current function

2020-05-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 5 May 2020 at 16:36:48 UTC, learner wrote: I mean, without using the function name in the body, like ReturnType!foo ? even easier: typeof(return)

Re: Get months / years between two dates.

2020-05-06 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 6 May 2020 at 19:51:01 UTC, bauss wrote: How will I get the months or years between the two dates? What's the length of a month or a year? That's the tricky part - they have variable lengths. So a difference of one month is not super precise. You could probably just do days /

Re: Thread to watch keyboard during main's infinite loop

2020-05-06 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 7 May 2020 at 01:33:12 UTC, Daren Scot Wilson wrote: import core.thread: sleep; It sould be import core.thread : Thread; Thread.sleep(1.secs); // or whatever sleep is a static method on the Thread class.

Re: Arsd dom.d examples

2020-05-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 9 May 2020 at 16:10:37 UTC, ByR wrote: Are there are tutorials or examples on how to manipulate HTML using dom.d? Replace tag, text, end so on. ByR I don't think so really. There's a wee bit of documentation here http://dpldocs.info/experimental-docs/arsd.dom.html but for the m

Re: How to get the UDAs for a function parameter correctly?

2020-05-10 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 11 May 2020 at 02:25:39 UTC, Heromyth wrote: I want to get the UDAs for for a function parameter. Here the test code and I got some errors: I think my blog aside is one of the few if only write-ups on how to do this: http://dpldocs.info/this-week-in-d/Blog.Posted_2019_02_11.html#h

Re: Bug?

2020-05-11 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 11 May 2020 at 12:20:06 UTC, Jack Applegame wrote: If you move the import to the global scope UFCS is only defined to work with global scope functions. A restricted import (module : symbol, symbols) puts things in local scope so ufcs doesn't apply. (interestingly an unrestricted

Re: Bug?

2020-05-11 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 11 May 2020 at 13:06:59 UTC, Steven Schveighoffer wrote: Clearly something isn't connecting properly, it's almost like it's resolving to the function itself instead of calling it. Since the imported front is also a local symbol the compiler probably thinks it is overloaded and not h

Re: Probably a trivial question regarding version identifier and unittest

2020-05-11 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 12 May 2020 at 01:54:49 UTC, WhatMeWorry wrote: version(demos) unittest { import arsd.terminal; void main() Shouldn't the version identifier demos and the unittest option activate the test block and therefore defines main() which then give the "Start Address"? The unitte

Re: Get unknown symbol (struct, method, class) tagged with User Defined Attributes

2020-05-11 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 12 May 2020 at 02:51:39 UTC, Doug wrote: So far I've only seen a way to get unknown UDAs from known symbols but not how to get unknown symbols from UDAs. Is there any documentation for how to get a list of symbols annotated with a specific UDA? see std.traits.getSymbolsByUDA http

Re: Optional type parameter on a template

2020-05-12 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 12 May 2020 at 20:36:22 UTC, Luis wrote: I'm trying to make a SparseSet that on function of a optional type parameter, could alongside the index set, store other data. So I need a way to declare a optional type template parameter. A default argument of void is a common way to do i

Re: declaration of inner function is already defined

2020-05-13 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 13 May 2020 at 12:45:06 UTC, Andrey wrote: Why this works: It's just defined that way. Local functions follow local variable rules - must be declared before use and names not allowed to overload each other. There might be a deeper reason too but like that's the main thing, th

Re: How to run program with "dmd -i" compiler swich ?

2020-05-15 Thread Adam D. Ruppe via Digitalmars-d-learn
use the -run switch to dmd. Make sure it and te d file name are the LAST arguments. dmd -i other_dmd_args_you_need -run yourfile.d

Re: Testing template parameter has given API

2020-05-15 Thread Adam D. Ruppe via Digitalmars-d-learn
try changing delegate to function, on the type itself it is often function

Re: After compiling Hello World with DMD Compiler, .EXE file takes 1-3 seconds to run for the first time

2020-05-18 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 18 May 2020 at 15:47:40 UTC, BoQsc wrote: It seems strange that on the first run after D language compilation. Hello World program takes 1-3 seconds to launch. That's the Windows virus scanner again. It sees D programs as unusual and gives them additional scrutiny... You can set

Re: Spawn a Command Line application Window and output log information

2020-05-18 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 18 May 2020 at 16:36:11 UTC, BoQsc wrote: Would this require GUI library and how can this be achieved? you might enjoy using my terminal lib https://code.dlang.org/packages/arsd-official%3Aterminal include that and set "subConfigurations": { "arsd-official:terminal": "builtin_e

Re: None of the overloads of kill are callable using argument types:

2020-05-18 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 18 May 2020 at 20:11:25 UTC, BoQsc wrote: I'm trying to kill my own process Don't kill yourself, just `return` from main.

Re: After compiling Hello World with DMD Compiler, .EXE file takes 1-3 seconds to run for the first time

2020-05-18 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 18 May 2020 at 16:01:14 UTC, kinke wrote: Is that really the case for all D programs on Windows, or just those built with -m32 and thus using the exotic DigitalMars C runtime? -m32mscoff does it too, and -m64 has a slight delay as well (though possible that's just a cold disk cache

Re: Is it possible to implement operators as ordinary functions?

2020-05-18 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 19 May 2020 at 02:36:24 UTC, data pulverizer wrote: I was wandering if it possible to implement operators as ordinary functions instead of as member functions of a class or struct for example something like this: nope, it must be done as member functions.

Re: Is it possible to write some class members in another module ?

2020-05-19 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 19 May 2020 at 22:01:03 UTC, Vinod K Chandran wrote: Is it possible to write some class members in another module ? You can make some of members be other structs that you aggregate together.

Re: How to allocate/free memory under @nogc

2020-05-20 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 21 May 2020 at 02:50:22 UTC, data pulverizer wrote: Can you also confirm that `@nogc` in a class do the same thing in that class as it does for a function? I don't think it does anything in either case, but if it does anything it will just apply @nogc to each member function in th

Re: String interpolation

2020-05-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 21 May 2020 at 06:57:28 UTC, mw wrote: i.e how to write this 's'? gimme a like on the proposal to add to the language! https://github.com/dlang/DIPs/pull/186 If accepted, that would let you write i"stuff here".idup to get an interpolated string.

Re: String interpolation

2020-05-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 21 May 2020 at 17:10:31 UTC, mw wrote: BTW, is the .idup must be there? It is discussed more in the github document but basically the proposed built-in syntax returns a generic builder thing which can make more than just strings. The idup specifically asks it to make a copy into

Re: How to use base class & child class as parameter in one function ?

2020-05-22 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 22 May 2020 at 20:04:24 UTC, Vinod K Chandran wrote: sampleList.Add(New Child(10.5)) Is this possible in D without casting ? Direct translation of this code works just fine in D.

Re: Static assert triggered in struct constructor that shouldn't be called

2020-05-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 24 May 2020 at 21:34:53 UTC, jmh530 wrote: The following code results in the static assert in the constructor being triggered, even though I would have thought no constructor would have been called. static assert is triggered when the code is *compiled*, whether it is actually run

Re: alias this and initialisation

2020-05-25 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 25 May 2020 at 01:35:47 UTC, Danni Coy wrote: s = 8; // this works S s = 8 // but this does not? } alias this only applies if you already have an object. Construction is too soon. You can add a constructor to make that work though.

Re: How to get the pointer of "this" ?

2020-05-25 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 25 May 2020 at 21:45:39 UTC, welkam wrote: Where is DWORD_PTR defined? it is a win32 thing. should be able to directly cast to it most the time if there is opCast on the class it needs another layer of helper function but without opCast it should just work

Re: How to get the pointer of "this" ?

2020-05-25 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 25 May 2020 at 22:31:00 UTC, Vinod K Chandran wrote: A dword is an unsigned, 32-bit unit of data. We can use uint in D. I have tried that too, but no luck. A DWORD_PTR is *not* the same as a uint. It is more like a size_t or void* depending on context.

Re: How to get the pointer of "this" ?

2020-05-25 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 25 May 2020 at 22:32:52 UTC, Vinod K Chandran wrote: What is an opCast ? operator overload of the cast function. if you didn't write one, you don't have to worry about this.

Re: How to get the pointer of "this" ?

2020-05-26 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 26 May 2020 at 11:35:23 UTC, Vinod K Chandran wrote: Okay, but uint is working perfectly. It won't if you use -m64.

Re: Control flushing to stdout... core.osthread.Thread + arsd.terminal

2020-06-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 5 June 2020 at 11:45:31 UTC, aberba wrote: How can I make Thread.sleep() only run AFTER "Wait, signing you in ..." is written (force flushed) to stdout? just use explicit `terminal.flush();` any time you want the output to appear immediately. Terminal does its own aggressive buffe

Re: Control flushing to stdout... core.osthread.Thread + arsd.terminal

2020-06-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 5 June 2020 at 20:05:28 UTC, aberba wrote: Why was the initial decision to handle buffering that way in terminal? More buffering = more speed, it actually makes a surprisingly big difference sometimes, like you can notice the lag with your eyes alone as it prints in the more extrem

Re: Control flushing to stdout... core.osthread.Thread + arsd.terminal

2020-06-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 5 June 2020 at 20:11:16 UTC, aberba wrote: Didn't come to mind to lookup from terminal docs. Thought it was a Dlang/OS problem. Yeah, the OS by itself rarely buffers output like this, but both the C library (on which std.stdio is built) and my Terminal object do (they do separately

Re: Mixin and imports

2020-06-08 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 8 June 2020 at 02:55:25 UTC, jmh530 wrote: In the code below, foo!fabs compiles without issue, but foo!"fabs" does not because the import is not available in the string mixin. Why do you even want foo!"fabs"? Usually when I see people having this problem it is actually a misunderst

Re: Metaprogramming with D

2020-06-08 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 8 June 2020 at 14:41:55 UTC, Jan Hönig wrote: What is the name of this `q` thing? It is just a string that looks like code.

Re: What is the current stage of @property ?

2020-06-10 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 10 June 2020 at 22:50:17 UTC, Paul Backus wrote: static assert(isInputRange!S); // passes isInputRange doesn't check it but others do. std.random.isSeedable requires @property on front for example. Some apparently test incorrectly too, like std.range.primitives.moveFront seems

Re: Weird behavior with UDAs

2020-06-13 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 13 June 2020 at 12:55:36 UTC, realhet wrote: My first question is, how to avoid that error with A.i4? Why is there a difference between @UNIFORM and @UNIFORM(), do the first returns a type and the later returns a value? Basically yeah. a UDA in D is just whatever you write gets

Re: Should a parser type be a struct or class?

2020-06-17 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 17 June 2020 at 14:24:01 UTC, Stefan Koch wrote: Parser in dmd does even inherit from Lexer. why would a parser ever inherit from a lexer?

Re: why cannot spawn function defined in unittest block {}?

2020-06-20 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 20 June 2020 at 17:43:42 UTC, mw wrote: the function defined in unittest become a delegate? how to work-around this? just add the keyword static to the functions

Re: Passing a variable number of slices into a function

2020-06-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 22 June 2020 at 02:04:06 UTC, user1234 wrote: Maybe each slice has different type ? in some cases T[][]... will work better too. depends on the details here

Re: Some questions about strings

2020-06-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 22 June 2020 at 03:17:54 UTC, Denis wrote: - First, is there any difference between string, wstring and dstring? Yes, they encode the same content differently in the bytes. If you cast it to ubyte[] and print that out you can see the difference. - Are the characters of a string s

Re: Some questions about strings

2020-06-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 22 June 2020 at 03:43:58 UTC, Denis wrote: My code reads a UTF-8 encoded file into a buffer and validates, byte by byte, the UTF-8 encoding along with some additional validation. If I simply return the UTF-8 encoded string, there won't be another decoding/encoding done -- correct?

Re: figure out where a particular template function is located

2020-06-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 24 June 2020 at 20:28:24 UTC, Steven Schveighoffer wrote: Is there a way to figure this out from the call? The .mangleof the instance might help track it down since it should give you the module name as part of that mangle. Then go in there and start breaking things (or use the

Re: Downloading files over TLS

2020-06-26 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 26 June 2020 at 10:12:09 UTC, Jacob Carlborg wrote: * Arsd [4]. Relies on OpenSSL Yeah, I've been wanting to change that and use the native apis for years but like I just haven't been able to figure out the documentation of them. Though for plain download, on Windows there's a hi

Re: Recursive delegate inside template?

2020-06-26 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 26 June 2020 at 14:12:00 UTC, drathier wrote: I'm trying to get this to compile, without much luck: You might be able to make it a function: bool foo() { auto fn(A)() { A delegate(A) fn; fn = delegate A(A a) { return fn(a); };

Re: mixin template compile-time compute declared name

2020-06-27 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 27 June 2020 at 21:10:59 UTC, NonNull wrote: Is it possible to use a template to declare something whose name is computed at compile time? You'd have to string mixin the contents inside the mixin template.

Re: Why is this allowed

2020-06-30 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 30 June 2020 at 16:41:50 UTC, JN wrote: I like my code to be explicit, even at a cost of some extra typing, rather than get bitten by some unexpected implicit behavior. I agree, I think ALL implicit slicing of static arrays are problematic and should be removed. If you want to set

Re: Print only part of a stack trace

2020-07-01 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 1 July 2020 at 17:44:45 UTC, Dennis wrote: On assertion failure, the default error handler prints a stack trace that looks like this My cgi.d does something just like that. It just does `exception.toString()` then `splitLines` on that string. Element exceptionToEleme

Re: Catching OS Exceptions in Windows using LDC

2020-07-04 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 4 July 2020 at 12:45:50 UTC, realhet wrote: It was not a problem on other systems like: MSVC or Delphi, but on LDC these events are completely ignored. use dmd with -m32 or -m32mscoff and it works correctly automatically. For whatever reason, dmd 64 bit and ldc decided to do the

Re: GDC and DMD incompatability, can both be used?

2020-07-11 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 11 July 2020 at 04:28:32 UTC, cy wrote: 125 | static foreach (string member; FieldNameTuple!T) { The word "static" there can probably be removed and have it work exactly the same way. Worth a try. Does gdc not support static foreach at all? only the newest gdc d

Re: Bind C++ class to DLang : undefined reference to `Canvas::Foo()'

2020-07-13 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 13 July 2020 at 09:34:35 UTC, zoujiaqing wrote: # dmd source/main.d Canvas.o -L-lstdc++ && ./main [1]49078 segmentation fault ./main On my computer I got this warning out of the compiler: libstdc++ std::__cxx11::basic_string is not yet supported; the struct contains an interio

Re: Good way to send/receive UDP packets?

2020-07-18 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 18 July 2020 at 16:00:09 UTC, Dukc wrote: I have a project where I need to take and send UDP packets over the Internet. Only raw UDP I wrote an example using phobos on my blog a while ago that might help you get started: http://dpldocs.info/this-week-in-d/Blog.Posted_2019_11_11.

Re: Is there a compiler option to list all functions executed at compile time when compiling a file?

2020-07-20 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 20 July 2020 at 16:01:53 UTC, blizzard wrote: I am trying to learn D and knowing when code is run at compile time would be good for learning what functions can be used without thinking much about performance. No function is ever run at compile time unless you specifically request i

Re: miscellaneous array questions...

2020-07-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 20 July 2020 at 22:05:35 UTC, WhatMeWorry wrote: How does that pertain to an array? C arrays work as pointers to the first element and D can use that style too. 2) "The total size of a static array cannot exceed 16Mb" What limits this? The others aren't wrong about stack size l

Re: std/process.d: nothrow functions which throw (in struct ProcessPipes)

2020-07-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 21 July 2020 at 12:44:23 UTC, Drone1h wrote: Would it be possible to explain this, please ? nothrow only applies to Exception and its children. Error is a different branch. Error means you have a programming error and cannot be caught and recovered (though the compiler allows it

Re: miscellaneous array questions...

2020-07-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 21 July 2020 at 13:16:44 UTC, IGotD- wrote: Either the array will hit that page during initialization or something else during the execution. But the array isn't initialized in the justification scenario. It is accessed through a null pointer and the type system thinks it is fine

Re: miscellaneous array questions...

2020-07-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 21 July 2020 at 19:20:28 UTC, Simen Kjærås wrote: Walter gives some justification in the post immediately following: whelp proves my memory wrong!

Re: How do I convert a Base64 image url string to a png/jpg image file?

2020-07-30 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 30 July 2020 at 12:22:46 UTC, aberba wrote: I'm able to decode it to a buffer but the trouble is getting it from buffer to an actual image file. Any library function combination I can use? I don't think I wrote it as a library yet, but the idea is pretty simple: they all start wi

Re: Equivalent of C++ #__VA_ARGS__

2020-08-02 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 2 August 2020 at 15:30:27 UTC, Ronoroa wrote: How do I achieve equivalent semantics of following C++ code? ``` #define dbg(...) std::cout << __LINE__ << #__VA_ARGS__ << " = " << print_func(__VA_ARGS__) << std::endl; ``` You probably just want void dbg(Args...)(Args args, size_t

Re: Equivalent of C++ #__VA_ARGS__

2020-08-02 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 2 August 2020 at 16:05:07 UTC, Ronoroa wrote: That doesn't seem to stringize the args part like in #__VA_ARGS__ oh yeah i missed that part. D basically can't do that exactly, but if you pass the args as template things directly you can do this: --- void main(string[] args) {

Re: Question about UDAs

2020-08-02 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 3 August 2020 at 03:00:08 UTC, Cecil Ward wrote: When practically speaking would you use UDAs? A real-world use-case? They are useful when you want to attach some kind of metadata to the declarations for a library to read. For example, my script.d looks for `@scriptable` for method

Re: Are function literals deprecated?

2020-08-03 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 3 August 2020 at 14:23:56 UTC, Victor L Porton wrote: Are function literals considered deprecated in regard of using delegates instead? No, they both work well for different purposes.

Re: Template functions inside interface

2020-08-04 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 4 August 2020 at 13:36:15 UTC, Zans wrote: Is there any way to declare template functions inside interface and then override them in a class? No, the templates in the interface are automatically considered `final`. So the body must be in the interface too to avoid that undefined r

Re: Non-recursive maxSizeOf

2020-08-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 6 August 2020 at 00:58:39 UTC, Per Nordlöw wrote: Is it possible to implement in a non-recursive way? It is very easy too... just write an ordinary function: size_t maxSizeOf(T...)() { size_t max = 0; foreach(t; T) if(t.sizeof > max)

Re: Non-recursive maxSizeOf

2020-08-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 6 August 2020 at 01:17:51 UTC, lithium iodate wrote: more love for phobos pls That would add a lot to the cost and bring no real benefit

Re: Non-recursive maxSizeOf

2020-08-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 6 August 2020 at 01:23:33 UTC, Per Nordlöw wrote: How does the memory usage and speed of this code compare to the variant that uses template instantiations? I haven't tested this specifically, but similar tests have come in at like 1/10th the memory and compile time cost. There

Re: Non-recursive maxSizeOf

2020-08-06 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 6 August 2020 at 13:18:40 UTC, Per Nordlöw wrote: mixin(T.stringof ~ " _store" ~ T.mangleof ~ Never ever use mixin(T.stringof). Always just use mixin("T") instead. mixin("T _store", T.mangleof /* or just idx is gonna be better */,";"); Though I doubt this is g

Re: How does D's templated functions implementation differ from generics in C#/Java?

2020-08-07 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 7 August 2020 at 21:03:47 UTC, aberba wrote: Syntactically they look the same (although D's can do more things) so I'm trying to understand how why in D it's called template but in languages like C#/Java they're generics. In D, a copy of the function is created for each new template

Re: dpldocs not update

2020-08-07 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 7 August 2020 at 21:58:10 UTC, Per Nordlöw wrote: https://phobos-next.dpldocs.info/index.html aren't updated. For instance the file dpldocs never auto-updates. You must either link to a specific tagged version like this: https://phobos-next.dpldocs.info/v0.3.9/index.html Or go t

Re: Leaving a pointer to it on the stack

2020-08-13 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 13 August 2020 at 20:04:59 UTC, Andre Pany wrote: Hi, in the specification https://dlang.org/spec/interfaceToC.html#storage_allocation there is this paragraph: "Leaving a pointer to it on the stack (as a parameter or automatic variable), as the garbage collector will scan the st

Re: Types of lambda args

2020-08-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 17 August 2020 at 00:20:24 UTC, Cecil Ward wrote: In a lambda, how do we know what types the arguments are? In something like (x) => x * x In that the compiler figures it out from usage context. So if you pass it to a int delegate(int), it will figure x must be int. - there

Re: Creating a pointer array

2020-08-19 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 19 August 2020 at 13:03:54 UTC, data pulverizer wrote: How do you create an array of pointers in D? I tried something like ``` double* []y; ``` I'd write it double*[] y; but yeah that's it. Error: only one index allowed to index double[] That must be at the usage point whe

Re: BetterC + WASM Update

2020-08-19 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 19 August 2020 at 21:24:23 UTC, Mike Brown wrote: I can see that LDC supports WASM output, and I believe this requires BetterC to be enabled? Not really but anything beyond -betterC is still kinda diy right now. So I happened to do port my little tetris game in D to wasm just

Re: __FILE__ and __LINE__ in case of import expression

2020-08-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 21 August 2020 at 14:01:24 UTC, Andrey Zherikov wrote: mixin(import("foo.d")); // line #17(2) Why are you doing this? This kind of thing is almost never an ideal solution in D. See, the compiler just sees a big string literal there. It isn't a separate file at that point

Re: __FILE__ and __LINE__ in case of import expression

2020-08-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 21 August 2020 at 21:06:11 UTC, Steven Schveighoffer wrote: The hybrid line number (original source line number + mixin line number) seems like a bug to me. I'm not so sure without seeing all the code. Remember to the compiler, the mixin thing is just a big string literal at the lo

Re: __FILE__ and __LINE__ in case of import expression

2020-08-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 21 August 2020 at 21:42:21 UTC, Steven Schveighoffer wrote: While not necessarily a "bug", it's not very useful. Maybe not in this case, but it is perfectly accurate for cases like: mixin(q{ some code here }); Where it will actually line back up to the original file's line nu

Re: __FILE__ and __LINE__ in case of import expression

2020-08-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 21 August 2020 at 22:12:48 UTC, Steven Schveighoffer wrote: Who does that though? An incompetent coder: http://dpldocs.info/experimental-docs/source/arsd.cgi.d.html#L5713 http://dpldocs.info/experimental-docs/source/arsd.cgi.d.html#L5943 http://dpldocs.info/experimental-docs/source/

Re: __FILE__ and __LINE__ in case of import expression

2020-08-23 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 23 August 2020 at 12:50:36 UTC, Andrey Zherikov wrote: Even this approach can lead to unclear result if you move 'q{...}' outside of mixin: Yes, that's why I write it very specifically the way I do, with q{ and mixin on the same line.

Re: opIndex for type list

2020-08-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 24 August 2020 at 14:19:14 UTC, data pulverizer wrote: I am trying to implement `opIndex` (e.g. T[i]) for types in a struct. So for I have `length`: Can't really do that, the operator overloads work on instances instead of static types. AliasSeq is magical because it just gives a

Re: Introspecting a package for submodules

2020-08-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 24 August 2020 at 22:32:52 UTC, Anonymouse wrote: How do I do this? (Is there some other way?) Not really a way. A package doesn't quite exist in D; there is no formal construct that is a package and has a defined list if stuff. It is just whatever modules are compiled in that ha

Re: what's this Error: corrupt MS Coff object module

2020-08-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 25 August 2020 at 00:41:27 UTC, mw wrote: How to fix this Coff object issues? there's two library formats: coff and omf. omf is the old one that dmd assumes without arguments. coff is the new one with `dmd -m32mscoff` or `dmd -m64`. I would guess one of those libs was built with

Re: what's this Error: corrupt MS Coff object module

2020-08-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 25 August 2020 at 01:08:49 UTC, mw wrote: Is it safe to just delete all the: yup. I have to do this every other week on my work box to keep its hard drive from filling up lol

Re: How to create compile-time container?

2020-08-31 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 31 August 2020 at 20:39:10 UTC, Andrey Zherikov wrote: How can I do that? You can use a normal string[] BUT it is only allowed to be modified inside its own function. Then you assign that function to an enum or whatever. string[] ctGenerate() { string[] list; list ~= "stuf

Re: I think Associative Array should throw Exception

2020-09-01 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 1 September 2020 at 18:55:20 UTC, Steven Schveighoffer wrote: This is the big sticking point -- code that is nothrow would no longer be able to use AAs. It makes the idea, unfortunately, a non-starter. You could always catch it though. But I kinda like things the way they are exac

Re: Bug in import(...) on Windows?

2020-09-02 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 2 September 2020 at 17:39:04 UTC, Andrey Zherikov wrote: Is this a bug in dmd? I think it is an old bug filed (I can't find it though) about inconsistent platform behavior but it is allowed by spec for the compiler to reject any path components. import("") is supposed to just

Re: Bug in import(...) on Windows?

2020-09-02 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 2 September 2020 at 18:40:55 UTC, Andrey Zherikov wrote: If I provide -Jfoo to dmd, doesn't it mean my consent to use the contents of directory foo? Yeah, but dmd has been inconsistent on platforms about if it allows subdirectories. Right now I think it just strips all slashes o

Re: Building LDC runtime for a microcontroller

2020-09-07 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 7 September 2020 at 20:55:54 UTC, IGotD- wrote: I guess this was written before betterC existed. Well, -betterC existed even then, but it was *completely* useless. It didn't become useful until 2016 or 2017. But around that same time, going minimal runtime got even easier, so I n

Re: Are @safe unittests actually checked for safety?

2020-09-07 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 7 September 2020 at 20:33:26 UTC, 0xEAB wrote: Are unittests that are marked @safe actually checked for safety? https://github.com/dlang/phobos/blob/v2.093.1/std/file.d#L4937 How comes this unittest is @safe when `dirEntries` appears to be @system? I see what happened now: those n

Re: GC.LDC2 on Android

2020-09-08 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 8 September 2020 at 12:47:11 UTC, Danny Arends wrote: How can I figure out which linker is used ? When performing a dub build, it just mentions that ldc2 is used for linking If you are using the d_android setup thing, it actually edits ldc2.conf so it uses the linker from the NDK.

Re: UDA inheritance

2020-09-10 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 10 September 2020 at 13:06:41 UTC, Joseph Rushton Wakeling wrote: `hasUDA!(T, AnotherUDA)` ...do you have to use hasUDA? The language works with class UDAs, but hasUDA doesn't support it. If you write your own test function though you can: ``import std.traits; class BaseUDA {

<    1   2   3   4   5   6   7   8   9   10   >