Re: Alias to struct memembers of a function paramater as a shortcut => need this for XYZ of type void*

2019-04-07 Thread ag0aep6g via Digitalmars-d-learn
On 07.04.19 14:23, Robert M. Münch wrote: struct X { TYPE a; TYPE b; } myFunc(X _struct){ alias a = _struct.a; a = myOtherFunc(); } X myStruct; myFun(myStruct); This gives an error: need this for a of type void* I don't understand why, because all I want is a shortcut

Re: alias sequences of sequences

2019-04-07 Thread ag0aep6g via Digitalmars-d-learn
On 07.04.19 06:58, Alex wrote: Is there any way to get sequences of sequences? Using RT, I have to use strings [[`string`, `0`], ...] when it would be much better to use [[string, 0], ...] Ideally it wouldn't add so much overhead that it defeats the purpose. You can make a template that do

Re: CTFE & code generators based on PEG grammars?

2019-04-07 Thread ag0aep6g via Digitalmars-d-learn
On 07.04.19 05:32, Alex wrote: readlin is not a CT function. You misinterpreted what I said. Yeah, bad example from me. This would probably have been better: auto v = "foo"; enum y = f(v); /* Error: variable v cannot be read at compile time */ Also, the `readln` example wasn't meant

Re: CTFE & code generators based on PEG grammars?

2019-04-06 Thread ag0aep6g via Digitalmars-d-learn
On 06.04.19 16:19, Alex wrote: That is CTFE is CT RTFE where runtime functions are executed at compile time when the inputs are CT. You may have the right idea, but the last part of that sentence is wrong/misleading. CTFE happens when the result is required at CT. The inputs must be available

Re: Using opOpAssign, cannot assign sequence

