Re: "in" operator gives a pointer result from a test against an Associative Array?

2024-05-09 Thread Meta via Digitalmars-d-learn
On Friday, 10 May 2024 at 00:18:16 UTC, Andy Valencia wrote: tst7.d(6): Error: cannot implicitly convert expression `e in this.members` of type `bool*` to `bool` tst7.d(15): Error: template instance `tst7.Foo!uint` error instantiating I'm getting this for this bit of source (trimmed from the

Re: Fix template parameter

2022-08-09 Thread Meta via Digitalmars-d-learn
On Monday, 8 August 2022 at 12:02:02 UTC, Dom Disc wrote: Hello. I found in the documentation functions declared like this: ```D pure @nogc @safe BigInt opAssign(T : BigInt)(T x); ``` This is a template function, even if T is constrained to always be BigInt (it may also include anything that

Re: A look inside "filter" function defintion

2022-08-09 Thread Meta via Digitalmars-d-learn
On Monday, 1 August 2022 at 23:35:13 UTC, pascal111 wrote: This is the definition of "filter" function, and I think it called itself within its definition. I'm guessing how it works? '''D template filter(alias predicate) if (is(typeof(unaryFun!predicate))) { /** Params: range =

Re: Alternative to C++ macro in D

2019-11-03 Thread Meta via Digitalmars-d-learn
On Sunday, 3 November 2019 at 16:55:36 UTC, Vinod K Chandran wrote: Hi all, I can do this in C++. #include using namespace std ; #define end }; #define log(x) cout << x << endl #define wait std::cin.get() int main() { log("Trying to avoid the visual clutter aused by closing curly braces

Re: Unexpectedly nice case of auto return type

2019-12-03 Thread Meta via Digitalmars-d-learn
On Tuesday, 3 December 2019 at 17:45:27 UTC, H. S. Teoh wrote: The thing is, `void` means "no return type" (or "no type" in some contexts), i.e., void == TBottom in that case. Not *quite* correct. void is not a bottom type; it's a unit type, meaning that it's a type with only 1 value (as is nu

Re: Unexpectedly nice case of auto return type

2019-12-03 Thread Meta via Digitalmars-d-learn
On Tuesday, 3 December 2019 at 22:11:39 UTC, Meta wrote: On Tuesday, 3 December 2019 at 17:45:27 UTC, H. S. Teoh wrote: The thing is, `void` means "no return type" (or "no type" in some contexts), i.e., void == TBottom in that case. Not *quite* correct. void is not a bottom type; it's a unit

Re: Using map result type

2019-12-11 Thread Meta via Digitalmars-d-learn
On Sunday, 8 December 2019 at 01:10:21 UTC, AA wrote: I'd like to accept the return type of map. From some previous questions that I should accept a template? So for something like: ``` void mapAccepter(Range)(Range r) { import std.array : array; import std.stdio : writeln; auto co

Re: Using map result type

2019-12-11 Thread Meta via Digitalmars-d-learn
On Wednesday, 11 December 2019 at 20:08:37 UTC, Meta wrote: import std.algorithm; import std.range; void mapAccepter(E)(InputRange!E r) { import std.array: array; import std.stdio: writeln; auto collected = r.array; writeln(collected); } void main() { int[] nums = [1, 2, 3]

Re: `in` parameters optimization

2019-12-25 Thread Meta via Digitalmars-d-learn
On Wednesday, 25 December 2019 at 01:24:52 UTC, Adnan wrote: Does the compiler automatically pass values by reference if possible with `in` parameters in higher level of optimization flags? I would normally use `in ref` but sometimes it's not compatible with different types. No. "in" is short

Re: Discord bot written in D

2020-04-07 Thread Meta via Digitalmars-d-learn
On Monday, 6 April 2020 at 21:23:22 UTC, Quantium wrote: Are there any libraries to creade a simple discord bot using D? And if you know these libraries, could you day me their pros and cons? I've used https://github.com/b1naryth1ef/dscord to build a Discord bot, a little over a year ago. How

Re: Checked!({short, ushort, byte, char}, Throw): compilation fails

2020-04-16 Thread Meta via Digitalmars-d-learn
Unlike C/C++, char is not a numeric type in D; It's a UTF-8 code point: import std.traits; void main() { pragma(msg, isNumeric!char); //Prints false }

Re: Retrieve the return type of the current function

2020-05-05 Thread Meta via Digitalmars-d-learn
On Tuesday, 5 May 2020 at 17:11:53 UTC, learner wrote: On Tuesday, 5 May 2020 at 16:41:06 UTC, Adam D. Ruppe wrote: typeof(return) Thank you, that was indeed easy! Is it possible to retrieve also the caller return type? Something like: ``` int foo() { return magic(); } auto magic(may

Re: Retrieve the return type of the current function

2020-05-05 Thread Meta via Digitalmars-d-learn
On Tuesday, 5 May 2020 at 18:19:00 UTC, Meta wrote: mixin template magic() { alias CallerRet = typeof(return); CallerRet magic() { return CallerRet.init; } } Small edit: you can remove the "CallerRet" alias by doing the following: mixin template magic() { typeof(r

Re: Should a parser type be a struct or class?

2020-06-18 Thread Meta via Digitalmars-d-learn
On Wednesday, 17 June 2020 at 11:50:27 UTC, Per Nordlöw wrote: Should a range-compliant aggregate type realizing a parser be encoded as a struct or class? In dmd `Lexer` and `Parser` are both classes. In general how should I reason about whether an aggregate type should be encoded as a struct

Re: opBinary : Static ifs or specialization?

2020-06-23 Thread Meta via Digitalmars-d-learn
On Tuesday, 23 June 2020 at 23:53:36 UTC, claptrap wrote: So you have opBinary and half a dozen operators to implement. Do you use a separate method for each operator or do you have one method and a big static if else if to select code path? I assume they are functionally equivalent? So its ju

Very confusing error message when calling a class method from an invariant

2021-03-09 Thread Meta via Digitalmars-d-learn
class Human { static immutable MAX_AGE = 122; bool alive = true; int age = 0; //Error: mutable method onlineapp.Human.checkAge is not callable using a const object invariant(checkAge()); void growOlder() in(alive) out(; checkAge()) { age++; i

Re: Very confusing error message when calling a class method from an invariant

2021-03-09 Thread Meta via Digitalmars-d-learn
On Wednesday, 10 March 2021 at 04:57:19 UTC, Paul Backus wrote: On Wednesday, 10 March 2021 at 03:39:15 UTC, Meta wrote: class Human { static immutable MAX_AGE = 122; bool alive = true; int age = 0; //Error: mutable method onlineapp.Human.checkAge is not callable using a const

Re: Immutable

2021-03-27 Thread Meta via Digitalmars-d-learn
On Saturday, 27 March 2021 at 20:44:12 UTC, Brad wrote: I was looking through lots of sample code on Rosetta Code. D has a lot of solutions out there. That is really nice but it has me wondering - coming from other languages that do not support the concept of immutability - do real world prog

Re: Is this bug ? format %(%)

2021-04-07 Thread Meta via Digitalmars-d-learn
On Wednesday, 7 April 2021 at 17:31:09 UTC, Paul Backus wrote: On Wednesday, 7 April 2021 at 17:04:56 UTC, novice2 wrote: On Wednesday, 7 April 2021 at 13:43:18 UTC, Paul Backus wrote: So, you should change your code to writefln("%-(%s, %)", s); sorry i dont read docs so carefully thanks

Re: Is there a more elegant way to do this in D?

2021-04-08 Thread Meta via Digitalmars-d-learn
On Thursday, 8 April 2021 at 12:19:29 UTC, WebFreak001 wrote: ```d string to01String(int[] x) @safe { auto conv = x.to!(ubyte[]); // allocates new array, so later cast to string is OK conv[] += '0'; // assume all numbers are 0-9, then this gives the correct result return (() @trus

Re: Is there a more elegant way to do this in D?

2021-04-08 Thread Meta via Digitalmars-d-learn
On Thursday, 8 April 2021 at 18:01:56 UTC, Meta wrote: On Thursday, 8 April 2021 at 12:19:29 UTC, WebFreak001 wrote: ```d string to01String(int[] x) @safe { auto conv = x.to!(ubyte[]); // allocates new array, so later cast to string is OK conv[] += '0'; // assume all numbers are 0-9, t

Re: nothrow and std.exception.ifThrown

2021-04-29 Thread Meta via Digitalmars-d-learn
On Thursday, 29 April 2021 at 16:02:20 UTC, novice2 wrote: Hello. I need use std.format.format() in nothrow function. format() can throw. For this case i have special default string. I don't want embrace format into try..catch block, and i found elegant std.exception.ifThrown. But DMD say "ifThro

Re: nothrow and std.exception.ifThrown

2021-04-30 Thread Meta via Digitalmars-d-learn
On Friday, 30 April 2021 at 13:05:00 UTC, Steven Schveighoffer wrote: On 4/29/21 1:50 PM, Meta wrote: The reason for this, apparently, is in the definition of `ifThrown`: ``` CommonType!(T1, T2) ifThrown(E : Throwable = Exception, T1, T2)(lazy scope T1 expression, lazy scope T2 errorHandler

Re: nothrow and std.exception.ifThrown

2021-04-30 Thread Meta via Digitalmars-d-learn
On Thursday, 29 April 2021 at 20:00:23 UTC, novice2 wrote: i dont understand why (templates too dificult for me yet), but if i comment "lazy" from T2, then compiler allow add "nothrow" to "ifThrown" ```d CommonType!(T1, T2) ifThrown(E : Throwable = Exception, T1, T2)(lazy scope T1 expression, /

Re: nothrow and std.exception.ifThrown

2021-04-30 Thread Meta via Digitalmars-d-learn
On Friday, 30 April 2021 at 13:42:49 UTC, Steven Schveighoffer wrote: On 4/30/21 9:24 AM, Meta wrote: My point is that I think marking the *function* nothrow is not correct, it's the second parameter that dictates the throwing of the result. And you can probably fix the second parameter to b

Re: What is the meaning of @future ?

2021-09-17 Thread Meta via Digitalmars-d-learn
On Friday, 17 September 2021 at 10:31:34 UTC, bauss wrote: On Thursday, 16 September 2021 at 20:53:34 UTC, Elmar wrote: Hello D community. I was browsing the `__traits` keywords and I found `isFuture` whose descriptions says something about `@future`-annotated variables. [link](https://dlan

Re: split Error - no overload matches

2022-02-15 Thread meta via Digitalmars-d-learn
A trick i use often: ```D import std; void main() { import uni = std.uni; writeln("Learning D is fun".split!(uni.isWhite)); } ``` Under-rated way of importing things, you don't bloat your scope anymore

Re: https://run.dlang.io/ vs All dmd compilers (2.060 - latest)

2022-02-27 Thread meta via Digitalmars-d-learn
Is the source of 'run.dlang.io' available somewhere?

Re: Colors in Raylib

2022-03-01 Thread meta via Digitalmars-d-learn
If the type is ``Color`` I think the compiler should allow ``GRAY`` if it is a member of ``Color``, isn't how strong statically typed language should work? I wonder what is the rational against it? How hard would it be to allow it?

Re: Colors in Raylib

2022-03-01 Thread meta via Digitalmars-d-learn
On Tuesday, 1 March 2022 at 12:29:56 UTC, Steven Schveighoffer wrote: On 3/1/22 7:22 AM, meta wrote: If the type is ``Color`` I think the compiler should allow ``GRAY`` if it is a member of ``Color``, isn't how strong statically typed language should work? I wonder what is the rational against

Re: Colors in Raylib

2022-03-03 Thread meta via Digitalmars-d-learn
On Tuesday, 1 March 2022 at 15:37:55 UTC, Ali Çehreli wrote: On 3/1/22 07:19, Mike Parker wrote: > On Tuesday, 1 March 2022 at 13:15:09 UTC, meta wrote: > >> >> enum Color >> { GRAY } >> >> void setColor(Color color); >> >> setColor(GRAY); > > Then that defeats the purpose of havi

Re: Warning on self assignment

2018-04-24 Thread Meta via Digitalmars-d-learn
On Wednesday, 25 April 2018 at 02:32:32 UTC, Per Nordlöw wrote: On Wednesday, 25 April 2018 at 02:23:04 UTC, Mike Franklin wrote: Are people using self assignment of structs as a way of force-running the postblit? Is there a valid use case for that? Mike If they are, there should be a bett

Re: Add property-like Function to Type ?

2018-04-24 Thread Meta via Digitalmars-d-learn
On Tuesday, 24 April 2018 at 21:36:19 UTC, Rubn wrote: I was wondering if I could create my own property in a way that can be used the same way as something like "T.sizeof". Right now I have the following to replace length: uint length32(T)(T[] array) { return cast(uint)array.length; } I

Re: Create variable for RedBlackTree range

2018-05-02 Thread Meta via Digitalmars-d-learn
On Wednesday, 2 May 2018 at 10:39:29 UTC, ag0aep6g wrote: On 04/28/2018 06:36 PM, Gerald wrote: What is the appropriate way to create a variable for the range returned by RedBlackTree lowerBound and upperBound. For example, given this code: ``` RedBlackTree!long promptPosition = redBlackTree!

Re: Ambiguous template parameter names

2018-05-02 Thread Meta via Digitalmars-d-learn
On Wednesday, 2 May 2018 at 20:32:43 UTC, jmh530 wrote: In the function below, there is a template parameter and a normal parameter both with the same name. However, the function returns the normal parameter. The template parameter is effectively ignored. I was surprised by this behavior. Is

Re: Ambiguous template parameter names

2018-05-02 Thread Meta via Digitalmars-d-learn
On Thursday, 3 May 2018 at 02:48:10 UTC, jmh530 wrote: On Thursday, 3 May 2018 at 00:52:58 UTC, Meta wrote: [snip] It's not a big per se. It's a consequence of the declaration expanding to the real template function form (I can't type it all out as I'm on my phone), thus the inner `val` from

Re: Extra .tupleof field in structs with disabled postblit blocks non-GC-allocation trait

2018-05-09 Thread Meta via Digitalmars-d-learn
On Wednesday, 9 May 2018 at 14:07:37 UTC, Per Nordlöw wrote: Why (on earth) does struct S { @disable this(this); int* _ptr; } pragma(msg, typeof(S.tupleof)); prints (int*, void*) when struct S { int* _ptr; } pragma(msg, typeof(S.tupleof

Re: Extra .tupleof field in structs with disabled postblit blocks non-GC-allocation trait

2018-05-09 Thread Meta via Digitalmars-d-learn
On Wednesday, 9 May 2018 at 18:04:40 UTC, Per Nordlöw wrote: On Wednesday, 9 May 2018 at 17:52:48 UTC, Meta wrote: I wasn't able to reproduce it on dmd-nightly: https://run.dlang.io/is/9wT8tH What version of the compiler are you using? Ahh, the struct needs to be in a unittest block for it t

Re: Extra .tupleof field in structs with disabled postblit blocks non-GC-allocation trait

2018-05-10 Thread Meta via Digitalmars-d-learn
On Thursday, 10 May 2018 at 12:55:36 UTC, Uknown wrote: On Thursday, 10 May 2018 at 11:06:06 UTC, Per Nordlöw wrote: On Wednesday, 9 May 2018 at 21:09:12 UTC, Meta wrote: It's a context pointer to the enclosing function/object/struct. Mark the struct as static to get rid of it. Ok, but why a

Re: Creating a template mixin for explicit casts.

2018-05-17 Thread Meta via Digitalmars-d-learn
On Thursday, 17 May 2018 at 15:25:37 UTC, Sjoerd Nijboer wrote: Given the following code `struct Foo(T) if(isNumeric!T) { T t; .. other code } struct Bar(T) if(isNumeric!T) { T t; .. other code } Foo!float foo_float; Foo!double foo_double; Bar!f

Re: try & catch / repeating code - DRY

2018-05-22 Thread Meta via Digitalmars-d-learn
On Tuesday, 22 May 2018 at 18:20:43 UTC, Robert M. Münch wrote: I see that I'm writing try { ... different code ... } catch (myException e) { ... same handling code ... } over and over again. Of course I can put the exception handling code into a function to not duplicate it. However,

Re: how to define infix function

2018-06-03 Thread Meta via Digitalmars-d-learn
On Saturday, 2 June 2018 at 23:17:48 UTC, Simen Kjærås wrote: On Saturday, 2 June 2018 at 22:09:49 UTC, Neia Neutuladh wrote: On Saturday, 2 June 2018 at 21:44:39 UTC, greatsam4sure wrote: Sorry for the typo is it possible to define infix function in D 3.min(5)// 3: where min is a function, w

Re: What is the point of nothrow?

2018-06-11 Thread Meta via Digitalmars-d-learn
On Monday, 11 June 2018 at 04:11:38 UTC, Bauss wrote: On Monday, 11 June 2018 at 00:47:27 UTC, Jonathan M Davis wrote: On Sunday, June 10, 2018 23:59:17 Bauss via Digitalmars-d-learn wrote: What is the point of nothrow if it can only detect when Exception is thrown and not when Error is thrown?

Re: foreach DFS/BFS for tree data-structure?

2018-06-14 Thread Meta via Digitalmars-d-learn
On Thursday, 14 June 2018 at 11:31:50 UTC, Robert M. Münch wrote: I have a simple tree C data-structure that looks like this: node { node parent: vector[node] children; } I would like to create two foreach algorthims, one follwing the breadth first search pattern and one the de

Re: Why tuples are not ranges?

2018-06-28 Thread Meta via Digitalmars-d-learn
On Thursday, 28 June 2018 at 17:00:37 UTC, Mr.Bingo wrote: I mean, if you think about it, the memory layout of a tuple is sequential types: T1 T2 ... So, to popFront a tuple is just changing the starting offset. You're right; it can definitely be done. struct TupleRange(T...) { size

Re: Implement Interface Using Super

2019-01-28 Thread Meta via Digitalmars-d-learn
On Monday, 28 January 2019 at 22:17:56 UTC, Steven Schveighoffer wrote: On 1/28/19 3:28 PM, Jonathan Levi wrote: On Sunday, 27 January 2019 at 09:31:46 UTC, bauss wrote: On Sunday, 27 January 2019 at 05:37:57 UTC, Jonathan Levi wrote: This works in LDC *but not* DMD? . . . Is this a bug in DMD

Re: Implement Interface Using Super

2019-01-29 Thread Meta via Digitalmars-d-learn
On Wednesday, 30 January 2019 at 01:02:37 UTC, Jonathan M Davis wrote: Yeah. It would be like trying to do something like alias x = this.x; As it stands, I believe that super is always either used as a function call to the constructor or to mean the this pointer for the base class. I don't th

Re: Query for -dip1000

2019-02-11 Thread Meta via Digitalmars-d-learn
On Sunday, 10 February 2019 at 20:04:29 UTC, Per Nordlöw wrote: Is there a way to query if the -dip1000 flag has been passed to the compiler? I need it for enabling certain DIP-1000 escape analysis tests only when -dip1000 has been passed. For instance static assert(!__traits(compiles, {

Re: Block statements and memory management

2019-03-15 Thread Meta via Digitalmars-d-learn
On Saturday, 16 March 2019 at 03:47:43 UTC, Murilo wrote: Does anyone know if when I create a variable inside a scope as in {int a = 10;} it disappears complete from the memory when the scope finishes? Or does it remain in some part of the memory? I am thinking of using scopes to make optimize

Re: How to debug long-lived D program memory usage?

2019-04-17 Thread Meta via Digitalmars-d-learn
On Wednesday, 17 April 2019 at 22:37:38 UTC, Adam D. Ruppe wrote: On Wednesday, 17 April 2019 at 19:07:46 UTC, Jacob Carlborg wrote: Perhaps try some of these flags [1] and [2]. oooh, those are very interesting too. What I was kinda hoping is it would have stats for which file and line of co

Re: Elegant way to test if members of array A are present in array B?

2019-06-12 Thread Meta via Digitalmars-d-learn
On Tuesday, 11 June 2019 at 17:12:17 UTC, Robert M. Münch wrote: Is there a simple and elegant way to do this? Or is just using a foreach(...) with canFind() the best way? There are two versions of find that can find a range within another: https://dlang.org/phobos/std_algorithm_searching.ht

Re: Fiber based UI-Toolkit

2017-07-09 Thread Meta via Digitalmars-d-learn
On Sunday, 9 July 2017 at 21:12:24 UTC, bauss wrote: On Sunday, 9 July 2017 at 19:43:14 UTC, Christian Köstlin wrote: I wonder if there is any fiber based / fiber compatible UI-Toolkit out for dlang. The second question is, if it would make sense at all to have such a thing? christian It do

Re: replacement for squeeze and removechars.

2017-07-18 Thread Meta via Digitalmars-d-learn
On Tuesday, 18 July 2017 at 15:28:06 UTC, Antonio Corbi wrote: Hi all, I'm trying dmd-2.075.0-rc1 in one of my projects where I use `squeeze` and `removechars`. Both of them are flagged as obsolete and in the docs we are suggested to use functions from std.regex and/or std.algorithm. Does a

Re: Array of Template instantiations

2017-07-20 Thread Meta via Digitalmars-d-learn
On Thursday, 20 July 2017 at 13:11:56 UTC, Alex wrote: On Thursday, 20 July 2017 at 12:33:43 UTC, Alex wrote: The Problem is, i dont know what type WHAT_TYPE is / i don´t know how to build a loopable something of futures. Ok, i think i understood now. my function `load` returns `KpiResponseEn

Re: Pass range to a function

2017-07-28 Thread Meta via Digitalmars-d-learn
On Thursday, 27 July 2017 at 21:16:03 UTC, Chris wrote: I'm using regex `matchAll`, and mapping it to get a sequence of strings. I then want to pass that sequence to a function. What is the general "sequence of strings" type declaration I'd need to use? In C#, it'd be `IEnumerable`. I'd rathe

Re: Is std.xml seriously broken, or is it me?

2017-07-29 Thread Meta via Digitalmars-d-learn
On Sunday, 30 July 2017 at 02:58:09 UTC, Mike wrote: I'm trying to use std.xml, and I can't get it to work. I tried the simplest program I could think of: import std.xml; import std.stdio; void main() { auto parser = new DocumentParser("encoding=\"utf-8\"?>"); parser.onStartTag["device"]

Re: Template mixins and selective imports

2017-08-03 Thread Meta via Digitalmars-d-learn
On Thursday, 3 August 2017 at 15:29:47 UTC, jmh530 wrote: I am trying to create a vectorize function that mixes in a new version of function with the same name that applies the function (to an ndslice). The code below compiles without error and has the behavior I would expect. However, when

Re: Template mixins and selective imports

2017-08-03 Thread Meta via Digitalmars-d-learn
On Thursday, 3 August 2017 at 19:03:55 UTC, Meta wrote: `mixin vectorize!sin vsin; alias sin = vsin;` and see if it Should be `alias sin = vsin.sin;`

Re: if (auto x = cast(C) x)

2017-08-09 Thread Meta via Digitalmars-d-learn
On Wednesday, 9 August 2017 at 21:54:46 UTC, Q. Schroll wrote: For a class/interface type `A` and a class `C` inheriting from `A` one can do A a = getA(); if (auto c = cast(C) a) { .. use c .. } to get a `C` view on `a` if it happens to be a `C`-instance. Sometimes one cannot find a goo

Re: Why does stringof not like functions with arguments?

2017-08-10 Thread Meta via Digitalmars-d-learn
On Wednesday, 9 August 2017 at 01:39:07 UTC, Jason Brady wrote: Why does the following code error out with: app.d(12,10): Error: function app.FunctionWithArguments (uint i) is not callable using argument types () Code: import std.stdio; void FunctionWithoutArguments() { } void FunctionWith

Re: Why does stringof not like functions with arguments?

2017-08-10 Thread Meta via Digitalmars-d-learn
On Thursday, 10 August 2017 at 15:55:41 UTC, Jason Brady wrote: Wow. That makes perfect sense. I forgot stringof works only with expressions It works with symbols too. See the following: template test(){} pragma(msg, test.stringof);

Re: Automatic function body writing howto?

2017-08-16 Thread Meta via Digitalmars-d-learn
It's hard to tell offhand but I would recommend that you extract the inner string into a function that generates that string, allowing you to print out the finished product before mixing it in.

Re: Choosing between enum arrays or AliasSeqs

2017-08-24 Thread Meta via Digitalmars-d-learn
On Thursday, 24 August 2017 at 19:41:46 UTC, Nordlöw wrote: Given enum e = ['a', 'b', 'c']; import std.meta : AliasSeq; enum a = AliasSeq!['a', 'b', 'c']; is it somehow possible to convert (at compile-time) `e` to `a`? Is it cheaper CT-performance wise to use AliasSeq instead of enu

Re: How to check if string is available at compile time

2017-09-21 Thread Meta via Digitalmars-d-learn
On Thursday, 21 September 2017 at 12:30:15 UTC, David Bennett wrote: On Thursday, 21 September 2017 at 11:42:36 UTC, David Bennett wrote: [snip] ``` string[] escapeCTFE(Args...)(){ static foreach (arg; Args){ static if(__traits(compiles, ###WHATDOIPUTHERE###)){ [snip] So far the

Re: Alias on an array element

2017-10-12 Thread Meta via Digitalmars-d-learn
On Friday, 13 October 2017 at 01:12:38 UTC, solidstate1991 wrote: On Friday, 13 October 2017 at 01:09:56 UTC, solidstate1991 wrote: I'm making a struct for easy color handling Here's a code sample: ublic struct Color{ union{ uint raw; ///Raw representation in integer form, also force

Re: Alias on an array element

2017-10-13 Thread Meta via Digitalmars-d-learn
On Friday, 13 October 2017 at 13:22:42 UTC, Adam D. Ruppe wrote: * Use a @property ref function to return the array element and trust the compiler to inline it. You could also use pragma(inline, true).

Re: std.algorithm

2017-11-30 Thread Meta via Digitalmars-d-learn
On Thursday, 30 November 2017 at 20:49:36 UTC, flamencofantasy wrote: Hello, I have the following csv text; auto input = "Start Date,End Date,Subject,All day event,Categories,Show time as 1/1/2018,1/1/2018,New Year's Day,TRUE,Holiday,3 1/15/2018,1/15/2018,\"Martin Luther King, Jr. Day\",TRUE

Re: Using enum types

2017-12-04 Thread Meta via Digitalmars-d-learn
On Monday, 4 December 2017 at 22:34:41 UTC, helxi wrote: Why can't enums be used as types in this (simplified) example? enum Positivity { Positive, Negative } struct Wave { public: Positivity slope; } enum Waves { Sin = Wave(Positivity.Positive), Cos = W

Re: Alias example should supposedly be illegal, but runs fine

2017-12-18 Thread Meta via Digitalmars-d-learn
On Monday, 18 December 2017 at 23:44:46 UTC, Michael wrote: Hello, I have been looking at the following example found right at the end of the section here: https://dlang.org/spec/declaration.html#alias struct S { static int i; } S s; alias a = s.i; // illegal, s.i is an expression alias b =

Re: structs inheriting from and implementing interfaces

2018-01-01 Thread Meta via Digitalmars-d-learn
On Friday, 29 December 2017 at 12:03:59 UTC, Mike Franklin wrote: In C#, structs can inherit from and implement interfaces. using System; interface IPrint { void Print(); } struct MyStruct : IPrint { public void Print() { Console.WriteLine(ToString()); } } public

Re: Cannot use local lambda as parameter to non-global template

2018-01-15 Thread Meta via Digitalmars-d-learn
On Monday, 15 January 2018 at 13:55:57 UTC, Nordlöw wrote: Why do I get errors like template instance remove!((_) => _ == 1) cannot use local '__lambda5' as parameter to non-global template remove()(in K key) for x.remove!(_ => _ == 1); but not for x.remove!"a == 11"; ? How are

Re: Rewriting a c++ template to D (replacing iterator with ranges "properly")

2018-01-26 Thread Meta via Digitalmars-d-learn
On Friday, 26 January 2018 at 14:16:04 UTC, aliak wrote: 1) I've seen some phobos code checking for assignability like this: is(typeof(range.front = false)) ... is that an advantage of that over hasAssignableElements? Or is that just basically combining constraints 3 and 4 which I have abo

Re: Error in template instantiation from D-Cookbook example

2018-02-09 Thread Meta via Digitalmars-d-learn
On Friday, 9 February 2018 at 21:31:29 UTC, ShadoLight wrote: writeln(parse(code)); // to aid with debugging writeln(convertToD(parse(code))); // debugging aid ..to.. writeln(parse(code)[]); // to aid with debugging writeln(convertToD(parse(

Re: opCast cannot implicitly convert a.opCast of type X to Y

2018-02-14 Thread Meta via Digitalmars-d-learn
On Monday, 12 February 2018 at 02:05:16 UTC, aliak wrote: From spec: Cast expression: "cast ( Type ) UnaryExpression" converts UnaryExpresssion to Type. And https://dlang.org/spec/operatoroverloading.html#cast makes no mention of the return type of opCast. One could think that the return type

Re: opCast cannot implicitly convert a.opCast of type X to Y

2018-02-14 Thread Meta via Digitalmars-d-learn
On Wednesday, 14 February 2018 at 23:46:30 UTC, aliak wrote: On Wednesday, 14 February 2018 at 15:14:24 UTC, Meta wrote: I think the best way to do this is to implement `map` for your optional type. Optional!U map(U, alias f)() { return empty? no!U : some!U(f(t)); } Optional!int a = 3;

Re: opCast cannot implicitly convert a.opCast of type X to Y

2018-02-14 Thread Meta via Digitalmars-d-learn
On Thursday, 15 February 2018 at 00:27:40 UTC, Meta wrote: On Wednesday, 14 February 2018 at 23:46:30 UTC, aliak wrote: On Wednesday, 14 February 2018 at 15:14:24 UTC, Meta wrote: Ooh yes, of course! Thank you :) Even better: import std.conv; auto b = a.map!(to!float); Actually, that won'

Re: Going from string to identifier

2018-02-21 Thread Meta via Digitalmars-d-learn
On Wednesday, 21 February 2018 at 22:11:04 UTC, Jean-Louis Leroy wrote: Here's what I am trying to do: mixin template MakeFun(string ID, int X) { int mixin(ID)() { return X; } } mixin MakeFun!("one", 1); // int one() { return 1; } Alas I get: makefunc.d(3): Error: no identifier for declarato

Re: Issue with traits usability

2018-03-23 Thread Meta via Digitalmars-d-learn
On Wednesday, 21 March 2018 at 15:36:01 UTC, Márcio Martins wrote: Hi! How do I get past this? static struct X { int x; private enum T = 1; private alias M = string; } foreach (Member; __traits(allMembers, X)) { pragma(msg, __traits(getProtection, __traits(getMember,

Re: Better way to append to array than ~= ?

2018-04-03 Thread Meta via Digitalmars-d-learn
On Tuesday, 3 April 2018 at 19:02:25 UTC, Vladimirs Nordholm wrote: Hello people. I currently have a function which multiple times per second takes in arguments, and appends the argument as my special type. The following code should explain what I do more properly: struct MySpecialType {

Re: Better way to append to array than ~= ?

2018-04-03 Thread Meta via Digitalmars-d-learn
On Tuesday, 3 April 2018 at 20:02:46 UTC, Vladimirs Nordholm wrote: On Tuesday, 3 April 2018 at 19:53:11 UTC, Meta wrote: On Tuesday, 3 April 2018 at 19:02:25 UTC, Vladimirs Nordholm wrote: [...] In this specific case, since you know the length of `Args`, you can pre-allocate an array of tha

Re: Tree datatype

2015-10-14 Thread Meta via Digitalmars-d-learn
On Wednesday, 14 October 2015 at 14:42:31 UTC, Namal wrote: Hello, I don't remember exactly but I think when I first saw D code there was tree datatype implemented without pointers. Is it possible to make a tree struct without pointers? The answer is more or less no, unless you sort of fake

Re: Why does File.byLine() return char[] and not string

2015-10-16 Thread Meta via Digitalmars-d-learn
On Friday, 16 October 2015 at 10:38:52 UTC, Shriramana Sharma wrote: Is there a particular reason that File.byLine() returns char[] and not string i.e. immutable(char)[]? Is it just to avoid being overly restrictive? It seems that having to .idup it is inefficient... byLine reuses an internal

Re: Why can't function expecting immutable arg take mutable input?

2015-10-16 Thread Meta via Digitalmars-d-learn
On Friday, 16 October 2015 at 10:35:23 UTC, Shriramana Sharma wrote: Hello. I still haven't wrapped my mind around the const/immutable thing yet and am still stuck in C/C++ mode. :-( A function that takes mutable arguments cannot be called with immutable input at the call site since it does no

Re: Why can't function expecting immutable arg take mutable input?

2015-10-16 Thread Meta via Digitalmars-d-learn
On Friday, 16 October 2015 at 12:48:42 UTC, Meta wrote: This doesn't work for char because it has indirections (a pointer to its data). Whoops, should be char[], not char.

Re: Idiomatic adjacent_difference

2015-10-16 Thread Meta via Digitalmars-d-learn
On Friday, 16 October 2015 at 15:02:54 UTC, anonymous wrote: On Friday, October 16, 2015 02:03 PM, Per Nordlöw wrote: zip(r, r.dropOne).map!((t) => t[1]-t[0]); You should r.save one or both of those. The dropOne may affect both instances if you don't .save. By the way, what's the point of

Re: Why does File.byLine() return char[] and not string

2015-10-18 Thread Meta via Digitalmars-d-learn
On Sunday, 18 October 2015 at 15:03:22 UTC, Suliman wrote: Sorry, but could you explain more simply? I reread all information, bit can't understand about what buffer you are talking. This is more or less how byLine works, simplified: struct ByLine { File file; char[] line; char[]

Re: std.algorithm.startsWith only predicate

2015-10-18 Thread Meta via Digitalmars-d-learn
On Sunday, 18 October 2015 at 17:48:20 UTC, Freddy wrote: How do you call startsWith with only a predicate --- import std.algorithm; import std.ascii; bool iden(string str) { return str.startsWith!(a => a.isAlpha || a == '_'); } --- Is this a simplified use case of some actual code you hav

Re: Mimicing Python list of list

2015-10-26 Thread Meta via Digitalmars-d-learn
On Monday, 26 October 2015 at 18:46:45 UTC, Dandyvica wrote: Hi all, I'm trying to find out a solution to implement a generic tree or array container whose nodes can either be elements or a subtree (or sub-array). Pretty much like you can do in Python: l = [1, 2, [1, 2, 3], 4] l is a list o

Re: Mimicing Python list of list

2015-10-26 Thread Meta via Digitalmars-d-learn
On Monday, 26 October 2015 at 20:53:18 UTC, Dandyvica wrote: Thanks Meta, great idea. But does I'd like to have something like dynamic arrays and be able to do this: class A(T) { T _v; this(T v) { _v = v; } } auto myContainer = MyContainerArray!(A!int)(); myContainer ~= new A!int(1); myCon

Re: very very thank you

2015-10-29 Thread Meta via Digitalmars-d-learn
On Thursday, 29 October 2015 at 06:13:17 UTC, guodemone wrote: 衷心的谢谢你,(very veryvery thank you in english) 请问,你是学生吧?你是哪个中国大学的学生?我也希望DLang可以进入中国的大学,祝你的OS好运!

Re: conver BigInt to string

2015-11-05 Thread Meta via Digitalmars-d-learn
On Thursday, 5 November 2015 at 16:29:30 UTC, Namal wrote: Hello I am trying to convert BigInt to string like that while trying to sort it: string s1 = to!string(a).dup.sort; and get an error cannot implicitly convert expression (_adSortChar(dup(to(a of type char[] to string what do I

Re: conver BigInt to string

2015-11-05 Thread Meta via Digitalmars-d-learn
On Thursday, 5 November 2015 at 20:45:45 UTC, TheGag96 wrote: Whoa whoa whoa... This is the first time I've heard about this difference, and I've used .sort plenty of times... That seems like really, REALLY bad design, especially considering the language allows functions to be called without pa

Re: std.variant.Algebraic, self referential types and delegate members

2015-11-08 Thread Meta via Digitalmars-d-learn
On Sunday, 8 November 2015 at 10:31:13 UTC, Panke wrote: import std.variant, std.stdio; --- struct NodeTypeA(T) { T[] children; } struct NodeTypeB(T) { Tree children; } struct Leaf(T) { T delegate() dg; } alias Tree = Algebraic!(Leaf, NodeTypeA!This, NodeTypeB!This); void main() { Tree t; }

Re: What does the -betterC switch in dmd do?

2015-11-15 Thread Meta via Digitalmars-d-learn
On Sunday, 15 November 2015 at 15:34:19 UTC, Jacob Carlborg wrote: I'm pretty sure that the only things that are excluded are module info and type info. It's still possible to use "new" and all the array features that requires support in the runtime (slicing, concatenation, appending and so on)

Re: Unable to call each on a lockstep range containing 2 or more ranges

2015-11-18 Thread Meta via Digitalmars-d-learn
On Wednesday, 18 November 2015 at 12:20:42 UTC, maik klein wrote: https://stackoverflow.com/questions/33779822/unable-to-call-each-on-a-lockstep-range-containing-2-or-more-ranges http://dpaste.dzfl.pl/76c79f1f12ab void main(){ import std.container; import std.stdio; import std.algorithm.i

Re: Unable to call each on a lockstep range containing 2 or more ranges

2015-11-18 Thread Meta via Digitalmars-d-learn
On Wednesday, 18 November 2015 at 17:40:21 UTC, maik klein wrote: On Wednesday, 18 November 2015 at 17:22:52 UTC, Meta wrote: Which version of the compiler are you using? Linux - DMD64 D Compiler v2.069.0 https://issues.dlang.org/show_bug.cgi?id=15357 https://issues.dlang.org/show_bug.cgi?id

Re: char[] == null

2015-11-18 Thread Meta via Digitalmars-d-learn
On Wednesday, 18 November 2015 at 23:53:01 UTC, Chris Wright wrote: --- char[] buffer; if (buffer.length == 0) {} --- This is not true. Consider the following code: import std.stdio; void main() { int[] a = [0, 1, 2]; //4002E000 3 writeln(a.ptr, " ", a.length);

Re: char[] == null

2015-11-19 Thread Meta via Digitalmars-d-learn
On Thursday, 19 November 2015 at 06:57:20 UTC, Jack Applegame wrote: Really? http://dpaste.dzfl.pl/b11346e8e341 Sorry, I said the exact opposite of what I meant to say. The `assert(a == null)` *is* triggered because the expression `a == null` fails, even though a.length == 0. You should not u

Re: char[] == null

2015-11-19 Thread Meta via Digitalmars-d-learn
On Thursday, 19 November 2015 at 13:49:18 UTC, Meta wrote: On Thursday, 19 November 2015 at 06:57:20 UTC, Jack Applegame wrote: Really? http://dpaste.dzfl.pl/b11346e8e341 Sorry, I said the exact opposite of what I meant to say. The `assert(a == null)` *is* triggered because the expression `a

Re: `finally` is redundant?

2015-11-21 Thread Meta via Digitalmars-d-learn
On Saturday, 21 November 2015 at 05:45:25 UTC, Shriramana Sharma wrote: The page http://dlang.org/exception-safe.html says: "It's try-finally that becomes redundant." IIUC this is because we have scope(exit). Does this mean that `finally` should eventually be removed from the language? The

  1   2   3   4   5   >