Re: Temporarily protect array from garbage collection

2014-04-24 Thread Justin Whear via Digitalmars-d-learn
On Thu, 24 Apr 2014 19:55:37 +, Lars T. Kyllingstad wrote: Is it possible to temporarily prevent the garbage collector from collecting a memory block even if there are no references to it? The use case is as follows: I want to call a C library function which expects to take ownership

Re: AES encryption with openssl bindings

2014-04-25 Thread Justin Whear via Digitalmars-d-learn
On Fri, 25 Apr 2014 19:06:31 +, brad clawsie wrote: hi everyone. I'm trying to symmetrically encrypt some text using the openssl bindings. My code compiles and fails silently. Clearly there is something very wrong with it - it could be my novice D skills, or my misuse of the openssl

Re: Socket server + thread: cpu usage

2014-04-29 Thread Justin Whear via Digitalmars-d-learn
On Tue, 29 Apr 2014 17:16:32 +, Tim wrote: Hi guys, I've the following snipped: TcpSocket oSocket = new TcpSocket(AddressFamily.INET); oSocket.bind(new InternetAddress(127.0.0.1, 12345)); oSocket.blocking(false); oSocket.listen(0); while(true) { try { Socket

Re: byCodePoint for a range of chars

2014-05-20 Thread Justin Whear via Digitalmars-d-learn
On Tue, 20 May 2014 17:59:07 +, John Colvin wrote: Given a range with element type char, what's the best way of iterating over it by code-point, without filling an array first? Related to this: What's the status of std.utf and std.encoding? The comments in std.encoding say that some

Re: Example of filtering a Linked List that hold a custom class (Tango)

2014-06-05 Thread Justin Whear via Digitalmars-d-learn
On Thu, 05 Jun 2014 17:50:37 +, JJDuck wrote: let say I have a Linked List(tango) that holds custom class and how do I filter the LinkedList to extract the items that I want according to a particular field (a integer field) from my custom class? Is it easier to do it using phobos'

Re: Run child process with null stdin/stdout

2014-06-18 Thread Justin Whear via Digitalmars-d-learn
On Wed, 18 Jun 2014 19:37:58 +, David Nadlinger wrote: Hi all, is there a platform independent way to do the equivalent of some_program /dev/null /dev/null using std.process? I neither want to capture/print the standard output of the child process nor have anything available on its

Re: String cast error

2014-06-18 Thread Justin Whear via Digitalmars-d-learn
On Thu, 19 Jun 2014 00:05:36 +, SomeRiz wrote: Hi. My code running: http://dpaste.dzfl.pl/2183586524df Output: SerialNumber 927160020 (X = Some Numbers) How do I delete SerialNumber text? Example string SomeRiz = system(a); I get an error: b.d(10): Error:

Re: popcnt instruction

2014-06-24 Thread Justin Whear via Digitalmars-d-learn
On Tue, 24 Jun 2014 16:34:42 +, Archibald wrote: Hello, I need to use the popcnt processor instruction in a performance critical section. Is there a way to do this in D? D's inline assembler is described here: http://dlang.org/iasm.html

Re: Converting from C const(dchar*) to dstring

2014-06-24 Thread Justin Whear via Digitalmars-d-learn
On Tue, 24 Jun 2014 18:17:06 +, Danyal Zia wrote: On Tuesday, 24 June 2014 at 17:59:41 UTC, Steven Schveighoffer wrote: const(dchar *)x = ...; // assuming 0 terminated dstring text = x[0..x.strlen].idup; -Steve const(dchar)* x = Hello\0; dstring text = x[0..x.strlen].idup;

Re: popcnt instruction

2014-06-24 Thread Justin Whear via Digitalmars-d-learn
On Tue, 24 Jun 2014 19:44:52 +, Archibald wrote: Thanks for the answers. Unfortunately it seems like popcnt isn't supported by D's inline assembler. What if I import it as an external C function, will I get optimal performance? DMD 2.065 seems to support it. What compiler are you using

Re: popcnt instruction

2014-06-24 Thread Justin Whear via Digitalmars-d-learn
Also, see: http://forum.dlang.org/thread/alirjgygnwpifkijx...@forum.dlang.org

Re: std.algorithm.map - function by reference

2014-06-24 Thread Justin Whear via Digitalmars-d-learn
On Tue, 24 Jun 2014 21:46:15 +, kuba wrote: Hi there, I was wondering if std.algorithm.map can take functions with parameters passed by reference? The main point here is to avoid unnecessary copies by perhaps I'm using the wrong tool for the job. No, `map` is a _projection_ function

Re: Using two flags in conditonal compilation (version)

2014-06-25 Thread Justin Whear via Digitalmars-d-learn
On Wed, 25 Jun 2014 20:24:30 +, Danyal Zia wrote: Hi, In the development of my library, I'm in a position where I need to add support for multiple compilers. For instance, supporting both the assembly of LDC/DMD and GDC. I want to do something like: version(DigitalMars LDC) { }

