Re: how can I ensure that a template instantiation is unique?

2014-06-19 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 19 June 2014 at 05:48:24 UTC, Vlad Levenfeld wrote: I'm instantiating a couple of template structs that conflict with each other. I'd like them to be unique types, automatically. So I tried this: template Foo (string unique_id = __FILE__~__LINE__.to!string) {...} but it didn't

Re: how can I ensure that a template instantiation is unique?

2014-06-19 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 19 June 2014 at 07:26:12 UTC, Andrea Fontana wrote: On Thursday, 19 June 2014 at 05:48:24 UTC, Vlad Levenfeld wrote: I'm instantiating a couple of template structs that conflict with each other. I'd like them to be unique types, automatically. So I tried this: template Foo

Re: SImple C++ code to D

2014-07-14 Thread Andrea Fontana via Digitalmars-d-learn
Is there any counter-indication with this: immutable ubyte[5] stub = xb8 01 4c cd 21.representation; ? Is it a compile time value? On Monday, 14 July 2014 at 12:18:20 UTC, bearophile wrote: Alexandre: Look at line 114 of my code: http://dpaste.com/3B5WYGV The indentations are messed up.

Re: Reflections on isPalindrome

2014-10-27 Thread Andrea Fontana via Digitalmars-d-learn
On Monday, 27 October 2014 at 16:59:19 UTC, Nordlöw wrote: On Monday, 27 October 2014 at 12:10:59 UTC, Marc Schütz wrote: You could add an early `return false;` if the range has length and it is less than minLength. See update :) Thanks! And you can return true if length = 1 Why

Re: Reflections on isPalindrome

2014-10-28 Thread Andrea Fontana via Digitalmars-d-learn
On Monday, 27 October 2014 at 22:53:57 UTC, Nordlöw wrote: Why bidirectional range only? popBack() only for I mean: you should write a different version for non-bidirectional ranges too :)

Re: Possible to write a classic fizzbuzz example using a UFCS chain?

2015-04-28 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 28 April 2015 at 13:59:48 UTC, Ivan Kazmenko wrote: On Tuesday, 28 April 2015 at 10:46:54 UTC, Gary Willoughby wrote: After reading the following thread: http://forum.dlang.org/thread/nczgumcdfystcjqyb...@forum.dlang.org I wondered if it was possible to write a classic fizzbuzz[1]

Re: vibed: how to use pure HTML instead of template engine?

2015-05-06 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 6 May 2015 at 14:28:26 UTC, Adam D. Ruppe wrote: On Wednesday, 6 May 2015 at 14:23:27 UTC, Chris wrote: Especially this: http://vibed.org/templates/diet#embedded-code I think that's a misfeature... if I used vibe.d, I'd want to avoid the diet too. I agree

Re: Merging one Array with Another

2015-05-07 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 7 May 2015 at 06:53:39 UTC, Per Nordlöw wrote: On Wednesday, 6 May 2015 at 16:05:15 UTC, Andrea Fontana wrote: Maybe a way like this could be useful: http://dpaste.dzfl.pl/7b4b37b490a7 If r is a SortedRange this is very unneccesary wasteful because of the use AA. In that case

Re: Merging one Array with Another

2015-05-08 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 7 May 2015 at 21:53:24 UTC, Per Nordlöw wrote: On Thursday, 7 May 2015 at 13:38:23 UTC, Andrea Fontana wrote: Because it is a more generic operation and you can work on a lazy range. Anyway, to sort and to do uniq it isn't the fastest way. Or maybe I just didn't understand what

Re: Merging one Array with Another

2015-05-07 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 7 May 2015 at 09:21:58 UTC, Per Nordlöw wrote: On Thursday, 7 May 2015 at 08:03:41 UTC, Andrea Fontana wrote: It's not that difficult to implement. You just need to implement a merge() range that returns the min of all ranges' front(). Then you can define distinct() for

Re: Merging one Array with Another

2015-05-06 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 1 May 2015 at 19:08:51 UTC, Per Nordlöw wrote: What's the fastest Phobos-way of doing either x ~= y; // append x = x.uniq; // remove duplicates or x = (x ~ y).uniq; // append and remove duplicates in one go provided that T[] x, y; ? Maybe a way like this could

Re: Merging one Array with Another

