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 fun

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 memor

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 "inh

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; printf("

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 pop

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_); z.capacit

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. https://dpaste.dzfl.pl/adc

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 t

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 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 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 c

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. sorr

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. sorr

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 for

Re: Why is &array[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 &array[0] instead &array[0] is incredibly ugly and feels like an unnec

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 whe

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. i

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 st

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:04:23 UTC, Gianni Pisetta wrote: Hi all, but at the moment isStringLiteral will return true even with variables of type string. So i searched for a metod to check if an alias is a literal value, but found nothing. Anyone have any clue on how can be done? Th

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 is

Re: Meta-programming detecting anonymous unions inside structs.

2016-10-21 Thread TheFlyingFiddle via Digitalmars-d-learn
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 is for error reporting. Basically any struct that contains unions without serialization instructions cannot be seria

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 us

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 a

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] // Error:

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 wors

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 nu

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 impleme

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 imp

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 to

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 t

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 add

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 do

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 identica

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 windows.

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: 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 reall

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

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: http://dlang.org/phobos/std_algorithm_searching.html#

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 pr

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; whi

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: 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 out

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 sl

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 notice

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.

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 fo

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 min

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: 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 s

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: 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 the

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 thin

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 ar

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. F

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 finali

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 = argv[

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 01:42:58 UTC, Daniel Gibson wrote: Am 21.07.2014 03:34, schrieb Vlad Levenfeld: To get a foreach to run at compile-time, you have to give it something whose value is known to the compiler (so, T and typeof(argTuple) would suffice, and 0..T.length really should as wel

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: 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: template staticIota(size_t s, size_t e, size_t step = 1) { import std.typetuple : TypeTuple; static if(s < e) alias staticIota = TypeTuple!(s, staticIota!(s + step, e, step)); else alias staticIota = TypeTuple!

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 = MyCompare(SortO

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 tween

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; publi

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 answer...or