Re: Bidirectional PIPE, and do not wait for child to terminate

2014-07-01 Thread Justin Whear via Digitalmars-d-learn
On Tue, 01 Jul 2014 13:00:47 +, seany wrote: I read the manual here: http://dlang.org/phobos/std_process.html#.spawnProcess However, I need to (I can not remember, nor can I find in the forums any info thereon) create 1. Bidirectional Pipes - I would like to write something to a

Re: zipWith or map

2014-07-01 Thread Justin Whear via Digitalmars-d-learn
On Tue, 01 Jul 2014 17:49:53 +, Gecko wrote: Hello, is there a fancy way do a zipWith (map with multiple ranges). There is no in std.algorithm, or does it have a different name? There is a zip function in std.range. It produces a range of tuples that you can then map over.

Re: Bidirectional PIPE, and do not wait for child to terminate

2014-07-01 Thread Justin Whear via Digitalmars-d-learn
On Tue, 01 Jul 2014 13:00:47 +, seany wrote: 1. Bidirectional Pipes - I would like to write something to a second program (UNIX, resp GNU/LINUX environment) and listen to what it has to say. BTW, for convenience, you probably want to use pipeProcess or pipeShell.

Re: Bidirectional PIPE, and do not wait for child to terminate

2014-07-01 Thread Justin Whear via Digitalmars-d-learn
On Tue, 01 Jul 2014 20:42:14 +, seany wrote: On Tuesday, 1 July 2014 at 15:32:31 UTC, Justin Whear wrote: A pipe can be unidirectional only, but you can use more than one. and what about FIFO or LIFO s? You can use the C mkfifo function (import core.sys.posix.sys.stat) to create

Re: Bidirectional PIPE, and do not wait for child to terminate

2014-07-01 Thread Justin Whear via Digitalmars-d-learn
On Tue, 01 Jul 2014 21:00:58 +, Justin Whear wrote: On Tue, 01 Jul 2014 20:42:14 +, seany wrote: On Tuesday, 1 July 2014 at 15:32:31 UTC, Justin Whear wrote: A pipe can be unidirectional only, but you can use more than one. and what about FIFO or LIFO s? You can use the C

Re: Sparse Aggregate Assignment/Initialization (RAII)

2014-07-07 Thread Justin Whear via Digitalmars-d-learn
On Mon, 07 Jul 2014 21:34:05 +, Nordlöw wrote: However using this function through UFCS auto cx = new C().set!x(11); fails as algorithm_ex.d(1257,17): Error: template algorithm_ex.set cannot deduce function from argument types !(x)(C, int), candidates are:

Re: Sparse Aggregate Assignment/Initialization (RAII)

2014-07-07 Thread Justin Whear via Digitalmars-d-learn
On Mon, 07 Jul 2014 21:49:22 +, Justin Whear wrote: On Mon, 07 Jul 2014 21:34:05 +, Nordlöw wrote: However using this function through UFCS auto cx = new C().set!x(11); fails as algorithm_ex.d(1257,17): Error: template algorithm_ex.set cannot deduce function from

Re: Capture offset of matches in std.regex.matchAll?

2014-07-08 Thread Justin Whear via Digitalmars-d-learn
On Mon, 07 Jul 2014 21:32:29 +, JD wrote: I'm using a compile time regex to find some tags in an input string. Is it possible to capture the offset of the matches in some way? Otherwise I have to calculate the offsets myself by iterating over the results of matchAll. Thanks, Jeroen

Re: Introspecting a Module with Traits, allMembers

2014-07-09 Thread Justin Whear via Digitalmars-d-learn
On Wed, 09 Jul 2014 20:07:56 +, NCrashed wrote: On Wednesday, 9 July 2014 at 20:04:47 UTC, Maxime Chevalier-Boisvert wrote: auto members = [__traits(allMembers, ir.ir)]; pragma(msg, members); Have you tried without quotes? pragma(msg, __traits(allMembers, ir.ir)); Also, looks like it

Re: Sum a lot of numbers...

2014-07-10 Thread Justin Whear via Digitalmars-d-learn
On Thu, 10 Jul 2014 17:16:00 +, Alexandre wrote: Hi :) I need to sum a list of numbers... but, when I calculate the sum of this numbers, I got a simplify representation of sum: 2.97506e+,12 How I can make to get the correctly representation of this number ? A full decimal

Re: Sum a lot of numbers...

2014-07-10 Thread Justin Whear via Digitalmars-d-learn
On Thu, 10 Jul 2014 17:17:40 +, Justin Whear wrote: On Thu, 10 Jul 2014 17:16:00 +, Alexandre wrote: Hi :) I need to sum a list of numbers... but, when I calculate the sum of this numbers, I got a simplify representation of sum: 2.97506e+,12 How I can make to get the

Re: Binary IO

