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 import

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'm

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

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

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

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

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;

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

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

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

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

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

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

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

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

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

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

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

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 {

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

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

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 code

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

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

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

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

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

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

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 how

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

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 for int.

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

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:

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 style

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

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: templateclass T, class... Types constexpr T get(tupleTypes... 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

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 pointer

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 imports here. void main() { int[] a =

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

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

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 10:15:07 UTC, Ola Fosheim Grøstad wrote: On Wednesday, 25 February 2015 at 22:59:01 UTC, anonymous wrote: rule-breaking that's going on there. A public trusted_malloc would invite the un-initiated to shoot their feet. That's entirely social... Sure. A

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

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

Re: @trusted and return ref

2015-02-25 Thread anonymous via Digitalmars-d-learn
On Wednesday, 25 February 2015 at 07:07:00 UTC, Ola Fosheim Grøstad wrote: On Wednesday, 25 February 2015 at 00:12:41 UTC, anonymous wrote: [...] That sounds more attractive than the provided example, but the right thing to do is to establish proper encapsulation. That means you need a

Re: How can I do that in @nogc?

2015-02-25 Thread anonymous via Digitalmars-d-learn
On Wednesday, 25 February 2015 at 19:32:50 UTC, Namespace wrote: void glCheck(lazy void func, string file = __FILE__, uint line = __LINE__) { func(); glCheckError(file, line); } How can I specify that 'func' is @nogc? Or can define the function otherwise? First of

Re: How can I do that in @nogc?

2015-02-25 Thread anonymous via Digitalmars-d-learn
On Wednesday, 25 February 2015 at 20:36:33 UTC, Namespace wrote: On Wednesday, 25 February 2015 at 20:15:10 UTC, anonymous wrote: [...] It may be possible to hack through this limitation - NOT THOUGHT-OUT, NOT TESTED, NOT RECOMMENDED: --- void glCheck(scope lazy int thing) @nogc;

Re: @trusted and return ref

2015-02-25 Thread anonymous via Digitalmars-d-learn
On Wednesday, 25 February 2015 at 22:16:14 UTC, Ola Fosheim Grøstad wrote: My point was that there is no conceptual difference between having a named function trusted_malloc!int() and trusted_free() and wrapping them up individually unnamed. An ad-hoc declared @trusted malloc is just as

Re: @trusted and return ref

2015-02-24 Thread anonymous via Digitalmars-d-learn
On Tuesday, 24 February 2015 at 22:37:58 UTC, Ola Fosheim Grøstad wrote: 1. My understanding is that @trusted is supposed to give memory safety escapes by providing a context which reestablish a memory safety context on return. Yep, that's how I got it, too. A @trusted function is supposed to

Re: Passing variadic arguments to C

2015-02-22 Thread anonymous via Digitalmars-d-learn
On Sunday, 22 February 2015 at 17:09:27 UTC, Foo wrote: Is this possible? Example: void foo(Args...)(auto ref Args args) { sprintf(str.ptr, fmt.ptr, args); } yes

Re: What is the Correct way to Malloc in @nogc section?

2015-02-21 Thread anonymous via Digitalmars-d-learn
On Saturday, 21 February 2015 at 13:41:41 UTC, Foo wrote: Finally, I tried to take your criticism objectively and, as far as I can tell, I resolved the issues. Is there still any objections or misconduct? Nice. I think you fixed everything I had pointed out.

Re: Best practices for reading public interfaces

2015-02-21 Thread anonymous via Digitalmars-d-learn
On Saturday, 21 February 2015 at 20:46:09 UTC, Kenny wrote: b) Write DDocs and read documentation. The problem here is that I'm going to use D only for my own projects and in the last time I tend to write less documentation, for example I do not write it for the most methods of Vector3D. If

Re: Type-Strict Indexes: IndexedBy

2015-02-18 Thread anonymous via Digitalmars-d-learn
On Tuesday, 17 February 2015 at 19:46:09 UTC, Nordlöw wrote: Superb! I'd like to see this getting into std.typecons. Having this in the language will attract (more) Ada programmers to D. Should I do PR for std.typecons.[iI]ndexedBy? I'm not familiar with Ada, and I don't immediately see

Re: Type-Strict Indexes: IndexedBy

2015-02-17 Thread anonymous via Digitalmars-d-learn
On Tuesday, 17 February 2015 at 13:38:41 UTC, Per Nordlöw wrote: This looses most of the meaning of my idea. I still want my range to inherit all the powers of its wrapped range. Is there no way to disable member functions in D? I hadn't thought of @disable. Played around with it a bit. The

Re: Type-Strict Indexes: IndexedBy

2015-02-16 Thread anonymous via Digitalmars-d-learn
On Monday, 16 February 2015 at 20:09:09 UTC, Nordlöw wrote: How can I prevent jx[0] = 11; from compiling? Remove that `alias _r this;`. You don't want to forward opIndex, so you can't use alias this which forwards everything that doesn't compile. opDispatch may be an option to forward

Re: ranges reading garbage

2015-02-16 Thread anonymous via Digitalmars-d-learn
On Sunday, 15 February 2015 at 22:38:20 UTC, anonymous wrote: And more: import std.stdio; struct MapResult(alias fun) { @property int front() {return fun();} @property auto save() {return typeof(this)();} } void main() { int ys_length = 4; auto dg = {return MapResult!({return

Re: shared interfaces

2015-02-15 Thread anonymous via Digitalmars-d-learn
On Sunday, 15 February 2015 at 10:43:46 UTC, Andrey Derzhavin wrote: what is wrong in declarations, if I need to declare shared classes D and C? `shared` on a class/interface makes all members shared. And that's all it does. So this: interface IA { void fnA(); } shared class C :

Re: shared interfaces

2015-02-15 Thread anonymous via Digitalmars-d-learn
On Sunday, 15 February 2015 at 12:34:50 UTC, Andrey Derzhavin wrote: On Sunday, 15 February 2015 at 11:30:46 UTC, anonymous wrote: [...] interface IA { void fnA(); } shared interface IC : IA { void fnC(); } class D : IC { override void fnC() shared {} override void fnA() {} }

Re: ranges reading garbage

2015-02-15 Thread anonymous via Digitalmars-d-learn
On Sunday, 15 February 2015 at 18:13:44 UTC, John Colvin wrote: Simplified from something bigger: import std.range, std.algorithm, std.stdio; void foo(float[] data, float[] xs, float[] ys) { auto indices = iota(0, data.length, ys.length) .map!(xBase = iota(xBase,

Re: ranges reading garbage

2015-02-15 Thread anonymous via Digitalmars-d-learn
On Sunday, 15 February 2015 at 19:54:45 UTC, anonymous wrote: Reduced some more: import std.algorithm, std.stdio; void main() { int ys_length = 4; auto indices = [0] .map!(xBase = [0].map!(y = ys_length)) .joiner(); writeln(indices); } And more: import std.stdio;

Re: dmd-2.067.0-b1

2015-02-13 Thread anonymous via Digitalmars-d-learn
On Friday, 13 February 2015 at 13:25:55 UTC, Steven Schveighoffer wrote: Yes, the operator precedence (curiously not defined in the spec) is here: http://wiki.dlang.org/Operator_precedence Conditional operator is above assignment operators. It's specified through the grammar [1]:

Re: What is the Correct way to Malloc in @nogc section?

2015-02-13 Thread anonymous via Digitalmars-d-learn
On Thursday, 12 February 2015 at 23:52:41 UTC, Foo wrote: This is something I've done recently. Would be glad if my code will help you: https://github.com/Dgame/m3 Especially the m3.d module could be useful for you. /* Class and Struct */ emplace: You can't assume zero-initialization for

Re: What is the Correct way to Malloc in @nogc section?

2015-02-13 Thread anonymous via Digitalmars-d-learn
On Friday, 13 February 2015 at 23:04:25 UTC, Foo wrote: Don't understand me wrong. My code is not perfect, but maybe it can be helpful for someone. As it is right now, I fear it may do more harm than good.

Re: Cannot use the same template arguments on function as the ones on struct

2015-02-11 Thread anonymous via Digitalmars-d-learn
On Wednesday, 11 February 2015 at 22:14:44 UTC, MrSmith wrote: http://dpaste.dzfl.pl/5f1d5d5d9e19 Instead I need to use template constraint which is less compact. http://dpaste.dzfl.pl/571ae84d783e Why such behavior happens? Seems to work when you add an empty template argument list to

Re: Fun with floating point

2015-02-07 Thread anonymous via Digitalmars-d-learn
On Saturday, 7 February 2015 at 22:46:56 UTC, Ali Çehreli wrote: 1.0 is famously not representable exactly. 1.0 is representable exactly, though.

Re: strange work of GC

2015-02-06 Thread anonymous via Digitalmars-d-learn
On Friday, 6 February 2015 at 20:38:07 UTC, Andrey Derzhavin wrote: As I think, the garbage collector should start destoying of the C1 and C2 objects of arr array during the while cycle prosess, but this does not happen. Dtors are not called. Garbage is only collected when you allocate

Re: Syntax for checking if an element exists in a list

2015-02-05 Thread anonymous via Digitalmars-d-learn
On Thursday, 5 February 2015 at 13:31:21 UTC, Nicholas Wilson wrote: Note that D does NOT have default fall through. i.e. switch(myopt) { case opt1, opt2, opt3: do_A(); break; case opt4: do_B(); break; default: do_C(); } is equivalent to

Re: is it bug?

2015-01-30 Thread anonymous via Digitalmars-d-learn
On Friday, 30 January 2015 at 13:39:05 UTC, BBaz wrote: On Friday, 30 January 2015 at 13:34:57 UTC, drug wrote: On 30.01.2015 16:31, BBaz wrote: On Friday, 30 January 2015 at 12:32:05 UTC, drug wrote: static init() { auto instance = new typeof(this)(); instance._cont = new

Re: is it bug?

2015-01-30 Thread anonymous via Digitalmars-d-learn
On Friday, 30 January 2015 at 13:11:35 UTC, anonymous wrote: Lines 846-850: static if(less == a b) auto vals = [1, 2, 3, 4, 5]; else auto vals = [5, 4, 3, 2, 1]; assert(equal(r, vals)); (Tab + Enter strikes again.) That test looks wrong. So,

Re: is it bug?

2015-01-30 Thread anonymous via Digitalmars-d-learn
On Friday, 30 January 2015 at 12:32:05 UTC, drug wrote: ``` import std.container: RedBlackTree; class Manager(TT, alias Cmp = ab) { alias Container = RedBlackTree!(TT, Cmp); Container _cont; static init() { auto instance = new typeof(this)(); instance._cont =

Re: static class vs. static struct

2015-01-26 Thread anonymous via Digitalmars-d-learn
On Monday, 26 January 2015 at 21:33:10 UTC, Piotrek wrote: On Monday, 26 January 2015 at 14:11:32 UTC, bearophile wrote: Non-static structs/classes have an extra pointer. Bye, bearophile Since when structs have an extra pointer? Maybe you are talking about nested structs? Non-static means

Re: Segfault upon modifying immutable AA in static this

2015-01-24 Thread anonymous via Digitalmars-d-learn
On Saturday, 24 January 2015 at 13:24:02 UTC, Nordlöw wrote: This snippet static immutable words = [ `zero`, `one`, `two` ]; static immutable ubyte[string] wordsAA; static this() { foreach (ubyte i, e; words) { wordsAA[e] = i; } } compiles and links on dmd git

Re: What to do with InvalidMemoryOperationError

2015-01-23 Thread anonymous via Digitalmars-d-learn
On Friday, 23 January 2015 at 21:25:01 UTC, Nordlöw wrote: On Friday, 23 January 2015 at 10:13:43 UTC, Joakim wrote: InvalidMemoryOperationError generally means that you are performing certain disallowed memory operations during a full garbage collection, such as allocating while the gc is

<    1   2   3   4   5   6   >