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

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

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

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;

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,

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

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

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

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

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

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

Re: Bug? 0 is less than -10

2015-10-07 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 6 October 2015 at 14:46:56 UTC, tcak wrote: Maybe I am just too stressed out to see the problem. [code] import std.stdio; void main(){ size_t dec = 0; writeln( dec, " ", (dec <= -10), " ", (dec >= 10), " ", ((dec <= -10) || (dec >= 10)) ); } [/code] [output] 0 true

Re: Concatenation of ubyte[] to char[] works, but assignation doesn't

2015-10-06 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 6 October 2015 at 05:38:36 UTC, Jonathan M Davis wrote: Your suggestion only works by assuming that the result will fit in a char, which doesn't fit at all with how coversions are currently done in D. It would allow for narrowing conversions which lost data. And there's no way that

Re: Why do abstract class functions require definitions?

2015-09-16 Thread Marc Schütz via Digitalmars-d-learn
On Wednesday, 16 September 2015 at 09:31:25 UTC, Jacob Carlborg wrote: On 2015-09-16 10:49, FiveNights wrote: Every so often I'll get a compiler error that isn't particularly clear on what's wrong and eventually I'll figure out that what's causing it is having a function in an abstract class

Re: Why getting private member fails using getMember trait in a template?

2015-09-30 Thread Marc Schütz via Digitalmars-d-learn
On Wednesday, 30 September 2015 at 07:57:59 UTC, Atila Neves wrote: On Tuesday, 29 September 2015 at 09:40:41 UTC, Alexandru Ermicioi wrote: On Saturday, 26 September 2015 at 10:10:39 UTC, Alexandru Ermicioi wrote: Suppose we have, two modules: module testOne; [...] So, is this behavior

Re: Online Phobos Prerelease Docs

2015-10-05 Thread Marc Schütz via Digitalmars-d-learn
On Monday, 5 October 2015 at 08:19:26 UTC, Per Nordlöw wrote: Is there an (official or unoffical) prerelease version of the Phobos docs, typically for studying std.allocator? It would be nice to have the D servers auto-generate this every time a PR is merged into druntime/phobos. In each PR

Re: Concatenation of ubyte[] to char[] works, but assignation doesn't

2015-10-05 Thread Marc Schütz via Digitalmars-d-learn
On Sunday, 4 October 2015 at 21:57:44 UTC, Jonathan M Davis wrote: On Sunday, October 04, 2015 16:13:47 skilion via Digitalmars-d-learn wrote: Is this allowed by the language or it is a compiler bug ? void main() { char[] a = "abc".dup; ubyte[] b = [1, 2, 3]; a = b; // cannot

Re: Get AA key and value type

2015-09-19 Thread Marc Schütz via Digitalmars-d-learn
On Saturday, 19 September 2015 at 12:50:51 UTC, Pierre wrote: Hi everybody, I would like to extract key and value type from AA. You can also do it with built-in syntax: template AATypes(AA : K[V], K, V) { alias Key = K; alias Value = V; }

Re: Why is the constructor of B called?

2015-09-24 Thread Marc Schütz via Digitalmars-d-learn
On Thursday, 24 September 2015 at 01:01:09 UTC, Nicholas Wilson wrote: On Wednesday, 23 September 2015 at 21:25:15 UTC, tcak wrote: On Wednesday, 23 September 2015 at 21:14:17 UTC, Adam D. Ruppe wrote: On Wednesday, 23 September 2015 at 21:08:37 UTC, tcak wrote: I wouldn't expect B's

Re: Maximum number of threads

2015-09-24 Thread Marc Schütz via Digitalmars-d-learn
On Thursday, 24 September 2015 at 08:55:25 UTC, Alex wrote: This should be a not so long question to answer, I hope. I took an example from the "Programming in D" book, chapter "Message Passing Concurrency", around page 550. The question of interest was, how many threads I can have spawned at

Re: Concatenation of ubyte[] to char[] works, but assignation doesn't

2015-10-05 Thread Marc Schütz via Digitalmars-d-learn
On Monday, 5 October 2015 at 10:30:02 UTC, Jonathan M Davis wrote: On Monday, October 05, 2015 09:07:34 Marc Schütz via Digitalmars-d-learn wrote: I don't think math would be a problem. There are some obvious rules that would likely just work with most existing code: char + int = char char

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

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

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

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:

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) {

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

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

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

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

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

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:

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 =

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

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?)

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

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: Error: castSwitch

