How to get name of my application (project)

2019-08-03 Thread Andrey via Digitalmars-d-learn
Hello, how to get name of my application (project) that we write in dub.json? Is there any compile-time constant like __MODULE__?

Problem with aliasing member function

2019-08-18 Thread Andrey via Digitalmars-d-learn
Hello, I can't compile this piece of code: struct Object { void run(wstring ending, uint index)(int number) { } } void tester(alias callback, T)(int number, T object = null) { static if(is(T == typeof(null))) alias handler = callback; else auto handler(wstring ending, uint i

Import sources from parent project

2019-10-19 Thread Andrey via Digitalmars-d-learn
Hi, I have got this structure of my project: parentapp dub.json source common.d childapp1 dub.json source app.d somefile.d childapp2 dub.json source app.d The "childapp1" and "childapp2" are standanole s

Re: Import sources from parent project

2019-10-20 Thread Andrey via Digitalmars-d-learn
On Saturday, 19 October 2019 at 18:54:28 UTC, Andre Pany wrote: In dub.json of your child apps you need to add a dependency to parentapp. I added via "dependencies" parameter and after got this error: "Detected dependency cycle".

contains method on immutable sorted array

2019-10-21 Thread Andrey via Digitalmars-d-learn
Hello, I have got a global constant immutable array: immutable globalvalues = sort(cast(wstring[])["й", "ц", "ук", "н"]); Somewhere in program I want to check an existance: globalvalues.contains("ук"w).writeln; But get an error: Error: template std.range.SortedRange!(wstring[], "a < b").Sor

Re: contains method on immutable sorted array

2019-10-21 Thread Andrey via Digitalmars-d-learn
On Monday, 21 October 2019 at 20:44:29 UTC, Nicholas Wilson wrote: works, so I guess contains doesn't work with immutable? If you can do some more research into this and confirm it then, please file a bug report. As I understand - yes. It doesn't work with immutable object. Also I see the same

undefined symbol: _D3std7variant...

2019-10-22 Thread Andrey via Digitalmars-d-learn
Hello, During compilation on linking stage I get strange errors (LDC): lld-link: error: undefined symbol: _D3std7variant__T8VariantNVmi56TSQBf8typecons__T5TupleTAyuTSQCgQCf__TQCaVmi32TSQCzQBu__TQBoTAQBmTQBqZQCbTQnTQCbZQDrZQCqTQBcTQCrZQEh4typeMxFNbNdNeZC8TypeInfo referenced by E:\Programs\LDC2\im

Re: undefined symbol: _D3std7variant...

2019-10-22 Thread Andrey via Digitalmars-d-learn
On Tuesday, 22 October 2019 at 12:57:45 UTC, Daniel Kozak wrote: Have you try to clean all caches? Try to remove .dub folder I removed .dub folder but this error appears again.

CTFE and assoc array

2020-01-18 Thread Andrey via Digitalmars-d-learn
Hello, Why this doesn't work? import std; struct Qwezzz { shared static this() { qaz = qazMap; } enum qazMap = ["rrr": "vv", "hty": "4ft6"]; static immutable string[string] qaz; } void main() { enum sorted = Qwezzz.qaz.keys.sort(); } The variable "qaz" i

Re: CTFE and assoc array

2020-01-19 Thread Andrey via Digitalmars-d-learn
On Saturday, 18 January 2020 at 21:44:35 UTC, Boris Carvajal wrote: I read that thread. But: Deprecation: initialization of immutable variable from static this is deprecated. Use shared static this instead. And we get? No CTFE with static immutable AA?

Call of C function breaks memoty layout

2020-01-24 Thread Andrey via Digitalmars-d-learn
Hello, I'm trying to bind C library for Tcl/Tk in D code. There is a function called "Tcl_CreateInterp()" which I declared as extent(C). When I call this function then layout of memory become broken - one of my global wstring variables loses it's value. I don't know why it is happens. If I comm

declaration of inner function is already defined

2020-05-13 Thread Andrey via Digitalmars-d-learn
Hi, Why this works: void setBases(string type)(ref int data, string base, string[] syllables) { } void setBases(string type, T)(ref int data, const ref T source) { } void main() { int q = 6; setBases!"tt"(q, "qwerty", ["tg", "jj"]); setBases!"tt"(q, q); } and this doesn't work

Re: declaration of inner function is already defined

