std.string.assumeUTF() silently casting mutable to immutable?

2024-02-12 Thread Forest via Digitalmars-d-learn
I may have found a bug in assumeUTF(), but being new to D, I'm not sure. The description: Assume the given array of integers arr is a well-formed UTF string and return it typed as a UTF string. ubyte becomes char, ushort becomes wchar and uint becomes dchar. Type qualifiers are preserved. T

Re: std.string.assumeUTF() silently casting mutable to immutable?

2024-02-13 Thread Forest via Digitalmars-d-learn
On Tuesday, 13 February 2024 at 14:05:03 UTC, Johan wrote: On Tuesday, 13 February 2024 at 08:10:20 UTC, Jonathan M Davis wrote: So, there's definitely a bug here, but it's a dmd bug. Its checks for whether it can safely change the constness of the return type apparently aren't sophisticated

Re: std.string.assumeUTF() silently casting mutable to immutable?

2024-02-14 Thread Forest via Digitalmars-d-learn
On Wednesday, 14 February 2024 at 10:57:42 UTC, RazvanN wrote: This has already been fixed, you just need to use -preview=fixImmutableConv. This was put behind a preview flag as it introduces a breaking change. I just tried that flag on run.dlang.org, and although it fixes the case I posted

Re: How can i find my LAN IP Address using std.socket?

2024-02-17 Thread Forest via Digitalmars-d-learn
On Tuesday, 4 February 2014 at 13:02:26 UTC, TheFlyingFiddle wrote: I'm trying to find my own ip address using std.socket with little success. How would i go about doing this? (It should be a AddressFamily.INET socket) Sadly, the standard library doesn't seem to offer network interface enumer

Double ended arrays?

2017-10-07 Thread Chirs Forest via Digitalmars-d-learn
I have some data that I want to store in a dynamic 2d array... I'd like to be able to add elements to the front of the array and access those elements with negative integers as well as add numbers to the back that I'd acess normally with positive integers. Is this something I can do, or do I ha

Why do I have to cast arguments from int to byte?

2017-10-10 Thread Chirs Forest via Digitalmars-d-learn
I keep having to make casts like the following and it's really rubbing me the wrong way: void foo(T)(T bar){...} byte bar = 9; foo!byte(bar + 1); //Error: function foo!byte.foo (byte bar) is not callable using argument types (int) foo!byte(cast(byte)(bar + 1)); It wouldn't be so bad if I d

Class instance becoming null after calling bindings to C code???

2017-11-15 Thread Chirs Forest via Digitalmars-d-learn
I'm using the derelict fmod bindings to handle sounds in my application and I'm running into a weird bug... If I put calls to fmod in a function inside a class, upon calling those functions the instance of that class will be null, or otherwise changed. I obviously get an access violation if I t

Re: Class instance becoming null after calling bindings to C code???

2017-11-15 Thread Chirs Forest via Digitalmars-d-learn
On Wednesday, 15 November 2017 at 13:30:14 UTC, Adam D. Ruppe wrote: On Wednesday, 15 November 2017 at 13:24:02 UTC, Chirs Forest wrote: class Audio { Audio a; writeln(&a); // 281478 &class is usually wrong. That's the address of the reference, not of the actual object. You might want `ca

Turn a float into a value between 0 and 1 (inclusive)?

2017-11-21 Thread Chirs Forest via Digitalmars-d-learn
I'm interpolating some values and I need to make an (elapsed_time/duration) value a float between 0 and 1 (inclusive of 0 and 1). The elapsed_time might be more than the duration, and in some cases might be 0 or less. What's the most efficient way to cap out of bounds values to 0 and 1? I can d

Variadic Mixin/Template classes?

2017-11-25 Thread Chirs Forest via Digitalmars-d-learn
I'd like to make a class that takes multiple template types (1 - several) which can hold an array/tuple of a second class that are instantiated with those types. class Bar(T) { T bar; } class Foo(T[]){ // not sure how to take variadic types here? Bar!(?)[] bars; //not sure how I'd defi

Re: Variadic Mixin/Template classes?

2017-11-25 Thread Chirs Forest via Digitalmars-d-learn
On Saturday, 25 November 2017 at 10:08:36 UTC, vit wrote: On Saturday, 25 November 2017 at 09:52:01 UTC, Chirs Forest wrote: [...] import std.meta : staticMap; class Bar(T) { T bar; } class Foo(Ts...){ staticMap!(Bar, Ts) bars; this(){ static foreach(i, alias T; Ts) bars

Getting a Type from TypeInfo / Getting Variant Type

2018-01-11 Thread Chirs Forest via Digitalmars-d-learn
I'm using std.variant.Variant to hold a value of unknown type (not a string, could be a numeric type or a container holding multiple numeric types). I'm trying to retrieve this value with .get!T but I need the type to do that... .type gives me TypeInfo, but that's not a type so I'm not sure how