Re: Static array * scalar is not working for me

2017-07-30 Thread Marc Schütz via Digitalmars-d-learn
On Sunday, 30 July 2017 at 08:18:07 UTC, Danni Coy wrote: The following code is not working for me float[3] f; f[] = abs(f)[] * -1.0f; where abs is a function that returns a float[3]; it complains that f should be attached to some memory. Is it a bug or am I missing something? I cannot repro

Re: GC

2017-07-30 Thread Marc Schütz via Digitalmars-d-learn
On Sunday, 30 July 2017 at 09:12:53 UTC, piotrekg2 wrote: I would like to learn more about GC in D. For example can anyone explain why do we need memset(0) here: https://github.com/dlang/phobos/blob/master/std/container/array.d#L356 , doesn't it assume a certain type of GC? What if there is a ne

Re: How to call function with variable arguments at runtime?

2017-10-10 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 10 October 2017 at 02:58:45 UTC, Mr. Jonse wrote: I need to store a hetrogeneous array of delegates. How can I do this but still call the function with the appropriate number of parameters at run time? I have the parameters as Variant[] params and a function/delegate pointer(void*

Re: AWS API Dlang, hmac sha256 function.

2015-10-12 Thread Marc Schütz via Digitalmars-d-learn
On Sunday, 11 October 2015 at 23:16:51 UTC, holo wrote: auto hmac_sha256(ubyte[] key, ubyte[] msg) { auto hmac = hmac!SHA256(key); hmac.put(msg); auto digest = hmac.finish; return digest; } alias sig

Re: Ternary if and ~ does not work quite well

2015-10-12 Thread Marc Schütz via Digitalmars-d-learn
On Monday, 12 October 2015 at 05:34:13 UTC, anonymous wrote: It's `assert(("foo "~ true) ? ("bar") : ("baz" == "foo bar"));` though. "foo" ~ true Stupid C implicit conversion rules...

Re: Building and Running Unittests for a Specific Phobos Package Only

2015-10-15 Thread Marc Schütz via Digitalmars-d-learn
On Thursday, 15 October 2015 at 10:07:29 UTC, Nordlöw wrote: Is there a Make-target for building and running the unittests for a specific Phobos package, say `std.range`, only? make -f posix.mak std/range.test

Re: Caching of Template Instantiations

2015-10-17 Thread Marc Schütz via Digitalmars-d-learn
On Saturday, 17 October 2015 at 07:48:39 UTC, Nordlöw wrote: Does DMD cache template instantiations? Yes, and it's required by the spec: "Multiple instantiations of a TemplateDeclaration with the same TemplateArgumentList all will refer to the same instantiation." http://dlang.org/template.h

Re: Help with Concurrency

2015-11-04 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 3 November 2015 at 23:16:59 UTC, bertg wrote: while (true) { writeln("receiving..."); std.concurrency.receive( (string msg) { writeln("conn: received ws message: " ~ msg); } );

Re: Associative array with duplicated keys?

2015-11-05 Thread Marc Schütz via Digitalmars-d-learn
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?) This is an outright bug, please report on issues.dlang.org: void main() {

Re: Associative array with duplicated keys?

2015-11-05 Thread Marc Schütz via Digitalmars-d-learn
https://issues.dlang.org/show_bug.cgi?id=15290

Re: Align a variable on the stack.

2015-11-05 Thread Marc Schütz via Digitalmars-d-learn
On Thursday, 5 November 2015 at 03:52:47 UTC, TheFlyingFiddle wrote: I don't really know where to go from here to figure out the underlying cause. Does anyone have any suggestions? Can you publish two compilable and runnable versions of the code that exhibit the difference? Then we can have a

Re: Align a variable on the stack.

2015-11-06 Thread Marc Schütz via Digitalmars-d-learn
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 that this is on Linux x86_64, so that probably explains the di

Re: Align a variable on the stack.

2015-11-06 Thread Marc Schütz via Digitalmars-d-learn
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. It turns out that it's always the first tested function that's slower. You can test this by switching benchA and benchB in the call to benc

Re: AliasSeq + isExpression type specialization behavior

2015-11-10 Thread Marc Schütz via Digitalmars-d-learn
On Monday, 9 November 2015 at 22:41:50 UTC, Brian Schott wrote: Given the following code: ``` import std.meta; static assert(is(char : dchar)); static assert(is(AliasSeq!(int, char) : AliasSeq!(int, char))); static assert(is(AliasSeq!(int, char) : AliasSeq!(int, dchar))); ``` The third static a

Re: AliasSeq + isExpression type specialization behavior

2015-11-10 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 10 November 2015 at 13:47:23 UTC, Brian Schott wrote: On Tuesday, 10 November 2015 at 10:28:45 UTC, Marc Schütz wrote: This fails, too: static assert(is(AliasSeq!(char) : AliasSeq!(dchar))); Which makes sense IMO, because it can be thought of as an unnamed struct, cp. the following

Re: A new instance of a variable?

2015-11-13 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 13 November 2015 at 17:44:31 UTC, Ish wrote: On Friday, 13 November 2015 at 16:06:51 UTC, Alex Parrill wrote: On Friday, 13 November 2015 at 15:49:01 UTC, Ish wrote: foreach (i; 0..5) { immutable int j = i; etc. } I want each j to be assigned separate memory so that it can be p

Re: Epoch time + msecs

2015-11-16 Thread Marc Schütz via Digitalmars-d-learn
On Monday, 16 November 2015 at 10:29:25 UTC, Kagamin wrote: On Saturday, 14 November 2015 at 12:14:42 UTC, Handyman wrote: Of course. That's why I mentioned my purpose of using Clock.currTime(), in the hope I got corrected in using the right and offical seed method which I failed to find, whic

Re: Invalid foreach aggregate

2015-11-16 Thread Marc Schütz via Digitalmars-d-learn
On Monday, 16 November 2015 at 16:44:27 UTC, Chris wrote: Updating my code from 2.067.1 to 2.069.1 (I skipped 2.068, because I was too busy). I get this error: invalid foreach aggregate, define opApply(), range primitives, or use .tupleof for code like foreach (ref it; myArray.doSomething)

Re: Invalid foreach aggregate

2015-11-17 Thread Marc Schütz via Digitalmars-d-learn
On Monday, 16 November 2015 at 18:18:51 UTC, Chris wrote: On Monday, 16 November 2015 at 17:57:53 UTC, opla wrote: On Monday, 16 November 2015 at 16:55:29 UTC, Chris wrote: On Monday, 16 November 2015 at 16:49:19 UTC, Marc Schütz wrote: On Monday, 16 November 2015 at 16:44:27 UTC, Chris wrote:

Re: Invalid foreach aggregate

2015-11-17 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 17 November 2015 at 11:58:22 UTC, Chris wrote: I did just that and I could find the culprit. It's opIndex(). It works up until 2.068.0, with 2.068.1 I already get this error: "primitives.d(7): Error: invalid foreach aggregate doSomething(items).opIndex()" @property size_t op

Re: Invalid foreach aggregate

2015-11-17 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 17 November 2015 at 12:41:45 UTC, Chris wrote: On Tuesday, 17 November 2015 at 12:22:22 UTC, Marc Schütz wrote: In any case, I'd suggest you fix your opIndex(), except if there's a really good reason it is as it is. I see. Thanks for the explanation. What would be the easiest fix

Re: why --shebang for rdmd?

2015-11-21 Thread Marc Schütz via Digitalmars-d-learn
On Saturday, 21 November 2015 at 05:20:16 UTC, Shriramana Sharma wrote: Hello. The following code works fine for me: #! /usr/bin/env rdmd import std.stdio; void main() { writeln(2); } So what is the use of the --shebang option of rdmd? http://dlang.org/rdmd.html does not shed much light on thi

Re: Compile time strings auto concatenation!?

2015-11-21 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 20 November 2015 at 20:39:58 UTC, Ilya wrote: Can DMD frontend optimize string concatenation ``` enum Double(S) = S ~ S; assert(condition, "Text " ~ Double!"+" ~ ___FUNCTION__); ``` to ``` assert(condition, "Text ++_function_name_"); ``` ? At least for string (and array?) litera

Re: Something about Chinese Disorder Code

2015-11-25 Thread Marc Schütz via Digitalmars-d-learn
On Wednesday, 25 November 2015 at 04:09:29 UTC, magicdmer wrote: On Tuesday, 24 November 2015 at 19:41:12 UTC, Marco Leise wrote: Am Tue, 24 Nov 2015 17:08:33 + schrieb BLM768 : [...] thank you for your answers. I solved it. windows console like: fwide(core.stdc.stdio.stdout, 1); setloca

Re: Something about Chinese Disorder Code

2015-11-26 Thread Marc Schütz via Digitalmars-d-learn
On Thursday, 26 November 2015 at 01:59:12 UTC, magicdmer wrote: On Wednesday, 25 November 2015 at 12:33:00 UTC, Marc Schütz wrote: On Wednesday, 25 November 2015 at 04:09:29 UTC, magicdmer wrote: On Tuesday, 24 November 2015 at 19:41:12 UTC, Marco Leise wrote: Am Tue, 24 Nov 2015 17:08:33 +000

Re: Classes as enums in D?

2015-11-30 Thread Marc Schütz via Digitalmars-d-learn
On Monday, 30 November 2015 at 08:08:20 UTC, Meta wrote: class WhiteKey { private immutable int halfStepsToNext; private immutable int halfStepsToPrevious; enum { A = new WhiteKey(2, 2), B = new WhiteKey(2, 1), C = n

Re: utils.toBulkString is not accesible from utils

2015-12-02 Thread Marc Schütz via Digitalmars-d-learn
On Wednesday, 2 December 2015 at 06:33:36 UTC, Andre wrote: Hi, for following coding there is an error during compilation: module utils; package string toBulkString(string s) { import std.string: format; return "$%s\r\n%s\r\n".format(s.length, s); } unittest {

Re: Struct initializers as expressions

2015-12-04 Thread Marc Schütz via Digitalmars-d-learn
On Thursday, 3 December 2015 at 15:31:49 UTC, Chris Wright wrote: On Thu, 03 Dec 2015 06:38:20 +, Mike Parker wrote: AFAIK, your only option is to use a struct constructor. This is the sort of thing they're used for. Which brings be back to positional arguments, which means that someone

Re: Struct initializers as expressions

2015-12-04 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 4 December 2015 at 14:07:01 UTC, Jacob Carlborg wrote: On 2015-12-04 11:42, Marc Schütz wrote: I'd support that, too. I suggest to make the struct name optional: struct S { int a, b; } struct T { string a, b; } void foo(S s); void foo(T t); foo({b: 1, a: 2

Re: Struct initializers as expressions

2015-12-04 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 4 December 2015 at 11:25:12 UTC, Mike Parker wrote: On Friday, 4 December 2015 at 10:42:46 UTC, Marc Schütz wrote: ; Then we can add some syntax sugar to leave out the braces, too: void bar(int a, T t) bar(42, a: "bla", b: "xyz"); This effectively gives us strongly typed na

Re: Strange exception, with EXTREMELY SIMPLE toString() in a struct

2015-12-07 Thread Marc Schütz via Digitalmars-d-learn
On Monday, 7 December 2015 at 08:17:27 UTC, Enjoys Math wrote: Exception Message: First-chance exception: std.format.FormatException Unterminated format specifier: "%" at C:\D\dmd2\windows\bin\..\..\src\phobos\std\format.d(828) [CODE] module set; import std.conv; struct Set(T) { stri

Re: Reset all Members of a Aggregate Instance

2015-12-08 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 8 December 2015 at 05:13:51 UTC, Chris Wright wrote: On Tue, 08 Dec 2015 14:12:02 +1100, Daniel Murphy wrote: On 4/12/2015 8:38 AM, Chris Wright wrote: An object reference is just a pointer, but we can't directly cast it. So we make a pointer to it and cast that; the type system a

Re: How to split a string/array with multiple separators?

2015-12-16 Thread Marc Schütz via Digitalmars-d-learn
On Wednesday, 16 December 2015 at 14:47:26 UTC, Dragos Carp wrote: On Wednesday, 16 December 2015 at 14:18:28 UTC, Borislav Kosharov wrote: I want to split a string using multiple separators. In std.array the split function has a version where it takes a range as a separator, but it works diffe

Re: Problems with string literals and etc.c.odbc.sql functions

2015-12-19 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 18 December 2015 at 22:35:04 UTC, anonymous wrote: If the parameter is really not const, i.e. the function may mutate the argument, then the cast is not ok. You can use `.dup.ptr` instead to get a proper char* from a string. As this is going to be passed to a C function, it would ne

Re: Problems with string literals and etc.c.odbc.sql functions

2015-12-20 Thread Marc Schütz via Digitalmars-d-learn
On Saturday, 19 December 2015 at 17:30:02 UTC, Kagamin wrote: On Saturday, 19 December 2015 at 13:20:03 UTC, Marc Schütz wrote: As this is going to be passed to a C function No, ODBC API is designed with multilingual capability in mind, it doesn't rely on null terminated strings heavily: all

Re: Problems with string literals and etc.c.odbc.sql functions

2015-12-20 Thread Marc Schütz via Digitalmars-d-learn
On Saturday, 19 December 2015 at 14:16:36 UTC, anonymous wrote: On 19.12.2015 14:20, Marc Schütz wrote: As this is going to be passed to a C function, it would need to be zero-terminated. `.dup` doesn't do this, he'd have to use `std.string.toStringz` instead. However, that function returns a

Re: C string to D without memory allocation?

2015-12-21 Thread Marc Schütz via Digitalmars-d-learn
On Monday, 21 December 2015 at 09:46:58 UTC, Shriramana Sharma wrote: Jonathan M Davis via Digitalmars-d-learn wrote: If it isn't, all that means is that the array's capacity will be 0, so it's going to have to reallocate So it's safe to return a string produced by fromStringz without having

Re: immutable promise broken in unions?

2016-01-02 Thread Marc Schütz via Digitalmars-d-learn
On Saturday, 2 January 2016 at 12:08:48 UTC, Meta wrote: On Saturday, 2 January 2016 at 12:07:31 UTC, John Colvin wrote: You are manually breaking immutable by making a union of immutable and mutable data and then writing to the mutable reference. This is roughly equivalent to casting away imm

Re: Size of Compiled Program

2016-01-04 Thread Marc Schütz via Digitalmars-d-learn
On Monday, 4 January 2016 at 13:49:03 UTC, Martin Tschierschke wrote: When I was writing a small speed test - D versus Ruby, calculating the first n prime numbers, I realized, that for small n Ruby may be faster, than compiling and executing with D. But for n = 1,000,000 D outperforms Ruby by a

Re: Strange 'memset' error when using std.range.repeat and std.array.array

2016-01-04 Thread Marc Schütz via Digitalmars-d-learn
On Monday, 4 January 2016 at 12:20:09 UTC, Ur@nuz wrote: On Monday, 4 January 2016 at 12:00:32 UTC, tcak wrote: On Monday, 4 January 2016 at 10:50:17 UTC, Ur@nuz wrote: Sorry, the actual code is: ... lines ~= ' '.repeat.take(newIndentCount).array; ...with character quotes. But it still fails

Re: sliced().array compatibility with parallel?

2016-01-10 Thread Marc Schütz via Digitalmars-d-learn
On Sunday, 10 January 2016 at 01:16:43 UTC, Ilya Yaroshenko wrote: On Saturday, 9 January 2016 at 23:20:00 UTC, Jay Norwood wrote: I'm playing around with win32, v2.069.2 dmd and "dip80-ndslice": "~>0.8.8". If I convert the 2D slice with .array(), should that first dimension then be compatible

Re: How to declare an alias to a function literal type

2016-01-12 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 12 January 2016 at 15:41:02 UTC, ParticlePeter wrote: I have a function type and variable and assign a function to it: void function( int i ) myFunc; myFunc = void function( int i ) { myCode; } How would I declare an alias for void function( int i ) such that the case above would w

Re: How to declare an alias to a function literal type

2016-01-12 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 12 January 2016 at 16:55:48 UTC, ParticlePeter wrote: I can rewrite the definition of otherFunc like this: void otherFunc( MF mf ); But I cannot pass an anonymous function to otherFunc like this: otherFunc( MF { myCode; } ); Thats what I want. Any working example? If I understand

Re: Static Arrays in Structs/Classes and Dynamic Array Sizes

2016-01-18 Thread Marc Schütz via Digitalmars-d-learn
Here's what I suggest: alias T = int; class VariableLengthClass { private: string someMember; size_t length_; T[0] data_; public: static make(Args...)(size_t length, Args args) { static assert( typeof(this).init.data_.offsetof == __traits(classInstanceSize

Re: Mixin Template Function Attributes

2016-01-20 Thread Marc Schütz via Digitalmars-d-learn
On Wednesday, 20 January 2016 at 16:37:31 UTC, jmh530 wrote: I'm not sure if this is how the behavior is supposed to be or if it is a bug. I believe, however, that it _is_ a bug that the imported symbols are visible outside the template. Most likely related to the infamous https://issues.dlan

Re: Mixin Template Function Attributes

2016-01-20 Thread Marc Schütz via Digitalmars-d-learn
On Wednesday, 20 January 2016 at 16:37:31 UTC, jmh530 wrote: I'm not sure if this is how the behavior is supposed to be or if it is a bug. It's not a bug. The `@attribute:` syntax applies to all following declarations _inside the current scope_, i.e. until your mixin templates closing `}`.

Re: Template specialization

2016-01-22 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 22 January 2016 at 01:33:42 UTC, Darrell Gallion wrote: void foo(A)() if (!is (A == int)) { pragma(msg, "int"); } void foo(A)() if (is (A == int[])) { pragma(msg, "int[]"); } void main() { foo!(int)(); foo!(int[])(); } === source\app.d(15): Erro

Re: `static` symbol needs to be `immutable` for compile-time access?

2016-01-22 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 22 January 2016 at 10:15:19 UTC, Mike Parker wrote: A static variable is still a runtime variable. It's effectively the same as declaring a variable outside of the function scope at module scope, except that it's visible only in the current scope and the function name gets mangled in

Re: Template specialization

2016-01-22 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 22 January 2016 at 13:03:52 UTC, Darrell Gallion wrote: On Friday, 22 January 2016 at 11:23:56 UTC, Marc Schütz wrote: On Friday, 22 January 2016 at 01:33:42 UTC, Darrell Gallion wrote: void foo(A)() if (!is (A == int)) { pragma(msg, "int"); } void foo(A)() if (i

Re: alias template parameter

2016-01-24 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 21 June 2013 at 14:08:43 UTC, Sergei Nosov wrote: If I have a function auto apply(alias fun, T...)(T args) { return fun(args); } And then I have int y = 2; apply!(x => y)(1); How in the world does this work? Is the context address known at compile-time? No, but because lambdas

Re: First project: questions on how-to, and on language features

2016-01-24 Thread Marc Schütz via Digitalmars-d-learn
On Sunday, 24 January 2016 at 06:07:13 UTC, Alex Vincent wrote: (1) It's not clear how to specify certain parts of a module or library as non-exportable. Is that possible? Is it desirable? (It's not that important, yet, but still...) Yes, definitely. By default symbols in a module are `publ

Re: how to allocate class without gc?

2016-01-26 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 26 January 2016 at 13:56:39 UTC, Igor wrote: //ubyte[__traits(classInstanceSize, App)] buffer; auto buffer = core.stdc.stdlib.malloc(__traits(classInstanceSize, App))[0..__traits(classInstanceSize, App)]; works, so it is the ubyte line. Can you please post the f

Re: Digger 2.4 & DMD 2.070.0

2016-01-28 Thread Marc Schütz via Digitalmars-d-learn
On Thursday, 28 January 2016 at 07:45:01 UTC, Robert M. Münch wrote: Just compiled the latest release with digger. Everything works without any problems, but the resulting binary shows the following version: mac-pro:Digger robby$ ./result/bin/dmd --version DMD64 D Compiler v2.069-devel-682687b

Re: Region allocator strage error

2016-02-01 Thread Marc Schütz via Digitalmars-d-learn
On Monday, 1 February 2016 at 12:05:53 UTC, ref2401 wrote: On Sunday, 31 January 2016 at 14:48:34 UTC, ref2401 wrote: I am getting runtime error: core.exception.AssertError@std\experimental\allocator\building_blocks\region.d(235): Assertion failure At least tell me can anyone replicate it? M

Re: chain(const(array of class)) fails

2016-02-02 Thread Marc Schütz via Digitalmars-d-learn
The constraint that fails is the one with `CommonType`: pragma(msg, CommonType!(const(B), const(C))); // void `CommonType` uses the `?:` operator to derive the common type: writeln(true ? b : c); // Error: incompatible types for ((b) : (c)): 'const(B[])' and 'const(C[])' write

Re: chain(const(array of class)) fails

2016-02-02 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 09:51:52 UTC, Marc Schütz wrote: The constraint that fails is the one with `CommonType`: pragma(msg, CommonType!(const(B), const(C))); // void `CommonType` uses the `?:` operator to derive the common type: writeln(true ? b : c); // Error: incompatible

Re: Variadic template parameters T... bounding

2016-02-02 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 13:20:33 UTC, Voitech wrote: Hi, Is it possible to bound T... in template with some type ? For single Parameter declaration it can be done by T:SomeType but variadics does not seems to have that possibility ? Cheers Two possible solutions... If you don't need to

Re: Variadic template parameters T... bounding

2016-02-02 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 13:52:55 UTC, Marc Schütz wrote: The last call should work IMO, but it doesn't. I believe that's a compiler bug. Filed: https://issues.dlang.org/show_bug.cgi?id=15640

Re: Variadic template parameters T... bounding

2016-02-02 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 14:12:54 UTC, Daniel Kozak wrote: On Tuesday, 2 February 2016 at 13:57:54 UTC, Marc Schütz wrote: On Tuesday, 2 February 2016 at 13:52:55 UTC, Marc Schütz wrote: The last call should work IMO, but it doesn't. I believe that's a compiler bug. Filed: https://issue

Re: Variadic template parameters T... bounding

2016-02-02 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 14:55:42 UTC, Daniel Kozak wrote: On Tuesday, 2 February 2016 at 14:47:43 UTC, Marc Schütz wrote: if you mix ints and floats, the common type is deduced correctly: this is a bug for me :). I do not like this. I am ok with (u)byte to int conversion and similar, b

Re: std.typecons.Proxy requires a nothrow destructor and toHash?

2016-02-03 Thread Marc Schütz via Digitalmars-d-learn
On Wednesday, 3 February 2016 at 10:16:56 UTC, Saurabh Das wrote: Why doesn't this work? Is it a requirement that a proxied struct must have a nothrow destructor and toHash? It used to work in 2.066.1; bisecting points to this PR: https://github.com/D-Programming-Language/phobos/pull/3043 When

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

2016-02-03 Thread Marc Schütz via Digitalmars-d-learn
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? template forceCTFE(alias expr) { alias forceCTFE = expr; } aut

Re: Proper Use of Assert and Enforce

2016-02-05 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 5 February 2016 at 08:45:00 UTC, Minas Mina wrote: Use assertions when a variable's value should not depend on external factors. For example, let's say you want to write a square root function. The input must be >= 0, and because this depends on external factors (e.g. user input), yo

Re: print function

2016-02-05 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 5 February 2016 at 07:04:27 UTC, cy wrote: Mind if I elaborate on this a bit? If that is unrolled, I understand it will unroll into several calls to write, as in print("1","2","3") => write("1"," ");write("2"," ");write("3","\n"); Up to here, yes. And presumably, write() unrolls

Re: Overloading free functions & run-time dispatch based on parameter types

2016-02-05 Thread Marc Schütz via Digitalmars-d-learn
Does the following help? import std.algorithm.comparison : castSwitch; import std.stdio; class A { } class B : A { } class C : A { } auto foo_impl(B b) { writeln("called foo(B)"); } auto foo_impl(C c) { writeln("called foo(C)"); } auto foo(A a) { return a.castSwitch!( (B b)

Re: Overloading free functions & run-time dispatch based on parameter types

2016-02-06 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 5 February 2016 at 19:48:45 UTC, Robert M. Münch wrote: I thought about it too, but I need it to work with more then one parameter, so I tried this which doesn't work: Value nativePlus(Value a, Value b){ // @@ not working, runtime exception castSwitch!( (IntV a) { castS

Re: Conflicting UDA

2016-02-06 Thread Marc Schütz via Digitalmars-d-learn
On Saturday, 6 February 2016 at 13:36:32 UTC, Márcio Martins wrote: I came across an issue with UDAs and was wondering if there really is no way or if I just missed something... Basically, my library has an @ignore UDA, which conflicts with vibe.d's vibe.data.serialization. If both mine and

Re: Bug or intended?

2016-02-07 Thread Marc Schütz via Digitalmars-d-learn
The specification doesn't list (non-static) members a valid template alias parameters: http://dlang.org/spec/template.html#TemplateAliasParameter

Re: Is this a bug in std.typecons.Tuple.slice?

2016-02-09 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 9 February 2016 at 09:05:58 UTC, Ola Fosheim Grøstad wrote: IMO one shouldn't be able to take the reference of a tuple, to ensure that it can be kept in registers. No need to restrict the language here, there's nothing stopping a decent compiler from storing tuples (actually _anyth

Re: Is this a bug in std.typecons.Tuple.slice?

2016-02-09 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 9 February 2016 at 11:38:14 UTC, Ola Fosheim Grøstad wrote: On Tuesday, 9 February 2016 at 10:54:42 UTC, Marc Schütz wrote: No need to restrict the language here, there's nothing stopping a decent compiler from storing tuples (actually _anything_) in registers, in some cases even if

Re: Is this a bug in std.typecons.Tuple.slice?

2016-02-09 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 9 February 2016 at 14:28:35 UTC, Ola Fosheim Grøstad wrote: On Tuesday, 9 February 2016 at 13:43:16 UTC, Marc Schütz wrote: So what? Using that argument, you could just as well forbid taking the address of any variable. What's so special about tuples, in contrast to structs and arra

Re: static array of structs clarification questions

2016-02-13 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 12 February 2016 at 21:56:09 UTC, Steven Schveighoffer wrote: That's odd. I think anonymous probably has the answer (they are context pointers), but I'm also surprised they are null, they shouldn't be. In this example, `void foo()` doesn't access any outer variables, so there's no

Re: static array of structs clarification questions

2016-02-13 Thread Marc Schütz via Digitalmars-d-learn
On Saturday, 13 February 2016 at 14:53:39 UTC, ZombineDev wrote: On Saturday, 13 February 2016 at 10:22:36 UTC, Marc Schütz wrote: On Friday, 12 February 2016 at 21:56:09 UTC, Steven Schveighoffer wrote: That's odd. I think anonymous probably has the answer (they are context pointers), but I'm

Re: Confusion regarding struct lifecycle

2016-02-16 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 16 February 2016 at 04:00:27 UTC, Mike Parker wrote: On Tuesday, 16 February 2016 at 03:39:00 UTC, Matt Elkins wrote: On Tuesday, 16 February 2016 at 03:31:51 UTC, maik klein wrote: In D you can always call Foo.init even with @disable this(), Foo.init can be called implicitly (not

Re: Why is there no combination of popFront and front to pop? (aka Python `next`)

2016-02-17 Thread Marc Schütz via Digitalmars-d-learn
On Wednesday, 17 February 2016 at 01:45:24 UTC, Rikki Cattermole wrote: On 17/02/16 1:19 PM, Seb wrote: In any case such a next method would be very easy to implement (see below) and thus I am wondering why it isn't part of phobos? ``` auto next(Range)(ref Range a){ auto b = a.front;

Re: Enforcing checks for return code

2016-02-18 Thread Marc Schütz via Digitalmars-d-learn
On Thursday, 18 February 2016 at 07:21:05 UTC, Chris Katko wrote: Hello. I'm almost brand-new to the D language and still absorbing things. I'm wondering if it's possible to fire off a compile-time (or worst case, a run-time) warning or error if a function is called, but the return value is n

Re: Simple performance question from a newcomer

2016-02-23 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 23 February 2016 at 11:10:40 UTC, ixid wrote: We really need to standard algorithms to be fast and perhaps have separate ones for perfect technical accuracy. While I agree with most of what you're saying, I don't think we should prioritize performance over accuracy or correctness

Re: constant expression

2016-02-24 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 23 February 2016 at 08:00:24 UTC, Nicholas Wilson wrote: Silly question. Why is this necessary? Due to a problem with the implementation, associative arrays currently can't be initialized statically. We hope it will eventually get fixed, but until then, you have to use module con

Re: Cannot compile program with DMD built from source

2016-03-10 Thread Marc Schütz via Digitalmars-d-learn
On Wednesday, 9 March 2016 at 16:13:38 UTC, Minas Mina wrote: Hello, I have followed the instructions here (http://wiki.dlang.org/Starting_as_a_Contributor#POSIX) to install DMD, druntime and phobos from source. My platform is Ubuntu 15.10 x64. This is the error I get: http://pastebin.com/kWC

Re: static if else behavior and is type comparison

2016-03-11 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 11 March 2016 at 12:10:53 UTC, Artur Skawina wrote: On 03/11/16 09:21, Ali Çehreli via Digitalmars-d-learn wrote: You've been bitten by a common usability issue. :) On 03/11/2016 12:02 AM, Fynn Schröder wrote: static if (is(U == ubyte)) { } else if (is(U == ushort)) {

Re: In D, lexically, which are the chars that can follow $, exactly ?

2016-03-13 Thread Marc Schütz via Digitalmars-d-learn
On Sunday, 13 March 2016 at 14:07:31 UTC, Basile B. wrote: '$' is only valid in an indexExpression (https://dlang.org/spec/grammar.html#IndexExpression), so it can only be followed by - ' ' - ']' - operators , usually '-' but also '/', '+', '>>' etc Is that right ? I'd like to relax the lexi

Re: Gdmd compiling error

2016-03-14 Thread Marc Schütz via Digitalmars-d-learn
On Monday, 14 March 2016 at 14:46:06 UTC, Orkhan wrote: On Monday, 14 March 2016 at 11:11:28 UTC, Ali Çehreli wrote: On 03/14/2016 02:56 AM, Orkhan wrote: > THe output like that : > root@ubuntu:/opt/xcomm# gdmd > Can't exec "/usr/local/bin/gdc": No such file or directory at Ok, now you need to

Re: size_t index=-1;

2016-03-18 Thread Marc Schütz via Digitalmars-d-learn
On Thursday, 17 March 2016 at 17:09:46 UTC, Steven Schveighoffer wrote: On 3/16/16 6:37 PM, Mathias Lang wrote: On Wednesday, 16 March 2016 at 21:49:05 UTC, Steven Schveighoffer wrote: No, please don't. Assigning a signed value to an unsigned (and vice versa) is very useful, and there is no goo

Re: Checking if a port is listening

2016-03-19 Thread Marc Schütz via Digitalmars-d-learn
On Wednesday, 16 March 2016 at 22:22:15 UTC, Anonymouse wrote: import core.thread; // for .seconds Nitpick: `seconds` is defined in `core.time`; `core.thread` just reexports it. s.setOption(SocketOptionLevel.SOCKET, SNDTIMEO, 10.seconds); s.setOption(SocketOptionLevel.SOCKET, RCVTIMEO, 10.

Re: Checking if a port is listening

2016-03-19 Thread Marc Schütz via Digitalmars-d-learn
Looking at an strace of nmap, it seems it opens a bunch of sockets, puts them into non-blocking mode, calls connect on them (which will return EINPROGRESS), and then uses select(2) to wait for them (in a loop, until all have either been accepted or rejected). select(2) accepts a timeout value,

Re: Whitch can replace std::bind/boost::bind ?

2016-03-19 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 18 March 2016 at 10:50:34 UTC, Dsby wrote: foreach (i ; 0..4) { auto th = new Thread(delegate(){listRun(i);});//this is erro _thread[i]= th; th.start(); } void listRun(int i) { writeln("i = ", i); // the value is not(0,1,2,3), it all is 2. } I want to

Re: Checking if a port is listening

2016-03-19 Thread Marc Schütz via Digitalmars-d-learn
On Saturday, 19 March 2016 at 09:55:13 UTC, Lucien wrote: const int MAX = 64; Socket[] sockets = new Socket[MAX]; string ipb = "192.168.0."; for (int i = 1; i < MAX; i++) { Here's the reason for your SEGV: You need to start at 0, because otherwise `sockets[0]` is `null`. When

Re: getOverloads, but also include all the imported members

2016-03-24 Thread Marc Schütz via Digitalmars-d-learn
On Wednesday, 23 March 2016 at 20:54:20 UTC, Yuxuan Shui wrote: Say: module one; void func(int a){} / module two; import one; void func(float a){} Is there a way to get both func() in module two? Add in module two: alias func = one.func;

Re: Checking if a port is listening

2016-03-24 Thread Marc Schütz via Digitalmars-d-learn
On Wednesday, 23 March 2016 at 21:37:09 UTC, Lucien wrote: When I remove the Thread.sleep, it doesn't find all adresses. Why ? Socket.select() will wait _at most_ 100 msecs. If a socket gets ready before that timeout, it will return immediately. Therefore, you might not get the full TIMES*100

Re: parsing fastq files with D

2016-03-24 Thread Marc Schütz via Digitalmars-d-learn
On Thursday, 24 March 2016 at 08:24:15 UTC, eastanon wrote: On Thursday, 24 March 2016 at 06:34:51 UTC, rikki cattermole wrote: As a little fun thing to do I implemented it for you. It won't allocate. Making this perfect for you. With a bit of work you could make Result have buffers for result

Re: how to parse a string into a phobos datatype with additional logic

2016-04-07 Thread Marc Schütz via Digitalmars-d-learn
On Thursday, 7 April 2016 at 08:06:03 UTC, Puming wrote: On Thursday, 7 April 2016 at 07:45:06 UTC, yawniek wrote: what is the way one is supposed to parse e.g. a double of unixtime (as delived by nginx logs) into a SysTime? currently i'm creating a wrapper struct around SysTime with alias thi

Re: Problem with circular imports of modules with static ctors an immutable variables

2016-04-15 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 15 April 2016 at 05:35:24 UTC, Uranuz wrote: In my program I have error with circular imports of modules with static ctors. So I decided to move ctors in separate file and import it only from the 1st file. But problem is that in the first file I have immutables that should be initial

Re: multithreading profiling

2016-04-18 Thread Marc Schütz via Digitalmars-d-learn
Which platform/OS, dmd version, and command line are you using?

Re: Shallow copy object when type is know

2016-04-21 Thread Marc Schütz via Digitalmars-d-learn
On Wednesday, 20 April 2016 at 19:58:15 UTC, Tofu Ninja wrote: How does D not have shallow copy? Seems like a very basic functionality... You could implement a `dup()` method. `dup` is already used for shallow copying of arrays, why not reuse it for classes (as a convention)?

Re: vibe.d is blocking threads

2016-04-28 Thread Marc Schütz via Digitalmars-d-learn
On Wednesday, 27 April 2016 at 23:30:10 UTC, Nicholas Wilson wrote: On Wednesday, 27 April 2016 at 13:00:29 UTC, RuZzz wrote: Code: import std.concurrency; import core.thread; //import vibe.http.client; // If uncommented this line, the thread "worker" does not start void w

Re: Setting a list of values

2016-05-01 Thread Marc Schütz via Digitalmars-d-learn
On Sunday, 1 May 2016 at 05:42:00 UTC, Ali Çehreli wrote: On 04/30/2016 10:05 PM, Joel wrote: > This has no effect: > _bars.each!(a => { a._plots.fillColor = Color(255, 180, 0); }); This is a common issue especially for people who know lambdas from other languages. :) Your lambda does not do

Re: Setting a list of values

2016-05-02 Thread Marc Schütz via Digitalmars-d-learn
On Monday, 2 May 2016 at 08:46:31 UTC, Ali Çehreli wrote: On 05/01/2016 12:54 PM, Xinok wrote: > On Sunday, 1 May 2016 at 05:42:00 UTC, Ali Çehreli wrote: >> On 04/30/2016 10:05 PM, Joel wrote: >> > This has no effect: >> > _bars.each!(a => { a._plots.fillColor = Color(255, 180, 0); >> }); >> >>

Re: Compiler silently ignores some method overloads

2016-05-11 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 10 May 2016 at 22:17:00 UTC, pineapple wrote: On Tuesday, 10 May 2016 at 09:57:11 UTC, pineapple wrote: On Monday, 9 May 2016 at 18:56:15 UTC, Peter Häggman wrote: No problem here (tested with everything in a single module). I can't help more. Front end version ? Well, this is th

Re: Using shorthand *= leads to unexpected result?

2016-05-15 Thread Marc Schütz via Digitalmars-d-learn
On Sunday, 15 May 2016 at 13:01:45 UTC, Michael wrote: It may be that I'm doing something wrong here, but after updating DMD to the latest version, my simulations started producing some very odd results and I think I've pinpointed it to a sign inversion that I was making. Here is some code from

Re: Immutable objects and constructor ?

2016-05-20 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 20 May 2016 at 15:07:53 UTC, chmike wrote: The error message is gone, but I now have another compilation error message I don't understand. This is what I have in fact interface Info { . . . } class MyInfos { . . . protected: class Obj : Info { . . . } public:

  1   2   >