32/64 bit in Phobos
Hi I noticed that in 32bit, many Phobos functions use int and uint, while in 64bit, they use long and ulong. As a result I am having some difficulty in writing code that works for both 32 bit and 64 bit. Is there an existing mechanism that allows writing code that will work in both 32 bit and 64 bit with regards to function calls to Phobos? Thanks. Regards
setup problem wih dub
Hi. Package in question: fpdf Dub version I'm using: 0.9.22 DMD version: 2.066.1 (64 bit) Platform: Fedora 19 (64-bit). I created the fpdf package, and it is dependant on the imageformats package, but it won't compile. When I place a copy of imageformats.d into the project source directory, it compiles fine. However when I rely on dub dependancy, the linker complains that it cannot find the functions in imageformats. Following is a copy of the dub package. Any insight would be appreciated. Thanks in advance. { name: fpdf, description: Minimalist class for generating PDF documents., authors: [ Jason den Dulk ], license: BSL-1.0, platforms: [posix], targetType: sourceLibrary, dependencies: { imageformats : =3.0.3 }, importPaths: [ src ], configurations: [ { name: sample, targetType: executable, platforms: [posix], mainSourceFile: src/sample.d } ] }
Template instantiation and string vs const char[]
I have this piece of code: template somet(R...) { static if (R.length) { string somet = [\n~R[0]~\n ~ somet!(R[1..R.length]) ~ ]\n; } else string somet = ; } void main() { writeln(somet!(name,tame)); writeln(somet!name); } When I compile it, it generates the error message static variable somet cannot be read at compile time. When I replace 'string' with 'const char[]', it works. Can anyone explain why this happens? Thanks. Regards
Re: Compile time regex matching
On Monday, 14 July 2014 at 11:43:01 UTC, Philippe Sigaud via Digitalmars-d-learn wrote: You can try Pegged, a parser generator that works at compile-time (both the generator and the generated parser). I did, and I got it to work. Unfortunately, the code used to in the CTFE is left in the final executable even though it is not used at runtime. So now the question is, is there away to get rid of the excess baggage? BTW Here is the code I am playing with. import std.stdio; string get_match() { import pegged.grammar; mixin(grammar(` MyRegex: foo - abc* def? `)); auto result = MyRegex(import(config-file.txt)); // compile-time parsing return writeln(\~result.matches[0]~\);; } void main() { mixin(get_match()); }
Re: lazy construction of an immutable object
On Tuesday, 15 July 2014 at 12:20:57 UTC, Puming wrote: @property immutable(T) freeze(T)(T obj) { return cast(immutable(T))(obj); } What is the idiomatic approach to do this in D? There is a Phobos function std.exception.assumeUnique which performs this for arrays. According to the docs, it does what 'freeze' does, and is considered idiomatic. But the draw back is that you can't garanteed that the mutable object is never used. I got the impression that assumeUnique has the same problem. Regards
Compile time regex matching
Hi I am trying to write some code that uses and matches to regular expressions at compile time, but the compiler won't let me because matchFirst and matchAll make use of malloc(). Is there an alternative that I can use that can be run at compile time? Thanks in advance. Jason