Re: C++ launched its community survey, too

2018-02-28 Thread TheFlyingFiddle via Digitalmars-d
On Wednesday, 28 February 2018 at 20:01:34 UTC, H. S. Teoh wrote: Just to give some background. At work I spend most of my time maintaining legacy systems adding some small features or replacing subcomponents. So most of what I do is reading code and making some minor changes (unless it's

Re: C++ launched its community survey, too

2018-02-28 Thread TheFlyingFiddle via Digitalmars-d
On Wednesday, 28 February 2018 at 10:15:13 UTC, Zoadian wrote: On Wednesday, 28 February 2018 at 00:53:16 UTC, psychoticRabbit wrote: It should have gone to the Java developers - cause they deserved it. C++ is the worst thing to have ever come out of computer science! yes c++ is not the

Re: Function template declaration mystery...

2018-02-28 Thread TheFlyingFiddle via Digitalmars-d-learn
On Wednesday, 28 February 2018 at 17:47:22 UTC, Robert M. Münch wrote: Hi, I'm lost reading some code: A a; auto do(alias f, A)(auto ref A _a){ alias fun = unaryFun!f; return ... ... } How is this alias stuff working? I mean what's the type of f? Is it an anonymous

Re: Cast a 2d static array to a 1d static array. T[s][r] -> T[s*r]

2018-02-27 Thread TheFlyingFiddle via Digitalmars-d-learn
On Tuesday, 27 February 2018 at 22:17:25 UTC, Jonathan wrote: On Tuesday, 27 February 2018 at 22:13:05 UTC, Jonathan wrote: Is it possible to cast a 2d static length array to a 1d static length array? E.g. int[2][2] a = [[1,2],[3,4]]; int[4]b = cast(int[4])a; Is not the byte data in

Re: implicit construction operator

2018-02-27 Thread TheFlyingFiddle via Digitalmars-d
On Monday, 26 February 2018 at 23:33:48 UTC, H. S. Teoh wrote: Not really a big deal (and auto kind of ruins it) but it would make stuff consistent between user types and built in ones. Not sure what you mean here. In a user type, if opBinary!"/" returns an int, then you still have the same

Re: implicit construction operator

2018-02-26 Thread TheFlyingFiddle via Digitalmars-d
On Monday, 26 February 2018 at 21:30:09 UTC, aliak wrote: On Monday, 26 February 2018 at 19:32:44 UTC, ketmar wrote: WebFreak001 wrote: And if that's also a no no, how about char -> int. Or int -> float? Is ok? Maybe there're some valid arguments, to disallow it *completely* though?

Re: Destructor called twice.

2018-02-26 Thread TheFlyingFiddle via Digitalmars-d-learn
On Sunday, 25 February 2018 at 21:35:33 UTC, ketmar wrote: add postblit debug prints, and you will see. I get that it will call the postblit since it creates a temporary. What I expected though was that. auto s = S(0).foo(1); Would become something like: S s; s.__ctor(0).foo(1); But maybe

Re: Aliasing member's members

2018-02-26 Thread TheFlyingFiddle via Digitalmars-d-learn
On Monday, 26 February 2018 at 20:50:35 UTC, Kayomn wrote: I've been experimenting with D's Better C mode, and I have a question regarding something that I started thinking about after watching one of Jonathon Blow's talks on data-oriented programming - more specifically the aspect of fake

Destructor called twice.

2018-02-25 Thread TheFlyingFiddle via Digitalmars-d-learn
When writing some code to setup properties in a chain function manner I ran into some unexpected behavior with destructors. Example: struct S { int a, b; ref S foo(int b) { this.b = b; return this; } this(int ab) { this.a = this.b = ab;

Re: Double link list

2018-02-24 Thread TheFlyingFiddle via Digitalmars-d-learn
On Saturday, 24 February 2018 at 09:48:13 UTC, Joel wrote: I'm trying some code for practice, but it isn't working properly - it prints just one number when printing in reverse. I think the problem is here: void popFront() { head = head.next; if (head !is null) head.prev = null; } void

Re: array/Array: "hard" bounds checking

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

Re: array/Array: "hard" bounds checking

2018-02-21 Thread TheFlyingFiddle via Digitalmars-d-learn
On Thursday, 22 February 2018 at 00:34:59 UTC, kdevel wrote: Is there a D equivalent of the C++ at method? I would like to reformulate repro2.d --- void main () { import std.stdio; import std.container; import std.range; auto z = Array!char(); z.reserve(0xC000_);

Re: Policy-based design in D

2017-02-14 Thread TheFlyingFiddle via Digitalmars-d-learn
On Tuesday, 14 February 2017 at 06:48:33 UTC, TheGag96 wrote: Tonight I stumbled upon Andrei's concept of policy-based design (https://en.wikipedia.org/wiki/Policy-based_design) and tried to implement their example in D with the lack of multiple inheritance in mind.

Re: Yield from function?

2017-01-30 Thread TheFlyingFiddle via Digitalmars-d-learn
On Monday, 30 January 2017 at 11:03:52 UTC, Profile Anaysis wrote: I need to yield from a complex recursive function too allow visualizing what it is doing. e.g., if it is a tree searching algorithm, I'd like to yield for each node so that the current state can be shown visually. I realize

Re: Is it possible to "cache" results of compile-time executions between compiles?

2017-01-24 Thread TheFlyingFiddle via Digitalmars-d-learn
On Tuesday, 24 January 2017 at 21:41:12 UTC, Profile Anaysis wrote: On Tuesday, 24 January 2017 at 21:36:50 UTC, Profile Anaysis wrote: ... Maybe with all this talk of the new CTFE engine being developed, a similar mechanism can be used optionally? This could help with debugging also. In

Re: Is it possible to "cache" results of compile-time executions between compiles?

2017-01-24 Thread TheFlyingFiddle via Digitalmars-d-learn
On Tuesday, 24 January 2017 at 21:36:50 UTC, Profile Anaysis wrote: On Tuesday, 24 January 2017 at 16:49:03 UTC, TheFlyingFiddle wrote: On Tuesday, 24 January 2017 at 16:41:13 UTC, TheFlyingFiddle wrote: Everything turned out s much better than expected :) Added bonus is that mixin output

Re: Is it possible to "cache" results of compile-time executions between compiles?

2017-01-24 Thread TheFlyingFiddle via Digitalmars-d-learn
On Tuesday, 24 January 2017 at 16:41:13 UTC, TheFlyingFiddle wrote: Everything turned out s much better than expected :) Added bonus is that mixin output can be viewed in the generated files :D

Re: Is it possible to "cache" results of compile-time executions between compiles?

2017-01-24 Thread TheFlyingFiddle via Digitalmars-d-learn
On Tuesday, 24 January 2017 at 12:19:33 UTC, ketmar wrote: On Tuesday, 24 January 2017 at 12:14:05 UTC, TheFlyingFiddle wrote: unittest { enum s = import("myfile"); } Is there something similar to this for outputting files at compile-time? no. this is by design, so it won't be fixed.

Re: Is it possible to "cache" results of compile-time executions between compiles?

2017-01-24 Thread TheFlyingFiddle via Digitalmars-d-learn
On Tuesday, 24 January 2017 at 12:19:33 UTC, ketmar wrote: On Tuesday, 24 January 2017 at 12:14:05 UTC, TheFlyingFiddle wrote: unittest { enum s = import("myfile"); } Is there something similar to this for outputting files at compile-time? no. this is by design, so it won't be fixed.

Re: Is it possible to "cache" results of compile-time executions between compiles?

2017-01-24 Thread TheFlyingFiddle via Digitalmars-d-learn
On Tuesday, 24 January 2017 at 11:19:58 UTC, TheFlyingFiddle wrote: Does D have any facilities that could make this possible? It seems that there is a feature I was unaware of/forgot called Import Expressions. unittest { enum s = import("myfile"); } Is there something similar to this

Re: Why is [0] @safer than array.ptr?

2017-01-24 Thread TheFlyingFiddle via Digitalmars-d-learn
On Tuesday, 24 January 2017 at 11:28:17 UTC, Atila Neves wrote: void main() { foo; } void foo() @safe { int[] array; auto ptr = array.ptr; } foo.d(7): Deprecation: array.ptr cannot be used in @safe code, use [0] instead [0] is incredibly ugly and feels like an unnecessary

Is it possible to "cache" results of compile-time executions between compiles?

2017-01-24 Thread TheFlyingFiddle via Digitalmars-d-learn
Context: I am currently writing a small library that compiles sql strings at compile-time and generates query objects. Something like this: unittest { mixin Sql!(q{ select feed.url, feed.title from users join user_feeds as feed on users.id = feed.user

Re: Problems with stored procedure using the mysql-native library.

2017-01-18 Thread TheFlyingFiddle via Digitalmars-d-learn
On Wednesday, 18 January 2017 at 19:40:12 UTC, TheFlyingFiddle wrote: Hi I am having problems using stored procedures that return results. Update: I am using the SvrCapFlags.MULTI_RESULTS flag when initiating the connection and have also tried using the SvrCapFlags.MULTI_STATEMENTS flag.

Problems with stored procedure using the mysql-native library.

2017-01-18 Thread TheFlyingFiddle via Digitalmars-d-learn
Hi I am having problems using stored procedures that return results. Example procedure: CREATE PROCEDURE GetUsers() SELECT * FROM users; When I use this procedure from the MySQL command line everything works fine. However, when I use it from the mysql-native library i get into problems.

Re: test if the alias of a template is a literal

2016-10-27 Thread TheFlyingFiddle via Digitalmars-d-learn
On Thursday, 27 October 2016 at 14:45:22 UTC, Gianni Pisetta wrote: On Thursday, 27 October 2016 at 14:34:38 UTC, TheFlyingFiddle wrote: On Thursday, 27 October 2016 at 14:04:23 UTC, Gianni Pisetta wrote: Hi all, but at the moment isStringLiteral will return true even with variables of type

Re: Meta-programming detecting anonymous unions inside structs.

2016-10-21 Thread TheFlyingFiddle via Digitalmars-d-learn
On Friday, 21 October 2016 at 08:18:58 UTC, rikki cattermole wrote: On 21/10/2016 9:13 PM, TheFlyingFiddle wrote: On Friday, 21 October 2016 at 07:56:27 UTC, rikki cattermole wrote: You're gonna have to use UDA's for that. Yes, to do the serialization you're right. But my usecase for this

Meta-programming detecting anonymous unions inside structs.

2016-10-21 Thread TheFlyingFiddle via Digitalmars-d-learn
I am trying to port a serialization library I wrote in Lua some time ago. I've ran into a problem relating to types with anonymous unions inside. Given this code: enum Kind { none = 0, array, integer, floating, } struct Foo { Kind type; union { ulong integer;

Re: How to do "inheritance" in D structs

2016-10-11 Thread TheFlyingFiddle via Digitalmars-d-learn
On Wednesday, 12 October 2016 at 02:18:47 UTC, TheFlyingFiddle wrote: void foo(ref ABase base) { base.ival = 32; } This should be: void foo(ref Base1 base) { base.ival = 32; }

Re: How to do "inheritance" in D structs

2016-10-11 Thread TheFlyingFiddle via Digitalmars-d-learn
On Wednesday, 12 October 2016 at 01:22:04 UTC, lobo wrote: Hi, I'm coming from C++ and wondered if the pattern below has an equivalent in D using structs. I could just use classes and leave it up to the caller to use scoped! as well but I'm not sure how that will play out when others start

Re: Working with ranges: mismatched function return type inference

2016-10-11 Thread TheFlyingFiddle via Digitalmars-d-learn
On Tuesday, 11 October 2016 at 15:46:20 UTC, orip wrote: On Tuesday, 11 October 2016 at 13:06:37 UTC, pineapple wrote: Rewrite `return chain(ints[0..5], ints[8..$]);` as `return ints[0..5] ~ ints[8..$];` The `chain` function doesn't return an array, it returns a lazily-evaluated sequence of

Re: bug, or is this also intended?

2016-10-04 Thread TheFlyingFiddle via Digitalmars-d-learn
On Monday, 3 October 2016 at 11:40:00 UTC, deed wrote: Unexpected auto-concatenation of string elements: string[] arr = ["a", "b" "c"];// ["a", "bc"], length==2 int[] arr2 = [[1], [2] [3]];// Error: array index 3 is out of bounds [2][0 .. 1] //

Re: How to make rsplit (like in Python) in D

2016-10-01 Thread TheFlyingFiddle via Digitalmars-d-learn
On Saturday, 1 October 2016 at 16:45:11 UTC, Uranuz wrote: How to make rsplit (like in Python) in D without need for extra allocation using standard library? And why there is no algorithms (or parameter in existing algorithms) to process range from the back. Is `back` and `popBack` somehow

What does the -betterC switch in dmd do?

2015-11-12 Thread TheFlyingFiddle via Digitalmars-d-learn
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 (if) completed what subset of the language would still be usable?

Re: String interpolation

2015-11-10 Thread TheFlyingFiddle via Digitalmars-d-learn
On Tuesday, 10 November 2015 at 10:41:52 UTC, tired_eyes wrote: On Tuesday, 10 November 2015 at 10:33:30 UTC, Tobias Pankrath wrote: Ruby: a = 1 b = 4 puts "The number #{a} is less than #{b}" PHP: $a = 1; $b = 4; echo "The number $a is less than $b"; D: ??? int a = 1, b = 4; writefln("The

Re: Associative arrays

2015-11-09 Thread TheFlyingFiddle via Digitalmars-d-learn
On Monday, 9 November 2015 at 04:52:37 UTC, rsw0x wrote: On Monday, 9 November 2015 at 04:29:30 UTC, Rikki Cattermole wrote: Fwiw, EMSI provides high quality containers backed by std.experimental.allocator. https://github.com/economicmodeling/containers I have a question regarding the

Re: Associative arrays

2015-11-09 Thread TheFlyingFiddle via Digitalmars-d-learn
On Monday, 9 November 2015 at 04:52:37 UTC, rsw0x wrote: On Monday, 9 November 2015 at 04:29:30 UTC, Rikki Cattermole wrote: On 09/11/15 4:57 PM, TheFlyingFiddle wrote: [...] Nope. [...] As far as I'm aware, you are stuck using e.g. structs to emulate AA behavior. I have a VERY basic

Re: Is D so powerfull ??

2015-11-08 Thread TheFlyingFiddle via Digitalmars-d
On Sunday, 8 November 2015 at 10:22:44 UTC, FreeSlave wrote: On Saturday, 7 November 2015 at 14:49:05 UTC, ZombineDev wrote: basically you don't have technical reasons not to use D :D What about the lack of proper support for dynamic libraries on Windows and OSX? I mean, GC merging is still

Re: D for TensorFlow-like library

2015-11-08 Thread TheFlyingFiddle via Digitalmars-d
On Sunday, 8 November 2015 at 17:47:33 UTC, Muktabh wrote: We cannot make D bindings to it because it is a closed source project by Google and only a spec like mapreduce will be released, so I thought maybe I might try and come up with an open source implementation. I was just curious if D

Re: Preferred behavior of take() with ranges (value vs reference range)

2015-11-08 Thread TheFlyingFiddle via Digitalmars-d-learn
On Monday, 9 November 2015 at 02:14:58 UTC, Jon D wrote: Here's an example of the behavior differences below. It uses refRange, but same behavior occurs if the range is created as a class rather than a struct. --Jon This is an artifact of struct based ranges being value types. When you use

Associative arrays

2015-11-08 Thread TheFlyingFiddle via Digitalmars-d-learn
I have a few questions about the pseudo built in associative arrays. 1. Is it possible to have the built in associative array use a custom allocator from std.experimental.allocator to service it's allocation needs? 2. A while ago I read on the newsgroup a while back that there was a plan

Re: Metaprogramming in D - From a beginner's perspective

2015-11-08 Thread TheFlyingFiddle via Digitalmars-d
On Sunday, 8 November 2015 at 21:03:44 UTC, maik klein wrote: Here is the blog post https://maikklein.github.io/2015/08/11/Metaprogramming-D/ And the discussion on reddit: https://www.reddit.com/r/programming/comments/3s1qrt/metaprogramming_in_d_from_a_beginners_perspective/ Interesting

Re: Align a variable on the stack.

2015-11-06 Thread TheFlyingFiddle via Digitalmars-d-learn
On Friday, 6 November 2015 at 11:38:29 UTC, Marc Schütz wrote: On Friday, 6 November 2015 at 11:37:22 UTC, Marc Schütz wrote: Ok, benchA and benchB have the same assembler code generated. However, I _can_ reproduce the slowdown albeit on average only 20%-40%, not a factor of 10. Forgot to

Re: Align a variable on the stack.

2015-11-05 Thread TheFlyingFiddle via Digitalmars-d-learn
On Thursday, 5 November 2015 at 21:24:03 UTC, TheFlyingFiddle wrote: On Thursday, 5 November 2015 at 21:22:18 UTC, TheFlyingFiddle wrote: On Thursday, 5 November 2015 at 11:14:50 UTC, Marc Schütz wrote: ~10x slowdown... I forgot to mention this but I am using DMD 2.069.0-rc2 for x86

Re: Align a variable on the stack.

2015-11-05 Thread TheFlyingFiddle via Digitalmars-d-learn
On Thursday, 5 November 2015 at 11:14:50 UTC, Marc Schütz wrote: On Thursday, 5 November 2015 at 03:52:47 UTC, TheFlyingFiddle wrote: Can you publish two compilable and runnable versions of the code that exhibit the difference? Then we can have a look at the generated assembly. If there's

Re: Align a variable on the stack.

2015-11-05 Thread TheFlyingFiddle via Digitalmars-d-learn
On Thursday, 5 November 2015 at 21:22:18 UTC, TheFlyingFiddle wrote: On Thursday, 5 November 2015 at 11:14:50 UTC, Marc Schütz wrote: ~10x slowdown... I forgot to mention this but I am using DMD 2.069.0-rc2 for x86 windows.

Re: Unittest in a library

2015-11-05 Thread TheFlyingFiddle via Digitalmars-d-learn
On Friday, 6 November 2015 at 03:59:07 UTC, Charles wrote: Is it possible to have unittest blocks if I'm compiling a library? I've tried having this: test.d: class Classy { unittest { assert(0, "failed test"); } } and then build it with `dmd test.d -lib -unittest` and it

Re: Align a variable on the stack.

2015-11-05 Thread TheFlyingFiddle via Digitalmars-d-learn
On Friday, 6 November 2015 at 00:43:49 UTC, rsw0x wrote: On Thursday, 5 November 2015 at 23:37:45 UTC, TheFlyingFiddle wrote: On Thursday, 5 November 2015 at 21:24:03 UTC, TheFlyingFiddle wrote: [...] I reduced it further: [...] these run at the exact same speed for me and produce

Re: Align a variable on the stack.

2015-11-04 Thread TheFlyingFiddle via Digitalmars-d-learn
On Wednesday, 4 November 2015 at 01:14:31 UTC, Nicholas Wilson wrote: Note that there are two different alignments: to control padding between instances on the stack (arrays) to control padding between members of a struct align(64) //arrays struct foo { align(16) short

Align a variable on the stack.

2015-11-03 Thread TheFlyingFiddle via Digitalmars-d-learn
Is there a built in way to do this in dmd? Basically I want to do this: auto decode(T)(...) { while(...) { T t = T.init; //I want this aligned to 64 bytes. } } Currently I am using: align(64) struct Aligner(T) { T value; } auto decode(T)(...) { Aligner!T t = void;

Re: Is it possible to filter variadics?

2015-11-03 Thread TheFlyingFiddle via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 23:41:10 UTC, maik klein wrote: Is it possible to filter variadics for example if I would call void printSumIntFloats(Ts...)(Ts ts){...} printSumIntFloats(1,1.0f,2,2.0f); I want to print the sum of all integers and the sum of all floats. //Pseudo code void

Re: foreach loop

2015-11-03 Thread TheFlyingFiddle via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 15:29:31 UTC, Namal wrote: well I tried this that way, but my count stays 0, same as if I do it in an int function with a return though I clearly have some false elements in the arr. You could also use count:

Re: Efficiency of immutable vs mutable

2015-11-02 Thread TheFlyingFiddle via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 03:16:07 UTC, Andrew wrote: I've written a short D program that involves many lookups into a static array. When I make the array immutable the program runs faster. This must mean that immutable is more than a restriction on access, it must affect the compiler

Re: Unionize range types

2015-11-02 Thread TheFlyingFiddle via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 01:55:27 UTC, Freddy wrote: Is there any way I can Unionize range Types? --- auto primeFactors(T)(T t, T div = 2) { if (t % div == 0) { return t.only.chain(primeFactors(t / div, div)); } if (div > t) { return []; } else

Re: Attributes on parameters in functions.

2015-10-31 Thread TheFlyingFiddle via Digitalmars-d
On Saturday, 31 October 2015 at 12:45:13 UTC, Jacob Carlborg wrote: On 2015-10-30 22:28, TheFlyingFiddle wrote: In other languages that have Attributes (Java and C# atleast) I can do stuff like this: (Java) //com.bar.java interface Bar { /*stuff*/ } //com.foo.java class Foo { Foo(@Bar int

Attributes on parameters in functions.

2015-10-30 Thread TheFlyingFiddle via Digitalmars-d
In other languages that have Attributes (Java and C# atleast) I can do stuff like this: (Java) //com.bar.java interface Bar { /*stuff*/ } //com.foo.java class Foo { Foo(@Bar int a) { //some stuff } } I don't seem to be able to do this in D. That is I cannot do this: enum Bar;

Re: Static constructors in structs.

2015-10-30 Thread TheFlyingFiddle via Digitalmars-d-learn
On Friday, 30 October 2015 at 21:29:22 UTC, BBasile wrote: __gshared is mostly usefull on fields (eg public uint a) because it prevents a data to be put on the TLS, which in certain case reduces the perfs up to 30%. The byte code using a global variable that's not __gshared can be incredibly

Static constructors in structs.

2015-10-30 Thread TheFlyingFiddle via Digitalmars-d-learn
Is this intended to work? struct A { __gshared static this() { //Add some reflection info to some global stuff. addReflectionInfo!(typeof(this)); } } I just noticed this works in 2.069, is this intended? I mean I love it! It makes it possible to do lot's of useful mixins

How can I distinguish an enum constant from an actual enum at compile time?

2015-10-30 Thread TheFlyingFiddle via Digitalmars-d-learn
I want to be able to do something like this: enum a = 32 enum b = { q,w,e,r,t,y } CtType ctype = getCtType!(a); // -> Would become CtType.enumConstant CtType ctype1 = getCtType!(b); // -> Would become CtType.enum_

Re: How can I distinguish an enum constant from an actual enum at compile time?

2015-10-30 Thread TheFlyingFiddle via Digitalmars-d-learn
On Friday, 30 October 2015 at 11:46:43 UTC, TheFlyingFiddle wrote: I want to be able to do something like this: enum a = 32 enum b = { q,w,e,r,t,y } CtType ctype = getCtType!(a); // -> Would become CtType.enumConstant CtType ctype1 = getCtType!(b); // -> Would become CtType.enum_ Never

Re: Static constructors in structs.

2015-10-30 Thread TheFlyingFiddle via Digitalmars-d-learn
On Friday, 30 October 2015 at 20:58:37 UTC, anonymous wrote: On 30.10.2015 21:23, TheFlyingFiddle wrote: Is this intended to work? struct A { __gshared static this() { //Add some reflection info to some global stuff. addReflectionInfo!(typeof(this)); } } I just

Re: Static constructors in structs.

2015-10-30 Thread TheFlyingFiddle via Digitalmars-d-learn
On Friday, 30 October 2015 at 20:59:46 UTC, Adam D. Ruppe wrote: On Friday, 30 October 2015 at 20:23:45 UTC, TheFlyingFiddle wrote: But yeah, the struct feature table http://dlang.org/struct.html shows them as checked. I gotta say the language documentation is shaping up nicely.

Re: Option types and pattern matching.

2015-10-27 Thread TheFlyingFiddle via Digitalmars-d
On Tuesday, 27 October 2015 at 07:55:46 UTC, Kagamin wrote: On Monday, 26 October 2015 at 16:42:27 UTC, TheFlyingFiddle wrote: If you instead use pattern matching as in your example you have much better context information that can actually help you do something in the case a value is not

Re: What's in a empty class?

2015-10-27 Thread TheFlyingFiddle via Digitalmars-d-learn
On Tuesday, 27 October 2015 at 21:28:31 UTC, Adam D. Ruppe wrote: On Tuesday, 27 October 2015 at 21:23:45 UTC, TheFlyingFiddle wrote: I can account for the first thing a vtable. But that should only cover 4bytes. What's in the other 4bytes? The monitor used for `synchronized`. (yes, this is

Re: Option types and pattern matching.

2015-10-27 Thread TheFlyingFiddle via Digitalmars-d
On Tuesday, 27 October 2015 at 17:48:04 UTC, Meta wrote: On Tuesday, 27 October 2015 at 15:06:07 UTC, TheFlyingFiddle wrote: This can arguably already be done cleaner in D. if (auto worldFile = getAFile("world.json")) { auto world = parseJSON(worldFile); if (auto mapFile =

What's in a empty class?

2015-10-27 Thread TheFlyingFiddle via Digitalmars-d-learn
With this code: class A { } pragma(msg, __traits(classInstanceSize, A)); I get the output 8 (32-bit). I can account for the first thing a vtable. But that should only cover 4bytes. What's in the other 4bytes?

Re: Option types and pattern matching.

2015-10-26 Thread TheFlyingFiddle via Digitalmars-d
On Monday, 26 October 2015 at 11:40:09 UTC, Edmund Smith wrote: On Sunday, 25 October 2015 at 06:22:51 UTC, TheFlyingFiddle wrote: You could also emulate constant matching using default parameters (albeit with the restriction that they must be after any non-default/constant parameters), since

Re: Option types and pattern matching.

2015-10-26 Thread TheFlyingFiddle via Digitalmars-d
On Monday, 26 October 2015 at 15:58:38 UTC, Edmund Smith wrote: On Monday, 26 October 2015 at 14:13:20 UTC, TheFlyingFiddle wrote: On Monday, 26 October 2015 at 11:40:09 UTC, Edmund Smith wrote: Scala's Option is really nice on the other hand since you can/should pattern match). Don't really

Re: Option types and pattern matching.

2015-10-25 Thread TheFlyingFiddle via Digitalmars-d
On Sunday, 25 October 2015 at 05:45:15 UTC, Nerve wrote: On Sunday, 25 October 2015 at 05:05:47 UTC, Rikki Cattermole wrote: Since I have no idea what the difference between Some(_), None and default. I'll assume it's already doable. _ represents all existing values not matched. In this case,

Re: Option types and pattern matching.

2015-10-25 Thread TheFlyingFiddle via Digitalmars-d
On Sunday, 25 October 2015 at 14:43:25 UTC, Nerve wrote: On Sunday, 25 October 2015 at 06:22:51 UTC, TheFlyingFiddle wrote: That is actually freaking incredible. It evaluates to a value, unwraps values, matches against the None case...I guess the only thing it doesn't do is have

Re: Option types and pattern matching.

2015-10-25 Thread TheFlyingFiddle via Digitalmars-d
On Sunday, 25 October 2015 at 18:23:42 UTC, Dmitry Olshansky wrote: I humbly believe that D may just add special re-write rule to the switch statement in order to allow user-defined switchable types. This goes along nicely with the trend - e.g. foreach statement works with anything having

Re: Array of templated classes or structs

2015-10-24 Thread TheFlyingFiddle via Digitalmars-d-learn
On Saturday, 24 October 2015 at 15:57:09 UTC, Dandyvica wrote: Hi guys, Apart from deriving from the same class and declaring an array of that root class, is there a way to create an array of templates? This seems not possible since template are compile-time generated, but just to be sure.

Re: Kinds of containers

2015-10-24 Thread TheFlyingFiddle via Digitalmars-d
On Saturday, 24 October 2015 at 09:22:37 UTC, Jacob Carlborg wrote: Can these be implemented by the user just declaring a regular container as immutable? The implement will recognize if it's declared as immutable and adapt. How can a type know it's qualifier? struct Container(T) { //

Re: Array of templated classes or structs

2015-10-24 Thread TheFlyingFiddle via Digitalmars-d-learn
On Saturday, 24 October 2015 at 19:00:57 UTC, TheFlyingFiddle wrote: One thing about variant is that if the struct you are trying to insert is larger then (void delegate()).sizeof it will allocate the wrapped type on the gc heap. This is not a concern if you want to have class templates as

Re: Array of templated classes or structs

2015-10-24 Thread TheFlyingFiddle via Digitalmars-d-learn
On Saturday, 24 October 2015 at 18:40:02 UTC, TheFlyingFiddle wrote: To complete TemplateStruct simply forward the remaing members of the variant. Or use something like proxy!T in std.typecons. Or use an alias this v. (I don't really recommend alias this it has all kinds of problems) One

Re: Array of templated classes or structs

2015-10-24 Thread TheFlyingFiddle via Digitalmars-d-learn
On Saturday, 24 October 2015 at 18:29:08 UTC, TheFlyingFiddle wrote: Variant[] array; array ~= S!int(...); array ~= S!double(...); array ~= S!long(...); array ~= "I am a string!"; And this is probably not what you want. You can do this if you want to ensure that items stored in the variant

Re: D serialization temporary fixup?

2015-10-22 Thread TheFlyingFiddle via Digitalmars-d-learn
On Thursday, 22 October 2015 at 16:15:23 UTC, Shriramana Sharma wrote: I wanted a D equivalent to: http://doc.qt.io/qt-5/qdatastream.html https://docs.python.org/3/library/pickle.html and saw that one is under construction: http://wiki.dlang.org/Review/std.serialization But till it's

Re: Ternary if and ~ does not work quite well

2015-10-12 Thread TheFlyingFiddle via Digitalmars-d-learn
On Monday, 12 October 2015 at 05:19:40 UTC, Andre wrote: Hi, writeln("foo "~ true ? "bar" : "baz"); André "foo" ~ true How does this compile? All i can see is a user trying to append a boolean to a string which is obvously a type error. Or are they converted to ints and then ~ would

Re: Degenerate Regex Case

2015-04-24 Thread TheFlyingFiddle via Digitalmars-d-learn
On Friday, 24 April 2015 at 18:28:16 UTC, Guillaume wrote: Hello, I'm trying to make a regex comparison with D, based off of this article: https://swtch.com/~rsc/regexp/regexp1.html I've written my code like so: import std.stdio, std.regex; void main(string argv[]) { string m =

Re: D Unittest shortcomings with DLLs

2015-03-04 Thread TheFlyingFiddle via Digitalmars-d
On Tuesday, 3 March 2015 at 17:49:07 UTC, Benjamin Thaut wrote: Any suggestions how to fix this issue? I'm also open for implementation hints. Kind Regards Benjamin Thaut Running unittests that access private symbols from the other side of the dll boundary sounds like a very hard problem to

Re: How can I do that in @nogc?

2015-02-25 Thread TheFlyingFiddle via Digitalmars-d-learn
On Wednesday, 25 February 2015 at 19:32:50 UTC, Namespace wrote: How can I specify that 'func' is @nogc? Or can define the function otherwise? An alternative solution would be to use function templated on an alias. import std.traits; void glCheck(alias func)(string file = __FILE__,

Re: Map one tuple to another Tuple of different type

2014-07-21 Thread TheFlyingFiddle via Digitalmars-d-learn
On Monday, 21 July 2014 at 15:04:14 UTC, TheFlyingFiddle wrote: //Outputs 1 to 10 at compile-time. Edit: 0 to 9

Re: How to define and use a custom comparison function

2014-06-17 Thread TheFlyingFiddle via Digitalmars-d-learn
On Tuesday, 17 June 2014 at 07:53:51 UTC, monarch_dodra wrote: On Tuesday, 17 June 2014 at 04:32:20 UTC, Jakob Ovrum wrote: On Monday, 16 June 2014 at 20:49:29 UTC, monarch_dodra wrote: MyCompare cmp(SortOrder.ASC, 10); This syntax is not valid D. It should be: auto cmp =

Re: Library design

2014-06-12 Thread TheFlyingFiddle via Digitalmars-d-learn
On Friday, 13 June 2014 at 04:11:38 UTC, Rutger wrote: I'm trying to create a minimal tweening library in D based on the commonly used easing equations by Robert Penner (http://www.robertpenner.com/easing/). One of the goals with the design of the library is that any numeric type should be

Re: Operator/concept interoperability

2014-06-03 Thread TheFlyingFiddle via Digitalmars-d
On Tuesday, 3 June 2014 at 19:55:39 UTC, Mason McGill wrote: I have a numerical/multimedia library that defines the concept of an n-dimensional function sampled on a grid, and operations on such grids. `InputGrid`s (analogous to `InputRange`s) can be dense or sparse multidimensional arrays, as

Re: std.benchmark

2014-05-28 Thread TheFlyingFiddle via Digitalmars-d
On Wednesday, 28 May 2014 at 16:33:13 UTC, Russel Winder via Digitalmars-d wrote: On Wed, 2014-05-28 at 15:54 +, Joakim via Digitalmars-d wrote: […] A google search turns up a long review thread a couple years ago:

Re: Cost of .dup vs. instantiation

2014-05-28 Thread TheFlyingFiddle via Digitalmars-d-learn
On Wednesday, 28 May 2014 at 14:36:25 UTC, Chris wrote: I use Appender to fill an array. The Appender is a class variable and is not instantiated with each function call to save instantiation. However, the return value or the function must be dup'ed, like so: Appender!(MyType[]) append;

Re: core.sync.rwmutex example

2014-05-10 Thread TheFlyingFiddle via Digitalmars-d-learn
On Friday, 9 May 2014 at 23:12:44 UTC, Charles Hixson via Digitalmars-d-learn wrote: But I'm worried about the receiving end. It needs, somehow, to ensure that the message it receives is the appropriate message, and that other messages don't get dropped while it's waiting for the