Re: Real implicitly converts to float?
On Wednesday, 22 June 2016 at 14:17:42 UTC, Jonathan M Davis wrote: Well, that particular value should probably work thanks to VRP (value range propagation), since 10 can fit into float with no loss of precision. However, what's far more disconcerting is that real x = real.max; float y = x; compiles. real to float is a narrowing conversion, which should be an error barring the compiler detecting that the value will fit in the target type even if it's a narrowing conversion (which only happens with VRP). That's not the sort of thing that I would have expected to be broken such that it begs the question as to whether it's intentional, but given that narrowing conversions without a cast are illegal everywhere else, this definitely seems broken. - Jonathan M Davis Should I make a bug report? I am not sure it's a bug, seems intentional. Maybe a dip for a compiler flag to warn on implicit down conversions, but it would be a pretty small dip.
Re: Get specific item by index from DList
On Wed, Jun 22, 2016 at 10:49:54PM +, TheDGuy via Digitalmars-d-learn wrote: > On Wednesday, 22 June 2016 at 22:25:21 UTC, lmpo wrote: > > On Wednesday, 22 June 2016 at 22:10:09 UTC, TheDGuy wrote: > > > Hi, > > > > > > i am currently programming a small game with GTKD and i have to > > > use a Dlist because an array is static > > > > Static ? An array is not static. a DList is only interesting when > > you have to insert or remove inside the list i.e not at the back. If > > the container grows always from the back than you should rather use > > an array. > > Thanks a lot for your answer. The main reason why i switched the DList > is, that i have to initialize an array with a fixed length but it is > important for me that the length-value of the property of the array is > not the maximum length but the amount of indexes which actually > contain values. I don't know how i could do this without creating an > extra variable? Take a look at: https://dlang.org/spec/arrays.html In particular, at the .reserve() method and .capacity property of arrays. It sounds like what you want is to call .reserve on the array but keep its length at 0 when you first initialize it. This way you don't need to keep an "extra variable" around. T -- When solving a problem, take care that you do not become part of the problem.
Re: How to use a char[] buffer in D
On Wed, Jun 22, 2016 at 09:57:04PM +, Andrew Chapman via Digitalmars-d-learn wrote: > Hi everyone, just wanting some help with optimisation if anyone is > kind enough :-) > > I have a loop that iterates potentially millions of times, and inside > that loop I have code that appends some strings together, e.g.: > > string key = s1 ~ "_" ~ s2; > > I discovered that due to the memory allocation required, this slows > the execution significantly. > > s1 is always a two character string, e.g "AA", and s2 is always a > single character. Yes, frequent allocation of small strings is a performance killer. Using a static array (as you've done below) is much better. > What I want to do is something like this: > > Outside the loop: > > char[4] buffer; > buffer[2] = '_'; > > Then inside the loop > > buffer[0] = s1[0]; > buffer[1] = s1[1]; > buffer[3] = s2[0]; > > This works OK, however, I then need to use the buffer value to check > for an existing value in a hashmap / associative array. > > Code such as: > > if(buffer in myHash) { > > } > > throws an access violation. A string value works without error. Is > there a way for me to use a buffer AND use it in functions expecting > strings? Maybe try: if (buffer[] in myHash) { ... } ? Does that make a difference? T -- This sentence is false.
Re: Get specific item by index from DList
On Wednesday, 22 June 2016 at 22:10:09 UTC, TheDGuy wrote: Hi, i am currently programming a small game with GTKD and i have to use a Dlist because an array is static Static ? An array is not static. a DList is only interesting when you have to insert or remove inside the list i.e not at the back. If the container grows always from the back than you should rather use an array.
Re: How to use a char[] buffer in D
On 06/22/2016 02:57 PM, Andrew Chapman wrote: > Code such as: > > if(buffer in myHash) { > > } > > throws an access violation. A string value works without error. Does it throw an exception? Can you reproduce the issue with a short program? Ali
Get specific item by index from DList
Hi, i am currently programming a small game with GTKD and i have to use a Dlist because an array is static but i want to add user inputs dynamically to a list. Now i am wondering how i can get a specific item from that list? I read that this isn't possible but is it possible to convert that DList temporarily to an array to get a specific element? My DList just contains integer values, anyone who could offer a short code example? This doesn't work: to!Array(level,int,userInput)[i]) Level is the length of the list, int is the type and userInput is the DList.
How to use a char[] buffer in D
Hi everyone, just wanting some help with optimisation if anyone is kind enough :-) I have a loop that iterates potentially millions of times, and inside that loop I have code that appends some strings together, e.g.: string key = s1 ~ "_" ~ s2; I discovered that due to the memory allocation required, this slows the execution significantly. s1 is always a two character string, e.g "AA", and s2 is always a single character. What I want to do is something like this: Outside the loop: char[4] buffer; buffer[2] = '_'; Then inside the loop buffer[0] = s1[0]; buffer[1] = s1[1]; buffer[3] = s2[0]; This works OK, however, I then need to use the buffer value to check for an existing value in a hashmap / associative array. Code such as: if(buffer in myHash) { } throws an access violation. A string value works without error. Is there a way for me to use a buffer AND use it in functions expecting strings? I can use idup() on the char[] to make a string, but again we're allocating memory which I'd rather avoid. Thanks sincerely in advance, Cheers, Andrew.
Re: Initialise dynamic array in array of structures
On Wednesday, 22 June 2016 at 09:27:01 UTC, cym13 wrote: what i meant is that "{}" should be fully equivalent to "Struct()" ctor in terms of calling postblits, and it isn't.
Re: Initialise dynamic array in array of structures
On Wednesday, 22 June 2016 at 09:27:01 UTC, cym13 wrote: On the other hand I don't see why you'd expect {} to call postblit at all. 'cause it essentially makes a copy. i gave the sample in bugreport. it worth me a hour of debugging to find why my refcounted struct keep crashing with invalid counter.
Re: GTKD - get CSS class for button
On Wednesday, 22 June 2016 at 17:50:53 UTC, Mike Wey wrote: "Type T wraps should match the type of the data" Does string match the type of the data? What is the type of the data? How do i tell the function that i want the Array as a string array? I am not familiar with Types and what 'TC' or 'T' is, i am afraid. toArray currently only works for GtkD classes, so it doesn't work for lists of stings. ListG is a linked list, the data is stored in the data property. to iterate over the list do something like this: ``` ListG list = widget.getStyleContext().listClasses(); while(list !is null) { string str = to!string(cast(char*)list.data); //do something with str. list = list.next; } ``` Thanks alot! Works perfectly!
Re: Behavior of __FILE__ in mixin template
On Wednesday, 22 June 2016 at 17:52:26 UTC, Ali Çehreli wrote: On 06/22/2016 10:07 AM, Andre Pany wrote: > Hi, > > I thought a mixin template is copied into the place where the mixin > statement > exists and then the coding is evaluated. > This seems not to be true for __FILE__ Apparently its the whole template that supports that. Is moving the 'file' parameter to the entire template acceptable? mixin template formTemplate(string file = __FILE__) { // ... } Ali Perfekt, thanks a lot. Kind regards André
Re: Using .lib and .dll in D applications
On Wednesday, 22 June 2016 at 05:34:33 UTC, Mike Parker wrote: On Wednesday, 22 June 2016 at 03:06:29 UTC, moe wrote: I meant like this: - PluginContract // not a dub project, just some folder -- iplugin.d - TestApp // all files for the app (separate project) -- packages DerelictUtil-master // contains the project for derelict -- source app.d // the app -- dub.json // the project file for the app The only dub project would be TestApp. PluginContract would just be some folder completely outside the TestApp dub project. I could not get a relative path to work like this. Just to be clear, are you compiling iplugin.d as well? I assumed you were referring to a compiler error (i.e. missing import), but based on this post I would guess you're getting a linker error. You should probably add this to your dub.json in addition to the importPaths: "sourceFiles": ["../PluginContract/iplugin.d"] I have added all of these to the dub.json: "sourcePaths": ["../PluginContract"], "importPaths": ["../PluginContract"], "sourceFiles": ["../PluginContract/iplugin.d"], In my app I use: import iplugin; I would expect that both the compiler and the linker finds the needed files. I would also prefer a path to link a folder rather than adding files individually. It seams more error prone when I have to remember to add every file in a bigger project. However, every combination of the above seams to fail. With a linker error. Linking... OPTLINK (R) for Win32 Release 8.00.17 Copyright (C) Digital Mars 1989-2013 All rights reserved. http://www.digitalmars.com/ctg/optlink.html OPTLINK : Warning 23: No Stack .dub\build\debug-debug-windows-x86-dmd_2071-0BEC1C92408DC77EE5C50BCF4B1225A9\tes tapp.obj(testapp) Error 42: Symbol Undefined _D18TypeInfo_Interface6__vtblZ .dub\build\debug-debug-windows-x86-dmd_2071-0BEC1C92408DC77EE5C50BCF4B1225A9\tes tapp.obj(testapp) Error 42: Symbol Undefined _D14TypeInfo_Class6__vtblZ OPTLINK : Warning 134: No Start Address --- errorlevel 2 dmd failed with exit code 2. Without the adjustments in the dub.json I get the following error (But that is expected if dub only searches in the source folder by default): testplugin ~master: building configuration "debug"... source\SomePlugin.d(3,8): Error: module iplugin is in file 'iplugin.d' which can not be read import path[0] = source import path[1] = C:\D\dmd2\windows\bin\..\..\src\phobos import path[2] = C:\D\dmd2\windows\bin\..\..\src\druntime\import dmd failed with exit code 1.
Re: Behavior of __FILE__ in mixin template
On 06/22/2016 10:07 AM, Andre Pany wrote: > Hi, > > I thought a mixin template is copied into the place where the mixin > statement > exists and then the coding is evaluated. > This seems not to be true for __FILE__ Apparently its the whole template that supports that. Is moving the 'file' parameter to the entire template acceptable? mixin template formTemplate(string file = __FILE__) { // ... } Ali
Re: GTKD - get CSS class for button
On 06/22/2016 05:16 PM, TheDGuy wrote: On Wednesday, 22 June 2016 at 13:47:01 UTC, Gerald wrote: On Wednesday, 22 June 2016 at 12:57:51 UTC, TheDGuy wrote: widget.getStyleContext().listClasses() to get a list of all classes assigned to the widget. If you just want to see if a specific class is assigned to the widget you can use widget.getStyleContext().hasClass() Thanks a lot for your answer. Do you know how i can get the first classname as string from the widget? I don't understand how the return type 'GList' is organized. ListG has a D specific method called toArray that allows you to convert it to a typed array, so you could use it in this case to get a string[] out of it. http://api.gtkd.org/src/glib/ListG.html "Type T wraps should match the type of the data" Does string match the type of the data? What is the type of the data? How do i tell the function that i want the Array as a string array? I am not familiar with Types and what 'TC' or 'T' is, i am afraid. toArray currently only works for GtkD classes, so it doesn't work for lists of stings. ListG is a linked list, the data is stored in the data property. to iterate over the list do something like this: ``` ListG list = widget.getStyleContext().listClasses(); while(list !is null) { string str = to!string(cast(char*)list.data); //do something with str. list = list.next; } ``` -- Mike Wey
Re: Is there anyway to make opApply @nogc?
On Wednesday, 22 June 2016 at 13:36:54 UTC, Marc Schütz wrote: On Tuesday, 21 June 2016 at 19:21:01 UTC, Gary Willoughby wrote: Right ok, thanks! It doesn't seem to help though as the compiler complains about it being not @nogc. You probably need to declare the delegate and opApply() itself as @nogc, too: int opApply(scope int delegate(int) @nogc dg) @nogc { } That fixed it, thanks all for your help. :)
Behavior of __FILE__ in mixin template
Hi, I thought a mixin template is copied into the place where the mixin statement exists and then the coding is evaluated. This seems not to be true for __FILE__ I have a module form, which has a class Form. This module also contains following mixin template mixin template formTemplate() { void generateForm() { string getFormName(string file = __FILE__)() { import std.string: indexOf; return file[0..file.indexOf(".")]~".frm"; } enum fileContent = import(getFormName()); } } In another module myform I have a class MyForm in which I call the mixin statement: mixin formTemplate. The purpose of the template coding is: The enum fileContent should contain the text of a file, which has the same name as the module but the file ending .frm. I tried different things, but either it doesn't compile or __FILE__ returns "form" instead of "myform". Is this behavior correct? Do you have any tip? Kind regards André
Re: TypeInfo_Interface from runtime string?
On Wednesday, 22 June 2016 at 15:46:15 UTC, Thalamus wrote: On Wednesday, 22 June 2016 at 15:43:08 UTC, Basile B. wrote: On Wednesday, 22 June 2016 at 15:15:51 UTC, Thalamus wrote: [...] No need for a constructor. typeid() returns a static instance that's pre-allocated. [...] Thanks Basile. Hit Send too soon... Thanks Basile. As it turned out I was already doing something very similar for mapping types to interfaces and to other types, using shared static constructors to perform registration into associative arrays, e.g. TypeInfo_Class[TypeInfo_Class] and TypeInfo_Interface[TypeInfo_Class] So I can easily add TypeInfo_Interface[string] and TypeInfo_Class[string] as part of the existing registration process and then expose a simple lookup method. Thanks for the good idea! :)
Re: TypeInfo_Interface from runtime string?
On Wednesday, 22 June 2016 at 15:43:08 UTC, Basile B. wrote: On Wednesday, 22 June 2016 at 15:15:51 UTC, Thalamus wrote: [...] No need for a constructor. typeid() returns a static instance that's pre-allocated. [...] Thanks Basile.
Re: TypeInfo_Interface from runtime string?
On Wednesday, 22 June 2016 at 15:15:51 UTC, Thalamus wrote: Hi everyone, My project includes lots of .Net interop via C linkage. One of the things I need to do is refer in C# to an interface declared in the D code, and then to actually work with the interface concretely in the D layer. So, I need to get a TypeInfo_Interface object from a string passed in from C#. The problem isn't in marshaling the string between C# and D, but rather what to do with the string once I have it in D. So in the D code, where interfaceName is the fully qualified name of an interface, e.g. "MyPackage.MyModule.MyInterface", what I would like is something like: TypeInfo_Interface theInterface = new TypeInfo_Interface(interfaceName); But there's no such constructor. No need for a constructor. typeid() returns a static instance that's pre-allocated. Apologies if this seems like it should be obvious, but I couldn't find anything in the forums or the wider web. :) No problem. What you need to do is to create a registry with all the possible TypeInfo_Interfaces. This registry will have the form of an associative array. Each TypeInfo_Interface will be selectable with the fully qualified string, for example: __gshared TypeInfo_Interface[string] registry; interface Foo{} interface Bar{} static this() { registry[typeid(Foo).toString] = typeid(Foo); registry[typeid(Bar).toString] = typeid(Bar); } That's the basic idea but with introspection (foreach(member; traits) you should be able to automate the creation of the registry, in a smarter way.
Re: GTKD - get CSS class for button
On Wednesday, 22 June 2016 at 13:47:01 UTC, Gerald wrote: On Wednesday, 22 June 2016 at 12:57:51 UTC, TheDGuy wrote: widget.getStyleContext().listClasses() to get a list of all classes assigned to the widget. If you just want to see if a specific class is assigned to the widget you can use widget.getStyleContext().hasClass() Thanks a lot for your answer. Do you know how i can get the first classname as string from the widget? I don't understand how the return type 'GList' is organized. ListG has a D specific method called toArray that allows you to convert it to a typed array, so you could use it in this case to get a string[] out of it. http://api.gtkd.org/src/glib/ListG.html "Type T wraps should match the type of the data" Does string match the type of the data? What is the type of the data? How do i tell the function that i want the Array as a string array? I am not familiar with Types and what 'TC' or 'T' is, i am afraid.
TypeInfo_Interface from runtime string?
Hi everyone, My project includes lots of .Net interop via C linkage. One of the things I need to do is refer in C# to an interface declared in the D code, and then to actually work with the interface concretely in the D layer. So, I need to get a TypeInfo_Interface object from a string passed in from C#. The problem isn't in marshaling the string between C# and D, but rather what to do with the string once I have it in D. So in the D code, where interfaceName is the fully qualified name of an interface, e.g. "MyPackage.MyModule.MyInterface", what I would like is something like: TypeInfo_Interface theInterface = new TypeInfo_Interface(interfaceName); But there's no such constructor. Apologies if this seems like it should be obvious, but I couldn't find anything in the forums or the wider web. :) thanks, Thalamus
Re: TickDuration depreciated, yet stopwatch not?
On Tuesday, June 21, 2016 19:17:00 Joerg Joergonson via Digitalmars-d-learn wrote: > Stopwatch depends on TickDuration and TickDuration is depreciated > yet Stopwatch isn't and hasn't been converted to MonoTime... > makes sense? TickDuration does have a note in its documentation about how it's _going_ to be deprecated, but it isn't deprecated yet - precisely because StopWatch has not been deprecated yet. A replacement which uses MonoTime is in the works, but there are issues with where to put it in Phobos, because putting it in std.datetime as things stand won't work, because it would conflict with the existing StopWatch. Plans are in place to sort that out, but until then, StopWatch won't be deprecated and neither will TickDuration. - Jonathan M Davis
Re: Real implicitly converts to float?
On Wednesday, June 22, 2016 05:04:42 Tofu Ninja via Digitalmars-d-learn wrote: > Is this intended behavior? I can't seem to find it documented > anywhere, I would think the loss in precision would atleast be a > warning. > > real x = 10; > float y = x; // No error or warning > > real to double and double to float also work. Well, that particular value should probably work thanks to VRP (value range propagation), since 10 can fit into float with no loss of precision. However, what's far more disconcerting is that real x = real.max; float y = x; compiles. real to float is a narrowing conversion, which should be an error barring the compiler detecting that the value will fit in the target type even if it's a narrowing conversion (which only happens with VRP). That's not the sort of thing that I would have expected to be broken such that it begs the question as to whether it's intentional, but given that narrowing conversions without a cast are illegal everywhere else, this definitely seems broken. - Jonathan M Davis
Re: GTKD - get CSS class for button
On Wednesday, 22 June 2016 at 12:57:51 UTC, TheDGuy wrote: widget.getStyleContext().listClasses() to get a list of all classes assigned to the widget. If you just want to see if a specific class is assigned to the widget you can use widget.getStyleContext().hasClass() Thanks a lot for your answer. Do you know how i can get the first classname as string from the widget? I don't understand how the return type 'GList' is organized. ListG has a D specific method called toArray that allows you to convert it to a typed array, so you could use it in this case to get a string[] out of it. http://api.gtkd.org/src/glib/ListG.html
Re: Is there anyway to make opApply @nogc?
On Tuesday, 21 June 2016 at 19:21:01 UTC, Gary Willoughby wrote: Right ok, thanks! It doesn't seem to help though as the compiler complains about it being not @nogc. You probably need to declare the delegate and opApply() itself as @nogc, too: int opApply(scope int delegate(int) @nogc dg) @nogc { }
Re: Access vialotion
On Wednesday, 22 June 2016 at 13:24:47 UTC, vladdeSV wrote: On Wednesday, 22 June 2016 at 12:47:31 UTC, TheDGuy wrote: On Wednesday, 22 June 2016 at 12:45:29 UTC, TheDGuy wrote: I have an array of buttons: class Window : MainWindow{ private Button[4] bArr; this(){ Button btn_1 = new Button(); Button btn_2 = new Button(); Button btn_3 = new Button(); Button btn_4 = new Button(); Button[4] bArr = [btn_1,btn_2,btn_3,btn_4]; } private void letButtonsFlash(){ for(int i = 0; i < 4; i++){ writeln(this.bArr[i].getName()); } } } i don't understand why i get an 'Access Violation' - Error in the 'for'-loop? Okay, i solved it, instead of: Button[4] bArr = [btn_1,btn_2,btn_3,btn_4]; this: bArr = [btn_1,btn_2,btn_3,btn_4]; I would also suggest you use a foreach loop to iterate over the buttons: private void letButtonsFlash() { foreach(button; bArr) { writeln(button.getName()); } } //Also, question to anyone: should a ref be used here? No, ref for classes is pointless. The ptr destination is always the same heap chunk, whatever you use the original pointer or not.
Re: Access vialotion
On Wednesday, 22 June 2016 at 12:47:31 UTC, TheDGuy wrote: On Wednesday, 22 June 2016 at 12:45:29 UTC, TheDGuy wrote: I have an array of buttons: class Window : MainWindow{ private Button[4] bArr; this(){ Button btn_1 = new Button(); Button btn_2 = new Button(); Button btn_3 = new Button(); Button btn_4 = new Button(); Button[4] bArr = [btn_1,btn_2,btn_3,btn_4]; } private void letButtonsFlash(){ for(int i = 0; i < 4; i++){ writeln(this.bArr[i].getName()); } } } i don't understand why i get an 'Access Violation' - Error in the 'for'-loop? Okay, i solved it, instead of: Button[4] bArr = [btn_1,btn_2,btn_3,btn_4]; this: bArr = [btn_1,btn_2,btn_3,btn_4]; I would also suggest you use a foreach loop to iterate over the buttons: private void letButtonsFlash() { foreach(button; bArr) { writeln(button.getName()); } } //Also, question to anyone: should a ref be used here?
Re: Real implicitly converts to float?
On Wednesday, 22 June 2016 at 08:57:38 UTC, Guillaume Piolat wrote: On Wednesday, 22 June 2016 at 05:04:42 UTC, Tofu Ninja wrote: Is this intended behavior? I can't seem to find it documented anywhere, I would think the loss in precision would atleast be a warning. real x = 10; float y = x; // No error or warning real to double and double to float also work. Intended behaviour (in TDPL and all), and same behaviour than C. I'm not sure of the reason. That's a little disconcerting, would be nice if there was a compiler flag to give a warning on the precision loss.
Re: Access vialotion
On Wednesday, 22 June 2016 at 12:47:31 UTC, TheDGuy wrote: On Wednesday, 22 June 2016 at 12:45:29 UTC, TheDGuy wrote: I have an array of buttons: class Window : MainWindow{ private Button[4] bArr; this(){ Button btn_1 = new Button(); Button btn_2 = new Button(); Button btn_3 = new Button(); Button btn_4 = new Button(); Button[4] bArr = [btn_1,btn_2,btn_3,btn_4]; } private void letButtonsFlash(){ for(int i = 0; i < 4; i++){ writeln(this.bArr[i].getName()); } } } i don't understand why i get an 'Access Violation' - Error in the 'for'-loop? Okay, i solved it, instead of: Button[4] bArr = [btn_1,btn_2,btn_3,btn_4]; this: bArr = [btn_1,btn_2,btn_3,btn_4]; I would expect DMD to output a warning here, because of the shadowing...but after 3 verifications, nothing. Dscanner does.
Re: GTKD - get CSS class for button
widget.getStyleContext().listClasses() to get a list of all classes assigned to the widget. If you just want to see if a specific class is assigned to the widget you can use widget.getStyleContext().hasClass() Thanks a lot for your answer. Do you know how i can get the first classname as string from the widget? I don't understand how the return type 'GList' is organized.
Re: Access vialotion
On Wednesday, 22 June 2016 at 12:45:29 UTC, TheDGuy wrote: I have an array of buttons: class Window : MainWindow{ private Button[4] bArr; this(){ Button btn_1 = new Button(); Button btn_2 = new Button(); Button btn_3 = new Button(); Button btn_4 = new Button(); Button[4] bArr = [btn_1,btn_2,btn_3,btn_4]; } private void letButtonsFlash(){ for(int i = 0; i < 4; i++){ writeln(this.bArr[i].getName()); } } } i don't understand why i get an 'Access Violation' - Error in the 'for'-loop? Okay, i solved it, instead of: Button[4] bArr = [btn_1,btn_2,btn_3,btn_4]; this: bArr = [btn_1,btn_2,btn_3,btn_4];
Access vialotion
I have an array of buttons: class Window : MainWindow{ private Button[4] bArr; this(){ Button btn_1 = new Button(); Button btn_2 = new Button(); Button btn_3 = new Button(); Button btn_4 = new Button(); Button[4] bArr = [btn_1,btn_2,btn_3,btn_4]; } private void letButtonsFlash(){ for(int i = 0; i < 4; i++){ writeln(this.bArr[i].getName()); } } } i don't understand why i get an 'Access Violation' - Error in the 'for'-loop?
Re: GTKD - get CSS class for button
On Wednesday, 22 June 2016 at 08:08:20 UTC, TheDGuy wrote: Hello, i would like to know if it possible to get the CSS-class which is asigned to a button (for example)? I didn't find any documentation about this, just the function "getStyleContext().getProperty()", my current attempt: Value value; bArr[0].getStyleContext().getProperty("Class",StateFlags.NORMAL,value); (bArr is an array of buttons). I get the error, that 'Value' is not defined, if i use 'GValue' (as it is described here: https://developer.gnome.org/gtk3/stable/GtkStyleContext.html#gtk-style-context-get-property) i get 'function is not callable with GValue' Any ideas? Thanks alot! widget.getStyleContext().listClasses() to get a list of all classes assigned to the widget. If you just want to see if a specific class is assigned to the widget you can use widget.getStyleContext().hasClass()
Re: Initialise dynamic array in array of structures
On Wednesday, 22 June 2016 at 08:06:26 UTC, ketmar wrote: On Wednesday, 22 June 2016 at 06:43:12 UTC, Paul wrote: Why is initialisation via {} bad (in simple terms please :D)? first, it is buggy. i.e. it doesn't always call postblit[1]. second, it's syntax is the same as the syntax of argument-less lambda, which makes it context-dependent -- so reader has to make some mental efforts to find out if it is really lambda or struct initialization. for me, it is enough to see it as bad. and for some other people too. ;-) [1] https://issues.dlang.org/show_bug.cgi?id=16146 On the other hand I don't see why you'd expect {} to call postblit at all. Postblit is meant for copy construction while here (with {}) there is no copy, just an initialization. And actually the "verbose" way doesn't call postblit either: import std.stdio; struct Coord { int x, y; this(this) { writeln("Postblit (", x, ",", y, ")"); } } void main(string[] args) { writeln("Building a"); Coord a = {1, 3}; writeln("Building b"); Coord b = Coord(4, 2); } /* (fcn) sym._Dmain 78 ; var int local_14h @ ebp-0x14 ; var int local_10h @ ebp-0x10 ; var int local_ch @ ebp-0xc ; var int local_8h @ ebp-0x8 ; var int local_4h @ ebp-0x4 ; DATA XREF from 0x08078f13 (sym.main) 0x080786e0 push ebp 0x080786e1 mov ebp, esp 0x080786e3 sub esp, 0x14 0x080786e6 mov dword [ebp - local_14h], ebx 0x080786e9 mov ecx, str.Building_a 0x080786ee mov eax, 0xa 0x080786f3 push ecx 0x080786f4 push eax 0x080786f5 call sym._D3std5stdio16__T7writelnTAyaZ7writelnFNfAyaZv ; Construction of 'a' 0x080786fa mov dword [ebp - local_10h], 1 0x08078701 mov dword [ebp - local_ch], 3 0x08078708 mov edx, str.Building_b 0x0807870d mov ebx, 0xa 0x08078712 push edx 0x08078713 push ebx 0x08078714 call sym._D3std5stdio16__T7writelnTAyaZ7writelnFNfAyaZv ; Construction of 'b' 0x08078719 mov dword [ebp - local_8h], 4 0x08078720 mov dword [ebp - local_4h], 2 0x08078727 xor eax, eax 0x08078729 mov ebx, dword [ebp - local_14h] 0x0807872c leave 0x0807872d ret */ No postblit.
Re: Real implicitly converts to float?
On Wednesday, 22 June 2016 at 05:04:42 UTC, Tofu Ninja wrote: Is this intended behavior? I can't seem to find it documented anywhere, I would think the loss in precision would atleast be a warning. real x = 10; float y = x; // No error or warning real to double and double to float also work. Intended behaviour (in TDPL and all), and same behaviour than C. I'm not sure of the reason.
Re: Searching for a T in a T[]
On Wednesday, 22 June 2016 at 08:07:51 UTC, David Nadlinger wrote: What about http://dlang.org/phobos/std_algorithm_searching.html#.canFind.canFind.2? My mistake. The reason for the template error message was another than I though of. Thanks.
Re: Searching for a T in a T[]
On Wednesday, 22 June 2016 at 08:04:34 UTC, Nordlöw wrote: Is there now algorithm (similar to `canFind`) that can search for a `T` in a `T[]`? Existing `canFind` only supports sub-sequence needles. I'm aware of `std.string.indexOf` but that's only for strings. I don't see why canFind isn't good enough for you, maybe I don't get what you want: void main(string[] args) { import std.algorithm: canFind; struct Coord { int x, y; } Coord[] list = [Coord(0, 0), Coord(3, 14), Coord(1, 2), Coord(4, 2)]; assert( list.canFind(Coord(3, 14))); assert( list.canFind(Coord(4, 2))); assert(!list.canFind(Coord(4, 3))); assert(!list.canFind(Coord(-1, 3))); }
GTKD - get CSS class for button
Hello, i would like to know if it possible to get the CSS-class which is asigned to a button (for example)? I didn't find any documentation about this, just the function "getStyleContext().getProperty()", my current attempt: Value value; bArr[0].getStyleContext().getProperty("Class",StateFlags.NORMAL,value); (bArr is an array of buttons). I get the error, that 'Value' is not defined, if i use 'GValue' (as it is described here: https://developer.gnome.org/gtk3/stable/GtkStyleContext.html#gtk-style-context-get-property) i get 'function is not callable with GValue' Any ideas? Thanks alot!
Re: Initialise dynamic array in array of structures
On Wednesday, 22 June 2016 at 06:43:12 UTC, Paul wrote: Why is initialisation via {} bad (in simple terms please :D)? first, it is buggy. i.e. it doesn't always call postblit[1]. second, it's syntax is the same as the syntax of argument-less lambda, which makes it context-dependent -- so reader has to make some mental efforts to find out if it is really lambda or struct initialization. for me, it is enough to see it as bad. and for some other people too. ;-) [1] https://issues.dlang.org/show_bug.cgi?id=16146
Re: Searching for a T in a T[]
On Wednesday, 22 June 2016 at 08:04:34 UTC, Nordlöw wrote: Is there now algorithm (similar to `canFind`) that can search for a `T` in a `T[]`? Existing `canFind` only supports sub-sequence needles. What about http://dlang.org/phobos/std_algorithm_searching.html#.canFind.canFind.2? — David
Searching for a T in a T[]
Is there now algorithm (similar to `canFind`) that can search for a `T` in a `T[]`? Existing `canFind` only supports sub-sequence needles. I'm aware of `std.string.indexOf` but that's only for strings.
Re: GTKD - overrideBackgroundColor of Button doesn't work
I am wondering if it is possible to get the name of the current CSS-class the button is asigned to?
Re: Initialise dynamic array in array of structures
On Tuesday, 21 June 2016 at 19:33:31 UTC, cym13 wrote: ... but “trackTemplates[0].coords = [{0, 9}, {1, 1}, {3, 6}];” is an assignment so the compiler can infer as much and doesn't understand that each of those list of values are really CoordLists. I see, but it seems a bit strange given that they are being assigned to .coords[] which is already defined as of type CoordList. trackTemplates[0].coords = [CoordList(0, 9), CoordList(1, 1), CoordList(3, 6)];” would have worked as expected. I'd want to avoid this wordy explicit way as the list can extend to several hundred pairs. Most likely I need a better way to store the information. @ketmar: Why is initialisation via {} bad (in simple terms please :D)? I noticed while working on this bit of code that I could initialise simple struct variables with {} but couldn't do the same with an array of structs. I guess this is for the same or similar reason to the above. Thanks both for the help.