2014-07-17 Thread Justin Whear via Digitalmars-d-learn
On Thu, 17 Jul 2014 20:35:24 +, seany wrote: Hello, What are the methods of unformatted binary IO in d? File.write seems to use formatted ASCII . I would like to write a binary file that I cna read in fortan. Similarly, I would like to write a file in Fortan, unformatted IO, and read

Re: Binary IO

2014-07-17 Thread Justin Whear via Digitalmars-d-learn
On Thu, 17 Jul 2014 21:01:35 +, seany wrote: Data is a built in type? what includefile do I need? No, just used as an example. What sort of data are reading from the binary file?

Re: Compile-Time Interfaces (Concepts)

2014-07-17 Thread Justin Whear via Digitalmars-d-learn
On Thu, 17 Jul 2014 22:49:30 +, Nordlöw wrote: AFAIK there is no compile-time variant of interfaces right? Why is that? Wouldn't it be nice to say something like struct SomeRange realize InputRange { /* implement members of InputRange */ } and then the

Re: Compile-Time Interfaces (Concepts)

2014-07-17 Thread Justin Whear via Digitalmars-d-learn
On Thu, 17 Jul 2014 23:06:30 +, bearophile wrote: Justin Whear: What benefits would accrue from adding this? Static verification that a structure implements the specified concepts? Not just that, but also the other way around: static verification that a Concept is strictly

Re: D JSON (WAT?!)

