Re: Simplifying a string mixin

2019-02-26 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-02-25 21:57, Victor Porton wrote: Can string mixing be split into several parts? I have a mixin like this:     mixin("struct " ~ name ~ " {\n" ~   "  struct Regular {\n" ~   "    // ..." ~   "  }\n" ~   "  struct WithDefaults {\n" ~   "   

Re: How to setup dub to use x86 and x64 dll's when appropriate?

2019-02-26 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-02-26 05:17, Michelle Long wrote: e.g., using sdl for different versions and have it automatically switch. What would be nice is if one could stick all the files for x86 in one dir and x64 in the others and they will be used depending on the build(and copied) Ideally one can do it

Re: local class instance (at module-level)

2019-03-14 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-03-14 12:05, spir wrote: I desperately try to declare/define/initialise a simple class instance at module-level. This is a special (conceptually static and immutable) instance used as a "marker", that just should exist and be accessible by methods of this class and/or other classes

Re: How are (Static) Libraries with Templates Compiled?

2019-03-12 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-03-11 21:59, jmh530 wrote: Ah, so you need the .lib files and the .di files to get it work. You need the .di or .d files regardless if it's a template or not. Because you need to know which declarations are available. In addition to that, for templates the source (and not just the

Re: Should D file end with newline?

2019-02-12 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-02-10 18:20, Jonathan M Davis wrote: I use (g)vim, which I would expect to show anything like trailing newlines. It usually shows everything, including rendering control characters and the like in a way that you know exactly what's there. Opening up std/algorithm/mutation.d in vim as an

Re: Singleton in Action?

2019-02-03 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-02-02 17:56, Ron Tarrant wrote: Hi guys, I ran into another snag this morning while trying to implement a singleton. I found all kinds of examples of singleton definitions, but nothing about how to put them into practice. Can someone show me a code example for how one would actually

Re: Singleton in Action?

2019-02-04 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-02-04 11:36, Ron Tarrant wrote: I've seen comments similar to this in several examples. When you say "no one else" you're personifying callers? Yes. And so this means: No caller outside the object? Which really amounts to: Since no one INside the object WILL call this() and no one

Re: bug in compiles?

2019-04-12 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-04-11 20:13, Alex wrote: The following code works when I comment out the static if //static if (__traits(compiles, __traits(getAttributes, T)))    static foreach(a;  __traits(getAttributes, T)) Attributes ~= There seems to be absolutely no reason why this code would fail with the

Re: How to debug long-lived D program memory usage?

2019-04-17 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-04-17 18:27, Adam D. Ruppe wrote: I am willing to recompile and run again, though I need to actually use the programs, so if instrumenting makes them unusable it won't really help. Is there a magic --DRT- argument perhaps? Or some trick with gdb attaching to a running process I don't

Re: Extract code of function

2019-05-26 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-05-26 19:46, Andrey wrote: Hello, Is it possible to extract code of some function into string variable using CT reflextion? For example: int test(bool flag) {     return flag ? 100 : getRandom(); } enum string code = GetFunctionCode!test; // "return flag ? 100 : getRandom();" No,

Re: Dub dependencies / How to use own Github fork?

2019-06-04 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-06-01 14:09, Robert M. Münch wrote: On 2019-05-30 18:29:44 +, Steven Schveighoffer said: You can dub add-local your local fork, and it will use that instead of going out to code.dlang.org. Ok, any chance to switch back and forth between local/remote versions? If you developing

Re: What external libraries are available

2019-06-05 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-06-05 03:20, Mike Brockus wrote: If you never herd about Meson before: 樂. https://mesonbuild.com/ Hay there I was just wondering, what is the D equivalent to C++ Boost and or Poco libraries? I don't think there are any libraries that are a direct comparison to Boost (I'm not

Re: Where can I find a reference for compiler flags?

2019-06-05 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-06-05 03:19, Mike Brockus wrote: Where can I find a reference for compiler flags? Here's the reference [1]. You can also run "dmd --help" to print out the available flags. [1] might not be up to date. [1] https://dlang.org/dmd-windows.html -- /Jacob Carlborg

Re: Get module file path from ModuleInfo

2019-06-07 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-06-06 12:43, Andre Pany wrote: Also __traits(getUnitTests) does not return the module file name. The approach above is working fine in the d-unit library (https://code.dlang.org/packages/d-unit) Well, to use __traits(getUnitTests) you need to collect all the files and generate a new

Re: Get module file path from ModuleInfo

2019-06-06 Thread Jacob Carlborg via Digitalmars-d-learn
On Thursday, 6 June 2019 at 04:20:52 UTC, Andre Pany wrote: Hi, I want to enhance a unittest framework to also report the results in SonarQube Generic Execution format. This format lists the file paths. The unittest framework loops through the modules and collects the module name and the

Re: How to "Inherit" the attributes from a given callable argument?

2019-06-13 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-06-12 22:42, Mek101 wrote: I didn't know it applied to templates other than lambdas. Thank you for your explanation. It applies to templates, lambdas (which basically are templates) and nested functions. -- /Jacob Carlborg

Re: How to get type returned by e.g. std.algorithm.iteration.filter

2019-05-19 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-05-19 15:36, Christian Köstlin wrote: Unfortunately I have no idea how to even store the result of this search in an attribute of ByMinimum, as I cannot writeout its type. In general you can use `typeof()`, where `` is the expression you want to get the type of. -- /Jacob Carlborg

Re: Framework design, initialization and framework usage

2019-05-06 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-05-06 20:03, Robert M. Münch wrote: What I want to avoid is that explicit init line in main(). So, the user should derive whatever make sense for the app, but main() is never touched by the user. main() should initialize the user's app code "automatically" and be part of the

Re: Run code before dub dependency's `shared static this()`

2019-05-06 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-05-05 14:52, Daniel N wrote: This might work: pragma(crt_constructor) extern(C) void early_init() { } Keep in mind that the D runtime is not full initialized at this point. -- /Jacob Carlborg

Re: __gshared 32 & 64 bit

2019-05-06 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-05-06 15:43, Aldo wrote: Hello, is there a difference between __gshared on 32 and 64 bit apps ? Shouldn't be. I have an IOCP app on windows that works correctly when compiled as 64 bit, but crash/block when compiled as 32 bit. Do you have a reduced test case? Which compilers have

Re: What's best practice to use compound literals with structs and C-APIs?

2019-05-02 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-05-01 14:47, Robert M. Münch wrote: I use some C library that uses structs and many functions that use pointer to structs as arguments: struct A {...}; myfunc(A *myA); In C you can do this to get a lvalue: myfunc(&(A){...}); In D this doesn't work and I get an "is not an lvalue and

Re: OSX DStep / Standard Includes

2019-04-27 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-04-26 23:16, Jacob Carlborg wrote: You need to install the Xcode command line tools, by running "xcode-select --install". This will create the "/usr/include" directory. I'm guessing this is because DStep is linked against the open source version of Clang and not the one provided by

Re: OSX DStep / Standard Includes

2019-04-27 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-04-26 17:14, Robert M. Münch wrote: I'm trying the new DStep version but have some problems with standard include files: => dstep --output ./d -v -I/opt/local/libexec/llvm-5.0/include/c++/v1 myinclude.h clang version 5.0.2 (tags/RELEASE_502/final) Target: x86_64-apple-darwin18.5.0

Re: OSX DStep / Standard Includes

2019-04-26 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-04-26 17:14, Robert M. Münch wrote: I'm trying the new DStep version but have some problems with standard include files: => dstep --output ./d -v -I/opt/local/libexec/llvm-5.0/include/c++/v1 myinclude.h clang version 5.0.2 (tags/RELEASE_502/final) Target: x86_64-apple-darwin18.5.0

Re: Call delegate from C++

2019-04-24 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-04-24 18:20, Nicholas Wilson wrote: How do you pass a delegate to a c++ function to be called by it? The function to pass the delegate to is: extern (C++) int fakeEntrypoint(     extern(C++) void function(void* /*delegate's context*/) func,     void* /*delegate's context*/ arg);

Re: What the abstrac final class mean?

2019-08-13 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-08-12 11:25, a11e99z wrote: its weird that next compiles in some weird form import std; static class A {     static a() { "a".writeln; } // forgot return type } Since you have specified an attribute on "a", the compiler can infer the return type. In this case it's inferred to

Re: Linking D Runtime

2019-09-03 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-09-03 10:43, Jacob Carlborg wrote: This depends on how the compiler is installed. There are several installers that do not put the libraries in `/usr/lib`. BTW, that directory doesn't exist by default anymore on macOS, even if Xcode and the command line tools are installed. My bad.

Re: Linking D Runtime

2019-09-03 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-09-03 03:45, Jonathan Levi wrote: It looks like what needs to be found are "libphobos2" and "libdruntime".  They can be found where ever your system puts lib files.  Windows (as far as I know) does not have a joined place for lib files so you need to look where dmd/ldc/etc installed

Re: Java to D

2019-08-28 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-08-28 10:14, GreatSam4sure wrote: Good day everyone. DWT is a library for creating cross-platform GUI applications. It's a port of the SWT Java library from Eclipse. Currently supported platforms are Windows, using Win32 and Linux, using GTK. What are the tools and step involved in

Re: Linking to -framework on MacOS

2019-09-05 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-09-04 17:12, Andrew Edwards wrote: Worked like a charm:  -L/System/Library/Frameworks/Cocoa.framework/Cocoa This probably not a good idea. It relies on how a framework is structured internally. Adam's solution is the correct one. -- /Jacob Carlborg

Re: C++ vs D: Default param values and struct to array casting

2019-09-07 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-09-06 11:14, Andrew Edwards wrote: C++ allows the for following: struct Demo { float a, b, c, d; Demo() { a = b = c = d = 0.0f; } Demo(float _a, float _b, float _c, float _d) {     a = _a;     b = _b;     c = _c;     d = _d; } float 

Re: Why are extern(C/C++) definitions and references mangled differently in separately compiled modules?

2019-09-07 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-09-06 21:03, Max Samukha wrote: Is there any practical use of having identically named .d and .di alongside? Same as in C/C++. This allows you to have a header file if you want to distribute a closed source library. -- /Jacob Carlborg

Re: Deprecation message sources

2019-09-18 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-09-17 22:55, Johan Engelen wrote: Wow. How come this is not caught by the CI testing? That issue seems to be because "writeln" is printing "type", which is an enum. For enums, "writeln" prints the actual name of the enum member and not the value. It seems it extracts the names of

Re: How to get name of my application (project)

2019-08-05 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-08-03 17:58, Jonathan M Davis wrote: Also, the first element in the array passed to main is the name of the executable. No, what's passed to "main" is the path to however the application was invoked, not the executable. If you invoke it as "./foo" it will pass "./foo" to the "main"

Re: Is there a way to bypass the file and line into D assert function ?

2019-07-19 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-07-19 17:30, Newbie2019 wrote: for example: void ASSERT(string fmt, string file = __FILE_FULL_PATH__, size_t line = __LINE__, T...) (bool c, scope T a)  @nogc {    assert(c, string, file, line); } but i get this error: error.d(39): Error: found file when expecting ) error.d(39):

Re: Is there a way to bypass the file and line into D assert function ?

2019-07-22 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-07-19 22:16, Max Haughton wrote: Isn't assert a template (file and line) rather than a plain function call? No. It's a keyword, it's built-in to the compiler. It get extra benefits compared to a regular functions: the asserts will be removed in release builds. -- /Jacob Carlborg

Re: Packaging and Distributing Dlang Applications with GtkD Dependency?

2019-09-27 Thread Jacob Carlborg via Digitalmars-d-learn
On Wednesday, 25 September 2019 at 11:46:04 UTC, Ron Tarrant wrote: Hi y'all, I've been Googling how to do this, but coming up with nothing definitive. Are there any articles for how to do this for: Windows? Linux? other UNIX-alike OSs? For macOS you should distribute a GUI application for

Re: Which is the active fork in DFL gui library ?

2019-11-04 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-11-03 17:48, Vinod K Chandran wrote: @Jesse Phillips, Thank you for the reply.  Does DWT is built upon Java's SWT ? Yes. It's a full translation of the Java code to D. No JNI, JVM or Java or remains. I heard that SWT is somewhat slower in windows. I don't know if that's the

Re: is the runtime implemented in betterC?

2019-11-09 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-11-08 16:25, dangbinghoo wrote: hmm, if runtime is implemented in regular D, how could the regular D code depends on regular D runtime be compiled when we doesn't have a D runtime even exists? thinking thant we just have xtensa-llvm, and building ldc for xtensa CPU,  the runtime will

Re: Read Once then reset/init value?

2019-10-30 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-10-30 00:28, Simen Kjærås wrote: Something like this? T readOnce(T)(ref T value) {     auto tmp = value;     value = T.init;     return tmp; } unittest {     int i = 3;     assert(i.readOnce == 3);     assert(i == 0); } Perhaps better to encapsulate it in a struct to avoid

Re: Running unittests of a module with -betterC

2019-10-30 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-10-30 16:09, jmh530 wrote: I feel like this should be added into the compiler so that it just works. This will only run the unit tests in the current modules. The standard way of running the unit tests will run the unit tests in all modules. -- /Jacob Carlborg

Re: dmd memory usage

2019-11-18 Thread Jacob Carlborg via Digitalmars-d-learn
On Monday, 18 November 2019 at 00:20:12 UTC, Steven Schveighoffer wrote: I'm fighting some out of memory problems using DMD and some super-template heavy code. Try to enable the GC using the `-lowmem` flag [1]. [1] https://dlang.org/changelog/2.086.0.html#lowmem — /Jacob Carlborg

Re: dmd memory usage

2019-11-18 Thread Jacob Carlborg via Digitalmars-d-learn
On Monday, 18 November 2019 at 15:31:02 UTC, Steven Schveighoffer wrote: I don't think this will work for me, as this isn't CTFE, and I'm assuming the instantiated templates won't be collected because they stay referenced for the whole program. You could also combine that flag with the GC

Re: Translating Java into D

2019-11-16 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-11-14 20:50, NonNull wrote: Greetings, Java seems to be almost a subset of D in various ways. Has there been any work done to automatically translate Java source into D? Yes, I'm working on a tool, JPort [1], for automatically translating Java to D. It's not done yet and there's been

Re: Translating Java into D

2019-11-16 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-11-16 08:13, GreatSam4sure wrote: I am of the opinion that D is much more powerful than Java since I am familiar with the language to some extent. I am even to start a GUI app in java due to the fact I have no find a GUI toolkit in D that meet all my need. There's DWT [1], which is

Re: PHP to D Conversion

2019-10-18 Thread Jacob Carlborg via Digitalmars-d-learn
On Friday, 18 October 2019 at 06:22:33 UTC, Vino wrote: Hi All, Request your help in converting a PHP code to D equivalent code PHP Code: class avmtest { private $con; function __construct() { global $config; $this->con = new

Re: A proper WAT moment

2019-10-16 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-10-15 09:06, John Colvin wrote: And all the other ones in my example that access members without an instance that also compile? There's something pretty strange about the rules here. The thing is that it should be possible to access a non-static member without an instance because

Re: Uninstalling DMG file

2019-10-16 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-10-16 05:30, Joel wrote: Everything seems to be working again - yay! Great. If you see a lot of warnings when linking, I have a PR for that [1]. [1] https://github.com/dlang/dmd/pull/10476 -- /Jacob Carlborg

Re: How to get child class Type and members from parent class?

2019-11-20 Thread Jacob Carlborg via Digitalmars-d-learn
On Wednesday, 20 November 2019 at 10:05:11 UTC, zoujiaqing wrote: import std.stdio; class A { this(T)(T t) { } void write() { T _this = cast(T) this; writeln(this.v); } } class B : A { string v = "hello"; } void main() { auto b = new B;

Re: Leak-detection of references to scoped class instances

2019-11-25 Thread Jacob Carlborg via Digitalmars-d-learn
On Sunday, 24 November 2019 at 21:49:19 UTC, Per Nordlöw wrote: I guess we need a builtin language qualifier for scoped classes for that to work, right? We have that: scope a = new Object; — /Jacob Carlborg

Re: dmd memory usage

2019-11-24 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-11-18 01:20, Steven Schveighoffer wrote: I'm fighting some out of memory problems using DMD and some super-template heavy code. I have ideas on how to improve the situation, but it involves redesigning a large portion of the design. I want to do it incrementally, but I need to see

Re: equivalent of typeid(Class).name at compile-time

2019-11-22 Thread Jacob Carlborg via Digitalmars-d-learn
On Thursday, 21 November 2019 at 20:44:19 UTC, Steven Schveighoffer wrote: I thought I could do typeid(Class).name to get the class name that will be returned at runtime if you did typeid(instance).name. But it's not accessible at compile-time. What compile-time string should I use for

Re: Template mixin / unresolved external / scope problem?

2019-11-28 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-11-28 16:40, Robert M. Münch wrote: I have: a.d: extern (C) void myFuncA(); void myFuncB() { myFuncA(); } b.d: public import a; mixin template MYFUNCA() { extern (C) void myFuncA() {...} } c.d: import b; mixin MYFUNCA; ...further code... Compiling such a structure gives

Re: Undefined symbol: _dyld_enumerate_tlv_storage (OSX)

2019-10-11 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-10-11 18:48, Robert M. Münch wrote: On 2019-10-10 18:31:25 +, Daniel Kozak said: What dmd version? I think I had an older one like 2.085 or so. I updated to 2.088 and it now seems to work. https://issues.dlang.org/show_bug.cgi?id=20019 I'm on OSX 10.14.6, so this might not

Re: Undefined symbol: _dyld_enumerate_tlv_storage (OSX)

2019-10-11 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-10-10 20:12, Robert M. Münch wrote: I have two project I want to compile and both times get this error: Undefined symbols for architecture x86_64:  "_dyld_enumerate_tlv_storage", referenced from: __d_dyld_getTLSRange in libphobos2.a(osx_tls.o) I'm wondering where this comes from

Re: Undefined symbol: _dyld_enumerate_tlv_storage (OSX)

2019-10-14 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-10-14 07:36, Joel wrote: I use Home Brew (brew upgrade dmd, and brew upgrade dub) Brew is only up to 2.087.1 at the moment - John Colvin seems to be the man that mantains dmd with brew. You can use DVM [1] to install the latest version of DMD. [1]

Re: Undefined symbol: _dyld_enumerate_tlv_storage (OSX)

2019-10-14 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-10-14 09:29, Robert M. Münch wrote: => nm /usr/lib/system/libdyld.dylib | grep _dyld_enumerate_tlv_storage 00017eca T _dyld_enumerate_tlv_storage Strange, the output shows that the symbol is present. -- /Jacob Carlborg

Re: dscanner and ref parameters

2020-02-23 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-02-23 13:28, mark wrote: Just realised that the arg is 'out' not 'ref'; don't know if that makes a difference to dscanner. Anyway, I've made a bug report: https://github.com/dlang-community/D-Scanner/issues/793 Same idea applies. dscanner should look at the signature. In the case of

Re: CTFE, string mixins & code generation

2020-01-24 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-01-24 19:43, H. S. Teoh wrote: (enums cannot take AA's or class objects as values, also, once assigned they are immutable). AA enums work. Class objects kind of work. One can use static const/immutable instead. The following snippet compiles: class A { int a = 3; } const bar =

Re: Porting D to custom OS

2020-02-23 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-02-22 20:30, IGotD- wrote: That's sound like a start. Is there some kind of automation behind this based on the target triple (-mtriple) or just some kind of hardcoded default versions identifiers somewhere in the source code? Have a look at [1] for a recent example. [1]

Re: Fastest linker on Mac OS X

2020-02-23 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-02-22 15:45, Per Nordlöw wrote: What's the fastest linker to use when building using dmd or ldc on Mac? There's only one linker that works properly, the official one, ld64. The LLVM LLD linker works in some cases but are missing some features. Some of the missing features are

Re: dscanner and ref parameters

2020-02-23 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-02-23 10:03, mark wrote: Then this would not only help dscanner, but also make it clear to programmers that the argument could be modified. It's not necessary for dscanner. It should look at the signature of `getKeyval` to see that it takes an argument by `ref`. -- /Jacob Carlborg

Re: Get memory used by current process at specific point in time

2020-01-15 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-01-15 19:45, Chris Katko wrote: Still, some internal instrumentation would be nice. But I'm not aware of any. There are some runtime flags that can be passed to the executable when running it to get some info about the GC. Of course these are not documented (except perhaps in the

Re: Get memory used by current process at specific point in time

2020-01-13 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-01-12 14:58, Per Nordlöw wrote: Is there a druntime/phobos function for getting the amount of memory (both, stack, malloc, and GC) being used by the current process? I don't think so. But if you're on macOS you can use Instruments (shipped with Xcode) and pick the Allocations

Re: Lexicographic comparison of arrays (of chars)

2020-01-22 Thread Jacob Carlborg via Digitalmars-d-learn
On Wednesday, 22 January 2020 at 08:44:15 UTC, Per Nordlöw wrote: I just found import core.internal.array.comparison : __cmp; I presume that is a better alternative if Phobos' independence is desired. That looks like it's for internal use. There is a `compare` method in the `TypeInfo`

Re: Lexicographic comparison of arrays (of chars)

2020-01-22 Thread Jacob Carlborg via Digitalmars-d-learn
On Wednesday, 22 January 2020 at 14:50:01 UTC, Per Nordlöw wrote: Will that incur an extra runtime cost compared to __cmp? I haven't looked at how `__cmp` is implemented but I would guess there's some extra overhead. Need to get type info and then there will be several virtual method calls

Re: Typescript with vibe.d

2020-03-10 Thread Jacob Carlborg via Digitalmars-d-learn
On Monday, 9 March 2020 at 09:42:16 UTC, GreatSam4sure wrote: I want to know if it is possible to use typescript with the vibe.d since typescript is a superset of javascript. I will appreciate any example if it is possible There's a Diet filter for TypeScript here [1], but it hasn't been

Re: Best way to learn 2d games with D?

2020-03-16 Thread Jacob Carlborg via Digitalmars-d-learn
On Sunday, 15 March 2020 at 17:58:58 UTC, Steven Schveighoffer wrote: I want to try and learn how to write 2d games. I'd prefer to do it with D. I've found a ton of tutorials on learning 2d gaming with other languages. Is there a place to look that uses D for learning? Should I just start

Re: A question about C++ interop

2020-03-28 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-03-27 20:17, YD wrote: Hi, I have a C++ header file which looks like     class A {     public:     static A *create();     virtual int f() const = 0;     }; And there is a C++ library file which provides the implementation, so that if I write a C++ program and call    

Re: Array fill performance differences between for, foreach, slice

2020-04-01 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-03-31 23:30, data pulverizer wrote: $ dmd fill.d && ./fill You have not enabled optimizations. You should compile with `-O -release -inline` to enable all optimizations. Without optimizations I get numbers like these: Slice: Mean time(usecs): 92.91, Standard Deviation: 49.8002

Re: DConf 2017 Videos

2020-04-25 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-04-24 22:24, matheus wrote: Hi, please could someone tell me where can I find videos from DConf 2017? I pretty sure I watched them on Youtube sometime ago, but I can't find anymore. By the way, I'm looking from one video where someone shows some "C flaws" and how to D as Better C

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

2020-05-13 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-05-12 06:02, Steven Schveighoffer wrote: If you want a list of ALL symbols that have the UDA in the application, that would require some form of runtime reflection (like Java). D has very limited support for runtime reflection. In D, you would use some form of registration to tell the

Re: Objective C protocols

2020-05-17 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-05-17 11:32, John Colvin wrote: On Saturday, 16 May 2020 at 19:14:51 UTC, John Colvin wrote: What's the best way to implement an Objective C protocol in D? I see mention here https://dlang.org/changelog/2.085.0.html#4_deprecated_objc_interfaces but it's not clear where things are

Re: Error running concurrent process and storing results in array

2020-05-06 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-05-06 05:25, data pulverizer wrote: I have been using std.parallelism and that has worked quite nicely but it is not fully utilising all the cpu resources in my computation If you happen to be using macOS, I know that when std.parallelism checks how many cores the computer has, it

Re: Error running concurrent process and storing results in array

2020-05-06 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-05-06 08:54, drug wrote: Do you try `--fast-math` in ldc? Don't know if 05 use this flag Try the following flags as well: `-mcpu=native -flto=full -defaultlib=phobos2-ldc-lto,druntime-ldc-lto` -- /Jacob Carlborg

Re: Error running concurrent process and storing results in array

2020-05-06 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-05-06 06:04, Mathias LANG wrote: In general, if you want to parallelize something, you should aim to have as many threads as you have cores. That should be _logical_ cores. If the CPU supports hyper threading it can run two threads per core. -- /Jacob Carlborg

Re: Retrieve the return type of the current function

2020-05-06 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-05-05 19:11, learner wrote: On Tuesday, 5 May 2020 at 16:41:06 UTC, Adam D. Ruppe wrote: typeof(return) Thank you, that was indeed easy! Is it possible to retrieve also the caller return type? Something like: Yes, kind of: void foo(string caller = __FUNCTION__)() { import

Re: D and Async I/O

2020-05-12 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-05-12 11:23, Russel Winder wrote: As far as I can tell D has no futures… Future and async in vibe.d [1]. Future in Mecca [2]. [1] https://vibed.org/api/vibe.core.concurrency/async [2]

Re: D and Async I/O

2020-05-11 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-05-11 16:44, Russel Winder wrote: Crickey, a third option. This wil increase my dithering! ;-) Forth: Mecca [1] :) [1] https://github.com/weka-io/mecca -- /Jacob Carlborg

Re: Error running concurrent process and storing results in array

2020-05-11 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-05-07 02:17, data pulverizer wrote: What is the difference between -O2 and -O3 ldc2 compiler optimizations? `--help` says -O2 is "Good optimizations" and -O3 "Aggressive optimizations". Not very specific. -- /Jacob Carlborg

Re: Error running concurrent process and storing results in array

2020-05-06 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-05-06 12:23, data pulverizer wrote: Yes, I'll do a blog or something on GitHub and link it. It would be nice if you could get it published on the Dlang blog [1]. One usually get paid for that. Contact Mike Parker. [1] https://blog.dlang.org -- /Jacob Carlborg

Re: Install multiple executables with DUB

2020-09-03 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-09-03 14:41, glis-glis wrote: Yes I already tried that, but I get the error Error: only one main allowed. Previously found main at src/scripts/copy.d Looks like DUB doesn't like multiple binaries? Oh, multiple binaries, I missed that. You can try to add multiple configurations [1].

Re: tupleof seems to break encapsulation

2020-09-06 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-09-05 07:14, 60rntogo wrote: I wouldn't dispute that it is useful, but that's besides the point. If I declare something private, it's usually because I want to preserve certain invariants and I want the compiler to provide a guarantee that I don't accidentally violate them. As it

Re: tupleof seems to break encapsulation

2020-09-04 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-09-04 12:16, 60rntogo wrote: Consider the following code. foo.d --- module foo; struct Foo {   private int i; } --- main.d --- void main() {   import std.stdio;   import foo;   auto x = Foo();   writeln(x);   // ++x.i;   ++x.tupleof[0];   writeln(x); } --- As expected, the

Re: Install multiple executables with DUB

2020-09-03 Thread Jacob Carlborg via Digitalmars-d-learn
On Thursday, 3 September 2020 at 08:22:25 UTC, glis-glis wrote: I usually would just write a makefile for that, but I thought I'd give DUB a go. Unfortunately, the DUB-documentation is a little thin and I cannot find a way to tell DUB "compile all the files in the scripts folder and put the

Re: Installing D on Fresh Windows 10 machine is a pain

2020-08-28 Thread Jacob Carlborg via Digitalmars-d-learn
On Friday, 28 August 2020 at 05:38:59 UTC, novice3 wrote: DMD x86 on Windows have no dependencies, just unpack .zip and use. It's a pitty, that DMD x64 depend on VS :( It does not. If VS is not installed the MinGW provided libraries, which are bundled, will be used. -- /Jacob Carlborg

Re: Escape this in pure members

2020-09-22 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-09-19 21:50, Per Nordlöw wrote: On Saturday, 19 September 2020 at 18:48:31 UTC, Jacob Carlborg wrote: A nested class seems to be able to escape the `this` reference: Ahh, thanks. I just realized that it can escape into other parameters without the `scope` qualifier? This class

Re: DDoc generation

2020-09-19 Thread Jacob Carlborg via Digitalmars-d-learn
On Saturday, 19 September 2020 at 07:43:24 UTC, Russel Winder wrote: Doesn't that then make the whole DDoc system fairly useless, despite it's use in Phobos? Yes. The problem is that most things in D are compared with C or C++. People are praising that the built-in support for unit tests

Re: Good repos to learn D

2020-09-19 Thread Jacob Carlborg via Digitalmars-d-learn
On Saturday, 19 September 2020 at 08:26:36 UTC, Imperatorn wrote: What are some good examples of pretty large/medium size, good structured repos in D? I'm looking for examples to learn from Thanks! Here are some examples of large projects: * DWT [1]. This is one of the largest D projects

Re: DDoc generation

2020-09-19 Thread Jacob Carlborg via Digitalmars-d-learn
On Saturday, 19 September 2020 at 07:43:24 UTC, Russel Winder wrote: Doesn't that then make the whole DDoc system fairly useless, despite it's use in Phobos? If you use Dub, you can run `dub build -b ddox` and it will use Ddox to build the documentation. This will include an index page

Re: Proper way to exit with specific exit code?

2020-09-19 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-09-17 16:58, drathier wrote: What's the proper way to exit with a specific exit code? I found a bunch of old threads discussing this, making sure destructors run and the runtime terminates properly, all of which seemingly concluding that it's sad that there isn't a way to do this

Re: DDoc generation

2020-09-19 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-09-18 13:41, Russel Winder wrote: Hi, I am trying to get to grips with DDoc for documenting an application. Getting the individual module HTML files seems to be the easy bit. The question is how to get an index.html (or equivalent) so as to have an application level entry point to the

Re: Question about linker errors when using slices

2020-09-19 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-09-19 04:45, tspike wrote: I’ve been using D for personal projects for almost a year now and I really love it. I recently ran across a linker error that I’m a little confused by. Consider the following files: platform.d:     module platform;     import app;     struct

Re: Escape this in pure members

2020-09-19 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-09-19 18:07, Per Nordlöw wrote: If an aggregate member is pure but not scope when can it escape the `this` pointer?. Only via return? I'm not sure if returning the `this` pointer is considered escaping it. The caller already had access to it. Under the hood, the `this` pointer is

Re: Neater "not version (...)" ?

2020-09-16 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-09-16 19:53, Vladimirs Nordholm wrote: Hello. I wonder if there is a better way to compile something if the current operating system is _not_ a specific platform. For example, I only want some code to compile if the operating system is not Windows. Currently I do this:    

Re: Neater "not version (...)" ?

2020-09-18 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-09-16 21:04, Vladimirs Nordholm wrote: Ah, I guess it boils down to this then. Doesn't really make it "neater", but thank you for the tip! You only need to declare the enums ones. -- /Jacob Carlborg

Re: get element index when using each!(x)

2020-09-18 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-09-17 05:16, Paul Backus wrote: Worth knowing that the tuples you get from enumerate actually have named members, so you can write:     s.enumerate.each!(x => writeln(x.index, ":", x.value)); It actually works out of the box for `each`: s.each!((index, value) => writeln(index,

Re: Two ways of receiving arrays on the C ABI

2020-10-25 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-10-20 02:16, Ali Çehreli wrote: Everything works at least on Linux. Is this kosher, or am I using some internal knowledge? Yes, you're using some internal knowledge. You cannot assume it works on any other platform or architecture. In theory, the D compiler could choose to change

Re: Can we do compile time reading part of a file using import?

2020-10-25 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-10-23 18:42, data pulverizer wrote: For me it's not make-or-break, it just something very useful and I think has clear use case. Please let me know if there are aspects or alternatives I am missing. You could always have the build tool split up the file in multiple smaller files and

Re: this T / variadic template and interfaces

2020-10-27 Thread Jacob Carlborg via Digitalmars-d-learn
On Tuesday, 27 October 2020 at 09:40:33 UTC, frame wrote: Hmm, a question of design. Is there also a convenient way to pass the arguments to a template or get a Variant[] from it? Convenient, no not that I know of. You can use a type safe variadic function that takes Variant, if you want to

<    1   2   3   4   5   6   7   >