Re: a way to specily floating-point numbers as bit patters

2017-06-09 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 9 June 2017 at 16:56:46 UTC, ketmar wrote: Petar Kirov [ZombineDev] wrote: Do HexFloats (http://dlang.org/spec/lex#HexFloat) help? hm. i somehow completely missed "%a" format specifier! yeah, "-0x1.6ep-3" did the trick. tnx. i should do my homework *before* posting big

Re: D for Web Development?

2017-06-08 Thread Nicholas Wilson via Digitalmars-d-learn
Welcome! On Thursday, 8 June 2017 at 07:32:44 UTC, Michael Reiland wrote: A few questions: - Is vibe.d the recommended way of doing web work? Yes. Adam D. Ruppe also has some easy to use libraries that may suit your need. - Is that book worth purchasing? Don't know. - Does D have a

Re: import statement placement

2017-06-07 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 7 June 2017 at 12:39:07 UTC, Russel Winder wrote: Are there any idiom rules as to where to put import statements in D? In Python they can go anywhere but PEP-8 suggests they should all go at the top of a file, just after the module documentation string. Well for ones that

Re: GDC options

2017-06-05 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 5 June 2017 at 18:22:31 UTC, Sebastien Alaiwan wrote: On Wednesday, 22 March 2017 at 13:42:21 UTC, Matthias Klumpp wrote: This is why most of my work in Meson to get D supported is adding weird hacks to translate compiler flags between GNU <-> non-GNU <-> DMD. It sucks quite badly,

Re: How to cleanup array of structs?

2017-06-04 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 4 June 2017 at 12:24:44 UTC, Suliman wrote: // Will reuse the array, overwriting existing data. // If other parts of the program are using existing data // in the array, this will lead to hard-to-track-down bugs. mytracks.length = 0; mytracks.assumeSafeAppend(); Could you give an

Re: C macros vs D can't do the right thing

2017-06-03 Thread Nicholas Wilson via Digitalmars-d-learn
On Saturday, 3 June 2017 at 13:17:46 UTC, Russel Winder wrote: A stripped down problem to avoid fluff. The C macro: #define FLOB(t) (sizeof(t)) Can be used in another macro: #define THINGY(a, b) (_THING(a, FLOB(b))) We can use this as in: THINGY(10, __u32) Now the D Way says

Re: "Lazy" initialization of structs

2017-06-01 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 1 June 2017 at 12:04:05 UTC, Daniel Tan Fook Hao wrote: Somehow this code works for me: ```D auto error (int status, string description){ struct Error { int status; string description; } Error err = { status, description }; return

Re: Error: func(const(A) a) is not callable using argument types (const(A)

2017-05-30 Thread Nicholas Wilson via Digitalmars-d-learn
On Tuesday, 30 May 2017 at 10:20:53 UTC, Andrew Edwards wrote: Sorry, rough day. Could someone please explain what this means and how do go about resolving it? Thanks, Andrew If you want to resolve it just do const label_size = CalcTextSize(...); but as others have mentioned make sure

Re: RAII pointers

2017-05-29 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 29 May 2017 at 23:39:17 UTC, Russel Winder wrote: C++ allows one to create types that are pointer types but wrap a primitive pointer to give RAII handling of resources. For example: [...] std.stdio.File does basically the same thing with C's FILE*

Re: Best way for handle missing args in REST interface in vibed

2017-05-29 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 29 May 2017 at 12:23:59 UTC, Suliman wrote: I am doing REST interface with vibed. And thinking about handling errors, if users forgot to pass all expected args in function. For example: foo(int x, int y) // get request { } /api/foo?x=111 And if user is forgot to pass `y` we will

Re: binding to C++

2017-05-26 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 26 May 2017 at 15:17:08 UTC, drug wrote: Trying to bind to cpp code I stop at some moment having undefined reference to some cpp function. But objdump -Ct cpplibrary.so shows me that this cpp function exists in the library. linker message about cpp function is _identical_ to

Re: Any way to reproduce Dart style constructors?

2017-05-25 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 25 May 2017 at 08:34:54 UTC, JN wrote: One of my favourite language features of Dart (other one being factory constructors) are auto-assign constructors, for example (writing it in pseudo-D): class Person { string name; int age; this(this.age, this.name); } would translate

Re: templatized delegate

2017-05-23 Thread Nicholas Wilson via Digitalmars-d-learn
On Tuesday, 23 May 2017 at 10:30:56 UTC, Alex wrote: On Monday, 22 May 2017 at 21:44:17 UTC, ag0aep6g wrote: With that kind of variadics, you're not dealing with a template. A (run-time) variadic delegate is an actual delegate, i.e. a value that can be passed around. But the variadic stuff is

Re: C++ binding issues with C++ function returning a simple POD struct.

2017-05-21 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 21 May 2017 at 19:33:06 UTC, ParticlePeter wrote: I am statically linking to ImGui [1] on Win 10 x64, quite successfully till this issue came up. The noticed error so far comes when an ImGui function returns an ImVec2, a simple POD struct of two float members. I can use this struct

Re: Implicit conversion from 'Ok' to 'Result' type when returning functions

2017-05-21 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 21 May 2017 at 09:55:41 UTC, David Zhang wrote: On Sunday, 21 May 2017 at 09:37:46 UTC, Nicholas Wilson wrote: On Sunday, 21 May 2017 at 09:29:40 UTC, David Zhang wrote: Well then it becomes Result!(T, E) ok(T,E) (T t) { return Result(t); } Result!(T, E) error(T,E)(E e) {

Re: Implicit conversion from 'Ok' to 'Result' type when returning functions

2017-05-21 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 21 May 2017 at 09:29:40 UTC, David Zhang wrote: On Sunday, 21 May 2017 at 09:15:56 UTC, Nicholas Wilson wrote: have free functions Result!(T, ErrorEnum) ok(T)(T t) { return Result(t); } Result!(T, ErrorEnum) error(T)(ErrorEnum e) { return Result(e); } then go if (!foo)

Re: Implicit conversion from 'Ok' to 'Result' type when returning functions

2017-05-21 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 21 May 2017 at 08:44:31 UTC, David Zhang wrote: Hi, I was reading a bit about this in Rust, and their enum type. I was wondering if this is replicate-able in D. What I've got right now is rather clunky, and involves using `typeof(return).ok` and `typeof(return).error)`.

Re: Fluent APIs

2017-05-21 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 21 May 2017 at 05:18:33 UTC, Russel Winder wrote: I am having a crisis of confidence. In two places I have structurally: datum.action() .map!(…) and then the fun starts as I need to actually do a flatMap. In one of the two places I have to: .array .joiner; but

Re: Code improvement for DNA reverse complement?

2017-05-19 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 19 May 2017 at 12:21:10 UTC, biocyberman wrote: On Friday, 19 May 2017 at 09:17:04 UTC, Biotronic wrote: On Friday, 19 May 2017 at 07:29:44 UTC, biocyberman wrote: [...] Question about your implementation: you assume the input may contain newlines, but don't handle any other

Re: How to check a struct exists at a particular memory address?

2017-05-18 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 18 May 2017 at 20:20:47 UTC, Gary Willoughby wrote: This might be a really silly question but: I've allocated some memory like this (Foo is a struct): this._data = cast(Foo*) calloc(n, Foo.sizeof); How can I then later check that there is a valid Foo at `this._data` or

Re: Structure of Arrays vs Array of Structures

2017-05-15 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 15 May 2017 at 06:44:53 UTC, Nordlöw wrote: After having watched Jonathan Blow's talk on Jai https://www.youtube.com/watch?v=TH9VCN6UkyQ=2880s I realized that we should add his Array-of-Structures (AoS) concept to Phobos, preferrably in std.typecons.StructArrays, as something like

Re: Do array literals still always allocate?

2017-05-14 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 14 May 2017 at 12:02:03 UTC, Eugene Wissner wrote: On Sunday, 14 May 2017 at 11:45:12 UTC, ag0aep6g wrote: On 05/14/2017 01:40 PM, Nicholas Wilson wrote: dynamic array literals is what I meant. I don't follow. Can you give an example in code? void main() { ubyte[] arr = [ 1,

Re: Do array literals still always allocate?

2017-05-14 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 14 May 2017 at 10:18:40 UTC, ag0aep6g wrote: On 05/14/2017 01:57 AM, Nicholas Wilson wrote: 1D arrays it doesn't, 2D or higher it does. What do you mean? This works just fine as well: import std.random; import std.stdio; int[2][2] testfunc(int num) @nogc { return [[0,

Re: Do array literals still always allocate?

2017-05-14 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 14 May 2017 at 01:15:03 UTC, Lewis wrote: On Saturday, 13 May 2017 at 19:22:09 UTC, Steven Schveighoffer wrote: It's just out of date. Can't remember the version, but this did use to allocate. It doesn't any more. But only for this case. In most cases it does allocate. Okay cool,

Re: Do array literals still always allocate?

2017-05-13 Thread Nicholas Wilson via Digitalmars-d-learn
On Saturday, 13 May 2017 at 18:32:16 UTC, Lewis wrote: import std.random; import std.stdio; int[4] testfunc(int num) @nogc { return [0, 1, num, 3]; } int main() { int[4] arr = testfunc(uniform(0, 15)); writeln(arr); return 0; } I've read a bunch of stuff that seems to indicate

Re: As many thanks As possible to who crates D and UFCS feature

2017-05-12 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 12 May 2017 at 21:26:01 UTC, Bastiaan Veelo wrote: On Friday, 12 May 2017 at 15:24:52 UTC, k-five wrote: A full version that I just added to my gitgub: https://github.com/k-five/dren You may like getopt[1] for command line argument parsing. https://dlang.org/phobos/std_getopt.html

Re: struct File. property size.

2017-05-11 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 11 May 2017 at 07:24:00 UTC, AntonSotov wrote: import std.stdio; int main() { auto big = File("bigfile", "r+"); //bigfile size 20 GB writeln(big.size); // ERROR! return 0; } // std.exception.ErrnoException@std\stdio.d(1029): Could

Re: Processing a gzipped csv-file by line-by-line

2017-05-10 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 10 May 2017 at 22:20:52 UTC, Nordlöw wrote: What's fastest way to on-the-fly-decompress and process a gzipped csv-fil line by line? Is it possible to combine http://dlang.org/phobos/std_zlib.html with some stream variant of File(path).byLineFast ? I suggest you take a look

Re: How to avoid throwing an exceptions for a built-in function?

2017-05-10 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 10 May 2017 at 12:40:41 UTC, k-five wrote: I have a line of code that uses "to" function in std.conv for a purpose like: int index = to!int( user_apply[ 4 ] ); // string to int When the user_apply[ 4 ] has value, there is no problem; but when it is empty: "" it throws an

Re: parallel foreach

2017-05-01 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 1 May 2017 at 12:42:01 UTC, Alex wrote: Hi all, the last foreach in the following code does not compile... Is this a bug, or is something wrong with my syntax? void main() { import std.parallelism : parallel; import std.range : iota; foreach(i;

Re: C++ Interfacing:'static' array function parameter contradiction

2017-04-28 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 28 April 2017 at 19:08:18 UTC, ParticlePeter wrote: On Friday, 28 April 2017 at 17:57:34 UTC, Ali Çehreli wrote: On 04/28/2017 08:56 AM, ParticlePeter wrote: > C++ Function: > bool cppFunc( float[3] color ); > > D binding: > extern(C++) bool cppFunc( float[3] color ); > > Using with:

Re: Recently added __equal

2017-04-17 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 17 April 2017 at 19:15:06 UTC, Nordlöw wrote: What's the plan for the recent adding __equal overloads at https://github.com/dlang/druntime/pull/1808/files Is it only meant for runtime and phobos to be updated? Or does user-libraries, such as container libraries, need to be updated

Re: check Input

2017-04-17 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 17 April 2017 at 11:51:45 UTC, dennis wrote: Hi, try to build a little programm, but need to know how to check the input. For example: input only numbers: 0 - 9 but 1.5 for example is ok. thanks I will point you to Ali's book (free), it goes through the basics of input and

Re: Compilation problems with GDC/GCC

2017-04-14 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 14 April 2017 at 11:32:57 UTC, DRex wrote: I have project which involves both C and D code. For reasons that are much too long to explain, I have to use GCC to compile the C code into object files (GDC to compile the D code into object files) and then ld to link all the object

Re: Practical difference between template "alias" arguments/normal generic arguments in this case?

2017-04-12 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 12 April 2017 at 11:06:13 UTC, Juanjo Alvarez wrote: Hi! With "alias this" accepting runtime variables I'm struggling to understand the difference between a generic function with an "alias this" parameter and another one with a "runtime" parameter of template type. Example:

Re: Command Line Parsing

2017-04-12 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 12 April 2017 at 09:51:34 UTC, Russel Winder wrote: Are Argon https://github.com/markuslaker/Argon or darg https://github. com/jasonwhite/darg getting traction as the default command line handling system for D or are they just peripheral and everyone just uses std.getopt

Re: Forwarding calls to objects of another type

2017-04-10 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 10 April 2017 at 21:27:34 UTC, Basile B. wrote: 2) This is about the reduce templates. As I've commented, I can't use a template lambda with reduce, but I can use a lambda taking ints as arguments. Why is this? The error message I get when using the template lambda is: "template

Re: Convert this C macro kroundup32 to D mixin?

2017-04-08 Thread Nicholas Wilson via Digitalmars-d-learn
On Saturday, 8 April 2017 at 11:01:34 UTC, biocyberman wrote: On Saturday, 8 April 2017 at 10:09:47 UTC, Mike Parker wrote: T kroundup32(T)(T x) { pragma(inline, true); --(x); (x)|=(x)>>1; (x)|=(x)>>2; (x)|=(x)>>4; (x)|=(x)>>8; (x)|=(x)>>16; return ++(x); } I

Re: Single exe vibe.d app

2017-04-05 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 5 April 2017 at 12:13:38 UTC, Satoshi wrote: Hi, How can I build single exe application with vibe.d (windows)? now it require zlib.dll, libeay32.dll and ssleay32.dll But I need it as single app. As Evilrat notes static libraries are one solution, the catch being you need to get

Re: Covert a complex C header to D

2017-04-05 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 5 April 2017 at 12:27:23 UTC, biocyberman wrote: On Monday, 3 April 2017 at 23:10:49 UTC, Stefan Koch wrote: On Monday, 3 April 2017 at 11:18:21 UTC, Nicholas Wilson wrote: prefer template over string mixins where possible. This will make the code much more readable. My

Re: pyd: implementing __hash__ and __str__ for PyD wrapped classes

2017-04-05 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 5 April 2017 at 09:31:09 UTC, harfel wrote: Dear all, Relatively new to D in general and PyD in particular, I am trying to wrap some D classes I wrote for use in Python. Following the documentation and code examples, I got the basic functionality working. However, I am

Re: OT: It is convert, not covert

2017-04-04 Thread Nicholas Wilson via Digitalmars-d-learn
On Tuesday, 4 April 2017 at 09:37:12 UTC, biocyberman wrote: On Tuesday, 4 April 2017 at 05:29:42 UTC, Ali Çehreli wrote: Covert has a very different meaning. :) Ali Thanks Ali. My fingers argued they are the same :) And I can't find a way to edit my post after posting. I would love to

Re: Covert a complex C header to D

2017-04-03 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 3 April 2017 at 10:04:53 UTC, biocyberman wrote: On Monday, 3 April 2017 at 00:00:04 UTC, Nicholas Wilson wrote: On Sunday, 2 April 2017 at 21:43:52 UTC, biocyberman wrote: template __KHASH_TYPE(string name){ "struct kh_" ~ name ~"_t { " ~ "khint_t n_buckets,

Re: Covert a complex C header to D

2017-04-02 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 2 April 2017 at 21:43:52 UTC, biocyberman wrote: template __KHASH_TYPE(string name){ "struct kh_" ~ name ~"_t { " ~ "khint_t n_buckets, size, n_occupied, upper_bound; " ~ "khint32_t *flags; " ~ "khkey_t *keys; " ~

Re: Covert a complex C header to D

2017-04-02 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 2 April 2017 at 21:43:52 UTC, biocyberman wrote: khash.h (http://attractivechaos.github.io/klib/#Khash%3A%20generic%20hash%20table) is a part of klib library in C. I want to covert it to D in the process of learning deeper about D. First I tried with Dstep

Re: clz

2017-04-01 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 2 April 2017 at 05:33:31 UTC, rikki cattermole wrote: On 02/04/2017 6:28 AM, Nicholas Wilson wrote: [...] BSR looks like its working. http://x86.renejeschke.de/html/file_module_x86_id_20.html http://stackoverflow.com/a/9353998 Ahh there's a subtraction involved. Many thanks!

clz

2017-04-01 Thread Nicholas Wilson via Digitalmars-d-learn
I have this c++ code with clang uint32_t val = 490560; int leading_zeros = __builtin_clz( val << 1); // equals 0 int leading_ones = __builtin_clz(~val << 1); // equals 1 return (lz == 0 ? lo - 1 : -lz); and want to translate it to D. import core.bitop : bsf,bsr; uint val = 490560;

Re: Building DMD

2017-03-31 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 31 March 2017 at 07:23:42 UTC, Inquie wrote: I am trying to build DMD 64-bit. I was able to build everything after getting the paths fixed for zlib, druntime, and phobos. Everything seems to compile. I replaced all the files generated in to the dmd directories of the old ones.

Re: how to define my own traits

2017-03-27 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 27 March 2017 at 21:18:31 UTC, XavierAP wrote: When I first read about inout as a device to obviate code duplication typical in C++ const ref overloads, I liked it but I assumed it was implemented by lowering it into the actual duplicate overloads. Though I'm not even sure right now

Re: Exporting template function instances to C

2017-03-25 Thread Nicholas Wilson via Digitalmars-d-learn
On Saturday, 25 March 2017 at 02:21:33 UTC, data pulverizer wrote: Thanks a lot ... I was half joking playing with the name "mangling" but I appreciate your explanations and suggestions. This is the internet, I can't tell if you're a newb or sarcastic, and given this is a learn forum I'm

Re: Exporting template function instances to C

2017-03-23 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 23 March 2017 at 19:46:43 UTC, data pulverizer wrote: On Thursday, 23 March 2017 at 17:58:21 UTC, H. S. Teoh wrote: On Thu, Mar 23, 2017 at 05:29:22PM +, data pulverizer via Thanks. Is there a less ham-handed way of exporting them other than wrapping them in functions as I

Re: Undefined Reference calling D from C using static linking

2017-03-23 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 23 March 2017 at 12:06:14 UTC, data pulverizer wrote: On Thursday, 23 March 2017 at 11:32:25 UTC, Nicholas Wilson wrote: On Thursday, 23 March 2017 at 10:49:37 UTC, data pulverizer wrote: [...] Those functions are the bounds checking function, the non unittest assert function,

Re: Undefined Reference calling D from C using static linking

2017-03-23 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 23 March 2017 at 10:49:37 UTC, data pulverizer wrote: On Thursday, 23 March 2017 at 10:16:22 UTC, Nicholas Wilson wrote: It has to do with module references to druntime stuff. You can either try adding a pragma(LDC_no_module_info); //I think it is spelled correctly. or you can

Re: Undefined Reference calling D from C using static linking

2017-03-23 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 23 March 2017 at 09:11:28 UTC, data pulverizer wrote: I am trying to call a D function from C. Here is the D code: ``` /* dcode.d */ extern (C) nothrow @nogc @system { double multNum(double x, double y) { return x*y; } } ``` [...] It has to do with module

Re: Delay allocating class instance in stack.

2017-03-22 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 22 March 2017 at 08:57:34 UTC, ANtlord wrote: On Wednesday, 22 March 2017 at 06:47:26 UTC, Ali Çehreli wrote: On 03/21/2017 09:57 PM, ANtlord wrote: > Thank you for clarification. But I have one more question. Do I have to > use destroy for deallocating object from stack? Yes

Re: Get most D type from type

2017-03-17 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 17 March 2017 at 23:54:36 UTC, Hussien wrote: I am using Parameters and ReturnType which give me the "name" of the type used. e.g., int foo(SomeEnum) will give SomeEnum and int for the type respectively. What I need to do, is also get the D types that these use. int is int, but

Re: scope(~this)

2017-03-12 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 12 March 2017 at 21:38:44 UTC, Inquie wrote: Is there any easy way to create a scope for termination of the object? I have a template method that takes a type and allocates and deallocates based on that type. class bar { void foo(T)() { T x; alloc(x);

Re: Code style for property

2017-03-12 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 12 March 2017 at 10:47:35 UTC, Andrey wrote: Hello, how better to declare properties, for example I have class: class Foo { this(in int x, in int y, Bar bar) { this.x = x; this.y = y; this.bar = bar; } private: int x; int y; Bar bar; } And

Re: Best ways to declare associative arrays

2017-03-12 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 12 March 2017 at 07:58:40 UTC, helxi wrote: How would an experienced programmer declare an associative array of strings that has 2 keys? My initial impression was string[string][2] my_array; which does not seem to work. Here is a snippet of the code I am working on: import

Re: Is there a more elegant way to do this?

2017-03-11 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 12 March 2017 at 05:13:41 UTC, bauss wrote: I was wondering if there's a more elegant way to do something like this? template BitSize(T) { enum BitSize = T.sizeof * 8; } struct Data(ParentType,ChildType) { @property { ChildType low() { return

Re: C interface provides a pointer and a length... wrap without copying?

2017-03-11 Thread Nicholas Wilson via Digitalmars-d-learn
On Saturday, 11 March 2017 at 22:39:02 UTC, cy wrote: So a lovely C library does its own opaque allocation, and provides access to the malloc'd memory, and that memory's length. Instead of copying the results into garbage collected memory (which would probably be smart) I was thinking about

Re: DUB specify version identifier on command line?

2017-03-07 Thread Nicholas Wilson via Digitalmars-d-learn
On Tuesday, 7 March 2017 at 22:30:30 UTC, XavierAP wrote: I'm talking about the conditional compilation keyword "version", not about version strings. I've looked in DUB's help and reference [1][2] but can't seem to find how to solve my problem. On the command line it seems to be possible to

Re: Building a project with CMAKE

2017-03-02 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 2 March 2017 at 09:13:40 UTC, berni wrote: On Tuesday, 28 February 2017 at 17:09:28 UTC, berni wrote: I'm using CMAKE to build my project. [...] Just a note: I now asked the same question on the cmake mailing list. Maybe, it's the better place to do so... I would take a look

Re: FEM library?

2017-02-22 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 22 February 2017 at 11:37:41 UTC, XavierAP wrote: @Nicholas yes such a FEM library to be developed would heavily depend on Mir. Ilya Yaroshenko pointed me to it in another thread. I didn't know about DlangScience, thanks. Looks like there is some overlap? I think mir used to be

Re: FEM library?

2017-02-21 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 22 February 2017 at 00:51:46 UTC, XavierAP wrote: Is there any D library for FEM (Finite Element Method, see Wikipedia) solving, meshing, etc... already existing somewhere? I'm asking because I'm considering making something in that field as a personal learning project.

Re: Converting multiple inheritance code into C ++ for D language

2017-02-17 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 17 February 2017 at 23:11:25 UTC, Jean Cesar wrote: import std.stdio; import std.string; I've been reading a bit about multi-inheritance in D, but I have to use interface like C # to use multiple inheritance, but I have the code in C ++ that I've been testing to understand how it

Re: Gc collects trigger access violation exception

2017-02-12 Thread Nicholas Wilson via Digitalmars-d-learn
On Saturday, 11 February 2017 at 03:21:29 UTC, mashomee wrote: Hi, everyone. I have a thread running in Dll. But it always halts because of access violation exception when GC begins collecting. [...] It's great that you're found a workaround. If you weren't doing something funky to

Re: Mallocator and 'shared'

2017-02-10 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 10 February 2017 at 23:57:18 UTC, bitwise wrote: https://github.com/dlang/phobos/blob/cd7846eb96ea7d2fa65ccb04b4ca5d5b0d1d4a63/std/experimental/allocator/mallocator.d#L63-L65 Looking at Mallocator, the use of 'shared' doesn't seem correct to me. [...] IIRC you're supposed to use

Re: D idom for removing array elements

2017-01-26 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 26 January 2017 at 08:22:09 UTC, albert-j wrote: What is the D idiom for removing array elements that are present in another array? Is this the right/fastest way? int[] a = [1, 2, 3, 4, 5, 6, 7, 4]; int[] b = [3, 4, 6]; auto c = a.remove!(x => b.canFind(x)); assert(c == [1, 2, 5,

Re: Can't understand if deallocation happens?

2017-01-22 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 23 January 2017 at 06:42:00 UTC, Suliman wrote: You have *two* distinct strings here. Yes, I understand, I am trying to find out how it's work on low level. Any ideas why zero is used? string *literals* in d are nul terminated to ease interoperation with C so string s = "foo";

Re: Can't understand if deallocation happens?

2017-01-22 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 22 January 2017 at 12:49:11 UTC, Suliman wrote: import std.stdio; import std.string; import core.memory; void main() { char [] str = "aaa".dup; char [] *str_ptr = writeln("before: ", str_ptr.ptr);// address of structure writeln(*str_ptr.ptr); // address of data

Re: Why does multidimensional arrays not allocate properly?

2017-01-22 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 22 January 2017 at 08:18:35 UTC, Jot wrote: On Sunday, 22 January 2017 at 08:07:26 UTC, rikki cattermole wrote: On 22/01/2017 9:05 PM, Jot wrote: auto x = new int[][](n,m); But one cannot freely assign anywhere in x: x[3,6] = 4 crashes. I, can, of course, convert everything to a

Re: @nogc and opengl errors check

2017-01-20 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 20 January 2017 at 22:47:17 UTC, Xavier Bigand wrote: Hi, I am writing some code with opengl commands that I want to check in debug, so I am using the function checkgl (from glamour lib). The issue is that checkgl throw exception and can't be @nogc, I had try to use

Re: Intelligent enums

2017-01-18 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 19 January 2017 at 03:47:34 UTC, Ignacious wrote: On Thursday, 19 January 2017 at 02:59:04 UTC, Ignacious wrote: I have the need to create an enum flag like structure to specify certain properties of a type easily. e.g., enum properties { Red, Blue, Hot, Sexy,

Re: DMD Refuses to Compile Multiple Source Files

2017-01-18 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 18 January 2017 at 19:28:20 UTC, Samwise wrote: On Wednesday, 18 January 2017 at 04:25:42 UTC, Mike Parker wrote: extern(C), not simply extern. It turns off the name mangling. But really, the proper thing to do is to drop the prototype and import the module with the

Re: Printing a floats in maximum precision

2017-01-17 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 18 January 2017 at 00:23:37 UTC, pineapple wrote: On Wednesday, 18 January 2017 at 00:09:42 UTC, Nordlöw wrote: What's the easiest way to print a double in maximum precision? https://github.com/pineapplemachine/mach.d/blob/master/mach/text/numeric/floats.d#L60 You can also try

Re: How can I implement this in D: a variant array of varying function pointer types (diff number of args or types)

2017-01-17 Thread Nicholas Wilson via Digitalmars-d-learn
On Tuesday, 17 January 2017 at 10:49:14 UTC, Enjoys Math wrote: Z add(Z...)(Z a...) { return a + b; } func[] operatorPool = [!int]; Variant library isn't liking that. Removing & causes another error. Essentially I want a pool of all operators that I define, but these operators can

Re: Initializing floating point types with explicit mantisa and exponent

2017-01-16 Thread Nicholas Wilson via Digitalmars-d-learn
On Tuesday, 17 January 2017 at 00:08:24 UTC, Nordlöw wrote: How do I best initialize a D double to an exact mantissa and exponent representation? I'm specifically interested in 2^^i for all i in [min_exp, max_exp] See std.bitmanip : FloatRep , DoubleRep;

Re: Hopefully a simple question...

2017-01-13 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 13 January 2017 at 16:56:43 UTC, WhatMeWorry wrote: I'm converting some C++ and glm code to D and gl3n. And I'm stumped at the following line. GLboolean CheckCollision(BallObject , GameObject ) // AABB - Circle collision { // Get center point circle first glm::vec2

Re: switch to member

2017-01-13 Thread Nicholas Wilson via Digitalmars-d-learn
On Saturday, 14 January 2017 at 03:20:24 UTC, Ignacious wrote: When doing common functionality for a switch, is there any way to optimize: switch(x) { case X: q.X = e; break; case Y: q.Y = e; break etc... } e is basically a value that, depending

Re: template instance does not match template declaration

2017-01-07 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 8 January 2017 at 03:27:26 UTC, Fabrice Marie wrote: Hi, On my first attempt to create a templated class, I'm hitting an issue that I can't seem to resolve. I've dustmite'd the code down to: class Cache(O, K, F) { } void main() { class BasicObject { }

Re: Iterate module membres

2017-01-07 Thread Nicholas Wilson via Digitalmars-d-learn
On Saturday, 7 January 2017 at 09:46:54 UTC, crimaniak wrote: Hi! I need to iterate module members and find specific classes (and make tuple). class foo{}; pragma (msg, __traits(allMembers,mixin(__MODULE__))); gives me empty tuple. I found also this thread from 2011:

Re: Reducing visual clutter.

2017-01-01 Thread Nicholas Wilson via Digitalmars-d-learn
On Saturday, 31 December 2016 at 12:31:07 UTC, Nicholas Wilson wrote: On Saturday, 31 December 2016 at 11:39:39 UTC, Nicholas Wilson wrote: [...] Oh and `kernel` could be a template function that would need its args forwarded to it. It's worse than that `kernel` could be a qualified name

Re: Reducing visual clutter.

2016-12-31 Thread Nicholas Wilson via Digitalmars-d-learn
On Saturday, 31 December 2016 at 11:39:39 UTC, Nicholas Wilson wrote: [...] Oh and `kernel` could be a template function that would need its args forwarded to it.

Reducing visual clutter.

2016-12-31 Thread Nicholas Wilson via Digitalmars-d-learn
so I have ``` struct Pipeline { // some fields. ref typeof(this) invoke(alias kernel)(TransformArgsOf!kernel args) { //... return this; } } ``` and it will be used like ``` void fun1(int a) {} void fun2(double b) {} void funn(ulong c) {} //... auto pipe =

Re: Android Status

2016-12-29 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 28 December 2016 at 23:33:57 UTC, Ignacious wrote: What is the current status for building android apps in D? I would like to create simple graphic based apps but don't wanna get bogged down in trying to get car moving without any wheels.

Re: How to initialize a associative array?

2016-12-23 Thread Nicholas Wilson via Digitalmars-d-learn
On Saturday, 24 December 2016 at 00:57:04 UTC, Yuxuan Shui wrote: On Saturday, 24 December 2016 at 00:55:01 UTC, Yuxuan Shui wrote: I tried this: immutable int[char] xx = ['Q':0, 'B':1, 'N':2, 'R':3, 'P':4]; And got a "non-constant expression" error (with or without 'immutable').

Re: returning struct, destructor

2016-12-21 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 21 December 2016 at 11:45:18 UTC, Eugene Wissner wrote: Consider we have a function that returns a struct. So for example: import std.stdio; struct A { ~this() { writeln("Destruct"); } } A myFunc() { auto a = A(), b = A(); if (false) { return a;

Re: sort, .array and folding on immutable data (finding most common character in column of matrix)

2016-12-19 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 19 December 2016 at 11:42:55 UTC, Ali wrote: On Monday, 19 December 2016 at 10:03:34 UTC, Nicholas Wilson wrote: [...] The seedless version without the typeof(a)(b[0], b[1]) hack (with default inited T) seems to crap out with: [...] Ah, oh well. It was nice in theory. [...]

Re: sort, .array and folding on immutable data (finding most common character in column of matrix)

2016-12-19 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 19 December 2016 at 09:24:38 UTC, Ali wrote: On Monday, 19 December 2016 at 00:11:49 UTC, Nicholas Wilson wrote: [...] Ok so laziness stops as soon as sort is required on a range then? No. Because a lazy range is not random access, and therefore does not meet sorts requirement.

Re: Pointer to private structure

2016-12-18 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 19 December 2016 at 05:51:09 UTC, Nikhil Jacob wrote: In C, we can define a struct without body in an include file and use pointer to that structure For examples in public header file. struct data; data* new_data(); We can then define the elements of struct data privately inside

Re: sort, .array and folding on immutable data (finding most common character in column of matrix)

2016-12-18 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 18 December 2016 at 22:26:50 UTC, Ali wrote: Hey, so I have this data file that has a list of a string of characters separated by new lines. The task is to find the most common letter in each column. Ie if file is: abc axy cxc Then the letters are a (column 1), x and c. I've

Re: extern(C++) struct - what is it?

2016-12-16 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 16 December 2016 at 12:40:19 UTC, Ilya Yaroshenko wrote: It was in DMD sources. How it can be used? Are methods virtual? How multiple inheritance works? Can this be used in betterC mode? What different between classes in C++? Thanks, Ilya See also

Re: extern(C++) struct - what is it?

2016-12-16 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 16 December 2016 at 12:40:19 UTC, Ilya Yaroshenko wrote: It was in DMD sources. How it can be used? Like any other struct. Are methods virtual? No. How multiple inheritance works? Don't think it works. Can this be used in betterC mode? Yes all it should affect is the

Re: Dynamically Loading a D DLL From a D Program

2016-12-14 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 14 December 2016 at 21:38:27 UTC, Benjiro wrote: Silly question: In this post about static / dynamic loading, i noticed that it uses the dlopen/dlclose, while there is a core.runtime for handling the loading. http://dlang.org/dll-linux.html#dso9 Dynamically Loading a D DLL From

Re: Question about compile-time functions.

2016-12-14 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 14 December 2016 at 07:15:08 UTC, Bauss wrote: If a function is only called during compile-time will it be available at runtime? It depends. When linking unused functions can be removed by -gc-sections, but only when linking an executable. But obviously if you use it at

Re: How to override impure function from pure function

2016-12-12 Thread Nicholas Wilson via Digitalmars-d-learn
On Tuesday, 13 December 2016 at 05:13:01 UTC, Nikhil Jacob wrote: I mistook the original statement to mean that an impure function can be called from a pure function with some manual overrides. Thank you for the clarification. Yeah you can't do that, except in a debug statement. You can

Re: How to override impure function from pure function

2016-12-12 Thread Nicholas Wilson via Digitalmars-d-learn
On Tuesday, 13 December 2016 at 04:48:11 UTC, Nikhil Jacob wrote: In the D spec for pure functions it says that a pure function can override "can override an impure function, but an impure function cannot override a pure one" Can anyone help me how to do this ? what this means is class

Re: Check whether function/delegate uses any shared or global variables

2016-12-12 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 12 December 2016 at 11:37:04 UTC, Nikhil Jacob wrote: On Monday, 12 December 2016 at 11:15:28 UTC, Nicholas Wilson wrote: On Monday, 12 December 2016 at 11:02:21 UTC, Nikhil Jacob wrote: Is there any way to check whether a function/delegate passed to a function uses any shared or

Re: Sanitizing forms in vibe.d. How?

2016-12-12 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 12 December 2016 at 10:25:05 UTC, aberba wrote: On Monday, 12 December 2016 at 00:42:54 UTC, Nicholas Wilson wrote: On Sunday, 11 December 2016 at 18:30:54 UTC, aberba wrote: You can enforce that the string that you receive is an email address with `isEmail` from `std.net.isemail`

<    1   2   3   4   5   6   7   >