Re: Using output-range overloads of SysTime.toISO{Ext}String with formatting code
08.07.2019 13:38, Joseph Rushton Wakeling пишет: Thanks for taking the time to answer, but I don't think this really addresses my question. Your example shows a struct with `toString` overloads. However, SysTime.toISOExtString does not work like this: it is a method with two explicit overloads, one of which just returns a newly allocated `string`, the other of which returns nothing but accepts an output range as input: https://dlang.org/phobos/std_datetime_systime.html#.SysTime.toISOExtString I want to know if there's an easy way to work with that in `format` and `writefln` statements. Note that while SysTime does also have `toString` methods, these give no control over the kind of datetime string that results: https://dlang.org/phobos/std_datetime_systime.html#.SysTime.toString Since I explicitly need the extended ISO format, I need to use `toISOExtString` directly. Sorry that my answer wasn't thoughtful. I guess that there is no way to have `writeln` automatically use the output range overload instead of allocating one. You need somehow to provide the output range to `toISOExtString` explicitly because `writeln` outputs the return of `toISOExtString` and have no ability to use specific overload. That is compiler calls `toISOExtString` and then passes its return to `writeln`. Probably library solution isn't possible in this case. Workaround is using own wrapper to provide output range to `toISOExtString`.
Re: Assert and the optional Message
On Friday, 9 March 2012 at 07:55:56 UTC, Jonathan M Davis wrote: What you should almost certainly be doing is changing Visual Studio's settings so that it doesn't close the Window when the program exits. I know that it's possible. I've done it, but I rarely use Windows, and I don't remember what you have to do. So, unfortunately, I can't be of much help to you there, but that's the solution that you should almost certainly be using. If no one else around here can post how to do it, then I would think that you'd be able to find how via google easily enough. - Jonathan M Davis Are you sure you've tested this with D? Because VisualD doesn't support that yet, afaik.
Re: std.socket with GDC
On Sunday, 26 February 2012 at 02:01:17 UTC, Andrew Wiley wrote: I recall having some issues because Winsock needs to be on the linker commandline *after* phobos. Try running with `gdc -v` to see what the linker commandline looks like. That's it... any way to get it in the correct order, without having to call the linker separately? :/
Re: std.socket with GDC
On Saturday, 25 February 2012 at 18:27:29 UTC, Vladimir Panteleev wrote: On Friday, 24 February 2012 at 19:15:26 UTC, Mars wrote: Hello everybody. When trying to compile a program using GDC (Windows), which includes an import std.socket, I get a lot undefined references, like undefined reference to `WSAGetLastError@0' Try linking with libws2_32.a. Still the same. Does that work for you?
Executable size when compiling with GDC
Hello everybody. Today I've tested GDC (on Windows), and a simple Hello World program results in a 5 MB exe file, while it's only about 200 KB with DMD. Is this normal? What does GDC (GCC?) put in there, to make it so big, and why? Mars
Re: Executable size when compiling with GDC
On Tuesday, 21 February 2012 at 13:19:11 UTC, Andrea Fontana wrote: Have you tried to strip executable using --strip or --strip-all? Down to 1 MB, a good start, thanks. I guess that's more bearable.
Removing items from an Array
Hello everybody. Once again I have a little question, this time about removing items from an assoc array in a foreach. Why does the following code: http://pastebin.com/65P9WDNS Result in this output: http://pastebin.com/4FzEE1zi It seems rather strange to me. I'd expect the foreach_reverse to go over the array from the end to the beginning, and when I remove stuff from it, it shouldn't be a problem. But apparently it is. Mars
Re: Removing items from an Array
On Friday, 17 February 2012 at 10:13:00 UTC, Jonathan M Davis wrote: I don't believe that removing elements from an AA while iterating over it is safe. - Jonathan M Davis Well, no. But from my experience it's okay from bottom to top... at least in other languages. What would be the alternative? Maybe build a new array while iterating, and set it after the loop?
Re: Removing items from an Array
On Friday, 17 February 2012 at 13:33:25 UTC, James Miller wrote: AAs don't keep the key order, so when you delete something out of it, what ever system iterates to the next pointer gets confused. Its generally a bad idea to modify an array as you loop through it. -- James Miller Too bad. So, what would be the correct way to do this? I mean... it's not that uncommon, to have this problem. Are creating a new array while iterating over it, or creating a list of elements to remove, and removing them afterwards, the only ways to do this?
Re: Compiling Lua for D
On Thursday, 16 February 2012 at 05:06:13 UTC, Jesse Phillips wrote: BTW, I totally recommend LuaD when interacting with lua. Thank you for the explanation. I've started with LuaD, but I kinda didn't like it, can't exactly say why. I rather want to use Lua directly for now, and maybe write my own wrapper later.
Compiling Lua for D
Hello, everybody. Originally I've posted this in the C++ section, but seeing how the posts there are almost ancient, I'll post it here as well, where probably more people will see it. I'm trying to compile Lua, using DMC, to use it in D. I got the compilation working, but I have no clue, on how to turn the .obj files into a .lib. In D I'd use the -lib argument, but I couldn't figure out how to do this with DMC/OPTLINK yet. If I just do dmc src\lapi.c src\lauxlib.c [...] -olua5.1.lib I get OPTLINK : Warning 134: No Start Address and when trying to use this .lib Not a Valid Library File from DMD. What's the correct way to do this? Mars
Re: Compiling Lua for D
On Wednesday, 15 February 2012 at 16:35:01 UTC, Andrej Mitrovic wrote: Have you tried https://github.com/JakobOvrum/LuaD ? It has binaries here: http://github.com/JakobOvrum/LuaD/tree/binaries LuaD works fine, but I'd rather learn to compile stuff like this myself. It will get me further in the long run^^
Re: Compiling Lua for D
On Wednesday, 15 February 2012 at 15:02:36 UTC, Mars wrote: What's the correct way to do this? I guess I did it. Using lib, I was able to bind those obj files to a lib file. lib -c obj_files... I really have to learn a bit more about this stuff... to successfully compile a program with this lib, I have to make another one, using LuaD's C header files, so all symbols are found. I assume I could compile those, and include them in my other lib... but why is that? Shouldn't the Lua lib, and the importing of those files be enough? I couldn't really wrap my head around that yet, if I import something, that's not in my project, aren't those files included? Is that why I also have to make a lib for it? What exactly happens when importing?
Re: Compiling Lua for D
On Wednesday, 15 February 2012 at 19:44:41 UTC, Trass3r wrote: LuaD works fine, but I'd rather learn to compile stuff like this myself. It will get me further in the long run^^ Try to switch to gdc. dmc, optlink Co. must die a bloody death anyway :) I guess GDC uses COFF? That would definitely be handy... although I couldn't compile and debug from VS anymore in that case, and that would be unfortunate^^
Re: A GUI library to begin with
On Wednesday, 8 February 2012 at 03:55:41 UTC, Mr. Anonymous wrote: Has anyone tried these? Any suggestions? What is the status of DWT? What's the difference between DFL and DGui? I've only tried DFL and DGui, since I kinda didn't like the others, and of those two, DFL is the better choice, as it seems more mature. But aside from that they're very similar. Mars
Re: Partial classes
On Monday, 30 January 2012 at 10:21:07 UTC, bls wrote: As already said template mixins are close to partial classes. A snippet. HTH Thanks everybody. I still hope support for partial classes may come some day, to make this cleaner, but I guess it works.
Structs and Classes
Hello everybody. I couldn't really think of a good title for this. It's just a little question, about this example code: http://pastie.org/private/4xqtze47dlx9fy9pn53sq Apperantly I get a copy of Bar, when I call bar(), and it doesn't modify the actual variable of the object. But if I define Bar as a class, it works as expected (by silly me). Why is that? And if I want to use a struct for this, is the passing around of a pointer (like in the example) correct? Mars
Re: Partial classes
On Tuesday, 31 January 2012 at 12:33:22 UTC, bearophile wrote: Mars: Thanks everybody. I still hope support for partial classes may come some day, to make this cleaner, but I guess it works. Generally it's not wise to go too much against the style of a language. What do you need partial classes for? Bye, bearophile Need? Nobody needs a feature that's basicly only cosmetic. In some cases it makes the files cleaner, as you can split big classes into several files. I just like that^^ Mars
Partial classes
Hello everybody. Quick question, is there anything like C#'s partial classes in D? Mars
Re: Singleton question (shared class)
On Thursday, 26 January 2012 at 19:13:11 UTC, Ali Çehreli wrote: You haven't asked, so I shouldn't be commenting on your design, but singleton is accepted as an anti-pattern for a long time now. It is more like a solution in search of a problem. For example, in your case, you can solve your problems by creating just one of those objects and pass them down to code that will use them. Ali Thanks for your opinion. Although I know singletons aren't exactly best practice in OOP, I simply can't live without them. Sure I could pass my objects down again and again, so I have them availale at some point, but in a bigger program this just gets tedious, and for me that's not what OOP is supposed to do. On the contrey, things should get easier, and cleaner. Maybe I'll change my mind some day (5 years ago I though OOP was nonsense after all), or some new solution may come along, but for the time being, singletons are valid practice in my eyes. Mars
Re: char* to long
Thanks for the replies, everyone.I guess I'll go with the double conversion for now.
Singleton question (shared class)
Hello everybody. I have a few classes which I want to implement as singletons (like configuration, database connection, etc.), because I have to access them throughout my whole program, and from different threads. I'm implementing the singletons like this: http://pastie.org/private/nltc3suxxuq6zyc6nqpdow (I've read there's some bug if implementing them this way, but I'll deal with that later...) Now to my actualy question/problem. My database (MySQL) class interfaces with C. So I constantly have to cast shared data, to get it in and out. And since I'm still a little insecure about shared, I'm wondering if that's okay. Example: http://pastie.org/private/vd7qfh8b9c1chjnrimpp9a If it's not... what's the right way to do this? Mars
Re: Singleton question (shared class)
Alternative approach, I just found: http://pastie.org/private/1jlcvfostnbopfp3quflg If I get that right, this is basically the classic singleton, like it would be in other languages, right? So... what's the best way? Mars
char* to long
Hello everybody. I have to convert a char* (from a C function) to long. At the moment I'm using long foo = to!long( to!string(bar) ); but this doesn't feel right... with 2 to calls. Is this the way to go? Or is there something better? Mars
Extend Enum
Hello everybody. I'd like to know if there's a way, to extend an Enum, based on version(). I have an Enum, that holds various values, but some are different, in other versions. So the alternative would be to define the Enum several times. version(x) { enum example { FOO = 1, BAR = 2, } } else { enum example { FOO = 1, BAR = 3, } } Is there a better way to do this? Maybe a class with static consts...? How should I do it? Mars
Re: Extend Enum
On Monday, 23 January 2012 at 22:48:02 UTC, Ali Çehreli wrote: If it makes sense, you can use version(x) blocks within the single enum definition, as opposed to putting version(x) outside. Could you give me an example, what that would look like? So far I couldn't find a way to use version inside an Enum. Mars
Re: MySQL
On Sunday, 22 January 2012 at 08:11:21 UTC, Ali Çehreli wrote: -L is dmd's the linker flag option. Anything after that is passed to the linker. So -L-l passes -l to the linker: http://www.d-programming-language.org/dmd-linux.html Ali Let me rephrase that, is this valid for OPTLINK? Unknown Option : LLIBMYSQL Normally I just include the lib files in the files list (dmd foo.d bar.lib). Mars
Re: MySQL
On Sunday, 22 January 2012 at 10:21:29 UTC, DNewbie wrote: I've took a look at MySQL headers, the functions use stdcall, but in libmysql.dll exports table they are not decorated. This means...? Shouldn't it at least compile, if they are listed in the def file, coming from the lib?
Re: MySQL
On Sunday, 22 January 2012 at 23:23:23 UTC, Kapps wrote: 2) Create the binding functions using extern(System). Oh man... that was the problem. The file I used was using extern(C). Thought that was okay, it's a C lib after all. Thank you! Mars
MySQL
Hello everyone. I've been trying to use MySQL in an application on Windows, but I always get Symbol Undefined _mysql_init I've put the lib in the correct folder, so I don't know what the problem might be. I've tried several libs, and tried to compile it myself (always converted using coffimplib), but it fails, no matter what. I've also tried to make a def file out of the lib, and the functions are definitly listed as exports there. Any idea what I might doing wrong? Mars
Re: MySQL
On Saturday, 21 January 2012 at 23:44:12 UTC, DNewbie wrote: Please check whether your MySQL lib is 64 bit and your app is 32 bit. The lib is 32 bit, just like my application.
Re: MySQL
On Sunday, 22 January 2012 at 00:50:28 UTC, Ali Çehreli wrote: Are you also including the library on the command line with -L-l? For example, for ncurses: dmd ... -L-lncurses ... And if needed, also -L-L to specify the location of library files for the linker. Ali Yes, I am including it. Tried pragma and command line. And I don't get a message that the lib couldn't be found. What exactly is -L-l supposed to do? Is this valid in DMD 2.057? I get an error with it (Unknown Option). Mars
Re: Passing arguments to a new thread
On Friday, 20 January 2012 at 15:33:34 UTC, Timon Gehr wrote: On 01/20/2012 03:12 PM, Mars wrote: Hello everybody. As the title states, I want to run a function in a new thread, and pass it some arguments. How would I do that? I guess I could make a class, deriving from Thread, and work with it, but out of curiosity, I'd like to know if it's possible with a simple function. Mars See std.concurrency. auto tid = spawn(function, arg1, arg2, arg3, ...); Very interesting, thank you. I'm currently writing a little clientserver application, and wanted to use 1 thread per client, for simplicity, but with this it's probably not harder to just loop through non-blocking recvs, and pass something to a handler thread. Am I right?