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

<    1   2