2016-06-07 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 7 June 2016 at 03:55:03 UTC, none wrote: import std.algorithm.iteration : map; import std.algorithm : castSwitch; import std.format : format; class A { int value; this(int value) { this.value = value; }} interface I { } class B : I { } Object[] arr = [new A(5), new

Re: full copies on assignment

2016-05-25 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 24 May 2016 at 20:58:11 UTC, John Nixon wrote: On Tuesday, 24 May 2016 at 15:17:37 UTC, Adam D. Ruppe wrote: On Tuesday, 24 May 2016 at 14:29:53 UTC, John Nixon wrote: This naively doesn’t seem right because the RHS of an assignment should not be altered by it. It's because the

Re: Operator overloading through UFCS doesn't work

2016-05-30 Thread Marc Schütz via Digitalmars-d-learn
On Sunday, 29 May 2016 at 07:18:10 UTC, Jonathan M Davis wrote: On Friday, May 27, 2016 09:08:20 Marc Schütz via Digitalmars-d-learn wrote: On Thursday, 26 May 2016 at 06:23:17 UTC, Jonathan M Davis wrote: > The difference is that it's impossible to do > 10.opBinary!"+"(1

Re: Why do some T.init evaluate to true while others to false?

2016-05-31 Thread Marc Schütz via Digitalmars-d-learn
On Monday, 30 May 2016 at 19:06:53 UTC, ArturG wrote: does this count? struct Foo { int x; float f; } void main() { Foo foo; if(foo is typeof(foo).init) "A: does'nt work".writeln; foo = Foo(); if(foo is typeof(foo).init) "B: works".writeln; } This one is a bug in DMD.

Re: full copies on assignment

2016-05-27 Thread Marc Schütz via Digitalmars-d-learn
On Thursday, 26 May 2016 at 10:51:30 UTC, John Nixon wrote: On Wednesday, 25 May 2016 at 15:44:34 UTC, Marc Schütz wrote: On Tuesday, 24 May 2016 at 20:58:11 UTC, John Nixon wrote: On Tuesday, 24 May 2016 at 15:17:37 UTC, Adam D. Ruppe wrote: On Tuesday, 24 May 2016 at 14:29:53 UTC, John

Re: Operator overloading through UFCS doesn't work

2016-05-27 Thread Marc Schütz via Digitalmars-d-learn
On Thursday, 26 May 2016 at 06:23:17 UTC, Jonathan M Davis wrote: The difference is that it's impossible to do 10.opBinary!"+"(15), so if you're forced to do foo.opBinary!"+"(bar) to get around a symbol conflict, it won't work with built-in types. Well, that begs the question: Why don't

Re: Why do some T.init evaluate to true while others to false?

2016-05-27 Thread Marc Schütz via Digitalmars-d-learn
On Thursday, 26 May 2016 at 16:45:22 UTC, ArturG wrote: im just playing with this template[1] is there anything else i missed? (if you dont mind) it basically treats any T.init as false and skips the function/delegate and just returns type. [1] https://dpaste.dzfl.pl/d159d83e3167 If you

Re: Testing array ptr for offset 0...

2016-05-27 Thread Marc Schütz via Digitalmars-d-learn
On Thursday, 26 May 2016 at 22:47:02 UTC, Era Scarecrow wrote: On Thursday, 26 May 2016 at 22:15:42 UTC, ag0aep6g wrote: Sorry, I'm still lost. Why can't you do whatever you're doing in opOpAssign directly there, or in a free function? Does the pseudo-array contain any additional data? Would a

Re: opCall override default constructor?

2016-06-02 Thread Marc Schütz via Digitalmars-d-learn
On Thursday, 2 June 2016 at 08:50:26 UTC, Jacob Carlborg wrote: Is it intentional that a non-static opCall overrides the default constructor of a struct? struct Foo { int a; void opCall(string b) { } } void main() { auto f = Foo(3); // line 14 f("asd"); } The above code

Re: Is there anyway to make opApply @nogc?

2016-06-22 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 21 June 2016 at 19:21:01 UTC, Gary Willoughby wrote: Right ok, thanks! It doesn't seem to help though as the compiler complains about it being not @nogc. You probably need to declare the delegate and opApply() itself as @nogc, too: int opApply(scope int delegate(int) @nogc dg)

Re: How to group similar member functions from different classes?

2016-06-20 Thread Marc Schütz via Digitalmars-d-learn
Untested: // foo.d import a, b; mixin template Foos { static if(is(typeof(this) == A)) void foo() { /* implementation for A */ } static if(is(typeof(this) == B)) void foo() { /* implementation for B */ } } // a.d import foo; class A { mixin Foos; } // b.d import foo; class

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

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

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

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: 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) {

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

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

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

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()

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),

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

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?

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

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,

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:

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[])'

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:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  1   2   >