2015-05-08 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 8 May 2015 at 09:23:42 UTC, Per Nordlöw wrote: On Friday, 8 May 2015 at 08:27:19 UTC, Andrea Fontana wrote: Name could be misleading. This is a sortedrange: [4,3,2,1,0]. In your case minElement is 4, maxElement is 0 :) On ranges with more complex elements sort order can be even less

About @ and UDA

2015-04-15 Thread Andrea Fontana via Digitalmars-d-learn
My 2 cents. If I remember correctly, @ prefix in @safe, @trusted, @system, etc was added just to avoid keywords pollution, right? Now UDA uses the same prefix: if some new keywords/properties/attributes will be added to D, the same problem will come back again... Is it a crazy idea to

Re: Strange behavior std.range.takeNone

2015-04-07 Thread Andrea Fontana via Digitalmars-d-learn
Yes it is. takeNone() take a char from a string. So you are going to append a char (with code 5) on the next line. If you replace that line with: s ~= 65; it will print A. (65 is ascii code for letter 'A') On Tuesday, 7 April 2015 at 02:24:00 UTC, Dennis Ritchie wrote: Hi, Is it OK? -

Re: Internal Compiler Error Help

2015-05-21 Thread Andrea Fontana via Digitalmars-d-learn
https://github.com/CyberShadow/DustMite/wiki On Thursday, 21 May 2015 at 08:28:30 UTC, Saurabh Das wrote: Hello, We have been working on a genetic programming project, and occasionally the compiler fails and gives an internal error. I've captured and reduced one of these down to a single

Null argument and function resolution

2015-05-27 Thread Andrea Fontana via Digitalmars-d-learn
Check this example: http://dpaste.dzfl.pl/53f85bae4382 Calling with null, both c-tor match. Is there a way to solve this? Something like: this(in ubyte* data) if( ??? ) { } Andrea

Re: Null argument and function resolution

2015-05-27 Thread Andrea Fontana via Digitalmars-d-learn
The first answer is the one I was looking for. Very useful. You should add to next this week in d tips. On Wednesday, 27 May 2015 at 14:09:48 UTC, Adam D. Ruppe wrote: Two options: 1) add an overload that takes typeof(null) this(typeof(null)) { /* handles the null literal specially */ } 2)

Re: Implicit conversion from null in custom type

2015-05-28 Thread Andrea Fontana via Digitalmars-d-learn
What's the problem with ctor taking typeof(null)? I've just used it, maybe I missed something? On Thursday, 28 May 2015 at 11:19:39 UTC, Vladimir Panteleev wrote: I'm trying to write a type which (to some extent) emulates built-in AAs. One thing I'm having trouble with is null function

Re: Implicit conversion from null in custom type

2015-05-28 Thread Andrea Fontana via Digitalmars-d-learn
void fun(typeof(null)) { } ? On Thursday, 28 May 2015 at 13:06:27 UTC, Vladimir Panteleev wrote: On Thursday, 28 May 2015 at 12:37:52 UTC, Andrea Fontana wrote: What's the problem with ctor taking typeof(null)? I've just used it, maybe I missed something? It doesn't work: //

Shouldn't __FUNCTION__ return function name?

2015-07-28 Thread Andrea Fontana via Digitalmars-d-learn
Check this code: http://dpaste.dzfl.pl/a76db2cde13d When __FUNCTION__ is called inside a foreach body, it appears to be: f212.myFunction.__foreachbody1 Rather than: f212.myFunction. Is it correct? How can I get the function name?

Re: Shouldn't __FUNCTION__ return function name?

2015-07-28 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 28 July 2015 at 15:13:28 UTC, Steven Schveighoffer wrote: How can I get the function name? Be outside foreach. The way foreach works in many cases (including foreach over an associative array), is that the compiler constructs an internal function delegate, then passes it to a

Re: Find on sorted range slower?

2015-08-07 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 7 August 2015 at 08:18:04 UTC, Nordlöw wrote: On Friday, 7 August 2015 at 05:21:32 UTC, Tofu Ninja wrote: HAHAH wow, this is hilarious, I just checked, nothing in std.algo takes advantage of sorted ranges, sort doesn't even take advantage of it! You pass a sorted range into sort and

std.net.curl and PATCH

2015-07-22 Thread Andrea Fontana via Digitalmars-d-learn
It seems that PATCH http method is missing from std.net.curl http methods. No way to use it?

Re: how to manage the list of immutable objects

2015-07-14 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 14 July 2015 at 10:09:56 UTC, aki wrote: I like to create immutable object which is identified by name as it's key. And also need get() to look up named object which is already created. class Foo { static immutable(Foo)[string] map; string name; // and other

