Re: how to detect ctfe

2014-06-01 Thread Philpax via Digitalmars-d-learn
__ctfe can be used for this purpose: The __ctfe boolean pseudo-variable, which evaluates to true at compile time, but false at run time, can be used to provide an alternative execution path to avoid operations which are forbidden at compile time. Every usage of __ctfe is evaluated before

Re: how to detect ctfe

2014-06-01 Thread bearophile via Digitalmars-d-learn
Vlad Levenfeld: Is there any way that I can detect whether or not a function is being evaluated at compile time? Specifically I want to switch between to use/not to use memoize!func without having to figure out when its CTFE-able and calling it with different syntax. Calling it with a

Re: enums

2014-06-01 Thread Philippe Sigaud via Digitalmars-d-learn
On Sat, May 31, 2014 at 10:14 PM, bearophile via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: In contrast to those two examples where immutable can be used at compile time, what are some other cases where it is necessary to use enum instead of immutable? By default use enum

Re: how to detect ctfe

2014-06-01 Thread Philippe Sigaud via Digitalmars-d-learn
But let's keep in mind it's a *runtime* value. You cannot use it at compile-time as a boolean for a 'static if'. So: if (__ctfe) // yes { // compile-time path } else { // runtime path } But not: static if (__ctfe) // no { // compile-time path, including new global declarations }

Re: Casting Structs

2014-06-01 Thread Philippe Sigaud via Digitalmars-d-learn
On Sun, Jun 1, 2014 at 12:34 AM, Timon Gehr via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: This behaviour is independent of templates. Struct values of the same size can be reinterpret-cast to each other this way even if their types are completely unrelated. Do you know if

Re: enums

2014-06-01 Thread Chris Nicholson-Sauls via Digitalmars-d-learn
On Saturday, 31 May 2014 at 22:45:32 UTC, bearophile wrote: Chris Nicholson-Sauls: Good... I was starting to fear I was the only one. In general you can't fix the names in a language because you always find someone that likes the ones present :) I think enum is a bad name for the purpose

Interfacing to const T or const T* C++ code

2014-06-01 Thread Atila Neves via Digitalmars-d-learn
So I was mucking about with calling C++ from D yesterday and was pleasantly surprised that this worked: D: struct Foo { int i; int j; } extern(C++) void useFoo(ref const(Foo) foo); C++: struct Foo { int i; int j; }; void useFoo(const Foo foo) { ... } In fact, omitting const

Re: Interfacing to const T or const T* C++ code

2014-06-01 Thread bearophile via Digitalmars-d-learn
Atila Neves: D: struct Foo { int i; int j; } extern(C++) void useFoo(ref const(Foo) foo); C++: struct Foo { int i; int j; }; void useFoo(const Foo foo) { ... } This doesn't look very safe because D const is transitive, unlike the C++ const. So in the C++ code you can

text() vs. format() for formatting assert/exception messages

2014-06-01 Thread Joseph Rushton Wakeling via Digitalmars-d-learn
Hello all, What's the current state of preference (if any) for using std.conv.text vs. std.string.format (or others?) when formatting error messages for assert/enforce/exceptions? I seem to recall a deprecation message pushing the use of std.string.format at some point in the past, but

Re: Different random shuffles generated when compiled with gdc than with dmd

2014-06-01 Thread Ivan Kazmenko via Digitalmars-d-learn
On Saturday, 31 May 2014 at 21:22:48 UTC, Joseph Rushton Wakeling via Digitalmars-d-learn wrote: On 31/05/14 22:37, Joseph Rushton Wakeling via Digitalmars-d-learn wrote: On 30/05/14 22:45, monarch_dodra via Digitalmars-d-learn wrote: Didn't you make changes to how and when the global PRNG is

floating point conversion

