Re: Weird array setting behaviour on Windows(-m64)

2016-04-13 Thread ref2401 via Digitalmars-d-learn
On Wednesday, 13 April 2016 at 15:07:09 UTC, rikki cattermole wrote: Verified that it is a codegen problem for Win64 and not *nix. Please file a bug report. https://issues.dlang.org/show_bug.cgi?id=15921 Done, Thanks

Weird array setting behaviour on Windows(-m64)

2016-04-13 Thread ref2401 via Digitalmars-d-learn
Hello, I got stuck with a weird array setting behaviour and I need help. Just have a look at the example. OS: Win 8.1 Pro DMD: v2.071.0 Build-cmd: dmd main.d -ofconsole-app.exe -debug -unittest -g -wi -m64 module dmain; import std.stdio; struct Vec { float a; } void main(string[]

Re: Error: template instance does not match template declaration

2016-03-30 Thread ref2401 via Digitalmars-d-learn
On Tuesday, 29 March 2016 at 18:29:27 UTC, Ali Çehreli wrote: So, dict is a template value parameter of type T[string]. I don't think you can use an associative array as a template value parameter. (Can we?) Found this in D language reference:

Re: Error: template instance does not match template declaration

2016-03-29 Thread ref2401 via Digitalmars-d-learn
On Tuesday, 29 March 2016 at 18:29:27 UTC, Ali Çehreli wrote: On 03/29/2016 11:21 AM, ref2401 wrote: So, dict is a template value parameter of type T[string]. I don't think you can use an associative array as a template value parameter. (Can we?) However, it is possible to use anything

Error: template instance does not match template declaration

2016-03-29 Thread ref2401 via Digitalmars-d-learn
OS: Win 8.1 Pro DMD: v2.070.0 cmd: dmd main.d -ofconsole-app.exe -debug -unittest -wi Code is successfully compiled until I uncomment test1 function call in the main. If it's uncommented I get the following compile-time error: main.d(58): Error: template instance impl!(string, bool,

pass a struct by value/ref and size of the struct

2016-03-21 Thread ref2401 via Digitalmars-d-learn
I have got a plenty of structs in my project. Their size varies from 12 bytes to 128 bytes. Is there a rule of thumb that states which structs I pass by value and which I should pass by reference due to their size? Thanks.

Re: Link error 42 (WinApi)

2016-02-15 Thread ref2401 via Digitalmars-d-learn
On Tuesday, 16 February 2016 at 06:22:33 UTC, Rikki Cattermole wrote: Found the problem, you haven't linked against gdi. Thank you It works. I should have done this: set filesToUse=main.d gdi32.lib dmd @filesToUse -ofconsole-app.exe -debug -unittest -wi

Re: Link error 42 (WinApi)

2016-02-15 Thread ref2401 via Digitalmars-d-learn
On Tuesday, 16 February 2016 at 05:39:26 UTC, Rikki Cattermole wrote: Try compiling with 64bit. If it works, its just the import libs not containing the symbol. dmd main.d -ofconsole-app.exe -debug -unittest -wi -m64 That's what I'm getting now: console-app.obj : error LNK2019: unresolved

Re: Region allocator strage error

2016-02-01 Thread ref2401 via Digitalmars-d-learn
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?

Region allocator strage error

2016-01-31 Thread ref2401 via Digitalmars-d-learn
I am getting runtime error: core.exception.AssertError@std\experimental\allocator\building_blocks\region.d(235): Assertion failure if LEN equals to 3, 5, 7, 9, ... void main(string[] args) { ubyte[1024] memory; auto stackAlloc = Region!NullAllocator(memory); IAllocator

InSituRegion + allocatorObject compile time error

2016-01-29 Thread ref2401 via Digitalmars-d-learn
Getting this error, could someone explain why? void main(string[] args) { InSituRegion!(1024) stackAlloc; IAllocator alloc = allocatorObject(stackAlloc); } ..\src\phobos\std\conv.d(5055): Error: static assert "Don't know how to initialize an object of type

Re: Make function nothrow

2016-01-28 Thread ref2401 via Digitalmars-d-learn
On Thursday, 28 January 2016 at 16:22:23 UTC, Ali Çehreli wrote: There is assumeWontThrow which terminates if an exception is indeed thrown: http://dlang.org/library/std/exception/assume_wont_throw.html Ali nice one, thx

static array crashes my program

2015-12-05 Thread ref2401 via Digitalmars-d-learn
I want to create a static array large enough to store 1MB of float values. What am I doing wrong? Here is a sample code with notes: void main(string[] args) { enum size_t COUNT = 1024 * 512 / float.sizeof; // works OK :) //enum size_t COUNT = 1024 * 512 * 2 / float.sizeof; //

Which type it better to use for array's indices?

2015-12-04 Thread ref2401 via Digitalmars-d-learn
Which type it better to use for array's indices? float[] arr = new float[10]; int i; long j; size_t k; // which one is better arr[i], a[j]or arr[k] ? It seem like `size_t` suites well because 'is large enough to represent an offset into all addressible memory.'

having problem with `std.algorithm.each`

2015-11-30 Thread ref2401 via Digitalmars-d-learn
It seems like `std.algorithm.each` is not executed in the example below. Could anyone tell why? Thank you. import std.algorithm; void main(string[] args) { int[] arr = [1, 2, 3, 4, 5]; arr.each!((ref e) => { writeln(e); // does not print ++e;

Re: having problem with `std.algorithm.each`

2015-11-30 Thread ref2401 via Digitalmars-d-learn
DMD 2.069.1 OS Win8.1 Enterprise

Re: having problem with `std.algorithm.each`

2015-11-30 Thread ref2401 via Digitalmars-d-learn
On Monday, 30 November 2015 at 12:03:08 UTC, anonymous wrote: On 30.11.2015 11:50, visitor wrote: though i don"t understand why it fails silently ?? ref2491's original code is valid, but doesn't have the intended meaning. `e => {foo(e);}` is the same as `(e) {return () {foo(e);};}`, i.e. a

Re: std.experimental.allocator optlink error

2015-11-10 Thread ref2401 via Digitalmars-d-learn
On Tuesday, 10 November 2015 at 08:48:37 UTC, ref2401 wrote: On Tuesday, 10 November 2015 at 01:04:16 UTC, uiop wrote: Can you find the sources in your setup ? Any chance that that phobos.lib is still the the one distributed with dmd 2.068 ? How can I do that? When you setup dmd 2.069, did

Re: std.experimental.allocator optlink error

2015-11-10 Thread ref2401 via Digitalmars-d-learn
On Tuesday, 10 November 2015 at 01:04:16 UTC, uiop wrote: Can you find the sources in your setup ? Any chance that that phobos.lib is still the the one distributed with dmd 2.068 ? How can I do that? When you setup dmd 2.069, did you use the 7z or installer ? Installer always btw. Thanks

std.experimental.allocator optlink error

2015-11-09 Thread ref2401 via Digitalmars-d-learn
Hello I wrote a small hello world app and imported the `std.experimental.allocator` module. I'm getting the following optlink error: --- OPTLINK (R) for Win32 Release 8.00.17 Copyright (C) Digital Mars 1989-2013 All rights reserved.

Re: std.experimental.allocator optlink error

2015-11-09 Thread ref2401 via Digitalmars-d-learn
On Monday, 9 November 2015 at 14:42:01 UTC, ref2401 wrote: Hello I wrote a small hello world app and imported the `std.experimental.allocator` module. I'm getting the following optlink error: --- OPTLINK (R) for Win32 Release 8.00.17 Copyright

Re: Allocation strategies question

2015-11-01 Thread ref2401 via Digitalmars-d-learn
On Friday, 30 October 2015 at 05:21:17 UTC, Rikki Cattermole wrote: What I normally do for memory to be owned by the thread is: auto foo(IAllocator alloc=theAllocator()) {...} Where as for if it is global to the process: auto foo(IAllocator alloc=processAllocator()) {...} Basically it is the

Re: good reasons not to use D?

2015-10-30 Thread ref2401 via Digitalmars-d-learn
On Friday, 30 October 2015 at 10:35:03 UTC, Laeeth Isharc wrote: I'm writing a talk for codemesh on the use of D in finance. I want to start by addressing the good reasons not to use D. (We all know what the bad ones are). I don't want to get into a discussion here on them, but just wanted

Allocation strategies question

2015-10-29 Thread ref2401 via Digitalmars-d-learn
As I understand the `std.experimental.allocator` package will be included in the upcoming DMD 2.069 release. I like the idea of composable allocators. Though I've got a question which I can not answer myself. Let's assume a team which is developing an application that can benefit from usage

Re: Allocation strategies question

2015-10-29 Thread ref2401 via Digitalmars-d-learn
On Friday, 30 October 2015 at 01:26:17 UTC, Rikki Cattermole wrote: Take a look at the functions theAllocator and processAllocator. It would be greate if compiler were able to use `theAllocator` and `processAllocator` but they don't seem much helpfull. Terrible naming by the way.

Re: Allocation strategies question

2015-10-29 Thread ref2401 via Digitalmars-d-learn
On Friday, 30 October 2015 at 04:11:05 UTC, ref2401 wrote: It would be greate if compiler were able to use `theAllocator` and `processAllocator` but they don't seem much helpfull. Terrible naming by the way. I should have suggested different names if don't like present ones

final class & final methods

2015-09-25 Thread ref2401 via Digitalmars-d-learn
If I declare a class as `final` do I have to mark all methods of the class as `final` too?

Re: any way to initialize an array of structs to void?

2015-09-16 Thread ref2401 via Digitalmars-d-learn
On Wednesday, 16 September 2015 at 14:48:59 UTC, Meta wrote: Don't do this with a dynamic array, though, as they work a bit differently from static arrays. Unfortunately I have to deal with dynamic arrays.

any way to initialize an array of structs to void?

2015-09-16 Thread ref2401 via Digitalmars-d-learn
struct MyStruct { @disable this(); this(int a, string b) { this.a = a; this.b = b; } int a; string b; } I know there is a way to create one instance of `MyStruct` and initialize it to void. MyStruct s = void; s =

Re: any way to initialize an array of structs to void?

2015-09-16 Thread ref2401 via Digitalmars-d-learn
On Wednesday, 16 September 2015 at 14:57:49 UTC, Meta wrote: In that case, you can use std.array.uninitializedArray or std.array.minimallyInitializedArray as needed. http://dlang.org/phobos/std_array.html#uninitializedArray http://dlang.org/phobos/std_array.html#.minimallyInitializedArray

D array to void* and back

2015-08-03 Thread ref2401 via Digitalmars-d-learn
Hello everyone, I pass a D array as void* into a function. When I'm trying to cast a void* parameter to a D array I get 'Access Violation' error. However if I define ArrayLike struct which looks like D array then casting will succeed. What should I do? Should I stick to ArrayLike wrapper and

Re: D array to void* and back

2015-08-03 Thread ref2401 via Digitalmars-d-learn
On Monday, 3 August 2015 at 21:28:29 UTC, Ali Çehreli wrote: But you still need to communicate how many elements there are in the array. (I used literal 3). Yes I do. I hope there is a neat way to pass array's length too.

'const' and 'in' parameter storage classes

2015-05-15 Thread ref2401 via Digitalmars-d-learn
What is the difference between 'const' and 'in' parameter storage classes? When should I use 'const' or 'in'? The documentation says 'in' is the same as 'const scope' but I can't write 'const scope ref' though it's legal to write 'in ref'. Thank you

Re: 'const' and 'in' parameter storage classes

2015-05-15 Thread ref2401 via Digitalmars-d-learn
On Friday, 15 May 2015 at 16:30:29 UTC, Steven Schveighoffer wrote: On 5/15/15 12:04 PM, ref2401 wrote: What is the difference between 'const' and 'in' parameter storage classes? When should I use 'const' or 'in'? The documentation says 'in' is the same as 'const scope' but I can't write

Re: 'const' and 'in' parameter storage classes

2015-05-15 Thread ref2401 via Digitalmars-d-learn
On Friday, 15 May 2015 at 16:08:31 UTC, Adam D. Ruppe wrote: The scope storage class means you promise not to escape any reference to the data. This isn't enforced but it is similar in concept to Rust's borrowed pointers - it may someday be implemented to be an error to store them in an

Error: cannot modify struct arr[0] MyStruct with immutable members

2015-05-11 Thread ref2401 via Digitalmars-d-learn
struct MyStruct { this(int a, int b) { this.a = a; this.b = b; } immutable int a; immutable int b; } void main(string[] args) { MyStruct[] arr = new MyStruct[3]; arr[0] = MyStruct(5, 7); } Why does it

Re: Error: cannot modify struct arr[0] MyStruct with immutable members

2015-05-11 Thread ref2401 via Digitalmars-d-learn
On Monday, 11 May 2015 at 13:44:14 UTC, Adam D. Ruppe wrote: On Monday, 11 May 2015 at 13:37:27 UTC, ref2401 wrote: Why does it happen? You'd just be writing to the immutable memory through a different name. Consider if someone took a reference to one of those immutable ints, expecting

Delegate type deduction compile error

2015-04-25 Thread ref2401 via Digitalmars-d-learn
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 -ofconsole-app.exe -debug -unittest -wi - if delegate has no

function ref param vs pointer param

2015-04-24 Thread ref2401 via Digitalmars-d-learn
What advantages do ref params give over pointer params? struct MyStruct { string str; this(string str) { this.str = str; } } void processRef(ref MyStruct ms) { writeln(processRef: , ms); } void processPointer(MyStruct* ms) { writeln(processPointer: , *ms); }

Re: function ref param vs pointer param

2015-04-24 Thread ref2401 via Digitalmars-d-learn
Thank you

Re: function ref param vs pointer param

2015-04-24 Thread ref2401 via Digitalmars-d-learn
processPointer(ms); I think doing this way is more descriptive. Now all readers know that ms might be changed inside the function.

Re: Fibers and async io stuff for beginners

2015-04-23 Thread ref2401 via Digitalmars-d-learn
Awesome!

Fibers and async io stuff for beginners

2015-04-23 Thread ref2401 via Digitalmars-d-learn
I'm intrested in fibers and async io. Could anyone suggest articles, books or tutorials about the subject? Thank you

Re: Invalid Floating Point Operation (DMD 2067)

2015-04-16 Thread ref2401 via Digitalmars-d-learn
Builds and runs fine for me. What is your OS and build command? -Steve Win 8.1 dmd main.d -ofmain.exe -debug -unittest -wi if %errorLevel% equ 0 (main.exe)

Invalid Floating Point Operation (DMD 2067)

2015-04-16 Thread ref2401 via Digitalmars-d-learn
Hi Everyone, After I switched to DMD 2067 my code that previously worked began crashing. If I change the return statement in the matrixOrtho function from: return Matrix(...); to: Matrix m = Matrix(...); return m; then the error won't occur anymore. What is going on?

An input range iteration question

2015-04-08 Thread ref2401 via Digitalmars-d-learn
If Iterator is a struct then Iterator.input won't be adjusted properly when the foreach loop ends. Iterator.input still holds abcde value. If i mark Iterator as class then Iterator.input will be an empty string after the foreach loop. Could anyone explain me the difference please? Thank you.

struct variable initialized with void.

2015-03-31 Thread ref2401 via Digitalmars-d-learn
struct MyStruct { // stuff } void main(string[] args) { MyStruct s1 = void; } Could anyone describe me what this initialization does, please? When do I need to use the void initialization?

Re: struct variable initialized with void.

2015-03-31 Thread ref2401 via Digitalmars-d-learn
Thank you.

final methods by default

2015-03-20 Thread ref2401 via Digitalmars-d-learn
Why aren't methods of class final by default?

Explicit Interface Implementation

2015-02-14 Thread ref2401 via Digitalmars-d-learn
Does D provide a way for explicit interface implementation? [C#] https://msdn.microsoft.com/en-us/library/ms173157.aspx

Re: spawn/executeInNewThread and module this/~this

2015-01-29 Thread ref2401 via Digitalmars-d-learn
It's written here: http://dlang.org/module.html#staticorder

Re: static class vs. static struct

2015-01-27 Thread ref2401 via Digitalmars-d-learn
For several times I've met struct(or static struct) usage in Phobos for singleton pattern implementation. Unfortunately now i can remember only core.runtime.Runtime. So I've got a question. Why do Phobos guys use struct or static struct for or singleton pattern implementation? Why don't use

static class vs. static struct

2015-01-26 Thread ref2401 via Digitalmars-d-learn
What's the difference between static class and static struct? What should i use?

Re: redirecting the unittests error output

2015-01-15 Thread ref2401 via Digitalmars-d-learn
Thank you.

redirecting the unittests error output

2015-01-14 Thread ref2401 via Digitalmars-d-learn
How can i redirect the unittests error output to a file?

Re: redirecting the unittests error output

2015-01-14 Thread ref2401 via Digitalmars-d-learn
Unfortunately i'm new to using shells. I use standard windows cmd. Here is my script: dmd main.d -debug -unittest -wi if %errorLevel% equ 0 ( start main.exe ) else ( echo --- Building failed! --- pause ) I wrote start main.exe 2 errorFile but it doesn't work.

Re: core.atomic: atomicFence, atomicLoad, atomicStore

2015-01-12 Thread ref2401 via Digitalmars-d-learn
Thanks for the links. I have shared class instance. There are two threads which can read/write fields of the class. As i understand i can declare class as synchronized or i can read/write using atomicLoad/atomicStore. What's the difference between these two approaches? In what circumstances

core.atomic: atomicFence, atomicLoad, atomicStore

2015-01-10 Thread ref2401 via Digitalmars-d-learn
I learned how 'atomicOp' and 'cas' work and why i need them from the following sources: http://ddili.org/ders/d.en/concurrency_shared.html (Ali's book) http://www.informit.com/articles/article.aspx?p=1609144 (Andrei's book) Can anybody tell me how 'atomicFence', 'atomicLoad' and

formattedWrite writes nothing

2014-05-02 Thread ref2401 via Digitalmars-d-learn
class MyClass { Appender!string _stringBuilder; this() { _stringBuilder = Appender!string(null); _stringBuilder.clear(); } @property string str() { return _stringBuilder.data; } void append(string

enum VS static immutable

2014-03-13 Thread ref2401
Hi. I have this structure: struct MyStruct { enum MyStruct VALUE = MyStruct(5f); static immutable MyStruct value = MyStruct(5f); float data; this(float v) { data = v; } } What's the difference between MyStruct.VALUE and MyStruct.value? How should I decide

Re: enum VS static immutable

2014-03-13 Thread ref2401
thank you

unittests and Windows App

2013-12-19 Thread ref2401
I'm using D 2064.2 and VisualD 0.3.37 VisualD Redirect stdout to output window checkbox is checked. In simple ConsoleApp unittests work properly. I can debug them and assertion fail results are printed to the Output window. But it seems that unittests don't work at all with any WindowsApp.

rounding floats up to specified number of decimal digits

2013-12-15 Thread ref2401
I'm seeking for a way to round floats up to specified number of decimal digits. e.g. roundToDigits(3.1415, 2) should return 3.14. Is there a standard function for that or what is the most correct way to do that?

Re: template instance testA.FormatParser!(F) forward reference of variable F

2013-10-09 Thread ref2401
i've found the solution: void put(T)(T mesh) { static if (is(T : MyClass!F, string F)) { writeln(put method: , F); } else { static assert(0, Invalid type ' ~ std.traits.fullyQualifiedName!T ~ '.); } }

template instance testA.FormatParser!(F) forward reference of variable F

2013-10-08 Thread ref2401
Everything works fine until 'put' method in 'testB' module is uncommented. With that code I'm getting error saying 'template instance testA.FormatParser!(F) forward reference of variable F.'. What does it mean and why is this happening ( to me:)) ]? module testA; // -- class

class MyClass(T) : Base if (ConstraintExpression) {} compilation error

2013-05-24 Thread ref2401
Version D 2.062 Please explain what is causing the error class Base { } class Class(T) : Base if (is(T == int)) { } Error: unrecognized declaration Error: members expected Error: Declaration expected, not 'if' Error: { } expected following aggregate declaration

Template alias parameter does not accept types

2013-05-09 Thread ref2401
Version D 2.062 http://dlang.org/template.html#TemplateAliasParameter Is is said in the documentation that is's possible but i get compile time error. template GetString(alias Arg) { enum string GetString = Arg.stringof; } void main(string[] argv) { writeln(GetString!1234);

unittest + struct ctorю + nested mixin template + alias

2013-05-07 Thread ref2401
Version D 2.062 class MyClass {} struct MyStruct(T) if (is(T == class)) { string _message = nothing; this(T obj) { if (obj is null){ _message = Null reference message; } else{

Re: unittest + struct ctorю + nested mixin template + alias

2013-05-07 Thread ref2401
i'm using VisualD. this assertion fails assert(msg == Null reference message); in my actual code instead of variable _message an exception is thrown if (obj is null) == true. i'm using the unittest block to test exception throwing. ... this(T obj) { if (obj is

Strange template instantiating behaviour

2013-01-12 Thread ref2401
public template rgba(uint value) { enum Color rgba = Color( cast(ubyte)((value 24) 0xFF), cast(ubyte)((value 16) 0xFF), cast(ubyte)((value 8) 0xFF), cast(ubyte)(value 0xFF)); } public struct Color { public

template function. test array parameter length

2013-01-05 Thread ref2401
I have a template function that must work with an array of float values. something like this: void foo(T : A[], A)(auto ref T arg) if(is(A == float)) { ... } Array may be static or dynamic. But the length of the array must be 16 or 32. How can i test length value?

Re: template function. test array parameter length

2013-01-05 Thread ref2401
thanks)

std.math.approxEqual, 'maxRelDiff' parameter?

2012-12-15 Thread ref2401
What does means 'maxRelDiff' parameter? I looked at the source code of this method and I still didn't get it. return fabs((lhs - rhs) / rhs) = maxRelDiff || maxAbsDiff != 0 fabs(lhs - rhs) = maxAbsDiff; In what cases can I use this parameter?

Re: std.math.approxEqual, 'maxRelDiff' parameter?

2012-12-15 Thread ref2401
Maybe you want to use std.math.feqrel instead. that's not what i was asking about

Re: std.math.approxEqual, 'maxRelDiff' parameter?

2012-12-15 Thread ref2401
now i got it, thanks.

template error instantiating

2012-11-17 Thread ref2401
I get template instance main.MyClass!(int) error instantiating in the following case: public class MyClass(TStuff) { public void foo(TStuff item) {} public void foo(TRange)(TRange items) if (isInputRange!TRange is(ElementType!TRange == TStuff)) {} }

Exception class descendants

2012-10-29 Thread ref2401
Could you please tell me if Phobos contains any Exception class descendants? If so, does the documentation contain a full list of these or even the hierarchy scheme?

Re: class opBinary overloading. value + null and null + value

2012-10-21 Thread ref2401
On Sunday, 21 October 2012 at 20:42:08 UTC, cal wrote: On Sunday, 21 October 2012 at 20:34:51 UTC, ref2401 wrote: what should i do to make my binary operation commutative? You can overload opBinaryRight: MyClass opBinaryRight(string op: +)(MyClass rhs) { if (rhs is null) { return

next power of 2

2012-10-06 Thread ref2401
is there any Phobos function to calculate the next power of 2 of the specified number?

is array an InputRange?

2012-10-05 Thread ref2401
import std.range; int[] numbers = [1, 3, 5, 7, 9, 11]; auto rangeObject = inputRangeObject(numbers); auto inputRange = cast(InputRange!(int[]))rangeObject; why does 'inputRange' equal null?

convert ubyte[k..k + 1] to int

2012-05-16 Thread ref2401
i have an array of ubytes. how can i convert two adjacent ubytes from the array to an integer? pseudocode example: ubyte[5] array = createArray(); int value = array[2..3]; is there any 'memcpy' method or something else to do this?

std.file, std.stdio(File), std.stream(File:Stream)

2012-05-15 Thread ref2401
general question: -std.file, -std.stdio.File, -std.stream.File which of the existing approaches i have to choose when working with files? what shall i look at? for example, i have a binary file. i want to read the first byte, process it and then read the following N bytes (N calculation