Re: @nogc with opApply
On Sunday, 12 August 2018 at 01:39:21 UTC, ag0aep6g wrote: On 08/11/2018 12:00 PM, Alex wrote: [...] [...] [...] [...] [...] [...] [...] You can provide to overloads: one with @nogc, one without it. To keep it somewhat DRY, you can let them forward to a template implementation: int opApply(scope int delegate(ref uint) operations) { return opApplyImpl(operations); } int opApply(scope int delegate(ref uint) @nogc operations) @nogc { return opApplyImpl(operations); } int opApplyImpl(O)(O operations) { /* ... implementation here ... */ } Ah... that's nice... Thanks!
Re: write a function template specialisation that tests if an argument is known at compile time
On Saturday, 11 August 2018 at 05:17:51 UTC, Cecil Ward wrote: T myfunc(T)( T x, uint mask ) if ( mask == 3 ) { return fast_func( x, mask ); } [...] Is it the volcano pattern you are looking for? https://p0nce.github.io/d-idioms/#Is-this-available-at-compile-time-or-runtime?
Re: dtoh
On Tuesday, 7 August 2018 at 12:46:31 UTC, Steven Schveighoffer wrote: On 8/7/18 6:08 AM, bauss wrote: On Monday, 6 August 2018 at 13:28:05 UTC, Laeeth Isharc wrote: Hi Walter. Can dtoh be open-sourced now that dmd is? https://github.com/adamdruppe/dtoh I might be confused, but it seems like it is there. I think he meant htod: https://dlang.org/htod.html Which I believe uses some of the dmc source. -Steve For the record, I think this is the source code for htod: https://github.com/DigitalMars/Compiler/blob/master/dm/src/dmc/htod.d
Re: dmd64 on Windows: how?
On Sunday, 12 August 2018 at 03:49:04 UTC, Mike Parker wrote: On Saturday, 11 August 2018 at 19:50:30 UTC, Ivan Kazmenko wrote: I've installed the components shown in wiki image: v141 tools and the SDKs. VS 2017 Community includes everything you need. There's no reason to install the SDK separately. If it's installed first, the DMD installer will find it. The latest version will install the MinGW system libs and the lld linker if no VS installation is found. And for the past few versions, when you run dmd it will look for the VS installation as needed. So it should work out of the box without the need for the separate SDK or mucking about with the paths in sc.ini. Is your VS 2017 the Community edition? Yeah, I have VS 2017 Community Edition, and I was struggling trying to make 64-bit linking work, both with .7z archive and with .exe installer. The .exe installer dmd-2.081.1.exe I've just tried again. With default settings, it just installs into C:\D\ . Its sc.ini is almost empty, no sign of Visual Studio environment variables or paths. Then I run cmd.exe: ~ Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\D>dmd2vars64.bat Setting up 64-bit environment for using DMD 2 from C:\D\dmd2\windows\bin. dmd must still be called with -m64 in order to generate 64-bit code. This command prompt adds the path of extra 64-bit DLLs so generated programs which use the extra DLLs (notably libcurl) can be executed. C:\D>echo void main () {} > a.d C:\D>dmd -m64 a.d C:\D\dmd2\windows\bin\lld-link.exe: error: could not open libcmt.lib: no such fi le or directory Error: linker exited with status 1 ~ My Windows version is Windows Server 2008 R2. Microsoft Visual Studio Community 2017, version 15.7.6. At C:\Program Files (x86), there are: Microsoft Visual Studio[ 2754M ] Microsoft Visual Studio 12.0 [ 50M ] Microsoft Visual Studio 14.0 [ 954M ] The latter two contain some remains of the previous installations, so that may be the issue with detecting the current Visual Studio version. Ivan Kazmenko.
Re: unimplemented abstract function compiles.
I thought it would work the same way as an interface (which must be implemented by the direct sub class, otherwise compile error). But apparently it's possible to implement an abstract function anywhere in the class hierarchy. That makes it, in this case, impossible to check during compile time. I ran into this while loading objects from a file using Object.factory and forgot to implement an abstract function in one class.
Re: unimplemented abstract function compiles.
On 08/12/2018 07:29 PM, Eric wrote: I thought it would work the same way as an interface (which must be implemented by the direct sub class, otherwise compile error). From the spec text [1], I'd also expect an error. It says: "An abstract member function must be overridden by a derived class." And later: "Classes become abstract if any of its virtual member functions are *declared* abstract or if they are defined within an abstract attribute" (emphasis mine). So, arguably, DMD shouldn't accept your `C` class as abstract. It's not marked as abstract itself, and it doesn't have a declaration of an abstract method either. But in cases like this it's more likely that the spec will be changed to reflect what DMD does than DMD getting changed to break existing code. But apparently it's possible to implement an abstract function anywhere in the class hierarchy. That makes it, in this case, impossible to check during compile time. You can check it at compile time. The compiler just doesn't do it for you proactively. `C` is an abstract class, just like `I` is, and there's a trait for that [2]: static assert(!__traits(isAbstractClass, C)); For nicer syntax, there's also a wrapper around it in std.traits [3]: import std.traits: isAbstractClass; static assert(!isAbstractClass!C); If you want to make sure that your class isn't accidentally abstract, you can add an assert like that. [1] https://dlang.org/spec/attribute.html#abstract [2] https://dlang.org/spec/traits.html#isAbstractClass [3] https://dlang.org/phobos/std_traits.html#isAbstractClass
Re: Could you anybody using DerelictSDL2 on Android?
On Sunday, 12 August 2018 at 03:42:34 UTC, Mike Parker wrote: On Saturday, 11 August 2018 at 14:36:59 UTC, zhani wrote: On Saturday, 11 August 2018 at 08:47:59 UTC, Mike Parker wrote: On Tuesday, 7 August 2018 at 12:05:33 UTC, zhani wrote: [...] I don't do any sort of Android development, so I've never tested any Derelict packages on the platform. A few years back someone did some work with the DerelictGLES binding on Android and IIRC I made some updates to the DerelictUtil package for it. And I've added some version statements to DerelictSDL2 for the Android-specific parts of the C headers. Beyond that, I don't know of anyone who's done anything with it. so sad... There's nothing sad about it. There's only so much time in a day. I have no reason to do any Android development. Nor iPhone development. Nor countless other platforms. The static binding configuration (see the docs [1]) *should* work for Android and will save you the time of implementing the bindings yourself. If you can compile DerelictSDL2 for Android using the DerelictSDL2_Static version, then link it and SDL2 with your app, it should work. All I'm saying is I've never tried it and I know of no one who has. If it works for you, or you can get it working, then we can tell the next person who comes along that it does work. [1] http://derelictorg.github.io/packages/sdl2/ I didnt say to “please, be make a android build now!” Yah, you’re right. You dont have to make a DerelictSDL2 for any platform. Im very sorry but i dont care about it. I just wanna know how to do it. Anything is ok for me. Links, advices with detail, experience. I wanna clue and its not a dev req to you. Ok, i got some clues in here. First, there is no people who tried it. Sad. Second, be use a SDL2 with static version. it will be working. but nobody unknow how to do it. And notice, A DerelictSDL2 IS NOT A REASON to development for any platform. RIGHT? It was i know, and what i know all. I just can, init a dub, replace a dmd to ldc2 for android, add a DerelictSDL2 and sit here in a corner, crying. Anyway thank you for reply to stupid question. :-) Regards,
SysTime comparesin - dropMiliseconds
I have to synchronize a directory. If remote file is newer I copy to local. If local file is newer I copy it to remote server. For some reason remote timestamp does not contain milliseconds, so comparison (localFileTime < remoteFileTime, etc) fails. I need help to drop milliseconds from local file timestamp.
Re: SysTime comparesin - dropMiliseconds
On Sunday, 12 August 2018 at 19:50:44 UTC, User wrote: I have to synchronize a directory. If remote file is newer I copy to local. If local file is newer I copy it to remote server. For some reason remote timestamp does not contain milliseconds, so comparison (localFileTime < remoteFileTime, etc) fails. I need help to drop milliseconds from local file timestamp. auto m = dur!("seconds")(1); if ((remote - local) > m)
?? How to subscribe to Multicast Broadcasts ??
Hello All! I've been trying every possible combination and cannot get anything working. (>_<) This is I think the closest I've got, I think the problem may be with the 3 argument. I'm not sure how to join the Multicast IP membership? (this code currently does not work - throws error: 'Unable to set socket option: An invalid argument was supplied'.) Socket listen_socket = new Socket(AddressFamily.INET, SocketType.DGRAM, ProtocolType.UDP); listen_socket.setOption(SocketOptionLevel.IGMP, SocketOption.IPV6_JOIN_GROUP, 1); auto adr = getAddress("0.0.0.0", "56000"); listen_socket.bind(adr[0]); This is how the messages are sent (which works fine): Socket udp_broadcast_soc = new UdpSocket(); udp_broadcast_soc.setOption(SocketOptionLevel.SOCKET, SocketOption.BROADCAST, 1); auto adr = getAddress("239.192.0.10", 54000); udp_broadcast_soc.sendTo(, adr[0]); Please Please Please Help, I am desperate! Many Thanks in Advance for your time & attention, -joe
Re: SysTime comparesin - dropMiliseconds
On Sunday, August 12, 2018 1:50:44 PM MDT User via Digitalmars-d-learn wrote: > I have to synchronize a directory. If remote file is newer I copy > to local. If local file is newer I copy it to remote server. For > some reason remote timestamp does not contain milliseconds, so > comparison (localFileTime < remoteFileTime, etc) fails. I need > help to drop milliseconds from local file timestamp. If you want to drop the milliseconds from a SysTime, you can always set its fracSecs to Duration.zero. e.g. st1.fracSecs = Duration.zero; if(st1 < st2) { ... } You could also cast the two SysTimes to DateTime and compare the result (since DateTime doesn't have fractional seconds), but you'd probably want to use toUTC() to ensure that the SysTimes had the same time zone when converting, or you'd risk subtle bugs. e.g. something like if(cast(DateTime)st1.toUTC() < cast(DatetTime)st2.toUTC()) { ... } - Jonathan M Davis
Re: InputRange help: (1) repeated dtor calls and (2) managing resources needing free()
On Thursday, 14 June 2018 at 00:42:25 UTC, James Blachly wrote: ... I assume the (apparent) lack of parity between ctor and dtor is because the "default postblit" (which I figured out for a struct means an empty `this(this)` ctor) is called when a copy is made. My understanding is that I cannot disable the default postblit and still act as a range, correct? Should I be overloading this? 2. Directly related to the above, I need, when the range is consumed, to free() the underlying library's iterator handle. Naively, I had the destructor do this, but obviously with multiple calls to ~this I end up with an error free()'ing a pointer that is no longer alloc'd. What is the correct way to handle this situation in D? Other Range and destructor advice generally (e.g., "You should totally change your design or approach to X instead") is always welcomed. James I think I have a handle on #1 (copy of the range is made for consumption which is why dtor is called more often than ctor), but would still be interested in advice regarding #2 (as well as general Range and dtor advice). Here: https://github.com/blachlylab/dhtslib/blob/master/source/dhtslib/tabix.d#L98 I need to free the library's iterator, but the Range's destructor is the wrong place to do this, otherwise memory is freed more than once. Is it a better approach to (a) somehow guard the call to tbx_itr_destroy or (b) create a postblit that creates a new iterator and pointer? (or (c), None of the above) As above, my understanding is that disabling the default posblit prohibits acting as a Range. Thanks in advance