Re: reading from file

2016-12-15 Thread Ali Çehreli via Digitalmars-d-learn
On 12/15/2016 10:47 PM, KaattuPoochi wrote: > On Tuesday, 13 December 2016 at 21:13:26 UTC, Ali wrote: >> >> And extending Ali's solution you can actually get the data in >> to a two dimentional array at compile time and have it in static >> memory with a small adjustment: >> >> static immutable

Re: reading from file

2016-12-15 Thread KaattuPoochi via Digitalmars-d-learn
On Tuesday, 13 December 2016 at 21:13:26 UTC, Ali wrote: And extending Ali's solution you can actually get the data in to a two dimentional array at compile time and have it in static memory with a small adjustment: static immutable matrix = import("data.txt") .split("\n") .map!(a =>

Re: Accessing members through pointers to structs (also, CTFE associative arrays)

2016-12-15 Thread Ali Çehreli via Digitalmars-d-learn
On 12/15/2016 05:30 PM, Stefan Koch wrote: On Thursday, 15 December 2016 at 19:30:08 UTC, Ali Çehreli wrote: Yeah, I think the compiler is confused because the function is called in a non-const context during the initialization of an immutable object. I would open an issue:

Re: Accessing members through pointers to structs (also, CTFE associative arrays)

2016-12-15 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 15 December 2016 at 19:30:08 UTC, Ali Çehreli wrote: Yeah, I think the compiler is confused because the function is called in a non-const context during the initialization of an immutable object. I would open an issue: https://issues.dlang.org/enter_bug.cgi?product=D Ali

Re: Simplest way to build a DMD compatible C lib, and how to link using DUB.

2016-12-15 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 15 December 2016 at 20:34:47 UTC, hardreset wrote: On Thursday, 15 December 2016 at 18:30:14 UTC, hardreset wrote: I have pragma(lib,**fullpath**) in my freetype.d file, is that the correct way? Never mind, figured it out, I needer to add "libs": ["libs/freetype27ST"] to

Re: Allocating a class within another class during object init w/o passing in an allocator