2019-04-05 Thread ag0aep6g via Digitalmars-d-learn
On 05.04.19 16:00, Alex wrote: I was thinking using tuple would work(of course is longer than Add but would allow for a more general approach, it would require automatic unpacking though and so doesn't work. `tuple` works for me: import std.typecons: tuple; class X(T ...) { void opO

Re: Wrong initialization of variables

2019-04-01 Thread ag0aep6g via Digitalmars-d-learn
On 01.04.19 18:31, Andrey wrote: Also with AST switch I get code where there aren't any lines with text "bool hasqwerty = false;" or "bool haszaqy = false;". What happens? Compiler bug. https://issues.dlang.org/show_bug.cgi?id=19479

Re: "if" statement

2019-03-24 Thread ag0aep6g via Digitalmars-d-learn
On 24.03.19 13:45, Francesco Mecca wrote: ``` alias Alg = Algebraic!(int, string); void main() { int n = 2;     Alg value;     value = n == 2 ? 2 : "string"; } ``` The original code used SumType but the effect is the same. I suppose that I could write the following: ```     if(n == 2

Re: local class instance (at module-level)

2019-03-14 Thread ag0aep6g via Digitalmars-d-learn
On 14.03.19 20:43, Jacob Carlborg wrote: class C {     uint i ;     this (uint i) {     this.i = i ;     }     this (uint i) shared {     this.i = i ;     }     this (uint i) immutable {     this.i = i ;     } } __gshared c0 = new C(0); shared c1 = new shared C(1); immuta

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

2019-03-11 Thread ag0aep6g via Digitalmars-d-learn
On Monday, 11 March 2019 at 19:53:53 UTC, jmh530 wrote: So what information is in the static library that allows this to take place? None. The information is in in the source or interface file (.d/.di). Templates can't be compiled before they're instantiated.

Re: Array of byLineCopy ranges behaves as they are byLine

2019-03-11 Thread ag0aep6g via Digitalmars-d-learn
On Monday, 11 March 2019 at 15:23:53 UTC, HaraldZealot wrote: ```d File[] files; foreach(filename; args[1 .. $]) { files ~= File(filename, "r"); } auto ranges = files.map!(a => a.byLineCopy); writeln(ranges[0].front); writeln(ranges[0].front); writeln(ranges[0].front); ``` produces ``` 1 2

Re: 2 class issues

2019-03-07 Thread ag0aep6g via Digitalmars-d-learn
On 07.03.19 11:38, spir wrote: -1- How to enforce that subclasses implement given methods without using "abstract", which seems to make the whole class abstract? Not, as far as I can tell. You can't force derived classes to override an existing implementation. And you can't omit the implementa

Re: Why is my @pure function @system when placed in a struct?

2019-02-27 Thread ag0aep6g via Digitalmars-d-learn
On 27.02.19 19:10, Dukc wrote: I tested a bit, and it appears that attribute inference is not done at all for templates inside structs -the attribute need not be a delegate: struct S     {     static int fImpl(Ret)() { return Ret.init; }     pragma(msg, __traits(getFunctionAttribute

Re: template alias argument accepts only class/interface types.

2019-02-23 Thread ag0aep6g via Digitalmars-d-learn
On 23.02.19 23:30, Alexandru Ermicioi wrote: According to https://dlang.org/spec/template.html#TemplateAliasParameter, simple types and arrays are excluded from the list of supported "alias X" arguments. I'm wondering why do we have such limitation? Is there any reasoning at limiting primitive

Re: Generalizing over function pointers and delegates

2019-02-15 Thread ag0aep6g via Digitalmars-d-learn
On 15.02.19 15:20, Bastiaan Veelo wrote: Exploiting this, it is possible to explicitly convert a function pointer into a delegate [2]: ``` Ret delegate(Args args) fun_to_dlg(Ret, Args...)(Ret function(Args args) fun) {     Ret delegate(Args) dlg;     dlg.funcptr = fun;     return dlg; } ```

Re: What is the Utility of Parent Class Method Hiding in Inheritance?

2019-01-14 Thread ag0aep6g via Digitalmars-d-learn
On 14.01.19 10:10, Vijay Nayar wrote: After a bit of reading, I understood the rule and how it works, but what I'm missing is the "why".  Why is it desirable to hide methods from a parent class which have the same name (but different arguments) as a method in a class? https://dlang.org/articl

Re: Dlang tour - Unittesting example

2018-10-02 Thread ag0aep6g via Digitalmars-d-learn
On 10/02/2018 03:24 PM, Basile B. wrote: The problem is the NaN madness. Since several values are NaN there's this strange stuff: void main() {     import std.stdio;     import std.math : isNaN;     double d;     writeln(d.init);    // nan     writeln(d); // nan     writeln(d.nan)

Re: "Error: function expected before (), not module *module* of type void

2018-09-22 Thread ag0aep6g via Digitalmars-d-learn
On 09/22/2018 04:51 AM, Samir wrote: Thanks for your help, Adam!  Right after posting my question, I started reading this site: https://www.tutorialspoint.com/d_programming/d_programming_modules.htm Better read the original: http://ddili.org/ders/d.en/modules.html

Re: Error: incompatible types for 'shared(SysTime)' and 'shared(SysTime)'

2018-09-13 Thread ag0aep6g via Digitalmars-d-learn
On 09/13/2018 03:25 PM, Arafel wrote:     // How can we update the timestamp? Neither of those work     timestamp = Clock.currTime;     timestamp = cast(shared) Clock.currTime; cast() timestamp = Clock.currTime;

Re: Process in parallel and output result to stdout theread-safely

2018-09-08 Thread ag0aep6g via Digitalmars-d-learn
On 09/03/2018 08:13 PM, Dr.No wrote: But it in the middle of output, I got output like this: outjson = {"barCode":"20","ade":"20"}♪◙outjson = {"barCode":"X21","ade":"21"} also there's that extra ♪◙ character. Thos sounds memory violation somewhere. This only happens when using paral

Re: Get max elemenr over RegexMatch

2018-08-24 Thread ag0aep6g via Digitalmars-d-learn
On 08/24/2018 01:13 PM, Andrey wrote: This code produces an error: auto matches = content.matchAll(pattern); auto max = matches.maxElement!"a => a.back.to!uint"(); You're mixing two different notations. It's either matches.maxElement!(a => a.back.to!uint)() or matches.maxElement!"a.

Re: Pure opEquals in a class

2018-08-20 Thread ag0aep6g via Digitalmars-d-learn
On Monday, 20 August 2018 at 19:36:15 UTC, werter wrote: The code below doesn't work. Is it possible to make a pure opEquals in a class? [...] pure bool opEquals(const A rhs) const { return b == rhs.b; } It doesn't work

Re: Make function alias

2018-08-20 Thread ag0aep6g via Digitalmars-d-learn
On 08/20/2018 03:14 PM, Andrey wrote: 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(); } Unfortuna

Re: Are properties mature enough?

2018-08-19 Thread ag0aep6g via Digitalmars-d-learn
On 08/19/2018 08:55 PM, Neia Neutuladh wrote: You *could* add @property to the next and seed functions. That forces people to use them as fields. It doesn't.

Re: unimplemented abstract function compiles.

2018-08-12 Thread ag0aep6g via Digitalmars-d-learn
On 08/12/2018 07:29 PM, Eric wrote: I thought it would work the same way as an interface (which must be implemented by the direct sub class, otherwise compile error). From the spec text [1], I'd also expect an error. It says: "An abstract member function must be overridden by a derived class."

Re: @nogc with opApply

2018-08-11 Thread ag0aep6g via Digitalmars-d-learn
On 08/11/2018 12:00 PM, Alex wrote: ´´´ import std.experimental.all; static assert(isIterable!S); [...] struct S { [...]     int opApply(scope int delegate(ref uint) /*@nogc*/ operations) //@nogc     { [...]     } } ´´´ Everything works fine, before I try to use the opApply function

Re: unimplemented abstract function compiles.

2018-08-11 Thread ag0aep6g via Digitalmars-d-learn
On 08/11/2018 10:55 PM, Eric wrote: Code below compiles while I would not expect it to compile. Is there a reason that this compiles? [...] class I {   abstract void f(); } class C : I { } unittest {   C c = cast(C) Object.factory("C");   c.f(); } Not a bug, as far as I see. You don't

Re: unimplemented abstract function compiles.

2018-08-11 Thread ag0aep6g via Digitalmars-d-learn
On 08/11/2018 11:20 PM, rikki cattermole wrote: On 12/08/2018 8:55 AM, Eric wrote: Code below compiles while I would not expect it to compile. Is there a reason that this compiles? [...] No bug. You forgot to throw -unittest when you compiled. [...] Error: program killed by signal 11 If th

Re: CJK problem when using console outputs

2018-07-16 Thread ag0aep6g via Digitalmars-d-learn
On 07/16/2018 11:30 AM, zhani wrote: i got some problem about using CJK in windows10 console. here my code(a code file encoded the utf-8): -- import std.stdio; /* static this(){ core.stdc.wchar_.fwide(core.stdc.stdio.stdout, 1); setlocale

Re: class that is initialized becomes null when outside of function

2018-07-09 Thread ag0aep6g via Digitalmars-d-learn
On 07/09/2018 11:18 AM, Flaze07 wrote: class Game { [...]     RenderWindow win; [...]     void init()     { [...]     auto win = new RenderWindow( VideoMode( 600, 600 ), "snake" ); [...]     }     void run()     { [...]     writeln( win is null ); [...]     } } the p

Re: How can I point an array to existing data in memory while using Better C?

2018-07-08 Thread ag0aep6g via Digitalmars-d-learn
On 07/08/2018 10:27 PM, Stijn Herreman wrote: https://forum.dlang.org/thread/ddckhvcxlyuvuiyaz...@forum.dlang.org is similar to what I want to do, but the code by Adam cannot be used when using Better C (I assume slicing isn't supported). Slicing a pointer works fine for me with -betterC (DMD

Re: Static member function returning immutable slice; compiler error: without this cannot be immutable

2018-07-05 Thread ag0aep6g via Digitalmars-d-learn
On 07/05/2018 09:43 PM, Ivo Maffei wrote: class Foo { private static Foo[] fooSlice = new Foo[0]; //private static slice static immutable Foo[] getFooList() { //static method returning an immutable slice     return fooSlice; } } However when compiling with dub I get the fo

Re: Inference of auto storage classes for interface function return type

2018-07-04 Thread ag0aep6g via Digitalmars-d-learn
On 07/04/2018 05:59 PM, Timoses wrote: There's an empty 19.10.10 point without content[3] : D. Maybe a placeholder? [...] [3]: https://dlang.org/spec/function.html#inout-functions Just a bug. https://github.com/dlang/dlang.org/pull/2407

Re: what's the correct way to handle unicode? - trying to print out graphemes here.

2018-07-04 Thread ag0aep6g via Digitalmars-d-learn
On 07/04/2018 05:12 PM, aliak wrote: Is updating unicode stuff to the latest a matter of some config file somewhere with the code point configurations that result in specific graphemes? I don't know. [...] Also, any reason (technical or otherwise) that we have to slice a grapheme to get it pr

Re: what's the correct way to handle unicode? - trying to print out graphemes here.

2018-07-03 Thread ag0aep6g via Digitalmars-d-learn
On Tuesday, 3 July 2018 at 13:36:56 UTC, aliak wrote: Hehe I guess the forum really is using D :p The two graphemes I'm talking about (which seem to not be rendered correctly above) are: family emoji: https://emojipedia.org/family-woman-woman-boy-boy/ rainbow flag: https://emojipedia.org/rain

Re: what's the correct way to handle unicode? - trying to print out graphemes here.

2018-07-03 Thread ag0aep6g via Digitalmars-d-learn
On Tuesday, 3 July 2018 at 13:32:52 UTC, aliak wrote: foreach (c; "👩‍👩‍👦‍👦🏳️‍🌈") { writeln(c); } So basically the above just doesn't work. Prints gibberish. Because you're printing one UTF-8 code unit (`char`) per line. So I figured, std.uni.byGrapheme would help, since that's what they ar

Re: template recursion

2018-06-26 Thread ag0aep6g via Digitalmars-d-learn
On 06/26/2018 11:35 AM, Alex wrote: ´´´ import std.range; void main() { T.member.tarr.length = 42; //put(T.member, 4); // line 6 T.member.put(4); // line 7 } struct T { void put(Type)(Type t){} // line 13 static B member; } struct B { T[] tarr; void put(Typ

Re: Making sense of recursion

2018-06-25 Thread ag0aep6g via Digitalmars-d-learn
On 06/25/2018 07:45 PM, zbr wrote: void mergeSort(int[] arr, int l, int r) {    if (l < r)   // 1    {   int m = l+(r-l)/2;    // 2   mergeSort(arr, l, m); // 3   mergeSort(arr, m+1, r);   // 4   merge(arr, l, m, r);  // 5   

Re: Determine if CTFE or RT

2018-06-25 Thread ag0aep6g via Digitalmars-d-learn
On 06/25/2018 07:47 AM, Mr.Bingo wrote: The docs say that CTFE is used only when explicit, I was under the impression that it would attempt to optimize functions if they could be computed at compile time. The halting problem has nothing to do with this. The ctfe engine already complains when on

Re: Create a List or Dictionary.

2018-06-19 Thread ag0aep6g via Digitalmars-d-learn
On 06/19/2018 11:50 AM, Sunny wrote: I read about D here - https://www.tutorialspoint.com/d_programming/index.htm I'd advise against using that tutorial. Last time I looked at it, it seemed to be of low quality [1]. And the better parts seemed to be stolen from Ali Çehreli's "Programming in D

Re: Pass function (not alias) to template and/or delegate-ize a template argument

2018-06-11 Thread ag0aep6g via Digitalmars-d-learn
On 06/11/2018 08:46 AM, cc wrote: struct MYUDA {} class Foo { @(MYUDA) int bar(int x) { return x*2; } } auto foo = new Foo(); [...] I did figure out I can do it with mixins like so: void MCALL(string func, V...)(V args) { mixin(`assert(hasUDA!(`~func~`, MYUDA));`); // Ok mixin(`

Re: how to sort the container Array from std.container

2018-06-08 Thread ag0aep6g via Digitalmars-d-learn
On 06/08/2018 10:52 AM, Flaze07 wrote: ah...well thank you, well...I did finds another way, but it is probably better to use linearRemove I used arr = make!( Array!uint )( remove( arr[], 2 ); so linearRemove is probably better Instead of creating a new array, you could update the length of the

Re: WTF! new in class is static?!?!

2018-06-07 Thread ag0aep6g via Digitalmars-d-learn
On 06/07/2018 11:26 PM, Ethan wrote: The spec isn't clear on this but it uses the same rules as struct field initialisation, ie it's defined once and copied to each instance on creation. https://dlang.org/spec/struct.html#default_struct_init It says there that "The default initializers may n

Re: how to sort the container Array from std.container

2018-06-06 Thread ag0aep6g via Digitalmars-d-learn
On 06/06/2018 04:20 PM, Flaze07 wrote: hmm, and sorry for asking more, what about removing an element from it ? I found no remove operation that can remove from the middle ( removeAny and removeBack both removes the latest element, linearRemove receive Array!uint...which  don't know how to prov

Re: determining if array element is null

2018-06-02 Thread ag0aep6g via Digitalmars-d-learn
On 06/02/2018 08:35 PM, Neia Neutuladh wrote: 2. `int[4] a = null` treats the initialization as a copy from an array whose value is null. If you run just that line of code, it will produce an error at runtime: "object.Error@(0): Array lengths don't match for copy: 0 != 4" If you want to initi

Re: range simple toy problem

2018-06-01 Thread ag0aep6g via Digitalmars-d-learn
On 06/01/2018 07:00 PM, Xiaoxi wrote: import std.range; import std.algorithm; import std.string; import std.stdio; void main() {   auto s = "1 2 3 4 5 6 7 8 9";   auto iter = s.split(" ").drop(2);   // How to find the unconsumed/not-split part of s here?   // i.e. "3 4 5 6 7 8 9" NOT ["3",

Re: C style callbacks fix for member callbacks

2018-05-20 Thread ag0aep6g via Digitalmars-d-learn
I tried this. Your code crashes in windows dmd x86 x64. Hm. Works for me in a virtual machine. But I'm not surprised that it's fragile. It might be completely wrong, and it just happens to look alright on my machine.

Re: C style callbacks fix for member callbacks

2018-05-20 Thread ag0aep6g via Digitalmars-d-learn
On 05/20/2018 06:48 PM, IntegratedDimensions wrote: alias callback = extern(C) int function(const(void) a, void *b, uint c, void* context); (I'm assuming that `a` is supposed to be a `const(void)*`.) Where context acts as this. I would like to assign a D method to this callback. class {   

Re: Splitting up large dirty file

2018-05-17 Thread ag0aep6g via Digitalmars-d-learn
On 05/17/2018 11:40 PM, Neia Neutuladh wrote: 0b1100_ through 0b_1110 is the start of a multibyte character Nitpick: It only goes up to 0b_0100. The highest code point is U+10. There are no sequences with more than four bytes.

Re: `free` for struct with C bindings.

2018-05-14 Thread ag0aep6g via Digitalmars-d-learn
On 05/15/2018 12:03 AM, Jonathan wrote: ``` xcb_generic_event_t*    event; event = xcb_wait_for_event (connection); free (event); ``` The problem is the `free` function.  It is not provided by the library but is part of the C standard library (in stdlib.h). D has the C functions in core.stdc.

Re: Store any callable in an array

2018-05-07 Thread ag0aep6g via Digitalmars-d-learn
On 05/07/2018 04:41 AM, wjoe wrote: Could you elaborate on the unsafe destructor please? If TFunc has an unsafe destructor, asDelegate is also not safe and can't be @trusted. An example of how that can break safety: auto asDelegate(TFunc)(TFunc func) @trusted { import std.function

Re: Store any callable in an array

2018-05-05 Thread ag0aep6g via Digitalmars-d-learn
On 05/05/2018 02:30 AM, Neia Neutuladh wrote: On Friday, 4 May 2018 at 19:12:16 UTC, ag0aep6g wrote: If toDelegate isn't (always) @safe, how can you be sure that your wrapper is? [...] Looking at the code, I believe there are several casts that the compiler can't verify but are used safely.

Re: Store any callable in an array

2018-05-04 Thread ag0aep6g via Digitalmars-d-learn
On 05/04/2018 06:33 PM, Neia Neutuladh wrote: auto asDelegate(TFunc)(TFunc func) @trusted {     import std.functional : toDelegate;     return toDelegate(func); } The "@trusted" means that you promise this thing is safe, even if the compiler can't be certain. If toDelegate isn't (always) @s

Re: using Unsized Arrays in Structures from d?

2018-05-04 Thread ag0aep6g via Digitalmars-d-learn
On Friday, 4 May 2018 at 13:02:08 UTC, NewUser wrote: How can I use the following c structure from d. struct Item { int id; }; struct Group { int i; int item_count; struct Item items[]; }; tried defining items[] as both "Item[] items" and "Item* items" in d, it compiles okay but gives

Re: Why does enumerate over range return dchar, when ranging without returns char?

2018-05-03 Thread ag0aep6g via Digitalmars-d-learn
On 05/03/2018 07:56 AM, rikki cattermole wrote: ``` import std.stdio; import std.range : enumerate; void main() {  char[] s = ['a','b','c']; char[3] x; auto i = 0; foreach(c; s) { x[i] = c; i++; } writeln(x); } ``` Above works without cast. ''' i

Re: Create variable for RedBlackTree range

2018-05-02 Thread ag0aep6g via Digitalmars-d-learn
On 04/28/2018 06:36 PM, Gerald wrote: What is the appropriate way to create a variable for the range returned by RedBlackTree lowerBound and upperBound. For example, given this code: ``` RedBlackTree!long promptPosition = redBlackTree!long(); long row = to!long(vte.getVadjustment().getValue())

Re: Can I convert the Range returned by asUpperCase to ubyte[]?

2018-05-01 Thread ag0aep6g via Digitalmars-d-learn
On 05/01/2018 10:13 PM, Dr.No wrote: I'm trying to do an optimization here: a hash function which expect a ubye[] array as argument, would just work if I cast string to ubyte[] but I need to convert it to upper case, so I'd like to do that lazily, so that the byte is converted to its upper case

Re: Purity of delegate-style toString

2018-05-01 Thread ag0aep6g via Digitalmars-d-learn
On 05/01/2018 01:44 PM, Per Nordlöw wrote: In which cases (if any) is it possible to make a delegate-style implementation of toString such as     void toString(scope void delegate(const(char)[]) sink) const @trusted pure     {     // sink("...");     // sink.formattedWrite!"..."(.

Re: Arguments of function as an array.

2018-04-26 Thread ag0aep6g via Digitalmars-d-learn
On 04/26/2018 11:28 PM, Jonathan wrote: Is there a way in D to take past arguments as an array?  A like a normal Variadic function.  All the arguments should be of the same type just as an array. Basically I want to allow a function like this to be called without square brackets. void fun(i

Re: Implicit Template Parameters Cannot Decipher Aliases?

2018-04-25 Thread ag0aep6g via Digitalmars-d-learn
On 04/25/2018 12:25 PM, Simen Kjærås wrote: It's a known issue, and could be solved in some cases by partial template expansion, which is currently not part of the language. I believe it's in bugzilla somewhere, but a cursory search yielded no results. https://issues.dlang.org/show_bug.cgi?id

Re: wstring double quotes to string double quotes

2018-04-20 Thread ag0aep6g via Digitalmars-d-learn
On 04/20/2018 09:45 AM, Joel wrote: On Friday, 20 April 2018 at 02:46:14 UTC, Jonathan M Davis wrote: [...] please create a bug report [...] Done. For reference, that was . But someone else was faster and filed

Re: Why is the error message coming by the end of the compilation?

2018-04-15 Thread ag0aep6g via Digitalmars-d-learn
On 04/15/2018 05:33 PM, bauss wrote: On Sunday, 15 April 2018 at 10:27:26 UTC, ag0aep6g wrote: On 04/14/2018 08:56 PM, bauss wrote: I wish there was a way to give a mixin some kind of identity like: mixin("mymixin", "somecode"); Where an error message would print something like: Error in mix

Re: "%s"-format template function arguments

2018-04-15 Thread ag0aep6g via Digitalmars-d-learn
On 04/15/2018 02:04 PM, vladdeSV wrote:     foo(1,2,3);     void foo(T...)(T args)     {     writefln("expected: %s", [1,2,3]);     writefln("actual: %s", args);     } The code above will output     expected: [1, 2, 3]     actual: 1 How would I go on about to print all the arg

Re: Why is the error message coming by the end of the compilation?

2018-04-15 Thread ag0aep6g via Digitalmars-d-learn
On 04/14/2018 08:56 PM, bauss wrote: I wish there was a way to give a mixin some kind of identity like: mixin("mymixin", "somecode"); Where an error message would print something like: Error in mixin("mymixin"): ... That would completely solve this issue and I wouldn't have to have pragma(ms

Re: stirling numbers and multidimensional arrays

2018-04-08 Thread ag0aep6g via Digitalmars-d-learn
On 04/08/2018 06:15 PM, popgen wrote: I am trying to implement some code to calculate Stirling numbers.  The code shown below provides the correct calculation but throws a Segmentation fault: 11 once it is done running. I suspect there is something with the way I am setting up the multidimensio

Re: how to correctly populate an array of dynamic closures?

2018-03-29 Thread ag0aep6g via Digitalmars-d-learn
On Thursday, 29 March 2018 at 20:26:59 UTC, kdevel wrote: What is the lifetime of the first loop's variable i? It lives as long as the delegate. What about this example: ``` bug2.d import std.stdio; void main () { int delegate () [] dg; foreach (i; 0..2) { int *j; if (i ==

Re: how to correctly populate an array of dynamic closures?

2018-03-29 Thread ag0aep6g via Digitalmars-d-learn
On Thursday, 29 March 2018 at 19:02:51 UTC, kdevel wrote: On Thursday, 29 March 2018 at 15:16:07 UTC, Ivan Kazmenko wrote: [...] int delegate () [] guns; foreach (i; 0..2) guns ~= () => i; foreach (i; 0..2) writeln (guns[i] ()); // 1 and 1, why? Isn't this undefined b

Re: how to correctly populate an array of dynamic closures?

2018-03-29 Thread ag0aep6g via Digitalmars-d-learn
On 03/29/2018 05:16 PM, Ivan Kazmenko wrote: int delegate () [] guns; foreach (i; 0..2) guns ~= () => i; foreach (i; 0..2) writeln (guns[i] ());  // 1 and 1, why? Because there's only variable `i`. All delegates refer to that same one. With `i` being mutable, this could maybe be

Re: C style array declaration.

2018-03-26 Thread ag0aep6g via Digitalmars-d-learn
On 03/26/2018 12:16 PM, Aedt wrote: I'm a big fan of betterC. In C, you can initialize an array without specifying the length like this int ia[ ] = {0, 2, 1}; What is the translation of this? The language doesn't have that feature. But there's a PR to add `staticArray` to the standard librar

Re: recursive template expansion: Why does this not compile?

2018-03-20 Thread ag0aep6g via Digitalmars-d-learn
On 03/21/2018 01:47 AM, Ontonator wrote: The following code does not compile: void main() {} class SuperClass {} class TemplatedClass(T : SuperClass) {} class A : SuperClass {     alias T = TemplatedClass!B; } class B : SuperClass {     alias T = TemplatedClass!C; } class C : SuperClass {}

Re: Function argument that is a pointer to memory which the function is not allowed to modify, as in C const

2018-03-14 Thread ag0aep6g via Digitalmars-d-learn
On 03/14/2018 11:23 PM, Cecil Ward wrote: say in C I have a function with a pointer argument     foo( const sometype_t * p ) I have asked about this D nightmare before. Using the same pattern in D or the in argument qualifier as far as I can see the value of the pointer is then itself effecti

Re: What is the "right" way to create a generic type getter (and setter) ?

2018-03-14 Thread ag0aep6g via Digitalmars-d-learn
On 03/14/2018 11:13 PM, James Blachly wrote: Suppose I have a struct (which is really a memory map of a data file I am reading in) with too many data members to reasonably code getters/setters for by hand.  I wish to either retrieve individual values or set individual values, which could be num

Re: "Error: address of variable this assigned to this with longer lifetime"

2018-03-13 Thread ag0aep6g via Digitalmars-d-learn
On Tuesday, 13 March 2018 at 20:49:16 UTC, Nathan S. wrote: "onlineapp.d(16): Error: address of variable this assigned to this with longer lifetime" ```d [...] struct SmallString { char[24] small; char[] data; [...] this(scope const(char)[] s) @safe { [...] dat

Re: Forwarding arguments through a std.algorithm.map

2018-03-10 Thread ag0aep6g via Digitalmars-d-learn
On 03/10/2018 09:48 PM, Nordlöw wrote: If I have a function     bool f(Rs...)(Rs rs) is it somehow possible to map and forward all its arguments `rs` to another function     bool g(Rs...)(Rs rs); through a call to some map-and-forward-like-function `forwardMap` in something like     b

Re: issue with each specifically for x86

2018-03-07 Thread ag0aep6g via Digitalmars-d-learn
On 03/07/2018 09:09 PM, ag0aep6g wrote: double f() { return 1; } void main() {     cast(void) f();     cast(void) f();     cast(void) f();     cast(void) f();     cast(void) f();     cast(void) f();     cast(void) f();     double b = 2;     assert(b == 2); /* fails; should pass */

Re: issue with each specifically for x86

2018-03-07 Thread ag0aep6g via Digitalmars-d-learn
On 03/07/2018 08:54 PM, Steven Schveighoffer wrote: Looking at each, it looks like it does this: cast(void) unaryFun!pred(r.front); So I tried this: auto pred = i => a[i] = a[i-1] + 2; foreach(i; 1 .. a.length)    cast(void)pred(i); And I see the -nan value. Remove the cast(void) and I don't

Re: isInputRange copied verbatim produces a different result than isInputRange from std.range

2018-03-04 Thread ag0aep6g via Digitalmars-d-learn
On 03/04/2018 08:54 PM, aliak wrote: wait a minute... so I can't use any std.range functions on a type if I add the range primitives as free functions? O.o Yes. In other words: You can't implement range primitives as free functions. Because std.range (and std.algorithm, etc.) doesn't know abo

Re: importing std.array: empty in a struct messes things up

2018-03-04 Thread ag0aep6g via Digitalmars-d-learn
On 03/04/2018 08:45 PM, ag0aep6g wrote: I don't know what's going on here. The error message doesn't make sense to me. Might be a bug in the compiler. This one works: struct Stack(T) { T[] stack; alias stack this; bool empty() {return empty(stack);} /* not using UFCS */ im

Re: importing std.array: empty in a struct messes things up

2018-03-04 Thread ag0aep6g via Digitalmars-d-learn
On 03/04/2018 08:17 PM, Dennis wrote: I was making a stack interface for an array: ``` struct Stack(T) {     import std.array: empty;     T[] stack;     alias stack this; } void main() {     Stack!int stack;     bool x = stack.empty; } ``` My expectation is that you can now call `empty` on

Re: Assigning to slice of array

2018-03-01 Thread ag0aep6g via Digitalmars-d-learn
On 03/01/2018 11:43 PM, Jamie wrote: So if I do     arr[0 .. 1][0] = 3; shouldn't this return     [[3, 0, 0], [0, 0, 0]] ? Because I'm taking the slice arr[0 .. 1], or arr[0], which is the first [0, 0, 0]? arr[0 .. 1] is not the same as arr[0]. arr[0 .. 1] is not the first element of arr; i

Re: Struct ctor called with cast

2018-02-27 Thread ag0aep6g via Digitalmars-d-learn
On 02/27/2018 09:59 PM, Radu wrote: On Tuesday, 27 February 2018 at 20:51:25 UTC, ag0aep6g wrote: On 02/27/2018 09:30 PM, Radu wrote: [...] enum Type { a }; struct S(Type t = Type.a) { this(Type)(Type t) { import std.stdio; writeln("ctor called."); } } [...] S

Re: Struct ctor called with cast

2018-02-27 Thread ag0aep6g via Digitalmars-d-learn
On 02/27/2018 09:30 PM, Radu wrote: enum Type { a }; struct S(Type t = Type.a) {     this(Type)(Type t)     {     import std.stdio;     writeln("ctor called.");     } } void main() {    auto x = S!(Type.a)(Type.a);    void* y = &x;    auto z = (cast(S!(Type.a)) y); } Surpris

Re: Searching string for character in binary search

2018-02-25 Thread ag0aep6g via Digitalmars-d-learn
On 02/25/2018 10:18 PM, Joel wrote:     if (arr[i]  > n)     arr = arr[i + 1 .. $]; When `arr[i]` is greater than `n`, then the values in `arr[i + 1 .. $]` will only be even greater. You're picking the wrong half of the array.

Re: Double link list

2018-02-24 Thread ag0aep6g via Digitalmars-d-learn
On 02/24/2018 11:26 AM, TheFlyingFiddle wrote: On Saturday, 24 February 2018 at 09:48:13 UTC, Joel wrote: [...] void popFront() { head = head.next;  if (head !is null) head.prev = null; } void popBack() { tail = tail.prev; if (tail !is null) tail.next = null; } Head and tail will point to th

Re: array/Array: "hard" bounds checking

2018-02-22 Thread ag0aep6g via Digitalmars-d-learn
On 02/22/2018 10:39 AM, bauss wrote: On Thursday, 22 February 2018 at 05:22:19 UTC, TheFlyingFiddle wrote: Eg: uint a = 3; int b = -1; assert(a > b); //No idea what should happen here. This is what happens: assert(cast(int)a > b); Nope. It's `assert(a > cast(uint)b);`.

Re: Cannot make my shared PureMallocator callable in pure functions

2018-02-17 Thread ag0aep6g via Digitalmars-d-learn
On 02/17/2018 03:04 PM, Steven Schveighoffer wrote: You have to be a bit careful here. pure functions can assume nothing is happening and simply not call the function. That's only a problem when the called function is strongly pure, right? Nordlöw's methods are only weakly pure. They have muta

Re: Cannot make my shared PureMallocator callable in pure functions

2018-02-17 Thread ag0aep6g via Digitalmars-d-learn
On 02/17/2018 01:35 PM, rikki cattermole wrote: pure means no globals. As in none :) ... except immutable ones. And since PureMallocator has no fields, `instance` can be made immutable, and all the methods can be made static or const. Then they can be used in `pure` code.

Re: std.zip size limit of 2 GB?

2018-02-15 Thread ag0aep6g via Digitalmars-d-learn
On 02/15/2018 10:20 PM, Tony wrote: Wouldn't using a uint for buffer size give a size limit of greater than 4GB? Seems like an int is in the mix somewhere. uint gives 4, int gives 2.

Re: No error message in DMD 2.078.2

2018-02-13 Thread ag0aep6g via Digitalmars-d-learn
On 02/13/2018 06:51 AM, Domain wrote: module main; void main () {     writeln("Hello"); } Of course, this won't compile, but error message is confused: C:\Git\hello\source>dmd app.d app.d(5): Error: object.Error@(0): Access Violation This is issue 18403. You should see an error message with

Re: Getting a reference to an immutable string

2018-02-10 Thread ag0aep6g via Digitalmars-d-learn
On 02/10/2018 11:46 PM, David Zhang wrote: This is what I'm talking about: void createWindow( ... ) {     assert( wndclassName.ptr ); //This fails     HWND hwnd = CreateWindowW(     wndclassName.ptr, //This too     null,     0,     CW_USEDEFAULT, CW_USEDEFAULT,     C

Re: Getting a reference to an immutable string

2018-02-10 Thread ag0aep6g via Digitalmars-d-learn
On 02/10/2018 11:26 PM, David Zhang wrote: I've got an immutable string declared in module scope, and I attempted to get a pointer to its characters through both &str[0] and str.ptr. However, it appears to me that the string is behaving like a manifest constant, in that the pointer is null. T

Re: more OO way to do hex string to bytes conversion

2018-02-06 Thread ag0aep6g via Digitalmars-d-learn
On 02/06/2018 07:33 PM, Ralph Doncaster wrote: I've been reading std.conv and std.range, trying to figure out a high-level way of converting a hex string to bytes.  The only way I've been able to do it is through pointer access: import std.stdio; import std.string; import std.conv; void main(

Re: enforce (i > 0) for i = int.min does not throw

2018-01-27 Thread ag0aep6g via Digitalmars-d-learn
On 01/27/2018 03:13 PM, kdevel wrote: I would expect this code enforce3.d --- import std.exception; void main () {    int i = int.min;    enforce (i > 0); } --- to throw an "Enforcement failed" exception, but it doesn't: $ dmd enforce3.d $ ./enforce3 [nothing] Wow, that looks really bad

Re: Help me understand how to contribute to bugs report / fixing

2018-01-26 Thread ag0aep6g via Digitalmars-d-learn
On 01/26/2018 09:43 PM, Fra Mecca wrote: Real world case: this bug has been reported recently: https://issues.dlang.org/show_bug.cgi?id=18288#add_comment [...] From a quick glance at the phobos repo, I found no mention of this bug in any closed or open PR, just a PR (#6056, bug 18280) on the s

Re: `Alias this` to a mixed in property

2018-01-24 Thread ag0aep6g via Digitalmars-d-learn
On 01/24/2018 02:24 PM, Bastiaan Veelo wrote: `Alias this` to mixed in properties does not seem to work, see below. If you think it should, I'll file an issue. Otherwise: can this be made to work somehow? Not supposed to work as it is. The spec says that you cannot make an overload set just b

Re: New integer promotion rules

2018-01-18 Thread ag0aep6g via Digitalmars-d-learn
On 01/18/2018 05:22 PM, Steven Schveighoffer wrote: Sure, but what does the statement "Once deprecated this will become an error" mean? Will I have to use the -transition=intpromote switch forever to avoid an error? As you quoted before: "Once deprecated this will become an error, and then th

Re: New integer promotion rules

2018-01-18 Thread ag0aep6g via Digitalmars-d-learn
On 01/18/2018 03:30 PM, Steven Schveighoffer wrote: Is there going to be a point where casts aren't needed? Otherwise, this is pretty ugly. You don't need casts when you use `-transition=intpromote`.

Re: cast ref pointer

2018-01-18 Thread ag0aep6g via Digitalmars-d-learn
On 01/18/2018 04:25 PM, Luís Marques wrote: This works, obviously (i.e. it prints 42):     void foo(ref int* a)     {     static int j = 42;     a = &j;     }     void bar(int* ptr)     {     foo(ptr);     writeln(*ptr);     }     void main()     {     int i =

Re: New integer promotion rules

2018-01-17 Thread ag0aep6g via Digitalmars-d-learn
On 01/17/2018 11:30 PM, rumbu wrote: 1. Why do I need explicitely to promote my byte to int in order to assign it to an ulong? 2.077: ulong u = -b; 2.088: ulong u = -cast(int)b; Those two snippets are not equivalent. When b = byte.min, the 2.077 snippet gives u = 18446744073709551488, while

Re: New integer promotion rules

2018-01-17 Thread ag0aep6g via Digitalmars-d-learn
On 01/17/2018 09:30 PM, rumbu wrote: And here is why is bothering me: auto max = isNegative ? cast(Unsigned!T)(-T.min) : cast(Unsigned!T)T.max); The generic code above (which worked for all signed integral types T in 2.077) must be rewritten like this in 2.078: static if (T.sizeof >= 4)   

Re: New integer promotion rules

2018-01-17 Thread ag0aep6g via Digitalmars-d-learn
On 01/17/2018 08:40 PM, rumbu wrote: This started in the last DMD version (2.078): byte b = -10; ulong u = b < 0 ? -b : b; //Deprecation: integral promotion not done for `-b`, use '-transition=intpromote' switch or `-cast(int)(b) Why do I need a to promote a byte to int to obtain an ulong? E

<    1   2   3   4   5   6   7   8   >