2014-06-01 Thread Martin Krejcirik via Digitalmars-d-learn
import std.conv; void main() { float a = 1.23f; double b = to!float(1.23); assert (a == b); // ??? } Should the assert fail or not ? (Please reply without trying first). If your reply is yes, should assert (a == to!float(1.23)) fail or not ? I'm bringing this up, because dmd and

Re: Casting Structs

2014-06-01 Thread Timon Gehr via Digitalmars-d-learn
On 06/01/2014 09:59 AM, Philippe Sigaud via Digitalmars-d-learn wrote: On Sun, Jun 1, 2014 at 12:34 AM, Timon Gehr via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: This behaviour is independent of templates. Struct values of the same size can be reinterpret-cast to each other

Re: floating point conversion

2014-06-01 Thread bearophile via Digitalmars-d-learn
Martin Krejcirik: float a = 1.23f; double b = to!float(1.23); assert (a == b); // ??? } Should the assert fail or not ? (Please reply without trying first). It's a bad question. Generally to compare floating point values for equality use std.math.feqrel. Bye, bearophile

Re: floating point conversion

2014-06-01 Thread Martin Krejcirik via Digitalmars-d-learn
On 1.6.2014 14:45, bearophile wrote: It's a bad question. Generally to compare floating point values for equality use std.math.feqrel. So it's just a coincidence, that GDC, LDC x86 and also DMD x86_64 doesn't fail ? And this bug https://issues.dlang.org/show_bug.cgi?id=12831 should be marked

Re: floating point conversion

2014-06-01 Thread Qox via Digitalmars-d-learn
So it's just a coincidence, that GDC, LDC x86 and also DMD x86_64 doesn't fail ? (Equality) Compareision of float/float or float/double are machine dependent (depends even on x86 on the generated code (SSE/SSE2/AVX/AVX2), rounding settings, maybe event the cpu vendor etc.). On other

Re: Different random shuffles generated when compiled with gdc than with dmd

2014-06-01 Thread Andrew Brown via Digitalmars-d-learn
Thank you for hunting down the difference, in my case it's not a deal breaking problem. I can just specify the compiler and language version, then the results become reproducible. And I'm sure I'll appreciate the performance boost! On Sunday, 1 June 2014 at 12:11:22 UTC, Ivan Kazmenko wrote:

How to convert int type to string int ?

2014-06-01 Thread bioinfornatics via Digitalmars-d-learn
Hi, All is in the title. I need this to do a tupleof enhanced, that mean: - .tupleof need an instance me i want to do this on type diretcly - .tupleof do not bind to member name i need this for this i strat to this code: import std.stdio; import std.typecons; import std.conv; struct

Re: How to convert int type to string int ?

2014-06-01 Thread bioinfornatics via Digitalmars-d-learn
On Sunday, 1 June 2014 at 13:34:20 UTC, bioinfornatics wrote: Hi, All is in the title. I need this to do a tupleof enhanced, that mean: - .tupleof need an instance me i want to do this on type diretcly - .tupleof do not bind to member name i need this for this i strat to this code:

Re: How to convert int type to string int ?

2014-06-01 Thread Tobias Pankrath via Digitalmars-d-learn
Maybe http://dlang.org/property.html#stringof helps.

Re: How to convert int type to string int ?

2014-06-01 Thread bioinfornatics via Digitalmars-d-learn
On Sunday, 1 June 2014 at 13:52:27 UTC, Tobias Pankrath wrote: Maybe http://dlang.org/property.html#stringof helps. yes that help a lot thanks

Re: How to convert int type to string int ?

2014-06-01 Thread bioinfornatics via Digitalmars-d-learn
I bam close to be done import std.stdio; import std.typecons; import std.conv; struct Coord { int x; int y; int z; } template toTuple(T){ static string maker(){ string statement = alias Tuple!(; foreach(const memberName; __traits(allMembers, T)){

Re: How to convert int type to string int ?

2014-06-01 Thread bioinfornatics via Digitalmars-d-learn
On Sunday, 1 June 2014 at 13:58:03 UTC, bioinfornatics wrote: On Sunday, 1 June 2014 at 13:52:27 UTC, Tobias Pankrath wrote: Maybe http://dlang.org/property.html#stringof helps. yes that help a lot thanks End of spam ( joke ^^) I found it :-) import std.stdio; import std.typecons; import

Re: Different random shuffles generated when compiled with gdc than with dmd

2014-06-01 Thread Joseph Rushton Wakeling via Digitalmars-d-learn
On 01/06/14 14:11, Ivan Kazmenko via Digitalmars-d-learn wrote: I second the thought that reproducibility across different versions is an important feature of any random generation library. Sadly, I didn't use a language yet which supported such a flavor of reproducibility for a significant

Re: Is there any way to differentiate between a type and an alias?

2014-06-01 Thread Rene Zwanenburg via Digitalmars-d-learn
On Tuesday, 27 May 2014 at 18:05:24 UTC, Steven Schveighoffer wrote: I get it. I don't necessarily agree with that, but it's not my library :) I think it would be difficult to achieve without changing the actual function definition. Perhaps you could wrap the functions with your own, and use

Re: floating point conversion

2014-06-01 Thread Famous via Digitalmars-d-learn
On Sunday, 1 June 2014 at 12:45:26 UTC, bearophile wrote: It's a bad question. Actually, Martin's question is a good one. Initializing a variable of type float via a literal or as conversion from string should be the same, exacly, always. Casting a float to double should be deterministic as

Re: floating point conversion

2014-06-01 Thread Famous via Digitalmars-d-learn
float a = 1.234f; float b = to!float(1.234); assert (a == b); assert (a == to!float(1.234)); // is allowed to fail due to constant folding

Re: floating point conversion

2014-06-01 Thread Martin Krejcirik via Digitalmars-d-learn
On 1.6.2014 16:42, Famous wrote: from string should be the same, exacly, always. Casting a float to double should be deterministic as well. void main() { float a = 1.234f; double b = 1.234; assert (a == cast(float) b); // fails in DMD x86, works in GDC, LDC } Maybe enhancement

Re: floating point conversion

2014-06-01 Thread Famous via Digitalmars-d-learn
On Sunday, 1 June 2014 at 15:31:53 UTC, Martin Krejcirik wrote: On 1.6.2014 16:42, Famous wrote: from string should be the same, exacly, always. Casting a float to double should be deterministic as well. void main() { float a = 1.234f; double b = 1.234; assert (a == cast(float)

DMD fail when using both reflection and UDA

2014-06-01 Thread bioinfornatics via Digitalmars-d-learn
DMD (dmdfe 2.066) fail when i use UDA which store a delegate code below works if i remove @section UDA otheswise it give this error: dmd: statement.c:714: ErrorStatement::ErrorStatement(): Assertion `global.gaggedErrors || global.errors' failed. is a bug ? --- CODE also on dpaste

Re: DMD fail when using both reflection and UDA

2014-06-01 Thread bioinfornatics via Digitalmars-d-learn
On Sunday, 1 June 2014 at 16:02:47 UTC, bioinfornatics wrote: DMD (dmdfe 2.066) fail when i use UDA which store a delegate code below works if i remove @section UDA otheswise it give this error: dmd: statement.c:714: ErrorStatement::ErrorStatement(): Assertion `global.gaggedErrors ||

Re: DMD fail when using both reflection and UDA

2014-06-01 Thread bioinfornatics via Digitalmars-d-learn
stupid me bug was at the end a[0] = 1; become a[0] = 1; but error error was so stnange to me i though that was a bug

Re: DMD fail when using both reflection and UDA

2014-06-01 Thread Philippe Sigaud via Digitalmars-d-learn
In any case, it's an internal compiler error, so it's a bug. Users should never see ICEs. Could you please report it, with the entire error message?

Re: floating point conversion

2014-06-01 Thread Wanderer via Digitalmars-d-learn
The General rule is not to compare floats for equality, (is 0.0==-0.0, etc.). Use a epsilon based comparision scheme instead or a wrapper around it. That's not exactly true. You cannot (and should not) compare floating points for equality, and use epsilon-based comparison instead, only in

rawRead linker error

2014-06-01 Thread Joseph Rushton Wakeling via Digitalmars-d-learn
Hello all, I'm trying to read from /dev/random using File.rawRead as follows: auto f = File(/dev/urandom, r); ulong b; f.rawRead((b)[0 .. 1]); writeln(b); This generates a linker error: rawread.o: In function `_D3std5stdio4File14__T7rawReadTmZ7rawReadMFAmZAm':

Re: rawRead linker error

2014-06-01 Thread Joseph Rushton Wakeling via Digitalmars-d-learn
On 01/06/14 19:04, Joseph Rushton Wakeling via Digitalmars-d-learn wrote: Passing a regular array as the buffer doesn't cause any issues In fact it seems to be a problem to pass any array other than a ubyte array; for example a ulong[] array is problematic. The problem vanishes if the

Re: floating point conversion

2014-06-01 Thread Famous via Digitalmars-d-learn
I have compiled some cases at http://dpaste.dzfl.pl/5611b8bce8e3 This implies that floating-point constants do not have fixed but minimum precision. Particularly, the literal 1.23 describes a floating-point value with either double or real precision depending on what it is compared to.

Test if member is static variable

2014-06-01 Thread Temtaime via Digitalmars-d-learn
Hi ! http://dpaste.dzfl.pl/e21082716396 Is there a way to optimize static if(is(typeof(__traits(getMember, T, name).offsetof)) == false is(FunctionTypeOf!(__traits(getMember, T, name)) == function) == false __traits(compiles, __traits(getMember, T, name))) ? I think there shoult be

Re: floating point conversion

2014-06-01 Thread Martin Krejcirik via Digitalmars-d-learn
On 1.6.2014 18:02, Famous wrote: This is different. The decimal 1.234 cannot be exacly represented as radix-2 floating-point number. In your example above, a and b are not equal. They are both approximations to 1.234 but the value of b is Still feels iffy to me. If you add:

support for unicode in identifiers

2014-06-01 Thread Vlad Levenfeld via Digitalmars-d-learn
I was pretty happy to find that I could use mu and sigma when writing statistical routines, but I've found that for more obscure non-ascii characters the support is hit or miss. For example, none of the subscripts are valid characters, but I can use superscript n as well as dot-notation for

How to detect a lambda expression get it is signature

2014-06-01 Thread bioinfornatics via Digitalmars-d-learn
Hi i am looking how to perform this action with traits. Below some code to show what it fail Regards CODE import std.traits : isDelegate, isSomeFunction, MemberFunctionsTuple, ParameterIdentifierTuple; struct section( alias start, alias end ) { alias checkStart = start;

Re: DMD fail when using both reflection and UDA

2014-06-01 Thread bioinfornatics via Digitalmars-d-learn
On Sunday, 1 June 2014 at 16:18:45 UTC, Philippe Sigaud via Digitalmars-d-learn wrote: In any case, it's an internal compiler error, so it's a bug. Users should never see ICEs. Could you please report it, with the entire error message? Ok thanks is don at

Re: support for unicode in identifiers

2014-06-01 Thread Chris Nicholson-Sauls via Digitalmars-d-learn
On Sunday, 1 June 2014 at 22:26:42 UTC, Vlad Levenfeld wrote: I was pretty happy to find that I could use mu and sigma when writing statistical routines, but I've found that for more obscure non-ascii characters the support is hit or miss. For example, none of the subscripts are valid

Re: support for unicode in identifiers

2014-06-01 Thread Vlad Levenfeld via Digitalmars-d-learn
With unicode support (especially with UCFS) I can really code more in the way I think. I never gave it much thought until I worked with D, but now that I have I feel it is a bit weird to work with epsilons and deltas on paper and eps and del or something on the screen. And what's a more

Re: support for unicode in identifiers

2014-06-01 Thread Vlad Levenfeld via Digitalmars-d-learn
Ah!, found it in utf.h as ALPHA_TABLE

Multi-file project problem with Visual D

2014-06-01 Thread Mike via Digitalmars-d-learn
I've created a small Windows based program using a win32 library I found online. That part is working just fine. I've also created a second file (called util.d) and within it defined a class called MyData (with a member function called Read()). Within my main program I instantiate and try

Re: Multi-file project problem with Visual D

2014-06-01 Thread Mike via Digitalmars-d-learn
On Monday, 2 June 2014 at 01:01:22 UTC, Mike wrote: I've created a small Windows based program using a win32 library I found online. That part is working just fine. I've also created a second file (called util.d) and within it defined a class called MyData (with a member function called

Re: Indicating incompatible modules

2014-06-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Sat, 31 May 2014 18:26:53 +0200 Joseph Rushton Wakeling via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Hello all, Is there a straightforward way to indicate that two modules should not be used together in the same program? Preferably one that does not require editing

Re: Forward reference to nested function not allowed?

2014-06-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Sat, 31 May 2014 16:18:33 + DLearner via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Hi, import std.stdio; void main() { writefln(Entered); sub1(); sub1(); sub1(); writefln(Returning); void sub1() { static int i2 = 6;

Re: Are tests interruptible/concurrent? Is use of a (thread local) global safe in tests?

2014-06-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Fri, 30 May 2014 20:13:19 + Mark Isaacson via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: I'm having fun running some unittests. I set up a simple homemade mock of std.net.curl's functions that essentially just consists of a global queue that I can add strings to and

Re: floating point conversion

2014-06-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Sun, 01 Jun 2014 14:42:34 + Famous via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Sunday, 1 June 2014 at 12:45:26 UTC, bearophile wrote: It's a bad question. Actually, Martin's question is a good one. Initializing a variable of type float via a literal or as