Question about @nogc

2014-05-20 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
Did I understand correct that a function can only be @nogc if also all functions that it calls are @nogc too (and of course it doesn't use the GC itself)? If so, should this be possible: string foo() { // use GC to allocate some string } bar @nogc { mixin(foo()); } Because, bar()

Re: Question about @nogc

2014-05-20 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Tuesday, 20 May 2014 at 17:14:31 UTC, John Colvin wrote: On Tuesday, 20 May 2014 at 12:25:11 UTC, Dominikus Dittes Scherkl wrote: Did I understand correct that a function can only be @nogc if also all functions that it calls are @nogc too (and of course it doesn't use the GC itself)? If

overloading operations for enums

2014-05-26 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
Hello. I want to create some finite algebra, where the elements are enumerated but operations on them are defined (with composition tables). e.g.: enum color = { white, yellow, red, blue, orange, violet, green, black }; color a = blue; a += yellow; assert(a == green); is this possible

Re: Opinions: The Best and Worst of D (for a lecture/talk I intend to give)

2014-07-09 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Wednesday, 9 July 2014 at 14:51:41 UTC, Meta wrote: One of the uglier things in D is also a long-standing problem with C and C++, in that comparison of signed and unsigned values is allowed. I would like that, if it would be implemented along this line: /// Returns -1 if a b, 0 if they

Re: Opinions: The Best and Worst of D (for a lecture/talk I intend to give)

2014-07-09 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
Of course without the ! after opCmp in the several cases.

Re: Opinions: The Best and Worst of D (for a lecture/talk I intend to give)

2014-07-09 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Wednesday, 9 July 2014 at 17:13:21 UTC, H. S. Teoh via Digitalmars-d-learn wrote: On Wed, Jul 09, 2014 at 04:24:38PM +, Dominikus Dittes Scherkl via Digitalmars-d-learn wrote: /// Returns -1 if a b, 0 if they are equal or 1 if a b. /// this will always yield a correct result, no matter

Re: Opinions: The Best and Worst of D (for a lecture/talk I intend to give)

2014-07-09 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Wednesday, 9 July 2014 at 17:13:21 UTC, H. S. Teoh via Digitalmars-d-learn wrote: The branched version would look something like this: mov eax, [address of u] mov ebx, [address of s] cmp ebx, $#0 jge label1 ; first branch mov

Re: Opinions: The Best and Worst of D (for a lecture/talk I intend to give)

2014-07-10 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Wednesday, 9 July 2014 at 19:54:47 UTC, H. S. Teoh via Digitalmars-d-learn wrote: [...] The problem is that the function needs to return int, but given two uints, their difference may be greater than int.max, so simply subtracting them will not work. So the best I can come up with is:

Re: Opinions: The Best and Worst of D (for a lecture/talk I intend to give)

2014-07-10 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
Should of course be: int compare2(uint x, int y) { return (x int.max) ? 1 : (cast(int)x - y); }

new properties for basic types

2014-07-14 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
Is it possible to write custom properties for basic types, so that I can write e.g. int.myProp instead of myProp!int() [analogue to x.myProp instead of myProp(x)]?

Re: new properties for basic types

2014-07-14 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Monday, 14 July 2014 at 11:28:15 UTC, Philippe Sigaud via Digitalmars-d-learn wrote: Halas, that's not what the OP wants. He needs properties on the *type* itself: int.foo instead of foo!int. Yes, exactly. So no, this is not possible. Hmm. So how do I use stuff like this: template

Re: new properties for basic types

2014-07-15 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Tuesday, 15 July 2014 at 05:26:57 UTC, Philippe Sigaud via Digitalmars-d-learn wrote: @property allows you to call a function without the parenthesis (), to imitate a field in a struct or class. Ah, ok. That means without @property I would need to write defaultInit!T() instead of

Re: funny behavior of ..

2014-08-08 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Friday, 8 August 2014 at 15:17:25 UTC, seany wrote: The .., range operator, when used like this : string a = abcd; string b = a[0 .. a.count()-1]; sets b to abc. is this the expected behavior? Yes. [..] is exclusive the last element. So [0..1] is a single element [0] That allows to avoid

Re: Separate Printing Mantissa and Exponent of a Floating Point

2014-08-11 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Monday, 11 August 2014 at 14:15:05 UTC, Nordlöw wrote: Here's my current try: string toMathML(T)(T x) @trusted /** pure */ if (isFloatingPoint!T) { import std.conv: to; import std.algorithm: findSplit; // immutable parts = to!string(x).findSplit(e); if (parts[2].length ==

Re: simple question about function call syntax

2014-08-18 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Monday, 18 August 2014 at 16:30:13 UTC, Nikolay wrote: I found this code sample in vibe: void connect(NetworkAddress addr) { enforce(.connect(m_ctx.socketfd, addr.sockAddr, addr.sockAddrLen) == 0, Failed to connect UDP socket.~to!string(getLastSocketError())); } What

Variadic parameter of length 1

2014-08-20 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
I have several times seen a construct template foo(T...) if(T.length == 1) { ... } What is that good for? Why using variadic parameter if anyway exactly one parameter is required?!?

Re: Variadic parameter of length 1

2014-08-20 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Wednesday, 20 August 2014 at 15:26:14 UTC, monarch_dodra wrote: AFAIK, it's a historical workaround to accept T as either alias or not alias, as varargs have auto alias. EG: foo!int //OK foo!hello //OK too Ah, ok. And why historical? Is that not necessary anymore? What better solution is

Re: Variadic parameter of length 1

2014-08-20 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Wednesday, 20 August 2014 at 15:37:18 UTC, Philippe Sigaud via Digitalmars-d-learn wrote: No better solution that I know of. alias template parameters (alias a) match symbols (names, user-defined types) whereas type parameter (T) match only pure types. So when we need to match anything,

Re: 'idiomatic' porting of c and or c++ code that does NULL checking

2014-08-27 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Wednesday, 27 August 2014 at 05:45:34 UTC, eles wrote: While this may be true in this case, I think that, in general, you cannot draw such a clear line between what's recoverable and what's not. If you really want to push things to the extreme, the sole unrecoverable error shall be

accessing numeric template parameters

2014-11-03 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
If I have a struct with numeric template parameter, how can I access it within member functions? Like normal member variables? And how about the constructor? struct polynomial(uint base) { private: uint[] N; public: this(uint x) { base = x; } ... void add(Polynomial!base P) {

Re: accessing numeric template parameters

2014-11-05 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Monday, 3 November 2014 at 21:17:09 UTC, Philippe Sigaud via Digitalmars-d-learn wrote: struct polynomial(uint base) { private: uint[] N; public: this(uint x) { base = x; } base is part of the type. polynomial is just a 'recipe' for a type, the real struct would be Polynomial!(0),

Re: Dynamic array head const in library code?

2014-11-28 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Friday, 28 November 2014 at 10:55:27 UTC, bearophile wrote: In D code it's a good idea to set as const/immutable (where possible) all variables that don't need to change, for both safety and compiler-enforced code documentation. In my D functions sometimes I create dynamic arrays that later

using the full range of ubyte with iota

2015-01-24 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
Maybe I'm just too stupid, but I cannot manage to call a simple function with all 256 possible values of ubyte with iote: int foo(ubyte c); auto myRange = iota(0,256).map!foo; -- Error: function foo(ubyte c) is not callable using argument types (int) and this is because of the f***

Re: Number of Bits Needed to Represent a Zero-Offset Integer

2015-01-20 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Monday, 19 January 2015 at 21:23:47 UTC, Nordlöw wrote: On Monday, 19 January 2015 at 20:54:50 UTC, Steven Schveighoffer wrote: Cool. I would point out that the commented code suggests you should be handling the 0 case, but you are not (when T.min == T.max) I believe that should trigger a

Re: BigFloat?

2015-02-17 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Tuesday, 17 February 2015 at 09:08:17 UTC, Vlad Levenfeld wrote: On Tuesday, 17 February 2015 at 08:05:49 UTC, Kagamin wrote: Periodic fractions. Or transcendental numbers, for that matter, but arbitrary != infinite. A max_expansion template parameter could be useful here. For my use

Re: shared Variant[string]

2015-01-29 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Wednesday, 28 January 2015 at 12:29:09 UTC, Fyodor Ustinov wrote: On Wednesday, 28 January 2015 at 11:27:53 UTC, Kagamin wrote: Associative array doesn't support thread-safe operations, that's why they don't work on shared instance. You should use std.concurrency or implement low-level

Re: using the full range of ubyte with iota

2015-01-24 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Saturday, 24 January 2015 at 23:19:11 UTC, ketmar wrote: people that are new to D aren't used to D lambdas, so it's fairly common. Oh, I am aware, but I didn't thought it would be necessary in this pace. if you'll stay with D, you'll find yourself dreaming about such handy thing in

Re: using the full range of ubyte with iota

2015-01-25 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Sunday, 25 January 2015 at 10:42:51 UTC, bearophile wrote: Vlad Levenfeld: What's this about !`[]` and std.range.uniform?? It's not in the documentation. It's an enhancement I have proposed. Hm. I had more something in mind like paramCast - a kind of big scissors that cut everything a

Re: using the full range of ubyte with iota

2015-01-25 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Sunday, 25 January 2015 at 13:03:16 UTC, bearophile wrote: Dominikus Dittes Scherkl: Because this is useful in more situations, Right, but it's still a cast. And in D you want to minimize the number of usages of casts. The proposed syntax iota![] is cast-safe. I don't case too much,

Re: using the full range of ubyte with iota

2015-01-24 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Saturday, 24 January 2015 at 21:00:06 UTC, Tobias Pankrath wrote: On Saturday, 24 January 2015 at 20:49:03 UTC, Dominikus Dittes Scherkl wrote: I would have no problem using an explicit cast, but where should I apply it? iota(0, 256).map!(x = foo(cast(ubyte) x)) Ok, thank you very much.

Re: using the full range of ubyte with iota

2015-01-25 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Sunday, 25 January 2015 at 12:56:14 UTC, Tobias Pankrath wrote: On Sunday, 25 January 2015 at 12:25:35 UTC, Dominikus Dittes Scherkl wrote: map!(x = fn(cast(ParameterTypeTuple!fn[0])x) but instead with map!(paramCast!fn) Because this is useful in more situations, e.g. in every place

unittest with Visual D

2015-01-25 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
I finaly got managed to install Visual D on my Windows PC (thanks to the new community version of Visual Studio), but the cool point Compile and Run seems to have a problem with some of my unittests: I get the error template instance xy is not defined if a specific instantiation is not used

reinterpret array

2015-01-13 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
Does the following construct hold water? version(LittleEndian) { /// interpret an array of one type as an array of a different type. /// if the array has odd length, the highest elements are /// not accessible, at worst an empty slice is returned inout ref T[] arrayOf(T, V:

Re: reinterpret array

2015-01-13 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Tuesday, 13 January 2015 at 17:12:42 UTC, Adam D. Ruppe wrote: On Tuesday, 13 January 2015 at 17:09:32 UTC, Dominikus Dittes Scherkl wrote: I assume taking a slice of a pointer uses the GC, so this cannot be @nogc, am I right? Nope, slicing never allocates, it just takes an address and

Re: reinterpret array

2015-01-13 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Tuesday, 13 January 2015 at 18:25:38 UTC, ketmar via Digitalmars-d-learn wrote: On Tue, 13 Jan 2015 17:09:31 + Dominikus Dittes Scherkl via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: /// interpret an array of one type as an array of a different type. may i point

Re: reinterpret array

2015-01-14 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Tuesday, 13 January 2015 at 23:36:51 UTC, Artur Skawina via Digitalmars-d-learn wrote: It's neat, but the real problems with it are: 1) obfuscation - it hides those trivial bit ops behind layers of functions and operator overloads, which everyone reading the code must then figure out; Ok,

Conditional functions

2015-01-05 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
Is it possible to use static if in a template structure to have some member functions only for specific types? E.g.: struct Foo(T) { ... T get() { ... } static if(isMutable!T) { void set(T x) { ... } } }

Re: Conditional functions

2015-01-05 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Monday, 5 January 2015 at 17:55:49 UTC, Justin Whear wrote: On Mon, 05 Jan 2015 17:47:09 +, Dominikus Dittes Scherkl wrote: Is it possible to use static if in a template structure to have some member functions only for specific types? Yep. This is actually a frequently used pattern

Re: using the full range of ubyte with iota

2015-01-25 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Sunday, 25 January 2015 at 18:59:04 UTC, ketmar wrote: auto x2 = (x4) | (x4); // swap nibbles - but result in an int! this is true for C and C++ too, as all three languages doing integer promotion. the only difference is that D forbids potentially lossy assigns. you best bet is to

Re: reinterpret array

2015-01-13 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Tuesday, 13 January 2015 at 20:11:45 UTC, anonymous wrote: On Tuesday, 13 January 2015 at 20:00:57 UTC, Dominikus Dittes Scherkl wrote: So if I have a function that allowes to do this: uint a; a.bit[16] = true; writeln(a); // 65536 Is it also already available? a |= 1 16; Of course

Re: Speed of horizontal flip

2015-04-02 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Wednesday, 1 April 2015 at 14:00:52 UTC, bearophile wrote: If you have to perform performance benchmarks then use ldc or gdc. Also disable bound tests with your compilation switches. Add the usual pure/nothrow/@nogc/@safe annotations where you can (they don't increase speed much,

Re: Why does not my program is not running?

2015-08-21 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Thursday, 20 August 2015 at 21:15:36 UTC, anonymous2 wrote: On Thursday, 20 August 2015 at 21:11:07 UTC, anonymous wrote: I severely limited the range of integer. I don't know off the top of my head how large you can make it without hitting overflow. I removed the file writing, because

Re: Problem with dmd 2.068 Win 32

2015-08-11 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Tuesday, 11 August 2015 at 15:04:29 UTC, MGW wrote: Hi! My project has an error link: Error 42: Symbol Undefined _D6object9Exception6__ctorMFNaNbNfAyaAyakC6object9ThrowableZC9Exception On dmd 2.067.* everything gathered without mistakes. Where to look for a mistake? See the changelog.

Re: Preventing implicit conversion

2015-11-05 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Thursday, 5 November 2015 at 09:33:40 UTC, ixid wrote: In C++ I can add two shorts together without having to use a cast to assign the result to one of the two shorts. It just seems super clunky not to be able to do basic operations on basic types without casts everywhere. +1 If

Re: Preventing implicit conversion

2015-11-05 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
And I want to have small number litterals automatically choosing the smallest fitting type. If I write ubyte b = 1u; auto c = b + 1u; I expect the 1u to be of type ubyte - and also c.

Re: Preventing implicit conversion

2015-11-05 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Thursday, 5 November 2015 at 13:23:34 UTC, Adam D. Ruppe wrote: On Thursday, 5 November 2015 at 10:07:30 UTC, Dominikus Dittes Scherkl wrote: ubyte b = 1u; auto c = b + 1u; I expect the 1u to be of type ubyte - and also c. This won't work because of the one-expression rule. In the

Re: Preventing implicit conversion

2015-11-05 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Thursday, 5 November 2015 at 22:15:46 UTC, Dominikus Dittes Scherkl wrote: On Thursday, 5 November 2015 at 13:23:34 UTC, Adam D. Ruppe wrote: On Thursday, 5 November 2015 at 10:07:30 UTC, Dominikus Dittes Scherkl wrote: ubyte d = b + (ubyte)1; Sorry, should of course be: ubyte d = b +

Re: foreach loop

2015-10-19 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Monday, 19 October 2015 at 14:28:06 UTC, Namal wrote: Is it possible to create a foreach loop with a breakstetemen? I mean something like that for the second loop where i want to break if element from: int [] g = [9,15,21]; int [] v = [2,3,5,7,8,9,11,13,17,19]; foreach(j;1..10) for(int

Re: Bug? 0 is less than -10

2015-10-08 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Wednesday, 7 October 2015 at 16:25:02 UTC, Marc Schütz wrote: Lionello Lunesu posted a PR that should fix this: https://github.com/D-Programming-Language/dmd/pull/1913 See also the discussion in the linked bug report. Unfortunately it seems it's been forgotten since then... Meanwhile I

Re: observation: D getting a bit complex

2015-08-30 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Sunday, 30 August 2015 at 07:36:55 UTC, BBasile wrote: On Sunday, 30 August 2015 at 02:42:30 UTC, Spacen Jasset wrote: immutable(ElementEncodingType!(ElementType!Range))[] buildPath(Range)(Range segments) if (isInputRange!Range isSomeString!(ElementType!Range)); pure nothrow @safe

Re: What's the "right" way to do openmp-style parallelism?

2015-09-08 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Tuesday, 8 September 2015 at 05:50:30 UTC, Russel Winder wrote: void main() { immutable imax = 10; immutable jmax = 10; float[imax][jmax] x; foreach(int j; 1..jmax){ foreach(int i, ref item; parallel(x[j-1])){ x[j][i] = complicatedFunction(i,

Re: Why 1f.iota(100f).array returns double[] not float[]?

2015-09-08 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Tuesday, 8 September 2015 at 07:17:01 UTC, Ali Çehreli wrote: https://github.com/D-Programming-Language/phobos/blob/master/std/range/package.d#L4630 auto iota(B, E)(B begin, E end) if (isFloatingPoint!(CommonType!(B, E))) { return iota(begin, end, 1.0); } Such kind of stuff would

Re: Prefer Signed or Unsigned in D?

2015-09-02 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Wednesday, 2 September 2015 at 09:47:16 UTC, BBasile wrote: On Tuesday, 1 September 2015 at 23:06:50 UTC, John Carter wrote: C/C++ discussion here http://blog.robertelder.org/signed-or-unsigned-part-2/ D rules here... http://dlang.org/type.html#integer-promotions It depends on

Re: Comparison operator overloading

2015-12-07 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Monday, 7 December 2015 at 13:31:52 UTC, Mike Parker wrote: On Monday, 7 December 2015 at 11:49:51 UTC, Dominikus Dittes Scherkl wrote: On the other hand the chapter also states that opCmp() should always return "int" - which is a bad idea if you e.g. want to provide a "NaN" value in your

Re: Comparison operator overloading

2015-12-07 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Sunday, 6 December 2015 at 15:01:08 UTC, cym13 wrote: Don't use opCmp, all binary operators should be overriden using opBinary. For more information I recommend this page http://ddili.org/ders/d.en/operator_overloading.html Why should we don't use opCmp() ? I can't see any recommendation

Re: Returning the address of a reference return value in @safe code - 2.072 regression?

2017-02-21 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Monday, 20 February 2017 at 21:05:17 UTC, Jack Stouffer wrote: On Monday, 20 February 2017 at 20:54:31 UTC, Jack Stouffer wrote: On Monday, 20 February 2017 at 20:49:43 UTC, Johan Engelen wrote: ... Yeah, this is another regression caused by DIP1000. Christ. For the record, the current

Re: How to specify a template that uses unqualified type, like any normal function

2017-08-14 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Monday, 14 August 2017 at 17:43:44 UTC, Dominikus Dittes Scherkl wrote: On Monday, 14 August 2017 at 15:20:28 UTC, Steven Schveighoffer wrote: What you can do, is: auto foo(T)(T n) if (is(T == Unqual!T)) { // normal implementation } auto foo(T)(T n) if (!is(T == Unqual!T) &&

How to specify a template that uses unqualified type, like any normal function

2017-08-14 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
if I use fixed-type functions, I can do the following: uint foo(uint n) { ++n; // modify n - as this function has received a copy of n, this is always possible return 42; } uint bar(const uint n) { assert(foo(n)==42); return 17; } void main() { bar(3); } But if I try the

Re: How to specify a template that uses unqualified type, like any normal function

2017-08-14 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Monday, 14 August 2017 at 15:20:28 UTC, Steven Schveighoffer wrote: On 8/14/17 9:48 AM, Dominikus Dittes Scherkl wrote: > uint foo(T)(Unqual!T n) // first try > { > ++n; // modify should be possible > return 42; > } > Any ideas what I need to do to make this work? This isn't exactly

Re: How to specify a template that uses unqualified type, like any normal function

2017-08-16 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Tuesday, 15 August 2017 at 14:24:57 UTC, Steven Schveighoffer wrote: What IFTI would need is a mechanism to change the parameter types to mutable similar to how you can do this: foo(T)(const(T) t); This now generates one function for int, const(int), immutable(int), and t is const

Re: New integer promotion rules

2018-01-18 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Thursday, 18 January 2018 at 06:05:08 UTC, rumbu wrote: On Thursday, 18 January 2018 at 02:30:17 UTC, Rubn wrote: On Wednesday, 17 January 2018 at 22:30:11 UTC, rumbu wrote: code like "m = n < 0 ? -n : n" doesn't worth a wrapper That code is worth a wrapper, it's called "abs"... m =

Re: Run-time initialised static variables

2018-02-07 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Wednesday, 7 February 2018 at 12:10:38 UTC, dekevin wrote: struct ℚ{ ℤ num, den; //cannot call constructors on these, since they require gmp_init, which requires runtime code //Default initialiser disabled, since else num=0,den=0 You can use a different default initializer:

Re: Can't add ubytes together to make a ubyte... bug or feature?

2018-03-17 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Saturday, 17 March 2018 at 18:36:35 UTC, Jonathan wrote: On Tuesday, 19 January 2016 at 23:36:14 UTC, Adam D. Ruppe wrote: On Tuesday, 19 January 2016 at 22:12:06 UTC, Soviet Friend wrote: I don't care if my computer needs to do math on a 4 byte basis, I'm not writing assembly. x86

Re: Getting rid of const/immutable

2019-09-15 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Monday, 16 September 2019 at 05:22:14 UTC, Cecil Ward wrote: I have a particular type name and that type may or may not be const and/or immutable. How do I make a new type based on this that is mutable, ie getting rid of both const and immutable, but not knowing what the original type is ?

Re: Using map result type

2019-12-10 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Tuesday, 10 December 2019 at 07:23:56 UTC, AA wrote: Would the second solution of declaring a template constraint like that be considering strange/out of place in D? e.g. do people normally try and declare the template constraints on a function or just rely on compile time failure from to

Re: @safe std.file.read

2020-01-06 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Monday, 6 January 2020 at 10:07:37 UTC, WebFreak001 wrote: I was wondering, how are you supposed to use std.file : read in @safe code when it returns a void[] but you want to get all bytes in the file? Is void[] really the correct type it should be returning instead of ubyte[] when it

Re: __init unresolved external when using C library structs converted with dstep

2020-04-17 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Friday, 17 April 2020 at 08:59:41 UTC, Robert M. Münch wrote: How would that look like? myStruct ms = void; // ??? Exactly.

Re: Why is BOM required to use unicode in tokens?

2020-09-15 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Tuesday, 15 September 2020 at 06:49:08 UTC, Jon Degenhardt wrote: On Tuesday, 15 September 2020 at 02:23:31 UTC, Paul Backus wrote: Identifiers start with a letter, _, or universal alpha, and are followed by any number of letters, _, digits, or universal alphas. Universal alphas are as

Re: Why is BOM required to use unicode in tokens?

2020-09-16 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Wednesday, 16 September 2020 at 00:22:15 UTC, Steven Schveighoffer wrote: Someone should verify that the character you want to use for a symbol name is actually considered a letter or not. Using phobos to prove this is kind of self-defeating, as I'm pretty sure it would be in league with

Re: Named parameters in function call

2020-09-09 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Tuesday, 8 September 2020 at 13:28:22 UTC, Cecil Ward wrote: int xcoord; int ycoord; You can define your own types, of course: struct xcoord { int x; alias x this; } struct ycoord { int y; alias y this; } void myfunc(xcoord x; ycoord y, color c) {}

Re: List of exceptions?

2020-10-12 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Saturday, 10 October 2020 at 19:51:10 UTC, DMon wrote: This is where I'm at: import std.stdio; import std.conv; // StdioException // ConvException // StringException // ErrnoException // FormatException // UnicodeException // UTFException // FileMissingException // DataCorruptionException

Re: Why is BOM required to use unicode in tokens?

2020-09-16 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Wednesday, 16 September 2020 at 07:38:26 UTC, Dominikus Dittes Scherkl wrote: We only need to define which properties a character need to be allowed in an identifier. I think the following change in the grammar would be sufficient: Identifier: IdentifierStart IdentifierStart

Re: Idiomatic D code to avoid or detect devision by zero

2020-08-03 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Monday, 3 August 2020 at 14:50:36 UTC, Steven Schveighoffer wrote: On 8/3/20 5:53 AM, Martin Tschierschke wrote: I prefer putting additional bracket around For really long expressions you could also split it on multiple lines: c = (b_expression == 0) ? (d_longer_expression) :

Re: How can I make executeShell ask for Admin Elevation?

2020-07-14 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Monday, 13 July 2020 at 19:32:33 UTC, Marcone wrote: alias runas = compose!(x => to!bool((cast(int) x) > 32), x => ShellExecute(null, "runas", "cmd", cast(wchar*) "/c \"cd /d %s && %s\"".format(getcwd(), x).to!wstring, null, SW_HIDE).WaitForSingleObject(WAIT_TIMEOUT)); runas("netsh

Re: how to assign to shared obj.systime?

2020-07-14 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Tuesday, 14 July 2020 at 07:05:43 UTC, Arafel wrote: *However*, for this to work, you shouldn't use `shared` member variables unless absolutely necessary, much less whole `shared` classes/structs This is generally true. Avoid sharing many variables! Tasks should be as independent from each

Re: opBinary : Static ifs or specialization?

2020-06-24 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Wednesday, 24 June 2020 at 09:01:28 UTC, claptrap wrote: On Wednesday, 24 June 2020 at 00:53:58 UTC, H. S. Teoh wrote: On Tue, Jun 23, 2020 at 11:53:36PM +, claptrap via If your implementations are based on built-in operators, you could use mixins to unify the implementations into

Re: GC.addRange in pure function

2021-02-10 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Tuesday, 9 February 2021 at 21:00:39 UTC, Paul Backus wrote: On Tuesday, 9 February 2021 at 19:53:27 UTC, Temtaime wrote: pure is broken. Just don't [use it] Allowing memory allocation in pure code in a language that can distinguish between pointer equality and value equality is, let's

Re: simple (I think) eponymous template question ... what is proper idimatic way ?

2021-08-18 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Wednesday, 18 August 2021 at 05:33:13 UTC, james.p.leblanc wrote: If I wanted to ensure that a function accepts only arguments of byte, int, uint, long, etc. (i.e. integer-like types). Is the accepted way to do this like so?: **auto foo( T : long )(T a, T b){ ... }** I very much prefer