Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-09 Thread Max Samukha via Digitalmars-d-learn
On Thursday, 9 February 2023 at 20:05:06 UTC, Ali Çehreli wrote: Besides, D has zero problems with its private implementation in the sense that there has been zero bugs related to it being that way. That is how a Python aficionado would defend the absence of visibility attributes therein.

Re: How to reliably detect an alias sequence?

2020-12-27 Thread Max Samukha via Digitalmars-d-learn
On Sunday, 27 December 2020 at 18:25:10 UTC, sighoya wrote: This should work: ``` static assert(is(int == AliasSeq!int)); Drepl: static assert: `is(int == (int))` is false ``` That will only work for type tuples. We need a general solution that would work for any alias tuple. The most

How to reliably detect an alias sequence?

2020-12-27 Thread Max Samukha via Digitalmars-d-learn
Given a name bound to an alias sequence, what is a reliable way to detect that? import std.meta: AliasSeq; alias a = AliasSeq!int; static if () { } __traits(isSame, a, AliasSeq!a) could work but doesn't, because it flattens singletons, which means __traits(isSame, int, AliasSeq!int) is

Re: How to get address of a nested function?

2020-11-11 Thread Max Samukha via Digitalmars-d-learn
On Tuesday, 10 November 2020 at 20:13:30 UTC, Daniel Kozak wrote: non static nested function is a delegate, so you can just assign it to delegate like I have posted or you can du this: import std.stdio; void main() { void foo() { writeln("It works as expected"); } enum

Re: How to get address of a nested function?

2020-11-10 Thread Max Samukha via Digitalmars-d-learn
On Tuesday, 10 November 2020 at 14:36:04 UTC, Steven Schveighoffer wrote: Is there a way to get a pointer to a non-static nested function? I don't think you can do it at compile time. You can at runtime by accessing the funcptr of the delegate. -Steve Thanks for the reply. I will post

How to get address of a nested function?

2020-11-10 Thread Max Samukha via Digitalmars-d-learn
We can get the compile time equivalent of a member function's address by applying '&' to the function in a static context: struct S { void foo() {} } enum pfoo = // ok void main() { // now we can use the pointer to create, for example, a delegate S s; void delegate() dg;

Re: What is the difference between enum and shared immutable?

2020-10-30 Thread Max Samukha via Digitalmars-d-learn
On Thursday, 29 October 2020 at 16:45:51 UTC, Ali Çehreli wrote: immutable string p; shared static this() { p = environment["PATH"]; // <-- Run time } Immutable static variables being implicitly non-thread-local is a design mistake. Thread-local immutable variables have the same right

Re: Send empty assoc array to function

2020-07-10 Thread Max Samukha via Digitalmars-d-learn
On Friday, 10 July 2020 at 08:15:24 UTC, Max Samukha wrote: a unfortunate an unfortunate

Re: Send empty assoc array to function

2020-07-10 Thread Max Samukha via Digitalmars-d-learn
On Thursday, 9 July 2020 at 21:04:57 UTC, Steven Schveighoffer wrote: Why isn't [] accepted as an empty AA literal? Because it's an empty dynamic array literal. If D were to accept an empty AA literal, I'd expect it to be [:]. -Steve Just as typeof(null) is a subtype of all nullable

Re: Send empty assoc array to function

2020-07-09 Thread Max Samukha via Digitalmars-d-learn
On Thursday, 9 July 2020 at 20:24:11 UTC, Steven Schveighoffer wrote: Yes, that is correct. -Steve Why isn't [] accepted as an empty AA literal?

Re: Send empty assoc array to function

2020-07-09 Thread Max Samukha via Digitalmars-d-learn
On Thursday, 9 July 2020 at 19:53:42 UTC, JN wrote: foo( [] ) doesn't Should work in principle, but you can foo(null) to work around.

Re: How to ensure template function can be processed during compile time

2020-07-08 Thread Max Samukha via Digitalmars-d-learn
On Wednesday, 8 July 2020 at 20:11:05 UTC, IGotD- wrote: Now since mySize is a template, shouldn't this work mySize!v, but it doesn't? What essential understanding have I missed here? You are trying to use a run-time value of v at compile-time, which is not possible. If you want the

Re: DMD 2.092 and DIP 25

2020-05-30 Thread Max Samukha via Digitalmars-d-learn
On Saturday, 30 May 2020 at 07:00:07 UTC, Mike Parker wrote: I find it rather annoying, as I'm returning `const(char)*` and not `char*`, but it is what it is. My question is, if I add `return` to the function declarations, will this compile all the way back to DMD 2.067 *without*

Re: Is it legal to have physical package structure not corresponding to logical one? How to generate .di from that?

2019-09-16 Thread Max Samukha via Digitalmars-d-learn
On Monday, 16 September 2019 at 13:13:50 UTC, Adam D. Ruppe wrote: On Monday, 16 September 2019 at 07:02:04 UTC, Max Samukha wrote: [...] Well, sort of, your code is perfectly legal and has worked since the beginning of D. The thing in the spec is referring to the assumption the compiler

Is it legal to have physical package structure not corresponding to logical one? How to generate .di from that?

2019-09-16 Thread Max Samukha via Digitalmars-d-learn
Please consider a project: src/p2/ |---a.d |---b.d in which it is desirable that the logical package tree does not fully correspond to the filesystem subtree: src/p2/a.d: module p1.p2.a; ... src/p2/b.d: module p1.p2.b; import p1.p2.a; ... dmd compiles the above structure

Re: Using CSS Data from Within My Code

2019-09-12 Thread Max Samukha via Digitalmars-d-learn
On Thursday, 12 September 2019 at 09:54:35 UTC, Ron Tarrant wrote: I found this presented as a solution in a 2016 post: On Wednesday, 15 June 2016 at 22:05:37 UTC, captaindet wrote: enum myCSS = q{ GtkNotebook { background-color: #e9e9e9; } GtkNotebook tab {

Re: How to force an array literal into a read-only data segment?

2019-09-12 Thread Max Samukha via Digitalmars-d-learn
On Thursday, 12 September 2019 at 08:54:09 UTC, a11e99z wrote: On Thursday, 12 September 2019 at 07:04:19 UTC, Max Samukha wrote: How to achieve the same for an array literal? The closest I could come: enum immutable(int[3]) _tmp = [1, 2, 3]; __gshared a = _tmp.ptr; Is it possible to force

How to force an array literal into a read-only data segment?

2019-09-12 Thread Max Samukha via Digitalmars-d-learn
test.d: __gshared t = "text".ptr; As expected, the "text" literal ends up in a read-only data segment, with a pointer to it stored in a writable data segment (_TMP0 pointing into .rodata.str1.1): .data segment _D4test1tPya: dd offset FLAT:_TMP0@64 db

Re: Learning delegates

2019-09-08 Thread Max Samukha via Digitalmars-d-learn
On Sunday, 8 September 2019 at 10:04:57 UTC, Joel wrote: I'm trying to understand delegates. Is there any good ways I can get a better understanding of them? You may want to read this: https://tour.dlang.org/tour/en/basics/delegates

Re: Should an 'extern(C++, "ns"):' override previous ones in the same scope?

2019-09-08 Thread Max Samukha via Digitalmars-d-learn
On Sunday, 8 September 2019 at 09:35:03 UTC, Jonathan M Davis wrote: The C++ support has been improved kind of piecemeal over time, and initially, none of it was documented. So, it wasn't exactly fully planned out when it was added. IIRC, it was added originally so that the dmd frontend

Re: Should an 'extern(C++, "ns"):' override previous ones in the same scope?

2019-09-08 Thread Max Samukha via Digitalmars-d-learn
On Saturday, 7 September 2019 at 22:19:48 UTC, Jonathan M Davis wrote: On Saturday, September 7, 2019 3:40:58 PM MDT Exil via Digitalmars-d-learn wrote: On Saturday, 7 September 2019 at 17:22:07 UTC, Jonathan M Davis wrote: > @safe: > @system: > > then @system overrides @safe. Just to add

Should an 'extern(C++, "ns"):' override previous ones in the same scope?

2019-09-07 Thread Max Samukha via Digitalmars-d-learn
extern(C++, "ns1"): extern(C++, "ns2"): // Not in nested scope. Should it supersede? void foo(); pragma(msg, foo.mangleof); // _ZN3ns13ns23fooEv instead of expected _ZN3ns23fooEv Is that by design?

Mingling string and identifier namespaces in nested extern(C++) decls

2019-09-07 Thread Max Samukha via Digitalmars-d-learn
extern(C++, "ns1") { extern(C++, ns2) { extern(C++, "ns3") { extern(C++, ns4) { void foo(); } } } } pragma(msg, foo.mangleof); // _ZN3ns23ns43ns13ns33fooEv That

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

2019-09-07 Thread Max Samukha via Digitalmars-d-learn
On Saturday, 7 September 2019 at 13:01:38 UTC, Jacob Carlborg wrote: 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

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

2019-09-06 Thread Max Samukha via Digitalmars-d-learn
On Friday, 6 September 2019 at 17:54:51 UTC, Adam D. Ruppe wrote: On Friday, 6 September 2019 at 17:42:08 UTC, Max Samukha wrote: That file was silently imported by the compiler (probably, a bug). That's by design - the automatic module import lookups actually always look for .di file first

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

2019-09-06 Thread Max Samukha via Digitalmars-d-learn
On Friday, 6 September 2019 at 16:55:31 UTC, Max Samukha wrote: On Friday, 6 September 2019 at 15:52:46 UTC, Stefan Koch wrote: If that is happening you hit a bug. It seems unlikely though. Could you elaborate a bit? How should extern(C/C++) definitions be mangled - fully qualified

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

2019-09-06 Thread Max Samukha via Digitalmars-d-learn
On Friday, 6 September 2019 at 15:52:46 UTC, Stefan Koch wrote: On Friday, 6 September 2019 at 15:09:22 UTC, Max Samukha wrote: Consider the following two modules: 1. test.d: module test; import lib.a; void main() { foo(); } 2. lib/a.d: module lib.a; extern(C) void foo() {} When

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

2019-09-06 Thread Max Samukha via Digitalmars-d-learn
On Friday, 6 September 2019 at 15:32:07 UTC, 0xEAB wrote: On Friday, 6 September 2019 at 15:09:22 UTC, Max Samukha wrote: Consider the following two modules: What compiler version are you using? DMD64 D Compiler v2.088.0-1-g4011382ea, linux

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

2019-09-06 Thread Max Samukha via Digitalmars-d-learn
Consider the following two modules: 1. test.d: module test; import lib.a; void main() { foo(); } 2. lib/a.d: module lib.a; extern(C) void foo() {} When compiled separately (dmd -c lib/a.d; dmd test.d a.o), the function in 'a.o' is mangled as 'foo', but the reference in 'test.o' is

Why are constructor definitions are preserved in interface files?

2019-09-06 Thread Max Samukha via Digitalmars-d-learn
module lib.a; class C { this() { } void foo() { } ~this() { } } dmd -H -o- a.d: // D import file generated from 'a.d' module lib.a; class C { this() { } void foo(); ~this(); } The destructor and

Why are constructor definitions preserved in interface files?

2019-09-06 Thread Max Samukha via Digitalmars-d-learn
module lib.a; class C { this() { } void foo() { } ~this() { } } dmd -H -o- a.d: // D import file generated from 'a.d' module lib.a; class C { this() { } void foo(); ~this(); } The destructor and

How to get the type of a derived class in a method of its base class?

2017-02-18 Thread Max Samukha via Digitalmars-d-learn
class A { this(T = this)() { static assert(is(T == B)); } } class B { } auto b = new B; Here, T becomes A, which may be reasonable but is completely useless. Is there a way to obtain the type of the class (or class instance reference) the method is called on?

Re: Why aren't overloaded nested functions allowed?

2016-05-31 Thread Max Samukha via Digitalmars-d-learn
On Tuesday, 31 May 2016 at 11:54:40 UTC, Timon Gehr wrote: On 30.05.2016 18:22, Max Samukha wrote: From the spec (https://dlang.org/spec/function.html#nested): "Nested functions cannot be overloaded." Anybody knows what's the rationale? The rationale is that nobody has i

Re: Why aren't overloaded nested functions allowed?

2016-05-31 Thread Max Samukha via Digitalmars-d-learn
On Monday, 30 May 2016 at 23:17:15 UTC, pineapple wrote: On Monday, 30 May 2016 at 16:22:26 UTC, Max Samukha wrote: From the spec (https://dlang.org/spec/function.html#nested): "Nested functions cannot be overloaded." Anybody knows what's the rationale? I'm guessing it

Why aren't overloaded nested functions allowed?

2016-05-30 Thread Max Samukha via Digitalmars-d-learn
From the spec (https://dlang.org/spec/function.html#nested): "Nested functions cannot be overloaded." Anybody knows what's the rationale?

Re: D, GTK, Qt, wx,…

2016-05-29 Thread Max Samukha via Digitalmars-d-learn
On Sunday, 29 May 2016 at 11:03:36 UTC, Russel Winder wrote: From what I can tell QtD is in need of effort or restarting. I will probably give it another shot when D has better interop with C++. Particularly, when multiple inheritance of C++ interfaces is implemented, Walter admits that

Weird "nested function cannot be accessed" error

2016-05-29 Thread Max Samukha via Digitalmars-d-learn
This code fails to compile: void bar(alias f)() { f(); } void foo(alias f)() { bar!f(); } void main() { void f()() { } foo!f(); } Error: function test.main.f!().f is a nested function and cannot be accessed from test.bar!(f).bar But non-template nested functions are

Re: C header file: tagged enumerations

2016-04-27 Thread Max Samukha via Digitalmars-d-learn
On Tuesday, 26 April 2016 at 22:57:36 UTC, Jesse Phillips wrote: typedef enum tagINSTALLMESSAGE { // 12 others ... INSTALLMESSAGE_INITIALIZE , INSTALLMESSAGE_TERMINATE , INSTALLMESSAGE_SHOWDIALOG , #if (_WIN32_MSI >= 500) INSTALLMESSAGE_PERFORMANCE

Re: Patterns for functions in template parameters

2014-10-24 Thread Max Samukha via Digitalmars-d-learn
On Friday, 24 October 2014 at 08:53:05 UTC, Kagamin wrote: maybe template Foo(T a, T: T[U], U) No luck. Error: undefined identifier T

Re: Patterns for functions in template parameters

2014-10-24 Thread Max Samukha via Digitalmars-d-learn
On Friday, 24 October 2014 at 14:13:10 UTC, ketmar via Digitalmars-d-learn wrote: sorry if this is not what you mean, template magic sometimes scares me and i'm loosing my mind. ;-) What I meant was your example with the delegate parameter moved to the template list: template Foo(T

Re: Patterns for functions in template parameters

2014-10-24 Thread Max Samukha via Digitalmars-d-learn
On Friday, 24 October 2014 at 17:08:00 UTC, Max Samukha wrote: Apparently, D doesn't allow type variables in value parameters at all. Nor does it allow passing delegates to value parameters, only alias parameters.

Patterns for functions in template parameters

2014-10-23 Thread Max Samukha via Digitalmars-d-learn
If I remember correctly, at some point a syntax was introduced for pattern-matching functions passed to templates. Something like: template Foo(B(A) foo, A, B) { } alias f = Foo!((int x) = x % 2 == 0); That would instantiate Foo with B == bool, A == int and foo bound to the lambda. The

Re: Patterns for functions in template parameters

2014-10-23 Thread Max Samukha via Digitalmars-d-learn
On Thursday, 23 October 2014 at 11:25:01 UTC, Kagamin wrote: Maybe, argument deduction? template Foo(T: T[U], U) { ... } Foo!(int[long]) // instantiates Foo with T set to int, U set to long Yes, but for a value template parameter. template Foo(int[long] a); { } Foo!([1: 2]); // ok,

Re: UDAs on templates

2013-10-16 Thread Max Samukha
On Wednesday, 16 October 2013 at 13:12:39 UTC, Max Samukha wrote: I'd rather have the same set of attributes on both the template and its instantiations Impossible, ignore

Re: UDAs on templates

2013-10-16 Thread Max Samukha
On Wednesday, 16 October 2013 at 12:37:23 UTC, Dicebot wrote: (quick experiments show that one can't attached UDA to template symbol itself by any means - weird limitation, don't know the rationale behind this) It is understandable why the attribute is transferred to the instantiation of the

Re: UDAs on templates

2013-10-16 Thread Max Samukha
On Wednesday, 16 October 2013 at 13:14:31 UTC, Max Samukha wrote: On Wednesday, 16 October 2013 at 13:12:39 UTC, Max Samukha wrote: I'd rather have the same set of attributes on both the template and its instantiations Impossible, ignore @(1) template Foo(T : int) {} @(2) template Foo(T

Re: UDAs on templates

2013-10-16 Thread Max Samukha
On Wednesday, 16 October 2013 at 13:38:44 UTC, Dicebot wrote: On Wednesday, 16 October 2013 at 13:24:59 UTC, Max Samukha wrote: @(1) template Foo(T : int) {} @(2) template Foo(T : short) {} __traits(getAttributes, Foo) == ? The current semantics seems quite reasonable. @(1) void foo(int

Re: Should I compare pointers with is of == ?

2009-10-14 Thread Max Samukha
On Wed, 14 Oct 2009 14:20:24 -0400, Justin Johansson n...@spam.com wrote: #ponce Wrote: It's a bit unclear to me. I know I must compare references with is but pointers ? Thanks for asking this question ponce; I've been getting into the habit of using 'is' for both pointers and classes, so

Re: Getting constructor's metadata

2009-10-09 Thread Max Samukha
On Thu, 08 Oct 2009 18:46:08 -0400, Christopher Wright dhase...@gmail.com wrote: Max Samukha wrote: Is it possible to get types or aliases of all constructors of a class in D2? No. __traits has some random functionality in this regard. It has a command getVirtualFunctions which only returns

Getting constructor's metadata

2009-10-08 Thread Max Samukha
Is it possible to get types or aliases of all constructors of a class in D2?

Re: wchar* question

2009-09-03 Thread Max Samukha
Sam Hu wrote: Given below code(Win32 SDK): int /*LRESULT*/ wndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { switch(msg) { case WM_LBUTTONDOWN: { wchar* szFileName=cast(wchar*)(new wchar[1024]);// ***questioned line HINSTANCE hInstance=GetModuleHandleW(null);

Re: Any way to workaround Optlink crash?

2009-09-01 Thread Max Samukha
Tom S wrote: And/or compile some modules without -g. Maybe you don't need debug symbols everywhere. And please vote for http://d.puremagic.com/issues/votes.cgi?action=show_bugbug_id=424. Something makes Walter think this bug is not critical.

Re: Three questions on std.range

2009-06-17 Thread Max Samukha
On Wed, 17 Jun 2009 00:04:51 -0400, Sam Hu samhudotsa...@gmail.com wrote: Hello, Just get to my point to save time: 1.retro: void testRetro() { int[] arr=[1,2,3,4,5]; auto retArr=retro(arr); for(int i=0;iretArr;i++) writef(%d ,retArr[i]); } void main() { testRetro; } output: 0 0 5 4 3 //not 5