2016-12-15 Thread ag0aep6g via Digitalmars-d-learn
On Thursday, 15 December 2016 at 21:37:34 UTC, David Zhang wrote: So the size of Foo would be the size of SomeClass plus members? ie. Is the size of the array stored too? With these definitions: class SomeClass {} class Foo { this() { import std.conv: emplace;

Re: Allocating a class within another class during object init w/o passing in an allocator

2016-12-15 Thread David Zhang via Digitalmars-d-learn
On Thursday, 15 December 2016 at 21:08:51 UTC, ag0aep6g wrote: On 12/15/2016 09:51 PM, David Zhang wrote: However, it leaves me with another question, how much (if any) space would the static array require from the class? Depends on SomeClass. The array's size is just the value of

Re: DRY version of `static if(__traits(compiles, expr)) fun(expr)`

2016-12-15 Thread Timon Gehr via Digitalmars-d-learn
On 15.12.2016 01:38, Basile B. wrote: On Wednesday, 14 December 2016 at 22:06:35 UTC, Ali Çehreli wrote: On 12/14/2016 09:25 AM, Basile B. wrote: > On Tuesday, 13 December 2016 at 23:37:59 UTC, Timon Gehr wrote: >> I usually do >> >> enum code = q{expr}; >> static

Re: Allocating a class within another class during object init w/o passing in an allocator

2016-12-15 Thread David Zhang via Digitalmars-d-learn
Thank you for your responses. Visitor, I don't want any reference to an allocator within the class if I can avoid it. ag0aep6g, thanks! That's what I was looking for. However, it leaves me with another question, how much (if any) space would the static array require from the class? It's not a

Re: Simplest way to build a DMD compatible C lib, and how to link using DUB.

2016-12-15 Thread hardreset via Digitalmars-d-learn
On Thursday, 15 December 2016 at 18:30:14 UTC, hardreset wrote: On Thursday, 15 December 2016 at 03:47:27 UTC, Mike Parker wrote: [1] https://github.com/DerelictOrg/DerelictFT Thanks, I'm trying the "-m32mscoff" method for now, but I get "error LNK2019: unresolved external symbol

Re: Sanitizing forms in vibe.d. How?

2016-12-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 12 December 2016 at 11:32:42 UTC, Nicholas Wilson wrote: for strip_tags I would look for an xml library (e.g. arsd.dom) and parse it and then reprint it without the tags. There's probably a better way to do it though. I'm sure Adam Ruppe will be able to help you there. Well, it

Re: Sanitizing forms in vibe.d. How?

2016-12-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 12 December 2016 at 10:25:05 UTC, aberba wrote: How about alternative to php strip_tags(), strip_slash() ? I wouldn't use those functions anyway in most cases: instead of stripping stuff, just encode it properly for the output. So, if it is being output to JSON or javascript,

Re: Accessing members through pointers to structs (also, CTFE associative arrays)

2016-12-15 Thread Ali Çehreli via Digitalmars-d-learn
On 12/14/2016 04:02 AM, Ali wrote: > On Tuesday, 13 December 2016 at 23:29:31 UTC, Ali Çehreli wrote: >> On 12/13/2016 01:36 PM, Ali wrote: >> >>> Now about that second part of my problem >> >> I'm not entirely sure whether this should work but I think the problem >> is with mutating the

Re: Allocating a class within another class during object init w/o passing in an allocator

2016-12-15 Thread ag0aep6g via Digitalmars-d-learn
On 12/15/2016 06:44 PM, David Zhang wrote: It is my understanding that a class can have a struct as one of its members, and it will be allocated in-line with the rest of the class' members. Yup. My question is this; how might I be able to do this with another class? I want to be able to

Re: Allocating a class within another class during object init w/o passing in an allocator

2016-12-15 Thread visitor via Digitalmars-d-learn
On Thursday, 15 December 2016 at 17:44:23 UTC, David Zhang wrote: would something like this be a solution ? import std.stdio; import std.experimental.allocator; class SomeClass { int someint = 42; static SomeClass opCall(int a) { auto inst = theAllocator.make!SomeClass;

Re: Simplest way to build a DMD compatible C lib, and how to link using DUB.

2016-12-15 Thread hardreset via Digitalmars-d-learn
On Thursday, 15 December 2016 at 03:47:27 UTC, Mike Parker wrote: On Wednesday, 14 December 2016 at 23:08:30 UTC, hardreset wrote: As Basile recommended, DerelictFT[1] will save you from the hassle of object formats. It's a dynamic binding, so you don't need to link with FreeType at all

Re: arsd.cgi - maximum length of form post

2016-12-15 Thread bachmeier via Digitalmars-d-learn
On Thursday, 15 December 2016 at 16:52:54 UTC, Adam D. Ruppe wrote: On Tuesday, 13 December 2016 at 22:55:55 UTC, bachmeier wrote: Here is a minimal program that can replicate the problem. Compiled and run with OK, try the new git cgi.d version, looks like my popFront was buggy and some data

Allocating a class within another class during object init w/o passing in an allocator

2016-12-15 Thread David Zhang via Digitalmars-d-learn
Hello, It is my understanding that a class can have a struct as one of its members, and it will be allocated in-line with the rest of the class' members. My question is this; how might I be able to do this with another class? I want to be able to allocate Foo using std.experimental.allocator

Re: arsd.cgi - maximum length of form post

2016-12-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 13 December 2016 at 22:55:55 UTC, bachmeier wrote: Here is a minimal program that can replicate the problem. Compiled and run with OK, try the new git cgi.d version, looks like my popFront was buggy and some data got misplaced over multiple chunks (so if the content was less than

Re: this is not an lvalue

2016-12-15 Thread kinke via Digitalmars-d-learn
On Thursday, 15 December 2016 at 15:29:13 UTC, Adam D. Ruppe wrote: General rule of thumb: if you are refing for performance, actually check it before and after first, ref isn't always faster. But D doesn't make this easy, as it disallows rvalues to be passed by ref. It's a very common

Re: arsd.cgi - maximum length of form post

2016-12-15 Thread Adam D. Ruppe via Digitalmars-d-learn
Well, I can reproduce the error now, the buffer it is getting is too long for some reason. Probably a slicing error that doesn't show up with smaller payloads. I should have a fix today though. BTW, interestingly, the more complex codepath for uploads does work fine (add

Re: this is not an lvalue

2016-12-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 15 December 2016 at 14:05:08 UTC, Andrey wrote: In D, probably, I could write something like this: void open(in string fileName) {...} Yes, though remember that `in` does have a specific meaning (even though the compiler rarely enforces it): it means you promise not to modify

Re: this is not an lvalue

2016-12-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 15 December 2016 at 13:59:05 UTC, Andrey wrote: Thanks it works, but where should I use the ref? Only when you need it, break the habit of using it everywhere. If it is a value type and you want modifications to the variable itself be seen outside the function, use it: void

Re: Alias variable from another class

2016-12-15 Thread Rene Zwanenburg via Digitalmars-d-learn
On Tuesday, 13 December 2016 at 19:13:24 UTC, Begah wrote: Any ideas? Closest you can get is wrapping it in a property. If you need to do this often you may be able to generate them, check the recent "Getters/Setters generator" thread in Announce for some inspiration.

Re: this is not an lvalue

2016-12-15 Thread Andrey via Digitalmars-d-learn
On Tuesday, 13 December 2016 at 16:23:16 UTC, Adam D. Ruppe wrote: On Tuesday, 13 December 2016 at 15:09:10 UTC, Andrey wrote: void moveTo(ref Parameter parent) { You probably don't want the `ref` there, nor likely on any other method definitions (especially check removeValue). In D,

Re: this is not an lvalue

2016-12-15 Thread Andrey via Digitalmars-d-learn
On Tuesday, 13 December 2016 at 16:23:16 UTC, Adam D. Ruppe wrote: On Tuesday, 13 December 2016 at 15:09:10 UTC, Andrey wrote: void moveTo(ref Parameter parent) { You probably don't want the `ref` there, nor likely on any other method definitions (especially check removeValue). Thanks it

Re: Dynamically Loading a D DLL From a D Program

2016-12-15 Thread Guillaume Piolat via Digitalmars-d-learn
On Wednesday, 14 December 2016 at 21:38:27 UTC, Benjiro wrote: It also seems that the core runtime is incomplete with basic loading but no handling of dlsym, so your still forced to use the basic c conversion casting. int function() fn = cast(int function())dlsym(lib, libFunction); fn();

Re: Get fils at compile-time

2016-12-15 Thread Bauss via Digitalmars-d-learn
On Thursday, 15 December 2016 at 07:56:40 UTC, Jacob Carlborg wrote: On 2016-12-14 21:47, bauss (wtf happend to my name took some old cached title LOL??) wrote: [...] I would recommend creating a small script that iterates a directory and generates a D file with string imports for all the

Re: Issue with dmd, linker, visualD on windows 10

2016-12-15 Thread 01010100b via Digitalmars-d-learn
On Wednesday, 14 December 2016 at 11:06:10 UTC, aberba wrote: I am trying to get a fellow to try D but just setting up on windows 10 has been headache. He's currently remote. Here's the problem. (Note I'm a Linux user and haven't used windows 10) 1. He installed dmd 2 but the command "dmd"

Re: Get fils at compile-time

2016-12-15 Thread Jacob Carlborg via Digitalmars-d-learn
On 2016-12-14 21:47, bauss (wtf happend to my name took some old cached title LOL??) wrote: Is there a way to get all files in a folder at compile-time. To be more specific I want to import the content of all files within a specific folder during compile-time. I know how to do it with a