2020-05-13 Thread Andrey via Digitalmars-d-learn
On Wednesday, 13 May 2020 at 12:58:11 UTC, Adam D. Ruppe wrote: On Wednesday, 13 May 2020 at 12:45:06 UTC, Andrey wrote: Why this works: It's just defined that way. Local functions follow local variable rules - must be declared before use and names not allowed to overload each other. There

Sum string lengths

2020-05-13 Thread Andrey via Digitalmars-d-learn
Hi, I want to sum lengths of all strings in array: auto data = ["qwerty", "az", ""]; Fold and reduce doesn't work: auto result = data.fold!`a + b.length`(0U); gives error: static assert: "Incompatible function/seed/element: binaryFun/uint/string" How to do it in one line?

Re: Sum string lengths

2020-05-14 Thread Andrey via Digitalmars-d-learn
Thanks everyone.

Count template parameters of method

2020-10-10 Thread Andrey via Digitalmars-d-learn
Hello, How to count a number of parameters in uninitialized template method? For example: struct Test { void abc(int a, bool status, string text)() {} { The method "Test.abc" has three template paramenters. I know that "TemplateArgsOf" exists but it is used only for INITIALIZED templa

Re: Count template parameters of method

2020-10-12 Thread Andrey via Digitalmars-d-learn
And what about: void test() {} and void text(alias qqq)() {} ?

Call method of object variable

2020-10-16 Thread Andrey via Digitalmars-d-learn
Hi, I have got: struct Qaz { wstring read() {return null;} wstring hear() {return "";} } void main() { // ... static if(some_condition) alias method = Qaz.hear; else alias method = Qaz.read; // ... Qaz qaz; qaz.method(); // ??? } How to call alias "method"

Re: Call method of object variable

2020-10-16 Thread Andrey via Digitalmars-d-learn
Thank you!

New vs length on dymamic array

2020-11-09 Thread Andrey via Digitalmars-d-learn
Hello, Are here any differences in creation of dynamic array with known size? auto array = new wchar[](111); and wchar[] array; array.length = 111;

Pass enum variable as const ref arg

2020-12-04 Thread Andrey via Digitalmars-d-learn
Hello, void test(const ref string[3] qazzz) { qazzz.writeln; } void main() { enum string[3] value = ["qwer", "ggg", "v"]; test(value); } Gives errors: onlineapp.d(26): Error: function onlineapp.test(ref const(string[3]) qazzz) is not callable using argument types (string[3]) online

Re: Pass enum variable as const ref arg

2020-12-04 Thread Andrey via Digitalmars-d-learn
Hm, you mean that enum variable is not a real variable? I thought that to make CT variable you should mark it as enum (in c++ as constexpr). How to do it here?

Re: Pass enum variable as const ref arg

2020-12-04 Thread Andrey via Digitalmars-d-learn
Thank you!

Cannot implicitly convert expression of type const(string[]) to string[]

2021-01-08 Thread Andrey via Digitalmars-d-learn
Hello, struct Value { int value; string data; string[] text; } void test(const ref Value value) { Value other = void; other.text = value.text; } void main() { Value row; row.value = 10; row.data = "ggg"; test(row); } I want to pass variable "row" insi

writeln and write at CTFE

2021-01-13 Thread Andrey via Digitalmars-d-learn
Hello all, Tell me please how can I "writeln" and "write" in function that is used in CTFE? At the moment I get this: import\std\stdio.d(4952,5): Error: variable impl cannot be modified at compile time Or may be exist some other ways to do it?

Re: writeln and write at CTFE

2021-01-13 Thread Andrey via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 11:31:16 UTC, Bastiaan Veelo wrote: On Wednesday, 13 January 2021 at 09:11:53 UTC, Guillaume Piolat wrote: On Wednesday, 13 January 2021 at 08:35:09 UTC, Andrey wrote: Hello all, Tell me please how can I "writeln" and "write" in function that is used in CTFE?

Cannot pass const(T) to function with ref const(T)

2021-03-13 Thread Andrey via Digitalmars-d-learn
Hello, Dmd gives an error: Error: function `_setPastBases(ref const(Data) item, ref const(Word!(wstring, wstring)) base)` is not callable using argument types `(const(Data), Word!(wstring, wstring)) where Data and Word - structs. What happens and how to pass arguments? Ldc compiles without s

Re: Cannot pass const(T) to function with ref const(T)

2021-03-13 Thread Andrey via Digitalmars-d-learn
Mistake. It says about simple argument: cannot pass rvalue argument `x` of type `Word!(wstring, wstring)` to parameter `ref const(Word!(wstring, wstring)) base` Function: void _setPastBases(const ref Data item, const ref UsualWord base)

Program exited with code 1

2018-04-19 Thread Andrey via Digitalmars-d-learn
Hello, I wrote a small test code with WinApi: import core.runtime; import std.utf; import core.sys.windows.windows; import core.sys.windows.wingdi; class Test { public this() nothrow { } } extern(Windows) int WinMain(HINSTANCE h

Re: Program exited with code 1

2018-04-19 Thread Andrey via Digitalmars-d-learn
On Thursday, 19 April 2018 at 08:24:55 UTC, user1234 wrote: The run-time is not already initialized but the "new" operator relies on it. What will be a solution?

Re: Program exited with code 1

2018-04-19 Thread Andrey via Digitalmars-d-learn
On Thursday, 19 April 2018 at 08:37:19 UTC, Andrey wrote: What will be a solution? It seems to me that I found a solution - just replace WinMain() with main().

Virtual table in class without overloading

2018-04-28 Thread Andrey via Digitalmars-d-learn
Hello, I have some questions about virtual table in classes. Example 1: class Test { void someMethod() { ... } int anotherMethod { ... } } Will this class have a vtable? Example 2: class Test2 : Test { void thirdMethod() { ... } } Will this class have a vtable? In C++ these classe

How to declare static compile-time assoc array inside struct?

2018-08-13 Thread Andrey via Digitalmars-d-learn
Hello, I need to declare a static compile-time assoc array inside struct: struct Test { enum Type : ubyte { One, Two, Three } static immutable string[Type] DESCRIPTION = [Type.One: "One!", Type.Two: "It's Two...", Type.T

Re: How to declare static compile-time assoc array inside struct?

2018-08-13 Thread Andrey via Digitalmars-d-learn
On Monday, 13 August 2018 at 11:53:06 UTC, rikki cattermole wrote: Unsupported. AA's don't go between CT and RT. You must use a module constructor to initialize it. Will be supported in future?

Importing struct

2018-08-13 Thread Andrey via Digitalmars-d-learn
Hello, This is my test project: source/app.d source/MyClass.d app.d: import std.stdio; import MyClass; void main(string[] args) { MyClass.MyClass.parse(args); // I want just MyClass.parse(args); } ---

Re: Importing struct

2018-08-13 Thread Andrey via Digitalmars-d-learn
On Monday, 13 August 2018 at 13:05:28 UTC, evilrat wrote: however the best option is simply avoid naming anything with same name as module. Hmm, I thought that name of class should match name of file... And how to name a file that contains only one class/struct? Like in my case. What usually

Re: How to declare static compile-time assoc array inside struct?

2018-08-13 Thread Andrey via Digitalmars-d-learn
On Monday, 13 August 2018 at 11:53:06 UTC, rikki cattermole wrote: You must use a module constructor to initialize it. Tried this: static this() { Test.DESCRIPTION = [Test.Type.One: "One!", Test.Type.Two: "It's Two...", Test.Type.Three: "And... Three!"]; } struct Test { // ... } I h

Re: Importing struct

2018-08-14 Thread Andrey via Digitalmars-d-learn
On Monday, 13 August 2018 at 14:30:36 UTC, Timoses wrote: On Monday, 13 August 2018 at 14:16:47 UTC, Mike Parker wrote: On Monday, 13 August 2018 at 13:09:24 UTC, Andrey wrote: [...] The convention is to use lowercase for the module name: module myclass; struct MyClass {} Using lowercase

Concat enum of strings into one string

2018-08-14 Thread Andrey via Digitalmars-d-learn
Hello, I have a enum: enum Type : string { One = "Q1", Two = "W2", Three = "R3" } I want to concat it in compile-time: enum result = doConcat!Type(); And get this result: writeln(result); // output: "Q1 W2 R3" Delimiter here is space symbol. How do do it?

Re: Concat enum of strings into one string

2018-08-14 Thread Andrey via Digitalmars-d-learn
On Tuesday, 14 August 2018 at 13:45:48 UTC, Mike Franklin wrote: I think you just need to use the concatenation operator `~`. enum Type : string { One = "Q1", Two = "W2", Three = "R3" } enum concatenation = Type.One ~ " " ~ Type.Two ~ " " ~ Type.Three; void main() { import st

Re: Concat enum of strings into one string

2018-08-14 Thread Andrey via Digitalmars-d-learn
On Tuesday, 14 August 2018 at 14:07:23 UTC, Timoses wrote: Here's one version: template StringEnumValues(alias Enum) { import std.traits : EnumMembers; string[] StringEnumValues() { string[] enumValues; static foreach (member; EnumMembers!Enum) enumValues

Re: Concat enum of strings into one string

2018-08-15 Thread Andrey via Digitalmars-d-learn
On Tuesday, 14 August 2018 at 16:03:05 UTC, vit wrote: import std.traits : EnumMembers; import std.string : join; import std.algorithm : map; pragma(msg, [EnumMembers!Type].map!(x => cast(string)x).join(" ")); Thank you! Jonathan M Davis, I understood.

Convert output of map() to array of strings

2018-08-15 Thread Andrey via Digitalmars-d-learn
Hello, I have the following code: string[] list; string text; // ... enum pattern = ctRegex!`^[0-9]+$`; list = text.split('\n').map!(line => line.matchFirst(pattern).hit); Compiler says that it can't convert result of map function to string[]... What I want: 1. Split some text into lines us

Set optional function parameter

2018-08-17 Thread Andrey via Digitalmars-d-learn
Hello, In D there is a nice function: auto Tuple!(int,"status",string,"output") executeShell ( scope const(char)[] command, const(string[string]) env = cast(const(string[string]))null, Config config = cast(Config)0, ulong maxOutput = 18446744073709551615LU, scope const(char)[] workDir = null

ushort + ushort = int?

2018-08-20 Thread Andrey via Digitalmars-d-learn
Hello, Here is a code that you can execute using online compiler https://run.dlang.io/: import std.stdio; void main() { ushort first = 5; ushort second = 1000; ushort result = first + second; writeln(result); } I hae this error: onlineapp.d(7): Error: cannot implicitly convert

Re: ushort + ushort = int?

2018-08-20 Thread Andrey via Digitalmars-d-learn
On Monday, 20 August 2018 at 08:42:20 UTC, rikki cattermole wrote: It's called integer promotion and it originates from C. And yes C++ does have such support in some variant (I really don't feel like comparing the two). And I should do? Always use "cast" operator when I operate not with ints?

Re: ushort + ushort = int?

2018-08-20 Thread Andrey via Digitalmars-d-learn
On Monday, 20 August 2018 at 08:49:00 UTC, rikki cattermole wrote: Yes. On x86 int's will be faster just an FYI so it does make sense to use them for computation. Inconveniently always use casts. Why in D one decided to do in such way?

Deduce type of struct in function arguments

2018-08-20 Thread Andrey via Digitalmars-d-learn
Hello, I have a function and a struct: void foo(ref Data data) { ... } struct Data { int a; string text; } How to pass struct into function without naming its type? This doesn't work: foo({1234, "Hello!"});

Re: ushort + ushort = int?

2018-08-20 Thread Andrey via Digitalmars-d-learn
On Monday, 20 August 2018 at 09:56:13 UTC, Jonathan M Davis wrote: It's a combination of keeping the C semantics (in general, C code is valid D code with the same semantics, or it won't compile) and the fact that D requires casts for narrowing conversions. When you add two shorts in C/C++, it c

Re: Deduce type of struct in function arguments

2018-08-20 Thread Andrey via Digitalmars-d-learn
On Monday, 20 August 2018 at 11:38:39 UTC, Paul Backus wrote: Create an overload of foo that takes two arguments and combines them into a `Data` struct internally: void foo(int a, string text) { Data data = {a, text}; foo(data); } Hmm, not very good solution. In C++ you can not to wri

Make function alias

2018-08-20 Thread Andrey via Digitalmars-d-learn
Hello, I want to make an alias to function "std.stdio.writeln" and "std.stdio.write" and use it like: static void log(bool newline = true)(string text) { alias print(T...) = newline ? &writeln : &write; _file.print(); text.print(); } Unfortunately, it doesn't work... Also tried wit

Re: Make function alias

2018-08-20 Thread Andrey via Digitalmars-d-learn
On Monday, 20 August 2018 at 13:14:14 UTC, Andrey wrote: Mistake... this is: static void log(bool newline = true)(string text) { alias print(T...) = newline ? &writeln : &write; _file.print(text); text.print(); }

Re: Make function alias

2018-08-20 Thread Andrey via Digitalmars-d-learn
On Monday, 20 August 2018 at 13:35:07 UTC, ag0aep6g wrote: On 08/20/2018 03:14 PM, Andrey wrote: Thanks everybody for your answers.

Re: Deduce type of struct in function arguments

2018-08-20 Thread Andrey via Digitalmars-d-learn
On Monday, 20 August 2018 at 17:45:25 UTC, Seb wrote: ... yet. Though you can vote for this DIP and show your support there: https://github.com/dlang/DIPs/pull/71 It even comes with an implementation in DMD already: https://github.com/dlang/dmd/pull/8460 How and where to vote?

Cast to original type each argument in template pack

2018-08-21 Thread Andrey via Digitalmars-d-learn
Hello, I have a function: string format(string pattern, T...)(T value) { auto writer = appender!string(); writer.formattedWrite!pattern(convertToUnderlyingType(value)); //Tuple!T(value).expand.to!(OriginalType!T) return writer.data; } The "value" in this function can be any type in

Coreect way to create delegate for struct method.

2018-08-21 Thread Andrey via Digitalmars-d-learn
Hello, This is a code: import std.stdio; struct Test { static Test opCall() { Test test; test.handler = &test.one; return test; } void one() const { writeln("In handler: Address = ", &this, "; Text = ", text); } void execute() { text = "Inited!"

Re: Coreect way to create delegate for struct method.

2018-08-22 Thread Andrey via Digitalmars-d-learn
On Tuesday, 21 August 2018 at 22:52:31 UTC, Alex wrote: Maybe, like this: Thank you but here you use heap to create ab object. I want only on stack. I know that one can do this: test_handler.ptr = null; and in place of call this: handler.ptr = cast(void*)&this; but it is ugly... Hmm, any

[Unit tests] Mocking D objects

2018-08-22 Thread Andrey via Digitalmars-d-learn
Hello, I know that D has build-in unit tests. If so, what mechanism D provides for mocking objects? For example: struct WebParser { // ... int download(string path) { SomeHttpClient client(path); auto result = client.request(path, 10, "Qwerty"); // ... re

How to map elements of a tuple?

2018-08-22 Thread Andrey via Digitalmars-d-learn
Hello, Is there a template/function/mixin... in the library that I can use to map elements of a tuple? object.foo(Mapper!myMapFunction(1, bool, "Qwerty", EnumedColor.Red)); where "Mapper" is this mapper and "myMapFunction" is a template function that I want to apply to each member in tuple.

Test if variable has void value

2018-08-22 Thread Andrey via Digitalmars-d-learn
Hello, How to test if variable has void value? string text = void; if(text == void) { writeln("Is void"); } Tried this: if(is(text == void)) but doesn't work.

Get max elemenr over RegexMatch

2018-08-24 Thread Andrey via Digitalmars-d-learn
Hello, This code produces an error: auto matches = content.matchAll(pattern); auto max = matches.maxElement!"a => a.back.to!uint"(); I have a RegexMatch array like: [["text1234", "1234"], ["zxs432fff", "432"], ["text000_", "000"]] Max element here is 1234. I apply map function "a => a.ba

How to pass alias as template parameter?

2018-08-27 Thread Andrey via Digitalmars-d-learn
Hello, This code doesn't compile: --- import std.meta; import std.stdio; enum Option : string { First = "-first" , Second = "-second", Qwerty = "-qwerty" } void handler(Option option)(string[] args, ref ushort index

How to mixin repeated text?

2018-08-27 Thread Andrey via Digitalmars-d-learn
Hello again, I have this part of code: ... if(index + 3 >= data.length || data[index + 1][0] == '&' || data[index + 2][0] == '&' || data[index + 3][0] == '&' || data[index + 4][0] == '&') { writeln("Some text..."); } I don't want to write manually these four "or" conditions because in ea

Re: How to mixin repeated text?

2018-08-27 Thread Andrey via Digitalmars-d-learn
On Monday, 27 August 2018 at 11:56:08 UTC, Kamil Koczurek wrote: Mixins seem to be an overkill here. Maybe something like this would suffice: data[index + 1 .. index + 5].map!(k => k[0]).array == "" Here there is dynamic code, with memory allocs. I found solution: ---

Create constraint for each parameter in template arg pack

2018-08-28 Thread Andrey via Digitalmars-d-learn
Hello, Let we have two variadic templates: template Qwerty(Values...) {} template Qaz(alias type, Data...) {} Now I want to add a constraint to "Qwerty" so that each type in "Values" pack must be a "Qaz" template. I don't care about values of "type" or "Data" in "Qaz". How to do it in D?

Re: Create constraint for each parameter in template arg pack

2018-08-28 Thread Andrey via Digitalmars-d-learn
On Tuesday, 28 August 2018 at 13:05:15 UTC, bauss wrote: I'm not sure if there is a better way, but isInstanceOf (std.traits) seems to work with a static foreach and a static if. template Qwerty(Values...) { static foreach (value; Values) { static if (!isInstanceOf!(Qaz, value)

Static foreach internal variable

2018-08-30 Thread Andrey via Digitalmars-d-learn
Hello, is it possible to declare an internal variable in "static foreach" and on each iteration assign something to it? Example: static foreach(arg; SomeAliasSeq) { internal = arg[0].converted;// a shortcut for expression "arg[0].converted" static if(internal.length == 0) { ... }

Can't print enum values

2018-08-30 Thread Andrey via Digitalmars-d-learn
Hello, This code doesn't print enum values: import std.meta; import std.traits; import std.stdio; enum MyEnum : string { First = "F_i_r_s_t", Second = "S_e_c_o_n_d" } alias QW(alias arg) = Alias!(cast(OriginalType!(typeof(arg)))arg); void print(T...)(T args) { writeln(cast(OriginalT

Re: Static foreach internal variable

2018-08-30 Thread Andrey via Digitalmars-d-learn
On Thursday, 30 August 2018 at 09:49:15 UTC, drug wrote: 30.08.2018 11:19, Andrey пишет: Thanks everybody. Works!

Re: Can't print enum values

2018-08-30 Thread Andrey via Digitalmars-d-learn
On Thursday, 30 August 2018 at 11:09:40 UTC, vit wrote: args are runtime arguments. import std.experimental.all; enum MyEnum : string { First = "F_i_r_s_t", Second = "S_e_c_o_n_d" } ///alias QW(alias arg) = Alias!(cast(OriginalType!(typeof(arg)))arg); auto QW(T)(const auto ref T x){

Re: Can't print enum values

2018-08-31 Thread Andrey via Digitalmars-d-learn
On Thursday, 30 August 2018 at 12:04:26 UTC, vit wrote: On Thursday, 30 August 2018 at 11:34:36 UTC, Andrey wrote: On Thursday, 30 August 2018 at 11:09:40 UTC, vit wrote: [...] I want to create a reusable template for this purpose. Why I can't use "staticMap" so that compiler it self would do

Re: Can't print enum values

2018-08-31 Thread Andrey via Digitalmars-d-learn
On Friday, 31 August 2018 at 12:21:48 UTC, aliak wrote: auto ToUnderlyingType(alias a)() { return cast(OriginalType!(typeof(a)))a; } void print(T...)(T args) { writeln(staticMap!(ToUnderlyingType, args)); } Oohhh. So easy! Killed 2 days - and templates and mixins tried... And the sol

Pass lambda into template

2018-09-03 Thread Andrey via Digitalmars-d-learn
Hello, Here is a code with comments: https://run.dlang.io/is/BNl2Up. I don't understand how to pass lambda into template. I get an error: onlineapp.d(18): Error: template instance `qwerty!((i) => "arg" ~ i.to!string ~ "[0] == '?'", "||")` cannot use local __lambda1 as parameter to non-global t

Cannot build project due to Derelict package

2018-11-26 Thread Andrey via Digitalmars-d-learn
Hello, I try to build my project using command "dub build" but I can\t because there is an error: Fetching derelict-util 3.0.0-beta.2 (getting selected version)... SSL connect error on handle 1F19AC0 And this happens every time... As I understand dub can't find package. In dub.json I have th

Re: Cannot build project due to Derelict package

2018-11-26 Thread Andrey via Digitalmars-d-learn
On Monday, 26 November 2018 at 12:11:03 UTC, Alex wrote: On Monday, 26 November 2018 at 11:57:40 UTC, Andrey wrote: Hello, I try to build my project using command "dub build" but I can\t because there is an error: Fetching derelict-util 3.0.0-beta.2 (getting selected version)... SSL connect e

How to pass -J switch to compiler via DUB?

2018-11-30 Thread Andrey via Digitalmars-d-learn
Hi, How to pass -J switch to compiler via DUB? I want to import some text file at compile time: string data = import("vertex.glsl"); In dub.json: "dflags": [ "-J=vertex.glsl" ] The file itself is located on the same level as "dub.json".

Re: How to pass -J switch to compiler via DUB?

2018-11-30 Thread Andrey via Digitalmars-d-learn
On Friday, 30 November 2018 at 11:21:04 UTC, fghost wrote: On Friday, 30 November 2018 at 11:05:26 UTC, Andrey wrote: Hi, How to pass -J switch to compiler via DUB? I want to import some text file at compile time: string data = import("vertex.glsl"); In dub.json: "dflags": [ "-J=vertex.gl

Initialize static array without explicit length

2018-12-03 Thread Andrey via Digitalmars-d-learn
Hi, I want to create a static array and immediately init it with values: uint[x] data = [1,3,10,44,0,5000]; I don't want to set the length of it explicitly (x in square brackets). I want that compiler itself counted number of values (in example it is 6). What should be a right synt

Reverse and sort array elements

2018-12-18 Thread Andrey via Digitalmars-d-learn
Hi, Have array: enum array = ["qwerty", "a", "baz"]; Need to reverse and sort array elements to get this result: [a, ytrewq, zab] Did this: enum result = array.map!(value => value.retro()).sort(); Got: Error: template std.algorithm.sorting.sort cannot deduce function from argument types !()

Re: Reverse and sort array elements

2018-12-18 Thread Andrey via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 12:32:35 UTC, angel wrote: On Tuesday, 18 December 2018 at 12:07:37 UTC, Andrey wrote: Thank you everybody. Here was another problem that local variable 'array' shadows function 'array()' from std.array.

chunkBy array at compile time

2018-12-19 Thread Andrey via Digitalmars-d-learn
Hi, I have got this code: import std.array : array; import std.algorithm.mutation; import std.algorithm.iteration; import std.stdio; void main() { string input = "sieviaghp"; enum data = ["emo", "emoze", "emow", "emuo", "evuo", "ete", "ie", "vuo", "sie", "w"]; enum index = 3;

Mixin operator 'if' directly

2018-12-19 Thread Andrey via Digitalmars-d-learn
Hi, Here is a template mixin: mixin template create(alias input, uint index, alias data) { if(input.length < index) return; // ... some code } When I try to compile it, I get: Error: declaration expected, not if Is it possible to mixin operator 'if' directly inside my template mixi

Filter AA at compile time

2018-12-26 Thread Andrey via Digitalmars-d-learn
Hi, I want to filter AA at compile time and do this: void main() { // datamap is some AA enum qaz = "qq"; enum types = datamap.byKeyValue.filter!(pair => qaz.isGood(pair)).assocArray(); types.writeln; } But compiler says: Error: _aaRange cannot be interpreted at compile time,

Creating fixed array on stack

2019-01-11 Thread Andrey via Digitalmars-d-learn
Hi, In C++ you can create a fixed array on stack: int count = getCount(); int myarray[count]; In D the "count" is part of type and must be known at CT but in example it is RT. How to do such thing in D? Without using of heap.

Re: Creating fixed array on stack

2019-01-12 Thread Andrey via Digitalmars-d-learn
On Friday, 11 January 2019 at 15:23:08 UTC, Dgame wrote: On Friday, 11 January 2019 at 14:46:36 UTC, Andrey wrote: Hi, In C++ you can create a fixed array on stack: int count = getCount(); int myarray[count]; In D the "count" is part of type and must be known at CT but in example it is RT.

How to break from parallel foreach?

2019-02-26 Thread Andrey via Digitalmars-d-learn
Hello, How to break from parallel foreach? More general question - how to control such loop?

Build AA from two simple array

2019-03-23 Thread Andrey via Digitalmars-d-learn
Hello, I have got 2 simple arrays with the same length: int[] values = [1, 2, 3, 4, 5]; char[] keys = ['a', 'b', 'c', 'd', 'e']; auto result = buildAA(keys, values); // [a: 1, b: 2, c: 3, d: 4, e: 5] I want to build AA "result" using "values" and "keys". How to do it?

How to decode UTF-8 text?

2019-03-27 Thread Andrey via Digitalmars-d-learn
Hello, I have got some text with UTF-8. For example this part: Παράλληλη αναζήτηση How to decode it to get this result? Παράλληλη αναζήτηση I have tried functions like "decode", "byUTF", "to!wchar"... but no success. Input string is correct - checked it with "https://ww

Re: How to decode UTF-8 text?

2019-03-29 Thread Andrey via Digitalmars-d-learn
On Wednesday, 27 March 2019 at 19:16:21 UTC, kdevel wrote: On Wednesday, 27 March 2019 at 13:39:07 UTC, Andrey wrote: Thank you!

Wrong initialization of variables

2019-04-01 Thread Andrey via Digitalmars-d-learn
Hello, Simple code: import std.stdio; mixin template DeclFlag(alias values) { static foreach(value; values) { mixin("bool has" ~ value ~ " = false;"); } } enum Key : string { First = "qwerty", Last = "zaqy" } void main() { enum data = [Key.First, Key.Last];

Pass template parameter into q{} string

2019-04-01 Thread Andrey via Digitalmars-d-learn
Hello, enum Key : string { First = "qwerty", Last = "zaqy" } void main() { enum decl(alias values1) = q{ static foreach(value; values1) mixin("bool " ~ value ~ " = false;"); }; enum qqq = [Key.First, Key.Last]; mixin(decl!qqq); } I don't

Error: this.__lambda2 has no value

2019-04-01 Thread Andrey via Digitalmars-d-learn
Hello, My code: import std.string : join; enum Key : string { First = "qwerty", Last = "zaqy" } struct Qaz { enum text(alias Values) = Values.map!(value => "bool has" ~ value ~ " = false;").join(); } //enum text(alias Values) = Values.map!(value => "bool has" ~ value ~ " = false

Access outer member of struct from inner struct

2019-04-02 Thread Andrey via Digitalmars-d-learn
Hello, In this example how can I access the members "read" and "q" of struct Outer from Inner struct? struct Outer { ulong q = 1; Inner inner; void read(ulong value) { q += value; } void run() { q.writeln; read(5); } struct Inner

How to mixin finction name?

2019-04-14 Thread Andrey via Digitalmars-d-learn
Hi, I want to do something like this: void main() { enum letters = ['A', 'B', 'C']; static foreach(ch; letter) { void mixin("print" ~ ch)(uint i) { writeln(ch, " - ", i); } } printB(6); } Create some function in loop and use it. But

Re: How to mixin finction name?

2019-04-14 Thread Andrey via Digitalmars-d-learn
On Sunday, 14 April 2019 at 11:44:16 UTC, Boris Carvajal wrote: On Sunday, 14 April 2019 at 10:07:30 UTC, Andrey wrote: Create some function in loop and use it. But I don't know how to mixin names? import std.stdio; void main() { enum letters = ['A', 'B', 'C']; static foreach(ch; le

Inherit enum members

2019-04-21 Thread Andrey via Digitalmars-d-learn
Hello, I have got 2 enums. How to inherit one enum from another? enum Key : string { K1 = "qwerty", K2 = "asdfgh" } enum ExtendedKey : Key { E1 = "q1", E2 = "w2", E3 = "e3" } Result: onlineapp.d(27): Error: cannot implicitly convert expression "q1" of type string to Key on

Make partial alias of template function

2019-04-23 Thread Andrey via Digitalmars-d-learn
Hello, I want to make partial alias of template function "format": void qaz(alias tmp, Values...)() { alias message = format!tmp; // ... enum v = message(Values); } void main() { qaz!("test %s!", "Qwerty"); } But I get this: Error: static assert: "Orphan

Check if function argument can be handled in CT

2019-04-24 Thread Andrey via Digitalmars-d-learn
Hi all, Do you know can we detect that some argument of a function can be handled in CT? For example: int value1 = 10; someFunction(value1); int value2 = getValueFromUserInput(); someFunction(value2); void someFunction(int arg) { static if(argCanBeHandledInCT(arg)) { // perform

Re: Check if function argument can be handled in CT

2019-04-24 Thread Andrey via Digitalmars-d-learn
On Wednesday, 24 April 2019 at 08:28:06 UTC, Basile.B wrote: On Wednesday, 24 April 2019 at 07:53:47 UTC, Andrey wrote: I know about this template. Unfortunally, it doesn't work inside functions. void test(string arg1, string arg2) { enum isKnown1 = is(typeof((){enum v = arg1;})); enu

incomplete mixin expression

2019-04-24 Thread Andrey via Digitalmars-d-learn
enum Qaz : wstring { One = "один" } template Qwerty(Values...) { enum text = "Values[%d]"; enum args = iota(Values.length).map!(value => format!text(value)).join(','); pragma(msg, args); alias Qwerty = Alias!(mixin("AliasSeq!(" ~ args ~ ");")); } void main() { Qwerty!

  1   2   >