Re: OPTLINK checkpoint(256)

2015-07-20 Thread Andrea Fontana via Digitalmars-d-learn
On Monday, 20 July 2015 at 13:16:43 UTC, Lemonfiend wrote: I was still using 2.066.1. When I try to build using 2.067.0 or 2.067.1 I get: Linking... checkpoint(256) --- errorlevel 1 with an Unexpected OPTLINK Termination popup which lists a bunch of registers. I'm not sure how to proceed..

Re: Mixin template, "no identifier for declarator"

2015-10-27 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 27 October 2015 at 07:56:51 UTC, SimonN wrote: Hi, I'd like to generate several very similar class methods with a mixin template. The mixin template shall take alias parameters, so that different methods can bind it to different fields. Reduced problem case: Template mixins can

Re: How to get DMD to stop littering my source dir with .o files?

2015-10-26 Thread Andrea Fontana via Digitalmars-d-learn
On Monday, 26 October 2015 at 11:55:48 UTC, Shriramana Sharma wrote: The subject line says it all. Every time I compile a D file to an executable I get an unwanted .o file and have to manually clean up things. I'm using DMD 2.0.68.2. Do you mean: -odobjdir write object & library files

Re: my first D program (and benchmark against perl)

2015-11-11 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 11 November 2015 at 13:32:00 UTC, perlancar wrote: While I am quite impressed with how easy I was able to write D, I am not so impressed with the performance. Using rdmd (build 20151103), the D program runs in 17.127s while the Perl version runs in 11.391s (so the D version is

Re: My is the order of parameters reversed for functions that are dynamically loaded from shared C libraries?

2015-11-15 Thread Andrea Fontana via Digitalmars-d-learn
On Sunday, 15 November 2015 at 18:02:01 UTC, David Nies wrote: On Sunday, 15 November 2015 at 18:00:09 UTC, David Nadlinger wrote: On Sunday, 15 November 2015 at 17:54:27 UTC, David Nies wrote: How can I make sure the order is correct? Whenever you use a C function, it must be marked as,

Re: String interpolation

2015-11-10 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 10 November 2015 at 12:40:07 UTC, Márcio Martins wrote: writeln(interp!"The number #{a} is less than #{b}"); Quite pleasant syntax this way :) Not sure if it's feasible to do this on the language side. Yes. Here a (stupid!) proof of concept: http://dpaste.dzfl.pl/74b1a4e3c8c6

Re: Associative array with duplicated keys?

2015-11-05 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 5 November 2015 at 09:27:35 UTC, tcak wrote: On Thursday, 5 November 2015 at 08:55:10 UTC, Andrea Fontana wrote: Check this: http://dpaste.dzfl.pl/ebbb3ebac60e It doesn't give any error or warning. And writeln seems confused (do you see that "," at the end?) I am sure the coder

Associative array with duplicated keys?

2015-11-05 Thread Andrea Fontana via Digitalmars-d-learn
Check this: http://dpaste.dzfl.pl/ebbb3ebac60e It doesn't give any error or warning. And writeln seems confused (do you see that "," at the end?)

Re: good reasons not to use D?

2015-10-31 Thread Andrea Fontana via Digitalmars-d-learn
On Saturday, 31 October 2015 at 18:23:43 UTC, rumbu wrote: My opinion is that a decimal data type must be builtin in any modern language, not implemented as a library. I agree

Re: User input parsing

2015-10-14 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 14 October 2015 at 07:14:45 UTC, Joel wrote: Is there a fast way to get a number out of a text input? Like getting '1.5' out of 'sdaz1.5;['. Here's what I have at the moment: string processValue(string s) { string ns;

Re: Bug? 0 is less than -10

