Re: Assigning parameter on entry to a function and assigning back on exit

2022-11-25 Thread Victor Porton via Digitalmars-d-learn
On Friday, 25 November 2022 at 11:01:09 UTC, Victor Porton wrote: Somewhere in my brain memory, it was written: A function argument that is both input and output, may be passed to the function either as reference or do two assignments: on entry of the function it is assigned to the

Assigning parameter on entry to a function and assigning back on exit

2022-11-25 Thread Victor Porton via Digitalmars-d-learn
Somewhere in my brain memory, it was written: A function argument that is both input and output, may be passed to the function either as reference or do two assignments: on entry of the function it is assigned to the parameter, on exit it is assigned back. Whether it is a reference or two

Re: `enum x;` - what is it?

2020-08-19 Thread Victor Porton via Digitalmars-d-learn
On Wednesday, 19 August 2020 at 14:06:16 UTC, Victor Porton wrote: This declaration does compile: enum x; But what is it? Is it an equivalent of enum x { } ? What in the specification allows this looking a nonsense enum x; ? Oh, found: "An empty enum body (For example enum E;) signifies

`enum x;` - what is it?

2020-08-19 Thread Victor Porton via Digitalmars-d-learn
This declaration does compile: enum x; But what is it? Is it an equivalent of enum x { } ? What in the specification allows this looking a nonsense enum x; ?

Why this eponymous template does not compile?

2019-03-25 Thread Victor Porton via Digitalmars-d-learn
/// template sychronizedMemoize(alias fun) { void sychronizedMemoize() { } } void f() { } void main() { synchronizedMemoize!f(); } /// /tmp/temp_7F3C101460D0.d(9,5): Error: template instance `synchronizedMemoize!f` template `synchronizedMemoize` is not defined, did you mean

Why this template code does not compile?

2019-03-13 Thread Victor Porton via Digitalmars-d-learn
Why this template code does not compile? /// module runnable; import std.meta; import std.typecons; template FieldInfo(argT, string argName) { template FieldInfo(Nullable!argT argDefault = Nullable!argT()) { } } alias processFields(T, string name) = AliasSeq!(FieldInfo!(T,

Re: Why a template with Nullable does not compile?