2014-07-24 Thread Justin Whear via Digitalmars-d-learn
On Thu, 24 Jul 2014 15:15:36 +, Pavel wrote: Ok, let me start with the sample code: import std.stdio; import std.json; void main() { scope(failure) writeln(FaILED!!); string jsonStr = `{ name: 1, type: r }`; auto parsed = parseJSON(jsonStr); string s =

Re: D JSON (WAT?!)

2014-07-24 Thread Justin Whear via Digitalmars-d-learn
On Thu, 24 Jul 2014 15:54:20 +, Pavel wrote: On Thursday, 24 July 2014 at 15:48:32 UTC, Edwin van Leeuwen wrote: On Thursday, 24 July 2014 at 15:42:58 UTC, Pavel wrote: On Thursday, 24 July 2014 at 15:38:06 UTC, John Colvin wrote: On Thursday, 24 July 2014 at 15:32:29 UTC, John Colvin

Re: D JSON (WAT?!)

2014-07-24 Thread Justin Whear via Digitalmars-d-learn
On Thu, 24 Jul 2014 16:04:01 +, Pavel wrote: Thanks to all you folks who explained in operator for me. My bad. Let's focus on the real problem, which is JSON wrapper class. Is it needed? Wouldn't it be better to get AA from parseJSON? The following are valid JSON: auto json1 =

Re: D JSON (WAT?!)

2014-07-24 Thread Justin Whear via Digitalmars-d-learn
On Thu, 24 Jul 2014 13:49:27 -0300, Ary Borenszweig wrote: Nope, a JSON can only be an array or an object (hash). Ary, can you point out the place in the spec where this is specified? Not to be pedantic, but the spec only seems to define a JSON value, not a JSON document.

Re: D JSON (WAT?!)

2014-07-24 Thread Justin Whear via Digitalmars-d-learn
On Thu, 24 Jul 2014 16:14:15 +, Pavel wrote: On Thursday, 24 July 2014 at 16:09:25 UTC, Justin Whear wrote: On Thu, 24 Jul 2014 16:04:01 +, Pavel wrote: Thanks to all you folks who explained in operator for me. My bad. Let's focus on the real problem, which is JSON wrapper class. Is

Re: How to copy an object to separate allocated memory?

2014-07-24 Thread Justin Whear via Digitalmars-d-learn
On Thu, 24 Jul 2014 17:05:17 +, Gary Willoughby wrote: I was reading Ali's book (http://ddili.org/ders/d.en/index.html) and saw this piece of code on how to get the true size of an object: MyClass* buffer = cast(MyClass*)GC.calloc(__traits(classInstanceSize, MyClass) * 10); That got

Re: How to copy an object to separate allocated memory?

2014-07-24 Thread Justin Whear via Digitalmars-d-learn
On Thu, 24 Jul 2014 17:07:29 +, Justin Whear wrote: On Thu, 24 Jul 2014 17:05:17 +, Gary Willoughby wrote: I was reading Ali's book (http://ddili.org/ders/d.en/index.html) and saw this piece of code on how to get the true size of an object: MyClass* buffer =

Re: Mocking serial device

2014-07-24 Thread Justin Whear via Digitalmars-d-learn
On Thu, 24 Jul 2014 17:15:02 +, Alfredo Palhares wrote: Hello, I am writing an application that connects to a serial device in /dev/ttyUSB0 and trows some binary data back and forth. How can i mock and run some unit testing without having to connect to the device every time? How

Re: D JSON (WAT?!)

2014-07-25 Thread Justin Whear via Digitalmars-d-learn
On Thu, 24 Jul 2014 22:00:43 +, Pavel wrote: On Thursday, 24 July 2014 at 16:09:25 UTC, Justin Whear wrote: On Thu, 24 Jul 2014 16:04:01 +, Pavel wrote: Thanks to all you folks who explained in operator for me. My bad. Let's focus on the real problem, which is JSON wrapper class. Is

Re: pointer array?

2014-07-30 Thread Justin Whear via Digitalmars-d-learn
On Wed, 30 Jul 2014 15:44:14 +, seany wrote: However some code is in C, legacy code, and for speed resons. So in some cases, I would like to send a bunch of variables , ints, dubles and floats to an external C function. The thing is, I do not always know the number of variables, so my

Re: Max/Min values in an associative array

2014-08-06 Thread Justin Whear via Digitalmars-d-learn
On Wed, 06 Aug 2014 17:57:54 +, TJB wrote: I am trying to find the max and min values in an associative array. Say I have: double[char] bids; bid['A'] = 37.50; bid['B'] = 38.11; bid['C'] = 36.12; How can I find the max and min values. I am thinking that I need to use max and min

Re: Very Stupid Regex question

2014-08-07 Thread Justin Whear via Digitalmars-d-learn
On Thu, 07 Aug 2014 16:05:16 +, seany wrote: obviously there are ways like counting the match length, and then using the maximum length, instead of breaking as soon as a match is found. Are there any other better ways? You're not really using regexes properly. You want to greedily

Re: Very Stupid Regex question

2014-08-07 Thread Justin Whear via Digitalmars-d-learn
On Thu, 07 Aug 2014 10:22:37 -0700, H. S. Teoh via Digitalmars-d-learn wrote: So basically you have a file containing regex patterns, and you want to find the longest match among them? // Longer patterns match first patterns.sort!((a,b) = a.length b.length); // Build

Re: D JSON (WAT?!)

2014-08-08 Thread Justin Whear via Digitalmars-d-learn
On Fri, 08 Aug 2014 14:07:33 +, Pavel wrote: I know that as per JSON spec there's no boolean type specified, only separate true and false values, which are specified as type in http://dlang.org/library/std/json/JSON_TYPE.html, so I guess the only way to check boolean in JSONValue it is

Re: Separate Printing Mantissa and Exponent of a Floating Point

2014-08-11 Thread Justin Whear via Digitalmars-d-learn
On Mon, 11 Aug 2014 13:47:13 +, Nordlöw wrote: Is there a way to separately stringify/print the mantissa and exponent of a floating point? I want this in my pretty-printing module to produce something like 1.2 \cdot 10^3 instead of 1.2e3 I could of course always split on the

Re: String Prefix Predicate

2014-08-14 Thread Justin Whear via Digitalmars-d-learn
On Thu, 14 Aug 2014 17:17:11 +, Nordlöw wrote: What's the preferrred way to check if a string starts with another string if the string is a 1. string (utf-8) BiDir 2. wstring (utf-16) BiDir 3. dstring (utf-32) Random std.algorithm.startsWith? Should auto-decode, so it'll do a utf-32

Re: Ropes (concatenation trees) for strings in D ?

2014-08-18 Thread Justin Whear via Digitalmars-d-learn
On Thu, 14 Aug 2014 05:57:17 +, Carl Sturtivant wrote: This is the idea I mean. http://citeseer.ist.psu.edu/viewdoc/download? doi=10.1.1.14.9450rep=rep1type=pdf Here's a C++ implementation supported I think by gcc. http://www.sgi.com/tech/stl/Rope.html Is there a D implementation of a

Re: iterate traits ?

2014-08-19 Thread Justin Whear via Digitalmars-d-learn
On Tue, 19 Aug 2014 18:15:33 +, ddos wrote: since i need to setup vertexpointers for opengl at runtime my next question? - is it possible to evaluate the traits also at runtime? but i'd also like to know how i can iterate them at compiletime thx in advance :) Take a look at this

Re: Can you explain this?

2014-08-20 Thread Justin Whear via Digitalmars-d-learn
On Wed, 20 Aug 2014 20:01:03 +, Colin wrote: It looks veryhacky. I see 3 distinct parts playing a role in my confusion: A) The 'is' keyword. What does it do when you have is(expression); B) typeof( expression ); whats this doing? Particularly when the expression its acting on is a

Re: commercial application with D

2014-09-15 Thread Justin Whear via Digitalmars-d-learn
On Mon, 15 Sep 2014 20:02:37 +, Andrey wrote: Can I develop commercial application with D programming language? There isn't anything in licensing of DMD, GDC, LDC, or the standard library which would prevent you from using them to create commercial applications.

Re: sort using delegate as predicate

2014-09-16 Thread Justin Whear via Digitalmars-d-learn
On Tue, 16 Sep 2014 16:19:10 +, Simon Bürger wrote: The following code does not compile, because the custom predicate of std.algorithm.sort is a template parameter, and therefore can only be a function, but not a delegate. In C++, there is a variant of sort taking a function-object as a