2015-10-07 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 7 October 2015 at 05:27:12 UTC, Laeeth Isharc wrote: On Wednesday, 7 October 2015 at 02:53:32 UTC, Steven Schveighoffer wrote: On 10/6/15 7:21 PM, Laeeth Isharc wrote: could we have ssize_t defined in phobos somewhere so your code ends up being portable ;) (It's trivial to do,

Re: Just one time

2015-10-20 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 20 October 2015 at 15:55:47 UTC, John Colvin wrote: Be aware that there will be one instance of val per thread, so you are detecting the first run in each thread, not in the program overall. This is the kind of thing I'm interested in. What happens if I call isFirstTime!"test"

Just one time

2015-10-20 Thread Andrea Fontana via Digitalmars-d-learn
It happens I need to perform an operation just one time (inside a function, a loop...) I wonder if doing this it's a good idea or not. bool isFirstTime(alias T)() { static val = true; if (val) { val = false; return true; }

Re: Just one time

2015-10-21 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 20 October 2015 at 18:08:33 UTC, Ali Çehreli wrote: On 10/20/2015 08:48 AM, Andrea Fontana wrote: It happens I need to perform an operation just one time (inside a function, a loop...) An idea that uses a function pointer where the first step does its task and then sets the

Re: Wrapping a C-style Array (Pointer + Length) in a Range Interface

2015-07-09 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 7 July 2015 at 12:26:33 UTC, Per Nordlöw wrote: I'm currently developing a high-level wrapper for FFMPEG at https://github.com/nordlow/justd/blob/master/tests/t_ffmpeg.d My question now becomes how to most easily wrap the iteration over streams at

Re: Fixed Length Array Syntax in extern(C) Function Signatures

2015-07-10 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 10 July 2015 at 08:42:06 UTC, Per Nordlöw wrote: On Friday, 10 July 2015 at 03:18:23 UTC, Mike Parker wrote: [1]http://dlang.org/interfaceToC.html Is there any tool out there that automatically creates D wrappers from C headers`? https://github.com/jacob-carlborg/dstep ?

Adding UDA at compile time

2015-08-26 Thread Andrea Fontana via Digitalmars-d-learn
I wonder if there's a way to add UDA to functions at compile-time (so I can read later from other parts of application). Andrea

Re: Adding UDA at compile time

2015-08-26 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 26 August 2015 at 14:01:00 UTC, Alex Parrill wrote: On Wednesday, 26 August 2015 at 08:19:04 UTC, Andrea Fontana wrote: I wonder if there's a way to add UDA to functions at compile-time (so I can read later from other parts of application). Andrea What do you mean? UDAs are

Re: Safe copy-paste using mixin

2015-08-31 Thread Andrea Fontana via Digitalmars-d-learn
On Monday, 31 August 2015 at 10:38:41 UTC, drug wrote: On 31.08.2015 13:35, drug wrote: I have code that is being duplicated in several places and I'd like to use mixins to simplify code maintenance but I failed to do it. For example

Re: Safe copy-paste using mixin

2015-08-31 Thread Andrea Fontana via Digitalmars-d-learn
On Monday, 31 August 2015 at 11:06:40 UTC, drug wrote: On 31.08.2015 13:57, Andrea Fontana wrote: Just create a function that return a string with those three lines and mixin it! Like: import std.stdio; string toMix( string a, string b, string c) { return `string a = "` ~ a ~ `";` ~

Re: Sum and other algorithm functions

2015-09-10 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 10 September 2015 at 13:48:16 UTC, Namal wrote: Hello, how can I define the range for the sum function which I want to sum up? For instance how do I sum up the first 3 elements of an array int[] a = [1,2,3,4,5,6,7,8,9]; or the last 3? In this case, you can simply slice array

Re: Speeding up text file parser (BLAST tabular format)

2015-09-14 Thread Andrea Fontana via Digitalmars-d-learn
On Monday, 14 September 2015 at 13:05:32 UTC, Andrea Fontana wrote: On Monday, 14 September 2015 at 12:30:21 UTC, Fredrik Boulund wrote: [...] Also if problem probabily is i/o related, have you tried with: -O -inline -release -noboundscheck ? Anyway I think it's a good idea to test it

Re: Speeding up text file parser (BLAST tabular format)

2015-09-14 Thread Andrea Fontana via Digitalmars-d-learn
On Monday, 14 September 2015 at 12:30:21 UTC, Fredrik Boulund wrote: [...] Also if problem probabily is i/o related, have you tried with: -O -inline -release -noboundscheck ? Anyway I think it's a good idea to test it against gdc and ldc that are known to generate faster executables.

Re: Initalizing complex array types or some other problem ;/

2015-09-16 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 16 September 2015 at 01:46:09 UTC, Prudence wrote: In any case, Maybe you are not as smart as you think you are if you can't understand it? Maybe next time you shouldn't assume you are the oracle of all knowledge and if you can't understand it then it's bad/wrong. In fact, it's

Re: Get template parameter value

2015-09-29 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 29 September 2015 at 07:50:42 UTC, rumbu wrote: Having a template: struct SomeStruct(int size) { } Is there any language trait returning the value of size template parameter for the template instantiation SomeStruct!10? Something like this is ok? struct SomeStruct(int size) {

Re: Get template parameter value

2015-09-29 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 29 September 2015 at 08:44:03 UTC, Andrea Fontana wrote: On Tuesday, 29 September 2015 at 07:50:42 UTC, rumbu wrote: Having a template: struct SomeStruct(int size) { } Is there any language trait returning the value of size template parameter for the template instantiation

Re: Struct initializers as expressions

2015-12-04 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 4 December 2015 at 10:42:46 UTC, Marc Schütz wrote: I suggest to make the struct name optional: ... but not forbidden. With templates or "auto" could be useful to force the type.

Re: Real Time-ing

2015-12-09 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 9 December 2015 at 10:00:46 UTC, Andrea Fontana wrote: On Tuesday, 8 December 2015 at 15:35:18 UTC, Taylor Hillegeist wrote: So, I mostly do programming that is of run to completion verity. But I have a dream of calling functions periodically. So my question is: What is the

Re: Real Time-ing

2015-12-09 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 8 December 2015 at 15:35:18 UTC, Taylor Hillegeist wrote: So, I mostly do programming that is of run to completion verity. But I have a dream of calling functions periodically. So my question is: What is the best (most time accurate) way to call a function every n time units?

Re: std.algorithm.remove from array of custom classes?

2015-12-09 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 9 December 2015 at 13:13:36 UTC, BBaz wrote: 3) opEquals can be 'const' because the method doesn't mutate the state of the object 4) your cast wasn't safe http://dlang.org/phobos/std_algorithm_mutation.html#.remove Maybe something like this works better: ... override

Re: std.algorithm.remove from array of custom classes?

2015-12-09 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 9 December 2015 at 13:23:00 UTC, Tim K. wrote: On Wednesday, 9 December 2015 at 13:13:36 UTC, BBaz wrote: 1) remove works with an index I guess I did read it wrong. Sorry. Is there a convenience function that allows me to remove an/all object(s) with a certain value from an

Re: Something about Chinese Disorder Code

2015-11-24 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 24 November 2015 at 09:48:45 UTC, magicdmer wrote: I display chinese string like: auto str = "你好,世界" writeln(str) and The display is garbled。 some windows api like MessageBoxA ,if string is chinese, it displays disorder code too i think i must use WideCharToMultiByte to convert

Re: How to call one static method from another?

2016-06-14 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 14 June 2016 at 07:20:47 UTC, Konstantin Kutsevalov wrote: May be my question was not enought clean... this is example of code: ``` class ClassName { public static void function method1() { // do something // and now I need to call other static method

Re: ndslice: convert a sliced object to T[]

2016-06-15 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 08:25:35 UTC, data pulverizer wrote: I guess foreach would not copy the elements? for example: foreach(el; slice.byElement) x ~= el; But it feels wrong to be doing work pulling elements that already exists by using foreach. I feel as if I am

Re: ndslice: convert a sliced object to T[]

2016-06-15 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 08:56:15 UTC, data pulverizer wrote: On Wednesday, 15 June 2016 at 08:53:22 UTC, Andrea Fontana wrote: On Wednesday, 15 June 2016 at 08:25:35 UTC, data pulverizer wrote: I guess foreach would not copy the elements? for example: foreach(el; slice.byElement)

Re: ndslice: convert a sliced object to T[]

2016-06-15 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 15 June 2016 at 07:24:23 UTC, data pulverizer wrote: On Wednesday, 15 June 2016 at 03:17:39 UTC, Seb wrote: On Wednesday, 15 June 2016 at 03:11:23 UTC, data pulverizer wrote: in that case: import std.array : array; int[] x = slice.byElement.array; Are you sure you want to

Re: Out of order execution

2016-06-16 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 16 June 2016 at 01:57:19 UTC, Joerg Joergonson wrote: Suppose I have a loop where I execute two functions: for(...) { if (x) Do1(x); if (y) Do2(y); } The problem is, I really always want to execute all the Do2's first then the Do1's. As is, we could get any order of calls.

Re: is increment on shared ulong atomic operation?

2016-02-08 Thread Andrea Fontana via Digitalmars-d-learn
On Sunday, 7 February 2016 at 20:25:44 UTC, Minas Mina wrote: Just noticed that there's no example. It's used like shared(ulong) a; atomicOp!"+="(a, 1); Wow, that syntax sucks a lot. a.atomicOp!"+="(1); sounds better. You can alias it too.

Re: Why this code can't take advantage from CTFE?

2016-02-05 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 3 February 2016 at 22:45:47 UTC, Timon Gehr wrote: I would use enum forceCTFE(alias expr)=expr; though. With alias it won't force compile-time evaluation of expressions that can be interpreted as symbols. I've a code that build a JSON object using a wrapper over std.json.

Re: Why this code can't take advantage from CTFE?

2016-02-05 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 5 February 2016 at 09:49:38 UTC, Luis wrote: Reading/parsing a JSON or a XML using std.json / std.xml could be done on CTFE ? parseJSON() from std.json doesn't work with CTFE. But I can build objects with with my code that works over std.json. So if you convert (with mixins) {

Re: Non-English characters in code - "character 0x2212 is not a valid token"

2016-01-28 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 28 January 2016 at 13:18:55 UTC, pineapple wrote: I experimented with using the character 'ħ' in a variable name, and wasn't terribly surprised when the compiler didn't like it. What did surprise me is that I still got a compile error even when the character was in a comment. Is

Why this code can't take advantage from CTFE?

2016-02-03 Thread Andrea Fontana via Digitalmars-d-learn
This code: import std.stdio; int very_very_long_function(in int k) { if (!__ctfe) writeln("Can't use ctfe!"); return k/2; } void main() { enum first = very_very_long_function(10); writeln("First is ", first); auto second = very_very_long_function(12);

Re: Why this code can't take advantage from CTFE?

2016-02-03 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 3 February 2016 at 17:49:39 UTC, Marc Schütz wrote: On Wednesday, 3 February 2016 at 16:07:59 UTC, Messenger wrote: What is a good way to try to force it? Using enum? Then optionally copying the value once to avoid the "manifest constant" copy/paste behaviour, where applicable?

Re: Why this code can't take advantage from CTFE?

2016-02-03 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 3 February 2016 at 16:24:19 UTC, Adam D. Ruppe wrote: On Wednesday, 3 February 2016 at 16:07:59 UTC, Messenger wrote: What is a good way to try to force it? Using enum? Then optionally copying the value once to avoid the "manifest constant" copy/paste behaviour, where applicable?

Re: template mixins vs alias

2016-02-22 Thread Andrea Fontana via Digitalmars-d-learn
On Monday, 22 February 2016 at 13:56:19 UTC, anonymous wrote: On Monday, 22 February 2016 at 13:35:10 UTC, Andrea Fontana wrote: Check this code: http://dpaste.dzfl.pl/fcf876acbbdc Structs A and B do the same things, in different way. Is there any difference/limitation between those? Andrea

template mixins vs alias

2016-02-22 Thread Andrea Fontana via Digitalmars-d-learn
Check this code: http://dpaste.dzfl.pl/fcf876acbbdc Structs A and B do the same things, in different way. Is there any difference/limitation between those? Andrea

Const vs Non const method

2016-02-25 Thread Andrea Fontana via Digitalmars-d-learn
Check this simple code: http://dpaste.dzfl.pl/2772c9144f1c I can't understand how to minimize code duplication for function like get(). Of course on real case body is much bigger and complex than that. The only way I found is to move the body of function inside a mixin template: mixin

Re: Const vs Non const method

2016-02-25 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 25 February 2016 at 10:48:34 UTC, Namespace wrote: Try inout: import std.stdio; struct Inner { int field = 3; } struct Test { auto get() inout { return inner; } private Inner inner; } void main() { {

Re: Linking C libraries with DMD

2016-01-21 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 21 January 2016 at 16:57:26 UTC, W.J. wrote: You need to port the header file to d. i believe there's the htod utility, however I haven't used that yet. You should try with dstep too. More info here: http://wiki.dlang.org/List_of_Bindings And here:

Create an empty json object with std.json

2016-01-22 Thread Andrea Fontana via Digitalmars-d-learn
If you declare a JSONValue like this: JSONValue json; then: assert(json.type() == JSON_TYPE.NULL); Documentation at https://dlang.org/phobos/std_json.html#.JSONValue.type.2 suggests not to change type but to assign a new value instead. My problem is: how can I assign an empty object like

Re: Create an empty json object with std.json

2016-01-22 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 22 January 2016 at 12:05:48 UTC, userABCabc123 wrote: when you add the first key, the value will be set to JSON_TYPE.OBJECT import std.json; void main(string[] args) { JSONValue json; json["first"] = 0; assert(json.type == JSON_TYPE.OBJECT); } That's right,

Re: Create an empty json object with std.json

2016-01-22 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 22 January 2016 at 16:45:22 UTC, userABCabc123 wrote: But soon or later you'll need to add values to your object so just imagine it's already an object, even if it will only become one when you'll start to add some values. You're wrong, I need an empty object for an API call!

Re: Lazy Range of Graph Links

2016-02-16 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 16 February 2016 at 08:04:29 UTC, Nordlöw wrote: In my knowledge hypergraph I currently have a struct Path { Node start; Step[] steps; } struct Step { Fact fact; Node node; } where Node and Fact a reference types (class). I now want to implement auto byLink(Path

Re: Member Access Based On A Runtime String

2016-03-01 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 1 March 2016 at 05:05:40 UTC, Jack Stouffer wrote: In Python, I can do this: my_obj = Obj() string_from_func = func() setattr(my_obj, string_from_func, 100) Say func() returns "member1" or "member2", the setattr would then set either one of those to 100. Is there any

Re: BitArray: count the number of bits set

2016-03-01 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 1 March 2016 at 09:03:47 UTC, yawniek wrote: i figured i can count the number of bits set for a BitArray with std.algorithm : count: BitArray([0,0,1]).bitsSet.count() but this seems not very optimal, is there a faster way directly accessible trough phobos? ideally something

Re: How to import for mixin contents only.

2016-03-10 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 10 March 2016 at 16:20:42 UTC, Taylor Hillegeist wrote: I feel like this should do what i want it too. but it doesn't. struct Color_t { static if(1==1){ import std.bitmanip:bitfields; immutable string item = bitfields!(

Classes and CTFE

2016-03-10 Thread Andrea Fontana via Digitalmars-d-learn
I used to think that classes can't be used with CTFE. Instead it appears to work, if they're not directly returned but, for example, they're wrapped inside a struct as on example [1]. Ctor is called *only* at compile time, and instance works fine. So, I can't understand: why wrapping a class

Re: Classes and CTFE

2016-03-10 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 10 March 2016 at 14:36:18 UTC, Adam D. Ruppe wrote: On Thursday, 10 March 2016 at 13:56:18 UTC, Andrea Fontana wrote: I used to think that classes can't be used with CTFE. Classes have worked normally with CTFE for several years now. You don't need to do anything special with

Re: How to import for mixin contents only.

2016-03-10 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 10 March 2016 at 17:43:08 UTC, Taylor Hillegeist wrote: I suppose the linker optimized the functions away since they are now in their own section. But it seems a hacky way to do this. AFAIK assert(0) and other falsey assert have a special meaning for compiler. So probably it's

Re: static if else behavior and is type comparison

2016-03-11 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 11 March 2016 at 08:02:41 UTC, Fynn Schröder wrote: Am I doing anything wrong here or is this a bug? You should write: static if { ... } else static if { ... } else static if { ... }

Re: How to set padding for base64 encoding

2016-04-07 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 7 April 2016 at 12:24:06 UTC, Suliman wrote: On Thursday, 7 April 2016 at 12:19:48 UTC, Kagamin wrote: Create a range that would remove the newline characters from string, then decode from that. std.file.write("output.png", Base64.decode(myimg.chomp)); The same error Anyway if

Re: Best properly way to destroy a 2 dimensional array?

2016-04-07 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 6 April 2016 at 20:30:33 UTC, Jonathan Villa wrote: On Wednesday, 6 April 2016 at 19:54:32 UTC, Jonathan Villa wrote: I wrote a little program that given some number it generates a TL;DR: My program generates a very large `ubyte[][]`, and after I call destroy and GC.collect()

Re: Best properly way to destroy a 2 dimensional array?

2016-04-07 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 7 April 2016 at 10:02:05 UTC, Andrea Fontana wrote: On Wednesday, 6 April 2016 at 20:30:33 UTC, Jonathan Villa wrote: On Wednesday, 6 April 2016 at 19:54:32 UTC, Jonathan Villa wrote: I wrote a little program that given some number it generates a TL;DR: My program generates a

Re: Destructor order

2016-03-19 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 18 March 2016 at 14:53:20 UTC, Steven Schveighoffer wrote: On 3/18/16 7:44 AM, Nicholas Wilson wrote: On Friday, 18 March 2016 at 10:20:40 UTC, Temtaime wrote: Hi ! I wonder if i can rely on this code : http://dpaste.dzfl.pl/745cc5b1cdfb There's two questions: 1) Is dtors always

Re: Does something like std.algorithm.iteration:splitter with multiple seperators exist?

2016-03-23 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 23 March 2016 at 12:00:15 UTC, ParticlePeter wrote: On Wednesday, 23 March 2016 at 11:57:49 UTC, ParticlePeter wrote: Stupid typos: I need to parse an ascii file with multiple tokens. ... ... to do this with a lazy result range and without new allocations. Any input =>

Re: parsing HTML for a web robot (crawler) like application

2016-03-23 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 23 March 2016 at 09:02:37 UTC, Martin Tschierschke wrote: Hello! I want to set up a web robot to detect changes on certain web pages or sites. Any hint to similar projects or libraries at dub or git to look at, before starting to develop my own RegExp for parsing? Best regards

Re: Lazy param with nothrow

2016-03-02 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 1 March 2016 at 13:41:38 UTC, Nemo wrote: On Tuesday, 1 March 2016 at 13:35:08 UTC, Andrea Fontana wrote: This very very simple function [1] won't compile. It says that param t is not nothrow. Why? What's wrong with this? http://dpaste.dzfl.pl/bfc382e62711 writeln isn't nothrow

Re: Create Windows "shortcut" (.lnk) with D?

2016-03-07 Thread Andrea Fontana via Digitalmars-d-learn
On Sunday, 6 March 2016 at 20:13:39 UTC, 岩倉 澪 wrote: On Sunday, 6 March 2016 at 11:00:35 UTC, John wrote: On Sunday, 6 March 2016 at 03:13:23 UTC, 岩倉 澪 wrote: IShellLinkA* shellLink; IPersistFile* linkFile; Any help would be highly appreciated as I'm new to Windows programming in D

Lazy param with nothrow

2016-03-01 Thread Andrea Fontana via Digitalmars-d-learn
This very very simple function [1] won't compile. It says that param t is not nothrow. Why? What's wrong with this? http://dpaste.dzfl.pl/bfc382e62711

Re: Destructor order

2016-03-19 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 18 March 2016 at 15:03:14 UTC, Steven Schveighoffer wrote: On 3/18/16 10:58 AM, Andrea Fontana wrote: On Friday, 18 March 2016 at 14:53:20 UTC, Steven Schveighoffer wrote: On 3/18/16 7:44 AM, Nicholas Wilson wrote: On Friday, 18 March 2016 at 10:20:40 UTC, Temtaime wrote: Hi ! I

Re: template auto instantiation when parameters empty

2016-05-05 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 4 May 2016 at 22:10:16 UTC, Erik Smith wrote: Any ideas? Using an alias could be a solution.

Re: LDC with ARM backend

2016-07-21 Thread Andrea Fontana via Digitalmars-d-learn
On Thursday, 21 July 2016 at 09:59:53 UTC, Claude wrote: I can build a "Hello world" program on ARM GNU/Linux, with druntime and phobos. I'll write a doc page about that. It's a good idea :)

Re: Probably trivial Linux link problem that I've spent hours on.

2016-07-05 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 5 July 2016 at 03:32:25 UTC, WhatMeWorry wrote: Just learning Linux. Got my first vibe/dub project which dies at: Compiling diet template 'index.dt'... Linking... /usr/bin/ld: cannot find -lsqlite3 collect2: error: ld returned 1 exit status I downloaded DUB's d2sqlite3 and built

Re: Build a SysTime from a string

2016-07-06 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 6 July 2016 at 14:55:51 UTC, Jonathan M Davis wrote: auto st = SysTime.fromISOExtString("2011-03-02T15:30:00+01:00"); That's perfect. I didn't notice that static method. My fault!

Build a SysTime from a string

2016-07-06 Thread Andrea Fontana via Digitalmars-d-learn
Ok, I have a string like: 2011-03-02T15:30:00+01:00 I need to convert it in a SysTime object. My problem is that from documentation I can't understand how to set +01:00 timezone on systime. I guess I'm missing something... Andrea

Re: Build a SysTime from a string

2016-07-06 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 6 July 2016 at 14:19:56 UTC, Dejan Lekic wrote: On Wednesday, 6 July 2016 at 14:15:22 UTC, Andrea Fontana wrote: My problem is that from documentation I can't understand how to set +01:00 timezone on systime. I guess I'm missing something... As far as I know, you can't do that.

  1   2   3   >