Re: How can I get this UDA at compile time?

2021-02-21 Thread Jacob Carlborg via Digitalmars-d-learn
On 2021-02-21 07:12, Jack wrote: I've had a struct like this: struct Attr { string value; } struct Foo { @(Attr("a attr")) enum a = Foo(10); @(Attr("b attr")) enum b = Foo(11); int x; int y; bool doY = true; int value() {     return

Re: How can I check if template variable parameter is iterable before handle it?

2021-02-21 Thread Boris Carvajal via Digitalmars-d-learn
On Sunday, 21 February 2021 at 11:58:11 UTC, Marcone wrote: import std; void foo(T)(T bar){ static if (bar.isiterable()) // Need Somethin to check if bar is iterable. { // Execute it if bar is iterable. foreach (i; bar) {

How can I check if template variable parameter is iterable before handle it?

2021-02-21 Thread Marcone via Digitalmars-d-learn
import std; void foo(T)(T bar){ static if (bar.isiterable()) // Need Somethin to check if bar is iterable. { // Execute it if bar is iterable. foreach (i; bar) { } } else { // Execute it

Re: How can I check if template variable parameter is iterable before handle it?

2021-02-21 Thread Marcone via Digitalmars-d-learn
On Sunday, 21 February 2021 at 12:47:46 UTC, Boris Carvajal wrote: On Sunday, 21 February 2021 at 11:58:11 UTC, Marcone wrote: import std; void foo(T)(T bar){ static if (bar.isiterable()) // Need Somethin to check if bar is iterable. { // Execute it if bar is

Re: How add png image to zip file using std.zip?

2021-02-21 Thread JN via Digitalmars-d-learn
On Sunday, 21 February 2021 at 17:17:56 UTC, Marcone wrote: ZipArchive zip = new ZipArchive(); std.file.write("foo.zip", zip.build()); ArchiveMember f = new ArchiveMember(); f.name = "Wallpaper_001.png"; zip.addMember(f);

Re: How can I get this UDA at compile time?

2021-02-21 Thread Jack via Digitalmars-d-learn
On Sunday, 21 February 2021 at 09:30:14 UTC, Jacob Carlborg wrote: On 2021-02-21 07:12, Jack wrote: I've had a struct like this: struct Attr { string value; } struct Foo { @(Attr("a attr")) enum a = Foo(10); @(Attr("b attr")) enum b = Foo(11); int x; int

Re: Foo Foo = new Foo();

2021-02-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 21 February 2021 at 21:03:27 UTC, Jack wrote: Why doesn't this compiles? class Baa { Foo Foo = new Foo(); } Local variables inside functions are a little bit special because everything happens in sequence. This is a declaration, where there is a new namespace, but order

Re: Foo Foo = new Foo();

2021-02-21 Thread Jack via Digitalmars-d-learn
Why doesn't this compiles? class Baa { Foo Foo = new Foo(); }

Problem Computing Dot Product with mir

2021-02-21 Thread Kyle Ingraham via Digitalmars-d-learn
I am trying to convert sRGB pixel values to XYZ with mir using the following guide: http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html My problem is that I cannot figure out how to calculate a dot product using mir. Here is my code: import std.stdio; import mir.glas.l1 : dot;

Foo Foo = new Foo();

2021-02-21 Thread JN via Digitalmars-d-learn
class Foo { } void main() { Foo Foo = new Foo(); } this kind of code compiles. Is this expected to compile?

Re: Foo Foo = new Foo();

2021-02-21 Thread FeepingCreature via Digitalmars-d-learn
On Sunday, 21 February 2021 at 18:07:49 UTC, JN wrote: class Foo { } void main() { Foo Foo = new Foo(); } this kind of code compiles. Is this expected to compile? Yes, why wouldn't it? main is a different scope than global; you can override identifiers from global in main. And "Foo"

Re: Class instance alignment

2021-02-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/20/21 6:39 PM, kinke wrote: On Saturday, 20 February 2021 at 18:43:53 UTC, Steven Schveighoffer wrote: Last I checked*, the GC uses pools of 16-byte, 32-byte, 64-byte, etc blocks. That has changed [to reduce wastage]; the new bin sizes are here and include sizes like 176 (11*16):

Restricting D applications to a single instance

2021-02-21 Thread Preetpal via Digitalmars-d-learn
I want to restrict a D application to a single instance. Is there a way to do this using the D standard library? I know this can be done using named mutexes on Windows using Windows-specific APIs but I want to avoid this in general because I want to port the code to FreeBSD without

Re: Restricting D applications to a single instance

2021-02-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/21/21 9:29 PM, Preetpal wrote: I want to restrict a D application to a single instance. Is there a way to do this using the D standard library? When you say "application", you mean a class or type? If so, you can do this: class C { private this() { /*ctor code for single instance */

How add png image to zip file using std.zip?

2021-02-21 Thread Marcone via Digitalmars-d-learn
ZipArchive zip = new ZipArchive(); std.file.write("foo.zip", zip.build()); ArchiveMember f = new ArchiveMember(); f.name = "Wallpaper_001.png"; zip.addMember(f); std.file.write("foo.zip", zip.build()); File is added with file size 0. How

Re: Foo Foo = new Foo();

2021-02-21 Thread JN via Digitalmars-d-learn
On Sunday, 21 February 2021 at 18:09:29 UTC, FeepingCreature wrote: On Sunday, 21 February 2021 at 18:07:49 UTC, JN wrote: class Foo { } void main() { Foo Foo = new Foo(); } this kind of code compiles. Is this expected to compile? Yes, why wouldn't it? main is a different scope than

Re: Foo Foo = new Foo();

2021-02-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 21 February 2021 at 18:15:22 UTC, JN wrote: I guess D is smart enough to figure out which is a type and which is a variable. C++ gets confused in similar situation. Well it isn't about type vs variable (except for in this exact declaration), it is just one is defined at top level

Re: Problem Computing Dot Product with mir

2021-02-21 Thread 9il via Digitalmars-d-learn
On Sunday, 21 February 2021 at 16:18:05 UTC, Kyle Ingraham wrote: I am trying to convert sRGB pixel values to XYZ with mir using the following guide: http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html [...] mir-glas is deprecated experimental project. It is worth use mir-blas

Re: Restricting D applications to a single instance

2021-02-21 Thread Preetpal via Digitalmars-d-learn
On Monday, 22 February 2021 at 02:39:58 UTC, Steven Schveighoffer wrote: On 2/21/21 9:29 PM, Preetpal wrote: I want to restrict a D application to a single instance. Is there a way to do this using the D standard library? When you say "application", you mean a class or type? I actually

Re: Restricting D applications to a single instance

2021-02-21 Thread Preetpal via Digitalmars-d-learn
On Monday, 22 February 2021 at 02:39:58 UTC, Steven Schveighoffer wrote: On 2/21/21 9:29 PM, Preetpal wrote: I want to restrict a D application to a single instance. Is there a way to do this using the D standard library? When you say "application", you mean a class or type? I decided to