Re: Is there a function that reads the entire contents of a std.stdio.File?

2014-09-16 Thread Justin Whear via Digitalmars-d-learn
On Tue, 16 Sep 2014 14:37:05 +, Jay wrote: all the functions/methods i've come across so far deal with either streams or just file names (like std.file.read) and there doesn't seem to be a way to wrap a std.stdio.File in a stream (or is there?). i need a function that takes a

Re: GC-less Hash-Tables (AA)

2014-09-17 Thread Justin Whear via Digitalmars-d-learn
On Wed, 17 Sep 2014 10:39:05 +, Nordlöw wrote: Have anybody cooked any GC-less variants of hash-tables (associative arrays) that take keys and values with value semantics only. Similar to how X[] relates to std.containers.Array!X I need this to index my nodes in

Re: Function parameters from TypeTuple

2014-10-17 Thread Justin Whear via Digitalmars-d-learn
On Fri, 17 Oct 2014 17:44:47 +, Tofu Ninja wrote: Basicly what I am trying to do is have a function template that will generate its parameters to be arrays of the types of a type tuple. So for instance the parameters of f!(int, char) would be (int[], char[])... No matter what I try,

Re: Function parameters from TypeTuple

2014-10-17 Thread Justin Whear via Digitalmars-d-learn
On Fri, 17 Oct 2014 11:56:31 -0700, Ali Çehreli wrote: You want to write a function that takes an index and a number of arrays; and returns an N-ary Tuple where N matches the number arrays passed to the function: :p http://dlang.org/phobos/std_range.html#transversal

Re: Removing whitespace duplicates

2014-10-20 Thread Justin Whear via Digitalmars-d-learn
On Mon, 20 Oct 2014 22:21:09 +, bearophile wrote: Use std.string.tr. Bye, bearophile std.string.squeeze might be more appropriate.

Re: Basic DerelictOrg and Deimos question

2014-10-24 Thread Justin Whear via Digitalmars-d-learn
On Fri, 24 Oct 2014 18:04:13 +, WhatMeWorry wrote: Just for clarity's sake, should I consider the DerelictOrg and Deimos (packages, projects, or libraries) as separate from one another? Or does DerelictOrg use Deimos behind the scenes? They are quite different. The Deimos packages are

Re: Need assistance translating this C++ template

2014-10-27 Thread Justin Whear via Digitalmars-d-learn
On Mon, 27 Oct 2014 22:43:22 +, John wrote: void opAssign(T2 val) Without looking at the rest of your code, looks like this line needs to be void opAssign(T2)(T2 val)

Re: readln with buffer fails

2014-10-29 Thread Justin Whear via Digitalmars-d-learn
On Wed, 29 Oct 2014 23:10:10 +, dcrepid wrote: On Wednesday, 29 October 2014 at 21:19:25 UTC, Peter Alexander wrote: You need to take a slice of the buffer: char[] buf = Input[]; readln(buf); // line now in buf The reason for this is because you need to know where the string ends. If

Re: Curiously Cyclic Template Pattern causes segfault?

2014-11-05 Thread Justin Whear via Digitalmars-d-learn
On Wed, 05 Nov 2014 20:48:06 +, Patrick Jeeves wrote: When I tried to test out the following code the compiler segfaulted: Is there some rule against doing this or is it a glitch? Please file a bug report on issues.dlang.org --any compiler crash is a bug regardless of whether the source

Re: undefined reference to `_D5xxxx6yyyyy12__ModuleInfoZ'

2014-11-05 Thread Justin Whear via Digitalmars-d-learn
On Wed, 05 Nov 2014 23:48:21 +, bioinfornatics wrote: Dear, maybe I'm too tired to see my errors or they are a bug. See below I have this: . |-- fasta.d `-- src `-- nicea |-- metadata.d |-- parser.d `-- range.d when I try to build it: $ dmd -I./src/ ./fasta.d

Re: transversal sum

2014-11-06 Thread Justin Whear via Digitalmars-d-learn
On Thu, 06 Nov 2014 16:57:48 +, Marc Schütz wrote: On Thursday, 6 November 2014 at 15:53:27 UTC, Jack Applegame wrote: I have rectangular forward range of forward ranges (not arrays): [ [a11, a12, ... a1N], [a21, a22, ... a2N], ... [aM1, aM2, ... aMN] ] I need lazy forward

Re: transversal sum

2014-11-06 Thread Justin Whear via Digitalmars-d-learn
On Thu, 06 Nov 2014 17:08:23 +, Justin Whear wrote: I think the correct solution will make use of std.range.frontTraversal, but it will be a bit more complex due to needing to sum every column. std.range.traversal would make it easy, but it requires random access. That should be

Re: is there any reason UFCS can't be used with 'new'?

2014-11-10 Thread Justin Whear via Digitalmars-d-learn
On Mon, 10 Nov 2014 19:07:38 +, Suliman wrote: I can't understand how to use UFCS with instance of class: void main() { string name = Suliman; userName username = new userName(name); /// How to use UFCS here? userName.name.sayHello(); /// } class userName { string

