Re: Initialising global associative array

2015-06-06 Thread anonymous via Digitalmars-d-learn
On Saturday, 6 June 2015 at 20:30:50 UTC, Paul wrote: However, I now get an 'undefined identifier' error when compiling and trying to access the AA from a function within the same module. static this() { string[string] tagWords = [ "DIST" : "Distance", . } ... if(tag in tagWords)

Re: string to char array?

2015-06-05 Thread anonymous via Digitalmars-d-learn
On Friday, 5 June 2015 at 19:30:58 UTC, Kyoji Klyden wrote: Okay, so it's primarily an interfacing with C problem that started all this? (My brain is just completely scrambled at this point xP ) Yeah, you wanted to call glShaderSource, which is a C function and as such it's not aware of D sli

Re: string to char array?

2015-06-05 Thread anonymous via Digitalmars-d-learn
On Friday, 5 June 2015 at 17:27:18 UTC, Kyoji Klyden wrote: On Thursday, 4 June 2015 at 22:28:50 UTC, anonymous wrote: [...] By the way, there are subtly different meanings of "array" and "string" which I hope you're aware of, but just to be sure: "array" can refer to D array types, i.e. a poin

Re: Emulation macros and pattern matching on D

2015-06-05 Thread anonymous via Digitalmars-d-learn
On Friday, 5 June 2015 at 14:15:09 UTC, Dennis Ritchie wrote: For example, why here I can simply write: void main() { int b = 5; mixin(`int a = b;`); assert(a == 5); } This becomes: int b = 5; int a = b; assert(a == 5); Why should not I write like this: void main()

Re: string to char array?

2015-06-04 Thread anonymous via Digitalmars-d-learn
On Thursday, 4 June 2015 at 21:35:40 UTC, Kyoji Klyden wrote: On Thursday, 4 June 2015 at 03:25:24 UTC, ketmar wrote: On Wed, 03 Jun 2015 11:59:56 +, Kyoji Klyden wrote: [...] what exactly is char**? Is it pointing to the first char of the first string in an array? it's a pointer to a

Re: Does using "const" keyword for scalar parameters mean anything?

2015-06-04 Thread anonymous via Digitalmars-d-learn
On Thursday, 4 June 2015 at 11:28:51 UTC, tcak wrote: [code] void test( const int a ){} [/code] Does that "const" make any difference at all? At the end, it is a scalar, and passed as value. All it does is it makes the variable "a" const: void test( const int a ) { a = 42; /* Error:

Re: Error: field r must be initialized in constructor, because it is nested struct

2015-06-03 Thread anonymous via Digitalmars-d-learn
On Wednesday, 3 June 2015 at 23:27:31 UTC, Ali Çehreli wrote: Pretty standard thing doesn't work and I can't find it on bugzilla: import std.algorithm; struct Foo(R) { R r; this(R r)// <-- Compilation error {} } auto foo(R)(R r) { return Foo!R(r); } void main() { aut

Re: Array declaration warning

2015-06-03 Thread anonymous via Digitalmars-d-learn
On Wednesday, 3 June 2015 at 20:28:57 UTC, Paul wrote: Ooops, this is what I meant to post: struct CoOrd { int x, y; } CoOrd[][NumPaths]pathList; I append values like so... pathList[][n] ~= CoOrd(cX, cY); The "[]" does nothing here. You can leave it (or add more) out without chang

Re: string to char array?

2015-06-03 Thread anonymous via Digitalmars-d-learn
On Wednesday, 3 June 2015 at 11:23:09 UTC, Kyoji Klyden wrote: Ooooh okay, I'm starting to get it. I think this last question should clear it up for me: When a string is made, how is the struct Slice handled? What does ptr get assigned? ptr is a pointer to the first char, in other words the ad

Re: string to char array?

2015-06-03 Thread anonymous via Digitalmars-d-learn
On Wednesday, 3 June 2015 at 10:56:21 UTC, Kyoji Klyden wrote: So in "const char* sources = source.ptr;" sources is just turning the property ptr of source into a variable, yes and then in glShaderSource you're passing the memory address of sources yes (which is technically source.ptr)

Re: string to char array?

2015-06-03 Thread anonymous via Digitalmars-d-learn
On Wednesday, 3 June 2015 at 10:21:20 UTC, Kyoji Klyden wrote: On Wednesday, 3 June 2015 at 08:11:16 UTC, Kagamin wrote: On Tuesday, 2 June 2015 at 16:41:38 UTC, Kyoji Klyden wrote: [...] string source = readText("test.glvert"); const char* sources = source.ptr; [...]

Re: Template elegance?

2015-06-03 Thread anonymous via Digitalmars-d-learn
On Wednesday, 3 June 2015 at 09:10:22 UTC, David Monagle wrote: What I was looking for is a more elegant way of defining those secondary functions. Originally I was hoping I could do something like: enum shouldEqual(E, V) = shouldValue((e, v) => e == v, "equal", E, V); Here you go: tem

Re: InvalidMemoryOperationError from File.byLine()?

2015-06-02 Thread anonymous via Digitalmars-d-learn
On Tuesday, 2 June 2015 at 21:43:45 UTC, Stiff wrote: So...in the meantime, I'll just pad my input I guess? It's a mess and I'm not sure what works and what doesn't, but here are some options: byLineCopy: Could be fine as it doesn't reuse any buffers. readln without passing a buffer: as abo

Re: InvalidMemoryOperationError from File.byLine()?

2015-06-02 Thread anonymous via Digitalmars-d-learn
On Tuesday, 2 June 2015 at 20:56:41 UTC, Steven Schveighoffer wrote: Hm... I think the issue might possibly be solved. What version of the compiler are you using? I think 14005 (and 14578) are fixed in git head, because there's no assumeSafeAppend in byLine anymore. But the underlying issue

Re: The Kernighan-Ritchie allocator is back with a vengeance

2015-06-02 Thread anonymous via Digitalmars-d-learn
On Tuesday, 2 June 2015 at 19:47:09 UTC, Andrei Alexandrescu wrote: I just updated the Kernighan-Ritchie allocator, including documentation: Wrong board?

Re: InvalidMemoryOperationError from File.byLine()?

2015-06-02 Thread anonymous via Digitalmars-d-learn
On Tuesday, 2 June 2015 at 19:18:15 UTC, Stiff wrote: Hi, I'm reading in a rather large text file (~25Mb) line by line, where I don't need to hang on to a line for more than one iteration through my loop. I'm consistently getting an InvalidMemoryOperationError on my 2,547th iteration, and bas

Re: TypeTuple!(T...) vs Tuple!(T...)

2015-06-02 Thread anonymous via Digitalmars-d-learn
On Tuesday, 2 June 2015 at 09:34:28 UTC, Ali Çehreli wrote: On 06/02/2015 01:10 AM, rsw0x wrote: [...] The tuple page is even confusing me http://dlang.org/tuple.html [...] Tuple can hold only values, TypeTuple can hold types as well. Tuple can be created at run time, TypeTuple is a compile

Re: TypeTuple!(T...) vs Tuple!(T...)

2015-06-02 Thread anonymous via Digitalmars-d-learn
On Tuesday, 2 June 2015 at 08:10:27 UTC, rsw0x wrote: The tuple page is even confusing me http://dlang.org/tuple.html A variable declared with a TypeTuple becomes an ExpressionTuple: alias TL = Tuple!(int, long); is it using Tuple!(T...) and TypeTuple!(T...) interchangeably? Almost. `Tuple

Re: template instance template 'appender' is not defined

2015-05-31 Thread anonymous via Digitalmars-d-learn
On Sunday, 31 May 2015 at 21:33:53 UTC, Assembly wrote: why that page I've linked use std.format? You mean that first example? Simple oversight. It's already fixed in the prerelease version where it imports std.array now: http://dlang.org/phobos-prerelease/std_format.html

Re: Woldemort Type can't even call "take" or "array"

2015-05-31 Thread anonymous via Digitalmars-d-learn
On Sunday, 31 May 2015 at 07:45:02 UTC, kerdemdemir wrote: Unfortunately not this time :) import std.stdio; import std.algorithm; import std.string; import std.conv; import std.array; ---> I added this line thanks to you. `take` is in `std.range`. Try importing that.

Re: Woldemort Type can't even call "take" or "array"

2015-05-31 Thread anonymous via Digitalmars-d-learn
On Sunday, 31 May 2015 at 08:02:10 UTC, Ali Çehreli wrote: auto maxElement(R)(R range) { return reduce!((current, a) => current >= a ? current : a) (ElementType!R.min, range); } [...] auto result = numArr.maxElement; Can be shortened to `auto result = numArr.reduce!m

Re: data-oriented struct abstraction ?

2015-05-30 Thread Anonymous via Digitalmars-d-learn
This may be somewhat related. http://forum.dlang.org/thread/ckeqxhkqjyvmqodrf...@forum.dlang.org#post-m9rj0d:242m9e:243:40digitalmars.com https://github.com/economicmodeling/soa On Saturday, 30 May 2015 at 14:17:51 UTC, short2cave wrote: On Saturday, 30 May 2015 at 13:57:28 UTC, Rikki Cattermo

Re: Replacing nested loops foreach using map/each/etc

2015-05-25 Thread anonymous via Digitalmars-d-learn
On Monday, 25 May 2015 at 17:52:09 UTC, Dennis Ritchie wrote: But why is the solution breaks down when `s = 1` ? :) import std.stdio, std.algorithm, std.range; int c; const x = 12, y = 65, z = 50, s = 10; Which is it, now? 4 or 5 zeros? void solve(Range)(Range r) { cartesianProduct

Re: ctfe and static arrays

2015-05-24 Thread anonymous via Digitalmars-d-learn
On Sunday, 24 May 2015 at 20:53:03 UTC, Jay Norwood wrote: On Sunday, 24 May 2015 at 18:14:19 UTC, anonymous wrote: [...] 1) static int[5] x; -- x is a static variable with a static array type 2) static int[] x; -- static variable, dynamic array 3) int[5] x; -- non-static variable, static arra

Re: ctfe and static arrays

2015-05-24 Thread anonymous via Digitalmars-d-learn
On Sunday, 24 May 2015 at 18:14:19 UTC, anonymous wrote: "Static array" has a special meaning. It does not mean "static variable with an array type". Static arrays are those of the form Type[size]. That is, the size is known statically. PS: You may also see the term "fixed-size array" which me

Re: ctfe and static arrays

2015-05-24 Thread anonymous via Digitalmars-d-learn
On Sunday, 24 May 2015 at 17:35:39 UTC, Jay Norwood wrote: I'm a bit confused by the documentation of the ctfe limitations wrt static arrays due to these seemingly conflicting statements, and the examples didn't seem to clear anything up. I was wondering if anyone has examples of clever things

Re: Python's features, which requires D

2015-05-23 Thread anonymous via Digitalmars-d-learn
On Saturday, 23 May 2015 at 21:08:19 UTC, Dennis Ritchie wrote: Perhaps that's not the site, and in Windows. That's what gives me in CMD: 456 4 4 8 99 456 [[456, 4, 4, 8, 99, 456]13 546 std.conv.ConvException@C:\D\dmd2\windows\bin\..\..\src\phobos\std\conv.d(2013): Unexpected end of input when

Re: Python's features, which requires D

2015-05-23 Thread anonymous via Digitalmars-d-learn
On Saturday, 23 May 2015 at 20:25:18 UTC, Dennis Ritchie wrote: This does not work! enum n1 = 5; writeln(stdin.byLine .map!(line => line.split(" ").map!(x => to!int(x))) ); - http://rextester.com/VGHZF81178 The code itself is ok. That site has broken newlines. You can see here tha

Re: -vgc Info ok?

2015-05-19 Thread anonymous via Digitalmars-d-learn
On Monday, 18 May 2015 at 14:34:38 UTC, ketmar wrote: it can throw "out of range" error, which is `new`ed. Array access can also throw RangeError, but -vgc and @nogc don't mind that: void main() @nogc { int[] a; auto b = a[0]; }

Re: Capturing Caller UDAs as CT Template Function Parameters

2015-05-18 Thread anonymous via Digitalmars-d-learn
On Monday, 18 May 2015 at 21:35:44 UTC, Per Nordlöw wrote: void yield(T)(ref T value) { mixin("alias caller = " ~ caller ~ ";"); } doesn't work across module boundaries not even for `__PRETTY_FUNCTION__`. Do we need need to fix the compiler, Walter?! ;) You have to impor

Re: Const is already there. It cannot deduce it

2015-05-18 Thread anonymous via Digitalmars-d-learn
On Sunday, 17 May 2015 at 21:34:21 UTC, tcak wrote: [code] void test(D)( const D data ) if( is(D: shared(char[]) ) ) { } void main() { char[] text = new char[4]; text[0] = 'a'; text[1] = 'b'; text[2] = 'c'; text[3] = 'd'; auto t = cast( shared(const(char[])) )tex

Re: ICE?

2015-05-17 Thread anonymous via Digitalmars-d-learn
On Sunday, 17 May 2015 at 10:09:11 UTC, Daniel Kozak wrote: On Sunday, 17 May 2015 at 09:25:33 UTC, Namespace wrote: [...] Error: e2ir: cannot cast malloc(length * 8u) of type void* to type char[] I would say this is not an ICE just normal error message. "e2ir: " shouldn't be there, though.

Re: How to create a mutable array of strings?

2015-05-17 Thread anonymous via Digitalmars-d-learn
On Sunday, 17 May 2015 at 09:26:15 UTC, Dennis Ritchie wrote: And no crashes on Windows :) Yeah, on windows it's even worse. void main() { auto s = cast(char[][])["foo", "bar"]; s[1][1] = 't'; import std.stdio; writeln("bar"); }

Re: How to create a mutable array of strings?

2015-05-17 Thread anonymous via Digitalmars-d-learn
On Sunday, 17 May 2015 at 09:20:17 UTC, Dennis Ritchie wrote: On Sunday, 17 May 2015 at 09:18:15 UTC, Daniel Kozak wrote: auto s = cast(char[][])["foo", "bar"]; Thanks. This version I was completely satisfied. Remember that Daniel Kozak wrote "if you are sure thats what you really need". I'

Re: Dynamic / resizable array type, and a crash problem

2015-05-15 Thread anonymous via Digitalmars-d-learn
On Thursday, 14 May 2015 at 20:50:05 UTC, ivoras wrote: I'm experimenting to get a feel for the language. Do you have a suggestion about this example code: https://goo.gl/F7LCAg to make it more "D-like", idiomatic? Quoting from the code: for (int i = 0; i < count; i++) { foreach(i; 0 .. c

Re: What wrong?

2015-05-15 Thread anonymous via Digitalmars-d-learn
On Saturday, 2 May 2015 at 02:51:52 UTC, Fyodor Ustinov wrote: Simple code: http://pastebin.com/raw.php?i=7jVeMFXQ This code works compiled by DMD v2.066.1 and LDC2 (0.15.1) based on DMD v2.066.1 and LLVM 3.5.0. $ ./z TUQLUE 42 11 Compiled by DMD v2.067.1 the program crashes: $ ./aa TUQLUE

Re: Cannot Qualify Variadic Functions with Lazy Arguments as nothrow

2015-05-14 Thread anonymous via Digitalmars-d-learn
On Thursday, 14 May 2015 at 09:53:20 UTC, Per Nordlöw wrote: I'm almost satisified with it except that the lazy evaluation at https://github.com/nordlow/justd/blob/master/algorithm_ex.d#L45 cannot be made nothrow. If I qualify the function as nothrow DMD complains as algorithm_ex.d(45,16): Er

Re: Dynamic / resizable array type, and a crash problem

2015-05-14 Thread anonymous via Digitalmars-d-learn
On Thursday, 14 May 2015 at 12:42:01 UTC, ivoras wrote: https://gist.github.com/ivoras/2d7737c214c3dc937c28 The crash is at line 20: core.exception.AssertError@/usr/include/dmd/phobos/std/container/array.d(334): [...] This is on DMD32 D Compiler v2.067.1 Seems to be fixed in git head.

Re: how does 'shared' affect member variables?

2015-05-09 Thread anonymous via Digitalmars-d-learn
On Saturday, 9 May 2015 at 19:59:58 UTC, tcak wrote: Stupidly, shared variables' value cannot be increased/decreased directly. Compiler says it is deprecated, and tells me to use core.atomic.atomicop. You will see this as well. How's that stupid? Sounds like the compiler is doing its job guar

Re: how does 'shared' affect member variables?

2015-05-09 Thread anonymous via Digitalmars-d-learn
On Saturday, 9 May 2015 at 18:41:59 UTC, bitwise wrote: What does 'shared' do to member variables? Makes them `shared`. :P It makes sense to me to put it on a global variable, but what sense does it make putting it on a member of a class? Globals are not the only way to pass data to other t

Re: Multiple template alias parameters

2015-05-08 Thread anonymous via Digitalmars-d-learn
On Friday, 8 May 2015 at 22:29:28 UTC, Biotronic wrote: Sadly, the ... syntax precludes the use of __LINE__ and __FILE__. :( You can put them in the runtime parameters: void traceVars(alias T, U...)(size_t line = __LINE__, string file = __FILE__) { import std.stdio : writeln; wr

Re: Bitfield-style enum to strings?

2015-05-07 Thread anonymous via Digitalmars-d-learn
On Thursday, 7 May 2015 at 20:55:42 UTC, Nick Sabalausky wrote: // There's gotta be a better way to convert EnumMembers!T // to a range, right? But std.range.only() didn't work, // due to a template instantiation error. T[] members; foreach(m; EnumMembers!(T)) members

Re: Linker command

2015-05-06 Thread anonymous via Digitalmars-d-learn
On Wednesday, 6 May 2015 at 19:52:44 UTC, Paul wrote: On Wednesday, 6 May 2015 at 19:30:33 UTC, anonymous wrote: On Wednesday, 6 May 2015 at 19:26:40 UTC, Paul wrote: but I don't understand the syntax. dmd --help mentions -Llinkerflag but what is '-L-L.' doing?? Passes '-L.' to the linker.

Re: Linker command

2015-05-06 Thread anonymous via Digitalmars-d-learn
On Wednesday, 6 May 2015 at 19:26:40 UTC, Paul wrote: but I don't understand the syntax. dmd --help mentions -Llinkerflag but what is '-L-L.' doing?? Passes '-L.' to the linker.

Re: opEquals optimized away?

2015-05-04 Thread anonymous via Digitalmars-d-learn
On Tuesday, 5 May 2015 at 04:09:03 UTC, Manfred Nowak wrote: class C{ override bool opEquals( Object o){ return true; } } unittest{ auto c= new C; assert( c == c); } `rdmd --main -unittest -cov' shows, that opEquals is not executed. Why? -manfred because `c is c` https://github

Re: CTFE & template predicates

2015-05-04 Thread anonymous via Digitalmars-d-learn
On Monday, 4 May 2015 at 11:41:23 UTC, Robert M. Münch wrote: Hi, I have one more questions: Is it possible to write something like this? alias rules = StaticFilter!(startsNotWith(?, 'p'), org_rules); The ? should be used for every memember of org_rules. No, we don't have template literals.

Re: CTFE & template predicates

2015-05-04 Thread anonymous via Digitalmars-d-learn
On Monday, 4 May 2015 at 11:22:16 UTC, Robert M. Münch wrote: Hi, ok, just to better understand this (I have a C++ background (even quite old)): When I want to use some functions I need to specify the type? It's not possible to use T.length() which would compile if T is a string? I thought that

Re: CTFE & template predicates

2015-05-03 Thread anonymous via Digitalmars-d-learn
On Sunday, 3 May 2015 at 21:46:11 UTC, Robert M. Münch wrote: Hi, I have now played a around couple of hours (reading everything I could find) to get something to work, but I think I'm missing some basic concepts/understanding. Maybe someone can enlighten me how these things work. I thought tha

Re: How to I translate this C++ structure/array

2015-05-03 Thread anonymous via Digitalmars-d-learn
On Sunday, 3 May 2015 at 02:31:51 UTC, WhatMeWorry wrote: On Saturday, 2 May 2015 at 22:36:29 UTC, anonymous wrote: [...] [1] `Vertex triangle[6]` works, but please don't do that. Thanks. I assume you would prefer I use triangle[] but with OpenGL calls the dynamic arrays don't work. But may

Re: How to I translate this C++ structure/array

2015-05-02 Thread anonymous via Digitalmars-d-learn
On Saturday, 2 May 2015 at 22:01:10 UTC, WhatMeWorry wrote: struct Vertex { vec3 position; vec3 color; } Vertex triangle[6] = [ vec3(0.0, 1.0, 0.0), vec3(1.0, 0.0, 0.0), // red // code removed for brevity. ]; I keep getting the

Re: Calling functions using mixins

2015-05-01 Thread anonymous via Digitalmars-d-learn
On Friday, 1 May 2015 at 21:41:10 UTC, Dennis Ritchie wrote: My final goal is to do something like this: - import std.stdio, std.string; int foo() { return 5; } int bar() { return 10; } void main() { immutable string[] s = [ "foo", "bar" ]; writeln(mixin(`

Re: Calling functions using mixins

2015-05-01 Thread anonymous via Digitalmars-d-learn
On Friday, 1 May 2015 at 21:04:10 UTC, Dennis Ritchie wrote: hi, Is it possible to call functions using mixins in this way? - import std.stdio; int fooTestMixin() { return 5; } void main() { enum t { fooTestMixin }; immutable string[] strArr = [ "fooTestMixin" ];

Re: Factory pattern in D

2015-05-01 Thread anonymous via Digitalmars-d-learn
On Friday, 1 May 2015 at 11:01:29 UTC, Chris wrote: This aside, how would I get something to load dynamically? It's either "mismatched function return type" or (with type check) "variable X cannot be read at compile time": void main(string[] args) { auto type = args[1]; auto myType = factory

Re: How to reuse functions

2015-05-01 Thread anonymous via Digitalmars-d-learn
On Friday, 1 May 2015 at 03:34:53 UTC, Luigi wrote: Hi everybody. I am tring to use a function where its parameter is another function, and at the same time are both already made - they cannot be modified - and the second one has to be conditioned before to be passed as argument. Let's say

Re: o!(const(T)) parameter.

2015-04-25 Thread anonymous via Digitalmars-d-learn
On Saturday, 25 April 2015 at 14:52:45 UTC, sclytrack wrote: I want a function with parameter o!(const(Form)) to accept both o!(Form) and o!(immutable(Form)) Is there a way to do it? import std.stdio; import std.traits; class Form { int number = 10; } struct o(T) { T dat

Re: Delegate type deduction compile error

2015-04-25 Thread anonymous via Digitalmars-d-learn
On Saturday, 25 April 2015 at 10:23:25 UTC, ref2401 wrote: struct MyStruct {} void main(string[] args) { string str = "blah-blah"; auto d1 = (MyStruct) { writeln("delegate-str: ", str); }; writeln(typeid(typeof(d1))); } dmd: 2067 os: Win8.1 build script: dmd main.d -

Re: how does isInputRange(T) actually work?

2015-04-21 Thread anonymous via Digitalmars-d-learn
On Tuesday, 21 April 2015 at 19:17:56 UTC, kevin wrote: On Tuesday, 21 April 2015 at 19:13:34 UTC, Meta wrote: On Tuesday, 21 April 2015 at 19:11:43 UTC, John Colvin wrote: On Tuesday, 21 April 2015 at 19:06:39 UTC, kevin wrote: enum bool isInputRange = is(typeof( (inout int = 0) { R r

Re: Weird link error

2015-04-20 Thread anonymous via Digitalmars-d-learn
On Monday, 20 April 2015 at 17:02:18 UTC, CodeSun wrote: I have test a snippet of code, and I encountered with a weird link error. The following is the demo: import std.stdio; interface Ti { T get(T)(int num); T get(T)(string str); } class Test : Ti { T get(T)(int num)

Re: Templates: Array slices not recognized

2015-04-20 Thread anonymous via Digitalmars-d-learn
On Monday, 20 April 2015 at 10:14:27 UTC, Chris wrote: string a = "bla"; string b = "blub"; auto res = doSomething(a, b); If I didn't use "auto ref" or "ref", string would get copied, wouldn't it? auto ref doSomething(R needle, R haystack); To avoid this, I would have to write a[0..$], b[0.

Re: Input ranges

2015-04-19 Thread anonymous via Digitalmars-d-learn
On Sunday, 19 April 2015 at 21:42:23 UTC, Ulrich Küttler wrote: groupBy is a nice example as it laboriously adds reference semantics to forward ranges but assumes input ranges to posses reference semantics by themselves. All ranges are input ranges, though. Input ranges are the least speciali

Re: Input ranges

2015-04-19 Thread anonymous via Digitalmars-d-learn
On Saturday, 18 April 2015 at 22:01:56 UTC, Ulrich Küttler wrote: Input ranges from std.stdio are used for reading files. So assuming we create a file auto f = File("test.txt", "w"); f.writeln(iota(5).map!(a => repeat(to!string(a), 4)).joiner.joiner("\n")); f.close(); We should be

Re: CTFE UFCs?

2015-04-14 Thread anonymous via Digitalmars-d-learn
On Tuesday, 14 April 2015 at 15:20:37 UTC, bitwise wrote: When I uncomment the nicer syntax, I get the errors below: [1] Error: variable refl cannot be read at compile time [2] Error: CTFE failed because of previous errors in base class Base { double d = 0.4; } class Test : Base { int

Re: Traits question and compiler crash

2015-04-14 Thread anonymous via Digitalmars-d-learn
On Tuesday, 14 April 2015 at 09:24:04 UTC, Filippo Fantini wrote: Hello everyone! I'm new to D. While playing with around with traits, I ended up writing this short example: module test; class Foo { private int _value = 21; void foo() { import std.traits; alias f

Re: Formatted output ranges

2015-04-11 Thread anonymous via Digitalmars-d-learn
On Saturday, 11 April 2015 at 20:10:49 UTC, Dennis Ritchie wrote: writefln("%(;; %(%s, %),\n%).", [ a[0 .. 15], a[15 .. 30], a[30 .. 45], a[45 .. 60], a[60 .. 75], a[75 .. 90],

Re: function shadowed

2015-04-08 Thread anonymous via Digitalmars-d-learn
On Wednesday, 8 April 2015 at 22:53:39 UTC, ddos wrote: why not just make it callable without the alias? It's to prevent "hijacking": http://dlang.org/hijack.html

Re: function shadowed

2015-04-08 Thread anonymous via Digitalmars-d-learn
On Wednesday, 8 April 2015 at 12:05:00 UTC, ddos wrote: vg.d: module vg; extern (C) void vgSetParameterfv(VGHandle object, VGint paramType, VGint count, VGfloat *values); openvg.d module openvg; public import vg; void vgSetParameterfv(VGHandle object, VGint paramType, const(VGfloat[]) value

Re: Accessing a field of a containing class from within a nested class

2015-04-01 Thread anonymous via Digitalmars-d-learn
On Wednesday, 1 April 2015 at 18:26:49 UTC, Charles Hixson wrote: Perhaps BTree needs to be a class? yes

Re: is it std.datetime bug?

2015-03-31 Thread anonymous via Digitalmars-d-learn
On Tuesday, 31 March 2015 at 11:51:26 UTC, drug wrote: import std.datetime; import std.stdio; void main() { long.max.SysTime.toISOExtString.writeln; } dmd 2.065 (dpaste.dzfl.pl): +29228-09-14T02:48:05.4775807 dmd v2.067-devel-c6b489b (using Digger): -29227-04-20T00:11:54.5224191 could

Re: Mapping with partial

2015-03-30 Thread anonymous via Digitalmars-d-learn
On Monday, 30 March 2015 at 19:03:05 UTC, matovitch wrote: Well I have a bit of a similar problem with foreach. If I use classic T[] range, I can do : foreach(int i, auto t, myRange)... But if I use an Array!T (from std.container) I get : cannot infer argument types, expected 1 argument, not

Re: Mapping with partial

2015-03-30 Thread anonymous via Digitalmars-d-learn
On Monday, 30 March 2015 at 19:15:25 UTC, matovitch wrote: Language ref -> Array -> Slice "An array slice does not copy the data, it is only another reference to it." So the total slice of a static array is a range using the underlying memory of the static array isnt it ? yes

Re: Mapping with partial

2015-03-30 Thread anonymous via Digitalmars-d-learn
On Monday, 30 March 2015 at 19:11:10 UTC, matovitch wrote: That settle the point for array as for [] ? I though that was clear. [] doesn't copy. I guess the documentation should have something to say about it too. ;) hopefully

Re: Mapping with partial

2015-03-30 Thread anonymous via Digitalmars-d-learn
On Monday, 30 March 2015 at 18:37:53 UTC, matovitch wrote: On Monday, 30 March 2015 at 18:34:19 UTC, Adam D. Ruppe wrote: [...] Aye, that would work too, but the slice I think is more efficient as I'm pretty sure... not completely sure, but I think .array makes a copy of static arrays, whereas

Re: string concatenation with %s

2015-03-30 Thread anonymous via Digitalmars-d-learn
On Monday, 30 March 2015 at 17:34:20 UTC, Suliman wrote: string sss = format("foo"-", ""bar"); It should be obvious now that you forgot to escape those double quotes. Thanks! Is there any way to stay string as is. without need of it's escaping and so on? It's seems I have seen something li

Re: rvalue based copy

2015-03-30 Thread anonymous via Digitalmars-d-learn
On Monday, 30 March 2015 at 17:21:53 UTC, Steven Schveighoffer wrote: One solution is to overload void opAssign(ref const S s) {...} void opAssign(const S s) {...} lvalues will go into the ref version, rvalues into the non-ref. There won't be any copying of data, so you still save a postblit

Re: string concatenation with %s

2015-03-30 Thread anonymous via Digitalmars-d-learn
On Monday, 30 March 2015 at 17:18:01 UTC, Suliman wrote: same problem. I am preparing string to next SQL request: string sss = format("SELECT * FROM test.imgs WHERE src LIKE CONCAT('%', REPLACE(CAST(CURDATE()as char), "-", ""), '%') OR CONCAT('%', CAST(CURDATE()as char), '%')"); Here's your

Re: Associative Array of Const Objects?

2015-03-29 Thread anonymous via Digitalmars-d-learn
On Sunday, 29 March 2015 at 20:29:50 UTC, bitwise wrote: 3) It's not how C++ rolls. `const Test test;` and `Test const test;` are equivalent in C++. You need that '*' in C++, too, to make a distinction between reference and data. I'm a little confused. I was comparing a C++ pointer-to-class

Re: Associative Array of Const Objects?

2015-03-29 Thread anonymous via Digitalmars-d-learn
On Sunday, 29 March 2015 at 19:13:32 UTC, bitwise wrote: Interesting, but I still don't understand why D doesn't have something like this: const Test test;// or const(Test) test; test = new Test() // fine, underlaying data is const, the reference is not Test const test = new Test(); tes

Re: Associative Array of Const Objects?

2015-03-29 Thread anonymous via Digitalmars-d-learn
On Sunday, 29 March 2015 at 18:43:32 UTC, bitwise wrote: I'm a little confused at this point why this doesn't work either: const(Test) test = new Test(); // fine test = new Test(); // error In C++, There is a clear distinction: const Test *test1 = nullptr; // const befor

Re: need help with CTFE

2015-03-26 Thread anonymous via Digitalmars-d-learn
On Thursday, 26 March 2015 at 16:19:17 UTC, Dmitri Makarov wrote: When I compile version DOES_NOT_WORK, I get the following error: c/tool.d(13): Error: variable name cannot be read at compile time c/tool.d(13):while looking for match for hasMember!(Tool, name) However, the other versi

Re: D's type classes pattern ?

2015-03-24 Thread anonymous via Digitalmars-d-learn
On Tuesday, 24 March 2015 at 16:56:13 UTC, matovitch wrote: Thanks, just to be clear : void Bar(T : Foo)(T t){ } is the same as void Bar(T)(T t) if (is(T == Foo)){ } and it is checked only at compile time ? (for the runtime I know that what interface were meant for ;)). Ali already mention

Re: The difference in string and char[], readf() and scanf()

2015-03-21 Thread anonymous via Digitalmars-d-learn
On Saturday, 21 March 2015 at 23:00:46 UTC, Ivan Kazmenko wrote: To me, it looks like a bug somewhere, though I don't get where exactly. Is it in bits of DigitalMars C/C++ compiler code glued into druntime? As far as I understand, the bug is in snn.lib's scanf. snn.lib is Digital Mars's impl

Re: The difference in string and char[], readf() and scanf()

2015-03-21 Thread anonymous via Digitalmars-d-learn
On Saturday, 21 March 2015 at 15:05:56 UTC, Ivan Kazmenko wrote: Generate a 10-character string: - import std.range, std.stdio; void main () {'a'.repeat (10).writeln;} - Try to copy it with D scanf and printf: - import std.stdio; void main () { char [10] a;

Re: The difference in string and char[], readf() and scanf()

2015-03-21 Thread anonymous via Digitalmars-d-learn
On Saturday, 21 March 2015 at 08:37:59 UTC, Dennis Ritchie wrote: Tell me, please, why this code works correctly always: [...] And this code works correctly is not always: import std.stdio; readf("%s\n", &n); char[200010] s, t; scanf("%s%s", s.ptr, t.ptr); Please go into more detail about

Re: std.typecons.Proxy + inheritance breaks cast'ing to inherited type

2015-03-17 Thread anonymous via Digitalmars-d-learn
On Tuesday, 17 March 2015 at 07:56:19 UTC, Ali Çehreli wrote: > Why can't you do this instead? > > t opCast(t)() > if (is(typeof(cast(T)this))) > { > return cast(T)this; > } That has the same problem: 'cast(T)this' happens to be an explicit cast, which is disabled by the opCast overload fo

Re: How to test for type without refs?

2015-03-17 Thread anonymous via Digitalmars-d-learn
On Tuesday, 17 March 2015 at 14:06:19 UTC, Charles Hixson wrote: I thought that in: T* user(T)() {static assert (T.sizeof < bfHdr.user_.length); static assert (__traits(isPOD, T) ); returncast(T*) bfHdr.user_.ptr; } the line: static assert (__traits(isPOD,

Re: ref for (const) variables

2015-03-16 Thread anonymous via Digitalmars-d-learn
On Monday, 16 March 2015 at 18:47:00 UTC, Namespace wrote: const(Matrix)* m = &t.getCurrentModelViewMatrix(); // currently } But IMO it would be a lot nicer if I could store the reference like this: ref const(Matrix) m = t.getCurrentModelViewMatrix(); // nicer [Of course t

Re: get from tuple by type

2015-03-15 Thread anonymous via Digitalmars-d-learn
On Sunday, 15 March 2015 at 23:13:58 UTC, Charles Cooper wrote: And yes, I could use names. But then you are subject to name clashes and using strings instead of types as member identifiers is more prone to error anyways. Ever gotten this wrong before -- void CRITICAL_TO_GET_THIS_RIGHT(uint ce

Re: get from tuple by type

2015-03-15 Thread anonymous via Digitalmars-d-learn
On Sunday, 15 March 2015 at 21:59:18 UTC, Charles Cooper wrote: C++14 has: template constexpr T& get(tuple& t); Which allows you to get a member of the tuple struct by type. Is there an idiomatic / library way to do this in D? Preferably by indexing. I don't think there is. I don't know if t

Re: What is: Orphan format arguments: args[0..1]

2015-03-15 Thread anonymous via Digitalmars-d-learn
On Sunday, 15 March 2015 at 18:46:52 UTC, Charles Hixson wrote: What is: Orphan format arguments: args[0..1] It appears to come from within unittest at the line: strings="{0}".format(cast(int)d2[i]); It means you gave `format` more arguments than placeholders. `format` uses C styl

Re: Using std.format required std.string?

2015-03-15 Thread anonymous via Digitalmars-d-learn
On Sunday, 15 March 2015 at 18:03:55 UTC, Robert M. Münch wrote: On 2015-03-15 17:36:24 +, Robert M. Münch said: Is there a way to use "version(...)" to have code sections depending on compiler version? Something like: version(dmd >= 2.067) or version(dmd < 2.067)? Answerting myself: st

Re: Garbage collector returning pointers

2015-03-14 Thread anonymous via Digitalmars-d-learn
On Saturday, 14 March 2015 at 18:26:34 UTC, Robert M. Münch wrote: Hi, I have a question about how the GC handles this case: export extern(C) char* foo(){ char[] x = "This is a dynamic D string.".dup; return(cast(char*)x); } Returning `x.ptr` would look a little nicer. Since x is "pointe

Re: Parallelization of a large array

2015-03-10 Thread anonymous via Digitalmars-d-learn
On Tuesday, 10 March 2015 at 20:41:14 UTC, Dennis Ritchie wrote: Hi. How to parallelize a large array to check for the presence of an element matching the value with the data? std.stdio; std.algorithm; std.parallelism; You forgot a couple "import"s here. void main() { int[] a = n

Re: Int to float?

2015-03-05 Thread anonymous via Digitalmars-d-learn
On Thursday, 5 March 2015 at 20:21:18 UTC, badlink wrote: On Thursday, 5 March 2015 at 20:16:55 UTC, anonymous wrote: On Thursday, 5 March 2015 at 20:03:09 UTC, Benjamin Thaut wrote: int someValue = 5; float sameBinary = *(cast(float*)cast(void*)&someValue); The cast(void*) isn't necessary.

Re: Object as function argument

2015-03-05 Thread anonymous via Digitalmars-d-learn
On Thursday, 5 March 2015 at 19:51:09 UTC, Max Klyga wrote: If you really need the actual pointer to object data you can use `*cast(void**)&myObject`. Compiler cannot cast object reference to `void*` but we can trick it ;) It can, actually. A class can define its own cast(void*) though, so th

Re: Int to float?

2015-03-05 Thread anonymous via Digitalmars-d-learn
On Thursday, 5 March 2015 at 20:03:09 UTC, Benjamin Thaut wrote: int someValue = 5; float sameBinary = *(cast(float*)cast(void*)&someValue); The cast(void*) isn't necessary.

Re: Strange alias behaviour in template arguments

2015-03-03 Thread anonymous via Digitalmars-d-learn
On Tuesday, 3 March 2015 at 13:42:09 UTC, Stefan Frijters wrote: So this is a strange thing I ran into while trying to streamline some templates in my code, where fixed-length arrays are passed as runtime arguments. I started out by trying variant fun2(), which disappointingly didn't work. fun3

Re: strage heisenbug (has scoped destruction, cannot build closure)

2015-03-03 Thread anonymous via Digitalmars-d-learn
On Tuesday, 3 March 2015 at 07:26:13 UTC, ketmar wrote: hi. the following (manually "dustmited" ;-)) code gives the error from subj on git HEAD: === ztest.d === module ztest; auto streamAsRange(STP) (STP st) { static struct StreamRange(ST) { private: ST strm; public:

Re: On opCmp

2015-02-27 Thread anonymous via Digitalmars-d-learn
On Friday, 27 February 2015 at 11:04:51 UTC, Nordlöw wrote: Is there a more compact way to describe the opCmp function in the following struct struct Hit { size_t count; // number of walkers that found this node NWeight rank; // rank (either minimum distance or maximum strength)

Re: @trusted and return ref

2015-02-26 Thread anonymous via Digitalmars-d-learn
On Thursday, 26 February 2015 at 20:56:52 UTC, Ola Fosheim Grøstad wrote: But it should matter, because when you mark a unit @trusted you basically are signing off a "certificate" that says it acts like @safe in @safe code. How can you verify anything if you allow injections? If you allow @sy

Re: Installing DMD From Zip

2015-02-26 Thread anonymous via Digitalmars-d-learn
On Thursday, 26 February 2015 at 10:55:40 UTC, Jonathan M Davis wrote: I think that it was the same page, though I could be remembering wrong. Several articles are missing as well (e.g. the one on std.datetime and the one on arrays), so I don't know how careful they really were in updating the

<    1   2   3   4   5   6   >