2019-03-12 Thread Victor Porton via Digitalmars-d-learn
On Tuesday, 12 March 2019 at 15:26:05 UTC, Victor Porton wrote: template FieldInfo(T, Nullable!T default_) { } On Tuesday, 12 March 2019 at 09:05:36 UTC, Nicholas Wilson wrote: It seems to be getting confused between the two types of Nullable, namely: Nullable(T), and Nullable(T, T

Re: Why a template with Nullable does not compile?

2019-03-12 Thread Victor Porton via Digitalmars-d-learn
On Tuesday, 12 March 2019 at 16:20:11 UTC, H. S. Teoh wrote: On Tue, Mar 12, 2019 at 03:26:05PM +, Victor Porton via Digitalmars-d-learn wrote: [...] On Tuesday, 12 March 2019 at 09:05:36 UTC, Nicholas Wilson wrote: [...] > template FieldInfo(T) { > template FieldInfo(Nulla

Re: Why a template with Nullable does not compile?

2019-03-12 Thread Victor Porton via Digitalmars-d-learn
template FieldInfo(T, Nullable!T default_) { } On Tuesday, 12 March 2019 at 09:05:36 UTC, Nicholas Wilson wrote: It seems to be getting confused between the two types of Nullable, namely: Nullable(T), and Nullable(T, T defaultVal) I don't understand why exactly it is getting confused. How

Re: Why a template with Nullable does not compile?

2019-03-11 Thread Victor Porton via Digitalmars-d-learn
On Tuesday, 12 March 2019 at 05:14:21 UTC, Victor Porton wrote: Why does this not compile? import std.typecons; template FieldInfo(T, Nullable!T default_) { } /usr/lib/ldc/x86_64-linux-gnu/include/d/std/typecons.d(2570,17): Error: `alias T = T;` cannot alias itself, use a qualified name to

Why a template with Nullable does not compile?

2019-03-11 Thread Victor Porton via Digitalmars-d-learn
Why does this not compile? import std.typecons; template FieldInfo(T, Nullable!T default_) { } /usr/lib/ldc/x86_64-linux-gnu/include/d/std/typecons.d(2570,17): Error: `alias T = T;` cannot alias itself, use a qualified name to create an overload set

Concatenating compile time sequences

2019-03-01 Thread Victor Porton via Digitalmars-d-learn
I try to split a compile time sequence of types and names into a sequence consisting of two-element subsequences (each of type and name). That is, I want to transform: (int, "x", float, "y", double, "z") into (AliasSeq!(int, "x"), AliasSeq!(float, "y"), AliasSeq!(double, "z")) I am

Re: My template tuple code does not compile

2019-02-27 Thread Victor Porton via Digitalmars-d-learn
I rewrote it again: https://github.com/vporton/struct-params-dlang/blob/f50f7e5919f90b1d06bf0cc08e3055548aad1797/source/struct_params.d But it does not work :-( What is my error? source/struct_params.d(43,60): Error: function expected before `()`, not `()` of type `()`

Re: How to enumerate a sequence?

2019-02-27 Thread Victor Porton via Digitalmars-d-learn
On Wednesday, 27 February 2019 at 13:15:06 UTC, Victor Porton wrote: .enumerate does not work for compile-time sequences. Consider for the sake of discussion the following nonsense (I know it cannot be done without enumerate) code: I want namely integer (or size_t) index!

How to enumerate a sequence?

2019-02-27 Thread Victor Porton via Digitalmars-d-learn
.enumerate does not work for compile-time sequences. Consider for the sake of discussion the following nonsense (I know it cannot be done without enumerate) code: import std.meta; import std.range; string join(Fields...)() { enum f(size_t i) = __traits(identifier, Fields[i]); return

Re: My template tuple code does not compile

2019-02-26 Thread Victor Porton via Digitalmars-d-learn
After following your suggestion to rewrite it with Stride it does not work either. I assume the error is somehow related to allSatisfy!. https://github.com/vporton/struct-params-dlang/blob/c1adc86672f46fd6b743903cc270dceef120a8fe/source/struct_params.d Please help. It is important for both D

Re: My template tuple code does not compile

2019-02-26 Thread Victor Porton via Digitalmars-d-learn
On Tuesday, 26 February 2019 at 22:51:15 UTC, Q. Schroll wrote: On Tuesday, 26 February 2019 at 21:43:31 UTC, Victor Porton wrote: Compilation of unittest at the bottom of this file fails with an error. What is my error? ... You have the line ProviderParams("S", ((int, "x"), (float,

My template tuple code does not compile

2019-02-26 Thread Victor Porton via Digitalmars-d-learn
Compilation of unittest at the bottom of this file fails with an error. What is my error? https://github.com/vporton/struct-params-dlang/blob/c32cfde60dbb03cb80a4a8aeb8185f5c86705790/source/struct_params.d It is very important both for this useful little D project and my bigger research

How to pass variables to string mixins?

2019-02-25 Thread Victor Porton via Digitalmars-d-learn
I want to create a string mixin based on a supplementary variable (name2 below): Let we have something like: mixin template X(string name) { immutable string name2 = '_' ~ name; mixin("struct " ~ name2 ~ "{ int i; }"); } But it would create variable name2 inside X, which should not be

Simplifying a string mixin

2019-02-25 Thread Victor Porton via Digitalmars-d-learn
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" ~ "// ..." ~ " }\n" ~ '}'); I

Variadic template parameter (for mixin) does not work

2019-02-25 Thread Victor Porton via Digitalmars-d-learn
I want to create a mixin with an arbitrary number of parameters. I tried this: mixin template ProviderParams(Types...)(Types t) { } But it does not compile. What's my error?

How to call other variadic function with the same arguments?

2019-02-24 Thread Victor Porton via Digitalmars-d-learn
Let f be a variadic function: Result f(...); How to implement variadic function g which calls f with the same arguments as one it receives? Result g(...) { // ... }

How to create a class-valued variable?

2019-02-19 Thread Victor Porton via Digitalmars-d-learn
What is the right way to store in a structure a class (not an instance) derived from a given interface(s)?

Should D file end with newline?

2019-02-09 Thread Victor Porton via Digitalmars-d-learn
ISO C++ specifies that the C++ file must end with a newline. Should D file end with newline, too?

Re: Why -I flag does not work?

2019-02-09 Thread Victor Porton via Digitalmars-d-learn
On Saturday, 9 February 2019 at 08:15:36 UTC, Victor Porton wrote: Why does -I flag in DFLAGS does not work? (Ubuntu Linux) https://github.com/dlang/dub/issues/1645

Re: Why -I flag does not work?

2019-02-09 Thread Victor Porton via Digitalmars-d-learn
On Saturday, 9 February 2019 at 11:40:57 UTC, Victor Porton wrote: On Saturday, 9 February 2019 at 08:35:53 UTC, JN wrote: On Saturday, 9 February 2019 at 08:15:36 UTC, Victor Porton wrote: Why does -I flag in DFLAGS does not work? (Ubuntu Linux) I'm no expert on dub, but it's possible that

Re: Why -I flag does not work?

2019-02-09 Thread Victor Porton via Digitalmars-d-learn
On Saturday, 9 February 2019 at 08:35:53 UTC, JN wrote: On Saturday, 9 February 2019 at 08:15:36 UTC, Victor Porton wrote: Why does -I flag in DFLAGS does not work? (Ubuntu Linux) I'm no expert on dub, but it's possible that it's overriding the import path anyway. One of the main points of

Re: Why -I flag does not work?

2019-02-09 Thread Victor Porton via Digitalmars-d-learn
On Saturday, 9 February 2019 at 10:32:36 UTC, DanielG wrote: On Saturday, 9 February 2019 at 08:15:36 UTC, Victor Porton wrote: Why does -I flag in DFLAGS does not work? (Ubuntu Linux) Try adding the -i flag as well ("include imported modules in -i in DFLAGS does not help. -I works when

Re: Why -I flag does not work?

2019-02-09 Thread Victor Porton via Digitalmars-d-learn
On Saturday, 9 February 2019 at 08:15:36 UTC, Victor Porton wrote: $ DFLAGS="-I/usr/local/include/d/librdf -L-L/usr/local/lib" dub build --compiler=dmd --build=unittest ... Why does -I flag in DFLAGS does not work? (Ubuntu Linux) This does not work too: $

Why -I flag does not work?

2019-02-09 Thread Victor Porton via Digitalmars-d-learn
For this project: https://github.com/vporton/xml-boiler-dlang/tree/85b5587f50617ad1b001c035c72a5780a1e69c24 $ DFLAGS="-I/usr/local/include/d/librdf -L-L/usr/local/lib" dub build --compiler=dmd --build=unittest Performing "unittest" build using dmd for x86_64. xml-boiler-dlang ~master:

Ordered set container?

2019-01-28 Thread Victor Porton via Digitalmars-d-learn
I want "ordered set" container (like list or vector but with the warranty of no duplicate elements). Which type can I use?

Should I prefix package names with the name of my program?

2019-01-28 Thread Victor Porton via Digitalmars-d-learn
Should I prefix all module names with `xmlboiler.` (where XML Boiler is the name of my program). These packages are expected to be used internally by my program, not as an exported API (however there are some little chances that in the future I will make a public API)

Re: unittest which uses a disk file

2019-01-16 Thread Victor Porton via Digitalmars-d-learn
This way I would make data duplication (data files distributed with the source and the same data embedding as strings into my D sources). Note that the source is multilingual (I am currently working on a multi-language bindings of a C library).

Re: unittest which uses a disk file

2019-01-16 Thread Victor Porton via Digitalmars-d-learn
On Wednesday, 16 January 2019 at 21:07:24 UTC, Victor Porton wrote: What is the rule for unittest which uses a file (containing example data for testing) available only in the source distribution, not in binary distribution? I am writing a library. The library has also a file main.d which is

unittest which uses a disk file

2019-01-16 Thread Victor Porton via Digitalmars-d-learn
What is the rule for unittest which uses a file (containing example data for testing) available only in the source distribution, not in binary distribution? I am writing a library. The library has also a file main.d which is compiled only in DUB "application" configuration (I use this

Subtypes with tighter constraints

2019-01-01 Thread Victor Porton via Digitalmars-d-learn
In Ada2012 there are "subtypes". Subtypes can have tighter constraints (such as type invariants) than their base types. I have a struct X in D. Is it possible to define a type equivalent to X except that having tighter invariants? As I understand if I derive Y from X, then it is no more X;