How to share modules when using -shared?

2014-12-09 Thread Justin Whear via Digitalmars-d-learn
I'm trying to build components that I can dynamically link and keep running into an issue with sharing modules between the host and the pluggable components. Assuming a layout like this: host.d -- loads components at runtime a.d -- a module that builds to `a.so` b.d -- a module

Re: generate an array of 100 uniform distributed numbers

2015-01-22 Thread Justin Whear via Digitalmars-d-learn
On Thu, 22 Jan 2015 19:26:44 +, ddos wrote: hi guys, firstly this has no direct application, i'm just playing around and learning i want to create 100 uniform distributed numbers and print them my first attempt, just written by intuition: [0 .. 100].map!(v = uniform(0.0, 1.0).writeln);

Re: About variant

2015-01-27 Thread Justin Whear via Digitalmars-d-learn
On Tue, 27 Jan 2015 20:46:59 +, bioinfornatics wrote: void main(){ auto a = Alpha!(int)( 6); auto b = Alpha!(string)( hello); The Alpha struct is not a template, only the constructor is. Remove the explicit instantiations and IFTI does the work: void main(){ auto a =

Re: For those ready to take the challenge

2015-01-09 Thread Justin Whear via Digitalmars-d-learn
On Fri, 09 Jan 2015 13:50:28 +, eles wrote: https://codegolf.stackexchange.com/questions/44278/debunking- stroustrups-debunking-of-the-myth-c-is-for-large-complicated-pro Was excited to give it a try, then remembered...std.xml :(

Re: For those ready to take the challenge

2015-01-09 Thread Justin Whear via Digitalmars-d-learn
On Fri, 09 Jan 2015 17:18:42 +, Adam D. Ruppe wrote: Huh, looking at the answers on the website, they're mostly using regular expressions. Weaksauce. And wrong - they don't find ALL the links, they find the absolute HTTP urls! Yes, I noticed that. `script src=http://app.js`/script` isn't

Re: Conditional functions

2015-01-05 Thread Justin Whear via Digitalmars-d-learn
On Mon, 05 Jan 2015 17:47:09 +, Dominikus Dittes Scherkl wrote: Is it possible to use static if in a template structure to have some member functions only for specific types? Yep. This is actually a frequently used pattern in functions that return ranges.

Re: string concatenation with %s

2015-01-07 Thread Justin Whear via Digitalmars-d-learn
On Wed, 07 Jan 2015 16:38:23 +, Suliman wrote: I except that writefln have some behavior as string concatenation, but it does not. IS there any way to put needed values in place of %s in string? std.string.format interpolates string with the same behavior as writefln but returns the

Re: Float to string with more digits?

2015-02-24 Thread Justin Whear via Digitalmars-d-learn
On Tue, 24 Feb 2015 20:04:04 +, Almighty Bob wrote: Is there a more accurate way to do a float and or double to string than... to!string(float); As that seems to limit itself to 6 digits. Use std.string.format or std.format.formattedWrite. std.format contains a description of the

Re: Duplicate another function's parameters in a template function

2015-04-20 Thread Justin Whear via Digitalmars-d-learn
On Mon, 20 Apr 2015 22:50:52 +, Tofu Ninja wrote: I am trying to write a template function that can take another function as an alias template argument and duplicate its parameters for it self. I tried.. auto pass(alias f, T...)(T t) { // other stuff... return f(t); } but

Re: ctags

2015-04-20 Thread Justin Whear via Digitalmars-d-learn
On Mon, 20 Apr 2015 20:14:34 +0200, Robert M. Münch wrote: Hi, is there anything for D that supports generating tags files like ctags does for C etc. ? Dscanner: https://github.com/Hackerpilot/Dscanner#ctags-output

Re: Structural exhaustive matching

2015-04-21 Thread Justin Whear via Digitalmars-d-learn
On Tue, 21 Apr 2015 15:36:27 +, Jadbox wrote: What's the best equivalent to Rust's structural enum/pattern (match)ing? Is it also possible to enforce exhaustive matches? Basically, I'm curious on what the best way to do ADTs in D. std.variant.Algebraic implements ADTs: import

Re: Create a case-insensitive startsWith

2015-04-28 Thread Justin Whear via Digitalmars-d-learn
On Tue, 28 Apr 2015 21:45:07 +, PhilipDaniels wrote: Beginner question. Given if (startsWith(input, 0x, 0X)) How do I turn that into a case-insensitive startsWith? startsWith says it takes a predicate but I can't figure out how to pass it one. The examples all use a == b !? These

Re: Example from d-idioms is incorrect

2015-04-30 Thread Justin Whear via Digitalmars-d-learn
On Thu, 30 Apr 2015 21:30:34 +, TheGag96 wrote: Was the behavior of the remove() function changed recently? Thanks guys. I believe remove has always worked this way. What you're seeing is explained by this note in the documentation for remove: The original array has remained of the same

Re: Readonly-to-outside variable

2015-04-28 Thread Justin Whear via Digitalmars-d-learn
On Tue, 28 Apr 2015 19:30:04 +, tcak wrote: Is there any way to define a variable or an attribute as read-only without defining a getter function/method for it? Thoughts behind this question are: 1. For every reading, another function call process for CPU while it could directly read

Re: Create a case-insensitive startsWith

2015-04-30 Thread Justin Whear via Digitalmars-d-learn
Note that my solution relies on the pre-release version of std.uni, those lazy functions aren't in the latest release.

Re: Baffled by compilation error for formattedRead

2015-05-07 Thread Justin Whear via Digitalmars-d-learn
On Thu, 07 May 2015 23:10:26 +, PhilipDaniels wrote: Why do the first two fail to compile but the last one does?! I cannot see any difference between the 's2' case and the second case, it is a completely mechanical source code transformation I have made. formattedRead takes its input by

Re: Bitfield-style enum to strings?

2015-05-07 Thread Justin Whear via Digitalmars-d-learn
On Thu, 07 May 2015 16:55:42 -0400, Nick Sabalausky wrote: // There's gotta be a better way to convert EnumMembers!T // to a range, right? But std.range.only() didn't work, // due to a template instantiation error. T[] members; foreach(m; EnumMembers!(T))

Re: Linker command

2015-05-06 Thread Justin Whear via Digitalmars-d-learn
On Wed, 06 May 2015 19:52:42 +, Paul wrote: On Wednesday, 6 May 2015 at 19:30:33 UTC, anonymous wrote: On Wednesday, 6 May 2015 at 19:26:40 UTC, Paul wrote: but I don't understand the syntax. dmd --help mentions -Llinkerflag but what is '-L-L.' doing?? Passes '-L.' to the linker. :D

Re: Return types of the methods of a struct

2015-06-19 Thread Justin Whear via Digitalmars-d-learn
On Fri, 19 Jun 2015 13:27:13 +, Quentin Ladeveze wrote: Is there any way to have a asTuple method in this struct that would returns something like : Tuple!(int, a, float, b, string, c) and that will contain the values of the methods of the struct ? Thanks. You'll want to work

Re: Why aren't Ranges Interfaces?

2015-06-26 Thread Justin Whear via Digitalmars-d-learn
On Fri, 26 Jun 2015 19:26:56 +, Jack Stouffer wrote: Thanks for the reply! I understand the reasoning now. On Friday, 26 June 2015 at 18:46:03 UTC, Adam D. Ruppe wrote: 2) interfaces have an associated runtime cost, which ranges wanted to avoid. They come with hidden function pointers

Re: Process a TypeTuple

2015-06-15 Thread Justin Whear via Digitalmars-d-learn
On Mon, 15 Jun 2015 04:06:12 +, Baz wrote: On Monday, 15 June 2015 at 03:53:35 UTC, Yuxuan Shui wrote: Is it possible to apply some operation on every member of a TypeTuple, then get the result back? Say I have a TypeTuple of array types, and I want a TypeTuple of their element types,

Re: Casting MapResult

2015-06-15 Thread Justin Whear via Digitalmars-d-learn
On Mon, 15 Jun 2015 15:10:20 +, jmh530 wrote: So I suppose I have two questions: 1) am I screwing up the cast, or is there no way to convert the MapResult to float[], 2) should I just not bother with map (I wrote an alternate, longer, version that doesn't use map but returns float[]

Re: lovely compiler error message - incompatible types

2015-07-02 Thread Justin Whear via Digitalmars-d-learn
On Thu, 02 Jul 2015 17:33:28 +, Laeeth Isharc wrote: FixedDecimal is a fixed decimal point struct that stores values as an int or long and takes number of decimal places as the second compile term argument. It's possible, if not likely I have made a mistake in implementing operator

Re: Multi-dimensional fixed arrays

2015-06-30 Thread Justin Whear via Digitalmars-d-learn
On Tue, 30 Jun 2015 21:02:37 +, DLearner wrote: Out of curiosity, why can't D define a 2-dim array by something like: int(2,1) foo; which defines two elements referred to as: foo(0,0) and foo(1,0)? Work is being done on multidimensional slicing, see this thread:

Re: Multi-dimensional fixed arrays

2015-06-30 Thread Justin Whear via Digitalmars-d-learn
On Tue, 30 Jun 2015 20:09:50 +, DLearner wrote: Suppose: 'int [1][2] foo;' Probably I misunderstand, but TDPL seems to say that foo has two elements: foo[0][0] and foo[1][0] as opposed to two elements: foo[0][0] and foo[0][1] Is this correct? No. The order of braces when

Re: lovely compiler error message - incompatible types

2015-07-02 Thread Justin Whear via Digitalmars-d-learn
On Thu, 02 Jul 2015 21:03:37 +, Laeeth Isharc wrote: Can you post the signature to the operator overload? I have an idea of what it might be, but it's difficult to explain without context. -Steve https://gist.github.com/Laeeth/6251fa731e4cee84bcdc not really a proper implementation.

Re: Hello Assembly!

2015-08-12 Thread Justin Whear via Digitalmars-d-learn
On Wed, 12 Aug 2015 22:10:30 +, Taylor Hillegeist wrote: I figure this should do it. but i'm running into problems. Anybody know why? Describe problems

Re: Calling Syntax (no, not UFCS)

2015-08-03 Thread Justin Whear via Digitalmars-d-learn
On Mon, 03 Aug 2015 22:42:14 +, SirNickolas wrote: Hello! I'm new in D and it is amazing! Can you tell me please if it is discouraged or deprecated to call a function by just putting its name, without brackets? It's quite unusual for me (used C++ and Python before), but I can see this

Re: How do I find the actual types of the elements in a list of classes?

2015-08-13 Thread Justin Whear via Digitalmars-d-learn
On Thu, 13 Aug 2015 21:42:52 +, Jack Stouffer wrote: foreach (item; parent_list) { string class_name = (cast(Object) item).classinfo.name; if (class_name == test.A) { (cast(A) item).method(); } else if

Re: NYT data article based on work of EMSI, who I think are a D shop

2015-08-25 Thread Justin Whear via Digitalmars-d-learn
On Tue, 25 Aug 2015 04:55:12 +, Laeeth Isharc wrote: http://www.nytimes.com/2015/08/23/magazine/the-creative-apocalypse-that- wasnt.html Interesting article as it corrects misconceptions of a few years back by looking at the data. This is based on tools from EMSI, who are a D shop.

Re: Problem Benchmarking HashSet from containers-em

2015-10-22 Thread Justin Whear via Digitalmars-d-learn
On Thu, 22 Oct 2015 11:55:37 +, Nordlöw wrote: > What's wrong? HashSet has a disabled default constructor; you need to supply the allocator instance to the constructor here https://github.com/nordlow/ justd/blob/master/containers_ex.d#L17

Re: Problem Benchmarking HashSet from containers-em

2015-10-22 Thread Justin Whear via Digitalmars-d-learn
On Thu, 22 Oct 2015 19:41:08 +, Nordlöw wrote: > My existing call to > > auto set = HashSet!(E, Allocator)(); > > works for Mallocator as in > > https://github.com/nordlow/justd/blob/master/containers_ex.d#L17 > > but not for > > InSituRegion!(1024*1024, T.alignof) > > Why?

Re: What does the -betterC switch in dmd do?

2015-11-12 Thread Justin Whear via Digitalmars-d-learn
On Thu, 12 Nov 2015 19:37:41 +, TheFlyingFiddle wrote: > The description in dmd help says: omit generating some runtime > information and helper functions. > > What runtime information are we talking about here? My > understanding is that it's basically an experimental feature but > when

Re: linux inotify on a std.process.ProcessPipes ?

2015-11-16 Thread Justin Whear via Digitalmars-d-learn
On Mon, 16 Nov 2015 23:08:46 +, opla wrote: > Does anyone know if it's possible to monitor the events that happen on > the output stream of a piped process ? > > I'm stuck on doc: > > - https://www.win.tue.nl/~aeb/linux/lk/lk-12.html - >

Re: Check Instance of Template for Parameter Type/Value

2015-10-19 Thread Justin Whear via Digitalmars-d-learn
On Mon, 19 Oct 2015 14:51:28 +, Stewart Moth wrote: > I'm working with a library that has template structs of mathematical > vectors that can sometimes be the type of an array I'm passing to a > function. > > The definition of the struct is like this: > > struct Vector(type, int

Re: How to get value of enum without casting

2015-07-09 Thread Justin Whear via Digitalmars-d-learn
On Thu, 09 Jul 2015 16:20:56 +, tcak wrote: Is there any way to get the type of enum without interacting with its items? std.traits.OriginalType Is there any way to get string representation of an item of enum without casting? I think casting to the OriginalType and then using to!string

Re: Why ElementType!(char[3]) == dchar instead of char?

2015-09-01 Thread Justin Whear via Digitalmars-d-learn
On Tue, 01 Sep 2015 19:40:24 +0300, drug wrote: > I'm just trying to automatically convert D types to hdf5 types so I > guess char[..] isn't obligatory some form of UTF-8 encoded text. Or I > should treat it so? Because of D's autodecoding it can be problematic to assume UTF-8 if other

Re: interprocess communication and sharing memory

2015-09-03 Thread Justin Whear via Digitalmars-d-learn
On Thu, 03 Sep 2015 01:27:14 +, j55 wrote: > I've read many posts about shared memory and interprocess communication > in D, but I didn't see any conclusive information about whether this > type of interprocess memory sharing will be convenient or practical in > D. If it doesn't work out, I

  1   2   >