Re: Checking if a function pointer is set or null

2018-04-08 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, April 09, 2018 00:25:08 solidstate1991 via Digitalmars-d-learn wrote: > Would the if(!(myFunctionPointer is null)){} work is I > intended? You can also do if(myFunctionPointer !is null) - Jonathan M Davis

Re: Proper way to fix core.exception.UnicodeException@src\rt\util\utf.d(292): invalid UTF-8 sequence by File.readln()

2018-04-06 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, April 06, 2018 16:10:56 Dr.No via Digitalmars-d-learn wrote: > I'm reading line by line the lines from a CSV file provided by > the user which is assumed to be UTF8. But an user has provided an > > ANSI file which resulted in the error: >

Re: Compile-time variables

2018-04-05 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, April 06, 2018 00:35:39 Kayomn via Digitalmars-d-learn wrote: > On Friday, 6 April 2018 at 00:21:54 UTC, H. S. Teoh wrote: > > On Thu, Apr 05, 2018 at 11:53:00PM +, Kayomn via > > Digitalmars-d-learn wrote: [...] > > > >> [...] > > > > [...] > > > >> [...] > > > > `lastID`, as

Re: Construct immutable member in derived class

2018-04-05 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, April 05, 2018 13:36:07 Alex via Digitalmars-d-learn wrote: > On Wednesday, 4 April 2018 at 21:49:08 UTC, Timoses wrote: > > "[...] the construction of the base class can be independent > > from the derived one." > > > > Hm, the points 7 and 8 don't clearly state what you wrote. > >

Re: Construct immutable member in derived class

2018-04-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, April 04, 2018 21:46:13 Timoses via Digitalmars-d-learn wrote: > On Wednesday, 4 April 2018 at 18:11:12 UTC, Jonathan M Davis > > That code doesn't compile - at least not with dmd master. It > > gives these two errors: > > > > q.d(5): Error: constructor `q.A.this` missing initializer

Re: Construct immutable member in derived class

2018-04-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, April 04, 2018 16:05:52 Timoses via Digitalmars-d-learn wrote: > On Wednesday, 4 April 2018 at 10:41:52 UTC, Simen Kjærås wrote: > > Because by the time B's constructor is called, A might already > > have initialized it, and rely on it never changing. > > What about: > > ``` > class

Re: Learning D - modules packages and the package.d

2018-04-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, April 04, 2018 04:54:50 Ali via Digitalmars-d-learn wrote: > I am going through the Learning D book by Michael Parker > So every now and then I will make post about the book > either critics of the book, book content or questions > > > First critic > chapter 2 - the special package

Re: Optional parameters?

2018-04-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, April 01, 2018 22:34:16 Seb via Digitalmars-d-learn wrote: > On Sunday, 1 April 2018 at 15:54:16 UTC, Steven Schveighoffer > > wrote: > > I currently have a situation where I want to have a function > > that accepts a parameter optionally. > > > > I thought maybe Nullable!int might

Re: Optional parameters?

2018-04-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, April 01, 2018 22:37:17 Boris-Barboris via Digitalmars-d-learn wrote: > On Sunday, 1 April 2018 at 22:25:45 UTC, Jonathan M Davis wrote: > > How would a pointer help? Instead of doing > > > > foo(nullable(42)) > > > > he'd have to do > > > > foo(new int(42)) > > > > which is just one

Re: Optional parameters?

2018-04-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, April 01, 2018 22:06:57 Boris-Barboris via Digitalmars-d-learn wrote: > On Sunday, 1 April 2018 at 15:54:16 UTC, Steven Schveighoffer > > wrote: > > I currently have a situation where I want to have a function > > that accepts a parameter optionally. > > I would simply use a pointer

Re: Optional parameters?

2018-04-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, April 01, 2018 11:54:16 Steven Schveighoffer via Digitalmars-d- learn wrote: > I currently have a situation where I want to have a function that > accepts a parameter optionally. > > I thought maybe Nullable!int might work: > > void foo(Nullable!int) {} > > void main() > { > foo(1);

Re: How would you create this construct?

2018-03-29 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, March 30, 2018 02:30:01 Chris Katko via Digitalmars-d-learn wrote: > void start_draw_calls(BITMAP target_bitmap); //locks onto a > resource > void end_draw_calls(); //frees previous resource lock > > void my_function() > { > //... > > start_draw_calls(target_bitmap)

Re: Cleaner way of working with a shared resource?

2018-03-29 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, March 29, 2018 18:50:39 Chris M. via Digitalmars-d-learn wrote: > On Thursday, 29 March 2018 at 18:07:50 UTC, Jonathan M Davis > > wrote: > > On Thursday, March 29, 2018 17:41:15 Chris M. via > > > > Digitalmars-d-learn wrote: > >> [...] > > > > In general, the correct way to deal

Re: Cleaner way of working with a shared resource?

2018-03-29 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, March 29, 2018 17:41:15 Chris M. via Digitalmars-d-learn wrote: > I'm working with mysql-native for a project, and have been using > a single, shared Connection > (http://semitwist.com/mysql-native-docs/v2.2.0/mysql/connection/Connection > .html) among multiple threads. The issue here

Re: unittests, dub and libraries

2018-03-28 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, March 28, 2018 21:29:22 Jesse Phillips via Digitalmars-d-learn wrote: > On Wednesday, 28 March 2018 at 03:07:23 UTC, Jonathan M Davis > > wrote: > > Run > > > > dub test > > > > The problem is that an executable needs a main, and a library > > doesn't have one, whereas when

Re: unittests, dub and libraries

2018-03-27 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, March 28, 2018 02:16:59 Joe via Digitalmars-d-learn wrote: > I'm trying to build a very simple library. For now it just has a > single class, constructor, destructor and one method. I added a > unit test right after the method, declared the targetType to be > "library" and a

Re: utf.d codeLength asserts false on certain input

2018-03-27 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, March 27, 2018 23:29:57 Anonymouse via Digitalmars-d-learn wrote: > My IRC bot is suddenly seeing crashes. It reads characters from a > Socket into an ubyte[] array, then idups parts of that (full > lines) into strings for parsing. Parsing involves slicing such > strings into

Re: "in" no longer "scope" since 2.079.0?

2018-03-27 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, March 27, 2018 16:16:15 Adam D. Ruppe via Digitalmars-d-learn wrote: > On Tuesday, 27 March 2018 at 09:27:07 UTC, Jonathan M Davis wrote: > > it was deemed too dangerous to have in suddenly really mean > > both scope and const, because it would potentially break a lot > > of code. > >

Re: "in" no longer "scope" since 2.079.0?

2018-03-27 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, March 27, 2018 09:58:11 bauss via Digitalmars-d-learn wrote: > On Tuesday, 27 March 2018 at 09:27:07 UTC, Jonathan M Davis wrote: > > On Tuesday, March 27, 2018 09:15:43 Boris-Barboris via > > > > Digitalmars-d-learn wrote: > >> Hello! Can someone point me to the changelong entry or

Re: "in" no longer "scope" since 2.079.0?

2018-03-27 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, March 27, 2018 09:15:43 Boris-Barboris via Digitalmars-d-learn wrote: > Hello! Can someone point me to the changelong entry or maybe a > pull request, wich changed the "in" from "scope const" to > "const"? I thought the previous matter of things was pretty > natural, and current "in"

Re: Atomic vs Mutex

2018-03-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, March 26, 2018 23:15:42 Jonathan via Digitalmars-d-learn wrote: > Everywhere I look the advice is to avoid atomic and just mutex > things. > > Why is this `a.atomicStore(b)`(memory order is seq) less safe > than `synchronized{a=b}`? I get that when more operations or > shared values

Re: Optional type - how to correctly reset a wrapped immutable T

2018-03-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, March 26, 2018 10:13:08 Simen Kjærås via Digitalmars-d-learn wrote: > On Monday, 26 March 2018 at 09:46:57 UTC, Nicholas Wilson wrote: > > Have a look at Rebindable: > > https://dlang.org/phobos/std_typecons.html#rebindable > > Allow me to quote from aliak's post: > > what I'm looking

Re: recursive template expansion: Why does this not compile?

2018-03-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, March 21, 2018 22:50:32 Ontonator via Digitalmars-d-learn wrote: > On Wednesday, 21 March 2018 at 06:39:22 UTC, ag0aep6g wrote: > > On 03/21/2018 01:47 AM, Ontonator wrote: > >> The following code does not compile: > >>> [...] > >> > >> It gives the error: > >>> [...] > >> > >> The

Re: D's type declarations seem to read right to left.

2018-03-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, March 21, 2018 20:07:09 tipdbmp via Digitalmars-d-learn wrote: > D's type declarations seem to read right to left. > > > int an_integer; > > int[10] an_array_of_10_integers; > int[10]* a_pointer_to_an_array_of_10_integers = > _array_of_10_integers; > > int*[10]

Re: recursive template expansion: Why does this not compile?

2018-03-20 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, March 21, 2018 00:47:18 Ontonator via Digitalmars-d-learn wrote: > The following code does not compile: > > void main() {} > > > > class SuperClass {} > > > > class TemplatedClass(T : SuperClass) {} > > > > class A : SuperClass { > > > > alias T = TemplatedClass!B; > > > > } > >

Re: Packages and module import

2018-03-19 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, March 19, 2018 17:29:10 Russel Winder via Digitalmars-d-learn wrote: > I had assumed that a directory of modules was a package. So for > example: > > A/a.d > A/b.d > > were two modules in package A. Especially given there is a module > statement at the beginning of each module: > >

Re: Should the "front" range primitive be "const" ?

2018-03-18 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, March 19, 2018 00:14:11 Drone1h via Digitalmars-d-learn wrote: > I am not sure whether I can make it work with "inout" instead of > "const". Perhaps I am missing something. ... > May I ask that you confirm that this is what you suggested ? > Thank you. Marking a empty or front with

Re: Testing D database calls code for regression

2018-03-18 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, March 18, 2018 19:51:18 aberba via Digitalmars-d-learn wrote: > On Friday, 16 March 2018 at 21:15:33 UTC, H. S. Teoh wrote: > > On Fri, Mar 16, 2018 at 08:17:49PM +, aberba via > > > > Digitalmars-d-learn wrote: > >> [...] > > > > The usual way I do this is to decouple the code from

Re: how to make private class member private

2018-03-18 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, March 18, 2018 18:59:39 Tony via Digitalmars-d-learn wrote: > On Sunday, 18 March 2018 at 18:32:42 UTC, Jonathan M Davis wrote: > > They're similar, but there are differences. For instance, you > > can do package(a) in D in order to do something like put the > > stuff in a.b.c in

Re: how to make private class member private

2018-03-18 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, March 18, 2018 18:04:13 Tony via Digitalmars-d-learn wrote: > On Tuesday, 13 March 2018 at 06:03:11 UTC, Mike Parker wrote: > > D is not C++, C#, or Java. C++ uses friend to get around the > > issue. Java has no solution. I don't know about C#. > > Java has four protection levels. If

Re: Convert output range to input range

2018-03-17 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, March 17, 2018 06:58:04 Dukc via Digitalmars-d-learn wrote: > On Friday, 16 March 2018 at 08:07:09 UTC, Jonathan M Davis wrote: > > For instance, std.array.Appender is an output range, and you > > get a dynamic array out of it, which would be an input range. > > So, if you have

Re: Convert output range to input range

2018-03-16 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, March 16, 2018 07:57:04 John Chapman via Digitalmars-d-learn wrote: > I need to write to a range created with outputRangeObject, then > read from it. Is there a way to convert it to an input range? The output range API only supports the put function. That's it. The output range

Re: How do I make only the array itself immutable?

2018-03-14 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, March 15, 2018 02:06:23 Marc via Digitalmars-d-learn wrote: > Can I make it work? > > >struct S > >{ > > > > int[] l; > > > >} > > then > > >auto s = S(); > >s.l ~= 1; // ok > >s.l = []; // error It's not possible to do anything like that, and it really doesn't make sense when you

Re: Function argument that is a pointer to memory which the function is not allowed to modify, as in C const

2018-03-14 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, March 14, 2018 22:23:47 Cecil Ward via Digitalmars-d-learn wrote: > say in C I have a function with a pointer argument > foo( const sometype_t * p ) > > I have asked about this D nightmare before. Using the same > pattern in D or the in argument qualifier as far as I can see

Re: Why does struct initializer works for arrays but not for associative arrays?

2018-03-14 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, March 14, 2018 13:36:51 Andre Pany via Digitalmars-d-learn wrote: > Hi, > > I do not understand why struct initializer works for arrays but > not for > associative arrays: > > struct Bar > { > string s; > } > > struct Foo > { > Bar[string] asso; > Bar[] arr; > } > >

Re: "Error: address of variable this assigned to this with longer lifetime"

2018-03-14 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, March 14, 2018 07:11:49 Nathan S. via Digitalmars-d-learn wrote: > On Tuesday, 13 March 2018 at 22:33:56 UTC, Jonathan M Davis wrote: > > And you can't get rid of it, because the object can still be > > moved, which would invalidate the pointer that you have > > referring to the

Re: how to make private class member private

2018-03-13 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, March 13, 2018 22:25:52 Nathan S. via Digitalmars-d-learn wrote: > On Tuesday, 13 March 2018 at 21:36:13 UTC, Arun Chandrasekaran > > wrote: > > On Tuesday, 13 March 2018 at 13:59:00 UTC, Steven Schveighoffer > > > > wrote: > >> On 3/12/18 10:06 PM, psychoticRabbit wrote: > >>> [...] >

Re: "Error: address of variable this assigned to this with longer lifetime"

2018-03-13 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, March 13, 2018 21:35:50 Nathan S. via Digitalmars-d-learn wrote: > On Tuesday, 13 March 2018 at 21:07:33 UTC, ag0aep6g wrote: > > You're storing a reference to `small` in `data`. When a > > SmallString is copied, that reference will still point to the > > original `small`. When the

Re: how to make private class member private

2018-03-13 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, March 13, 2018 21:36:13 Arun Chandrasekaran via Digitalmars-d- learn wrote: > On Tuesday, 13 March 2018 at 13:59:00 UTC, Steven Schveighoffer > > wrote: > > On 3/12/18 10:06 PM, psychoticRabbit wrote: > >> [...] > > > > OK, so I agree there are drawbacks. But these can be worked > >

Re: overload binary + operator to work with different types

2018-03-13 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, March 13, 2018 18:55:35 Marc via Digitalmars-d-learn wrote: > I want to basically make this work: > >auto l = new List(); > >l += 5; > > I managed to do this: > >class List > >{ > > > > int[] items; > > ref List opBinary(string op)(int rhs) if(op == "+") > > { > > > > items ~= rhs;

Re: how to make private class member private

2018-03-13 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, March 13, 2018 02:06:57 psychoticRabbit via Digitalmars-d-learn wrote: > On Tuesday, 13 March 2018 at 01:39:13 UTC, Jonathan M Davis wrote: > > private is private to the module, not the class. There is no > > way in D to restrict the rest of the module from accessing the > > members

Re: how to make private class member private

2018-03-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, March 13, 2018 01:12:15 psychoticRabbit via Digitalmars-d-learn wrote: > I cannot get my head around, why private is not private, in D. > > How do I make a private member, private? > > - > module test; > > import std.stdio; > > void main() > { > myClass c = new myClass(); >

Re: Date range iteration

2018-03-11 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, March 12, 2018 02:11:49 Jordan Wilson via Digitalmars-d-learn wrote: > I wanted to iterate through a date range, so I initially tried: > iota(Date(2016,1,1),Date(2018,1,1),dur!"days"(1)); > > That wouldn't compile, which is fair enough I guess. Maybe iota should be made to work, but

Re: Inner Classes vs. Inner Structs

2018-03-11 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, March 11, 2018 13:19:39 Mike Franklin via Digitalmars-d-learn wrote: > This works: > > ``` > class S { > int n, m; > int sum() { return n + m; } > Inner!(sum) a; > > class Inner(alias f){ > auto get() { > return f(); > } > } > } >

Re: UFCS in generic libraries, silent hijacking, and compile errors.

2018-03-11 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, March 11, 2018 08:39:54 aliak via Digitalmars-d-learn wrote: > On Saturday, 10 March 2018 at 23:00:07 UTC, Jonathan M Davis > > issue in practice. That doesn't mean that it's never a problem, > > but from what I've seen, it's very rarely a problem, and it's > > easy to work around if

Re: List installed modules

2018-03-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, March 11, 2018 01:04:27 Roberto via Digitalmars-d-learn wrote: > How do I list installed modules? > > dmd --list-modules > datefmt > dateparser > std.algorithm > std.array > std.conv > std.datetime > std.digest > std.exception > std.file > std.format > std.getopt > std.json > std.math >

Re: UFCS in generic libraries, silent hijacking, and compile errors.

2018-03-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, March 10, 2018 21:50:42 aliak via Digitalmars-d-learn wrote: > What are the recommended guidelines for using/not using UFCS in > writing generic libraries? > > I ask because if you have an internal generic free function that > you use on types in a generic algorithm via ufcs, then

Re: Consume binary files

2018-03-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, March 10, 2018 19:22:43 Bogdan via Digitalmars-d-learn wrote: > On Saturday, 10 March 2018 at 18:49:48 UTC, Jonathan M Davis > > wrote: > > Check out > > > > https://dlang.org/phobos/std_bitmanip.html#peek > > https://dlang.org/phobos/std_bitmanip.html#read > > > > They can be used to

Re: Consume binary files

2018-03-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, March 10, 2018 18:31:23 Bogdan via Digitalmars-d-learn wrote: > ... I accidentally posted that before it was complete because I > kept pressing TAB in order to indent ... > > Anyway, I'd like to know if there exists such a thing as > > ``` > int a = stream.ReadInt32(); > ```

Re: does the shared keyword work with mutable structs?

2018-03-09 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, March 09, 2018 19:33:26 WhatMeWorry via Digitalmars-d-learn wrote: > On Friday, 9 March 2018 at 10:42:47 UTC, Kagamin wrote: > > To make a struct noncopyable, add @disable this(this); to it, > > then compiler will give an error on an attempt to copy it. > > I tried the @disable

Re: How to fake a const method ?

2018-03-09 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, March 09, 2018 14:12:10 Basile B. via Digitalmars-d-learn wrote: > On Friday, 9 March 2018 at 13:47:34 UTC, Basile B. wrote: > > I would need this to work: > > > > ``` > > struct Foo > > { > > > > TypeInfo typeCache; > > > > TypeInfo getTypeCache() > > { > > > >

Re: Preffered way of writing variadic templated functions in 2.079

2018-03-08 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, March 08, 2018 08:36:09 Nordlöw via Digitalmars-d-learn wrote: > Is using > > https://dlang.org/changelog/2.079.0.html#default_after_variadic > > for instance as > > void show(Args...)(Args args, > string file = __FILE__, > uint line = __LINE__,

Re: How to use globals correctly?

2018-03-06 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, March 06, 2018 11:52:05 H. S. Teoh via Digitalmars-d-learn wrote: > On Tue, Mar 06, 2018 at 11:46:04AM -0700, Jonathan M Davis via Digitalmars-d-learn wrote: > > On Tuesday, March 06, 2018 18:34:34 bauss via Digitalmars-d-learn wrote: > [...] > > > > Singleton

Re: How to use globals correctly?

2018-03-06 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, March 06, 2018 18:34:34 bauss via Digitalmars-d-learn wrote: > On Monday, 5 March 2018 at 19:51:33 UTC, Steven Schveighoffer > > wrote: > > On 3/5/18 2:25 PM, Marc wrote: > >> Can __gshared be used instead of static in the singleton > >> pattern? I, comming from C++, ignorantly, have

Re: Are files in dub's "copyFiles" copied every time dub is run?

2018-03-05 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, March 05, 2018 21:26:48 Marc via Digitalmars-d-learn wrote: > if so, can I somehow make it copy only if newest? It actually would have been my guess that it would copy too infrequently - e.g. only on a fresh build - but I don't know. IIRC, it does have that problem when running

Re: isInputRange copied verbatim produces a different result than isInputRange from std.range

2018-03-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, March 04, 2018 21:03:23 arturg via Digitalmars-d-learn wrote: > On Sunday, 4 March 2018 at 19:58:14 UTC, ag0aep6g wrote: > > On 03/04/2018 08:54 PM, aliak wrote: > >> wait a minute... so I can't use any std.range functions on a > >> type if I add the range primitives as free functions?

Re: Template Class With Default Values

2018-03-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, March 04, 2018 14:43:41 bauss via Digitalmars-d-learn wrote: > On Sunday, 4 March 2018 at 11:57:12 UTC, Jonathan M Davis wrote: > > On Sunday, March 04, 2018 11:35:23 bauss via > > > > Digitalmars-d-learn wrote: > >> Why is the following not working? > >> > >> class Foo(string baz =

Re: Template Class With Default Values

2018-03-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, March 04, 2018 11:35:23 bauss via Digitalmars-d-learn wrote: > Why is the following not working? > > class Foo(string baz = "baz") > { > mixin("int " ~ baz ~ ";"); > } > > class Bar : Foo > { > } > > Shouldn't it implicit do, without me having to do it manually? > > class Bar :

Re: Unexpected behaviour of foreach statement

2018-03-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, March 02, 2018 10:21:39 Arredondo via Digitalmars-d-learn wrote: > Hi, > > The following works as expected: > > auto range = [1, 2, 3, 4, 5]; > foreach (i, el; range) { > writeln(i, ": ", el); > } > > but this slight modification doesn't: > > auto range = iota(5); > foreach (i, el;

Re: single loop copy in D

2018-03-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, March 02, 2018 09:44:20 psychoticRabbit via Digitalmars-d-learn wrote: > trying to do this C code, in D, but getting error: > "Error: assignment cannot be used as a condition, perhaps `==` > was meant?" > > any help much appreciated: > > -- > while ((*dst++ = *src++)) {} > --

Re: Assigning to slice of array

2018-03-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, March 01, 2018 23:51:37 Jamie via Digitalmars-d-learn wrote: > On a similar not, is there an accepted way to assign across > arrays? As Steve mentioned, cross-slicing isn't supported, so is > the best way to iterate through the array and assign as necessary? That's what you would

Re: Assigning to slice of array

2018-03-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, March 01, 2018 22:57:16 Jamie via Digitalmars-d-learn wrote: > On Thursday, 1 March 2018 at 21:34:41 UTC, Jonathan M Davis wrote: > > Don't put the indices within the brackets. What you want is > > > > auto arr = new int[][][](3, 2, 1); > > Okay thanks, but I don't understand what is

Re: Assigning to slice of array

2018-03-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, March 01, 2018 21:16:54 Jamie via Digitalmars-d-learn wrote: > I'm trying to understand arrays and have read a lot of the > information about them on this forum. I think I understand that > they are set-up like Type[], so that int[][] actually means an > array of int[]. > > I create

Re: Garbage collected pointers?

2018-03-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, March 01, 2018 15:53:08 Steven Schveighoffer via Digitalmars-d- learn wrote: > On 3/1/18 3:33 PM, H. S. Teoh wrote: > > Won't a precise GC scanning for pointers to aligned objects want to skip > > values that can't be an aligned pointer? Though in D's case, being > > required to be

Re: Garbage collected pointers?

2018-03-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, March 01, 2018 14:52:26 Steven Schveighoffer via Digitalmars-d- learn wrote: > On 3/1/18 2:04 PM, Jonathan M Davis wrote: > > On Thursday, March 01, 2018 10:55:34 Steven Schveighoffer via > > Digitalmars-d-> > > learn wrote: > >> It should really say that it's up to the GC

Re: Garbage collected pointers?

2018-03-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, March 01, 2018 10:55:34 Steven Schveighoffer via Digitalmars-d- learn wrote: > It should really say that it's up to the GC implementation whether it's UB > or not. Well, that arguably makes it UB in general then, because it can't be relied on. By putting restrictions on the GC in

Re: is it regression?

2018-02-28 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, February 28, 2018 14:28:47 bauss via Digitalmars-d-learn wrote: > On Wednesday, 28 February 2018 at 13:38:56 UTC, drug wrote: > > done https://issues.dlang.org/show_bug.cgi?id=18539 > > I would argue that isn't a regression and that you __should__ use > the .get and that it's not a

Re: iota to array

2018-02-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, February 26, 2018 18:33:13 H. S. Teoh via Digitalmars-d-learn wrote: > Well, the way I deal with floating point is, design my code with the > assumption that things will be inaccurate, and compensate accordingly. The way that I usually deal with it is to simply not use floating point

Re: iota to array

2018-02-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, February 26, 2018 17:49:21 H. S. Teoh via Digitalmars-d-learn wrote: > On Tue, Feb 27, 2018 at 12:26:56AM +, psychoticRabbit via Digitalmars- d-learn wrote: > > On Tuesday, 27 February 2018 at 00:04:59 UTC, H. S. Teoh wrote: > > > A 64-bit double can only hold about 14-15 decimal

Re: iota to array

2018-02-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, February 26, 2018 16:04:59 H. S. Teoh via Digitalmars-d-learn wrote: > On Mon, Feb 26, 2018 at 11:34:06PM +, psychoticRabbit via > Digitalmars-d-learn wrote: [...] > > > and what's going on here btw? > > > > assert( 1 == 1.01 ); // assertion error in DMD but not >

Re: mixed in struct constructor is ignored when another (non mixed in) constructor is specified

2018-02-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, February 26, 2018 12:30:24 ParticlePeter via Digitalmars-d-learn wrote: > mixin template Common() { >private int m_member; >this( int m ) { m_member = m; } > } > > struct Foo { >mixin Common; > } > > struct Bar { >mixin Common; >this( int m, float n ) { m_member = m

Re: iota to array

2018-02-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, February 25, 2018 06:22:03 psychoticRabbit via Digitalmars-d- learn wrote: > On Sunday, 25 February 2018 at 05:40:19 UTC, Jonathan M Davis > > wrote: > > int[] intArr = iota(1, 11).array(); > > > > - Jonathan M Davis > > thanks! > > oh man. It's so easy to do stuff in D ;-) > > But

Re: iota to array

2018-02-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, February 25, 2018 05:24:54 psychoticRabbit via Digitalmars-d- learn wrote: > Hi. Anyone know whether something like this is possible? > > I've tried various conversions/casts, but no luck yet. > > Essentially, I want to cast the result set of the iota to an > array, during

Re: countUntil to print all the index of a given string.

2018-02-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, February 25, 2018 02:58:33 Seb via Digitalmars-d-learn wrote: > On Sunday, 25 February 2018 at 02:37:00 UTC, Jonathan M Davis > > wrote: > > If any exceptions could be thrown, then a lazy solution can't > > be @nogc (something that's often the case with strings thanks > > to

Re: countUntil to print all the index of a given string.

2018-02-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, February 25, 2018 01:49:05 Seb via Digitalmars-d-learn wrote: > On Tuesday, 20 February 2018 at 08:44:37 UTC, aberba wrote: > > On Sunday, 18 February 2018 at 15:23:14 UTC, Cym13 wrote: > >> On Sunday, 18 February 2018 at 14:48:59 UTC, Cym13 wrote: > >>> [...] > >> > >> Just thought of

Re: compilers w/ different language features: version block

2018-02-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, February 25, 2018 00:36:16 kdevel via Digitalmars-d-learn wrote: > A code fragment using static foreach > > https://forum.dlang.org/thread/jiefcxwqbjzqnmtaz...@forum.dlang.org#post-b > eruryblsptnunsowjph:40forum.dlang.org > > does not compile with the current GDC (GCC 4.9.4 and 5.5.0).

Re: Template Constraints

2018-02-23 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, February 24, 2018 04:33:52 psychoticRabbit via Digitalmars-d- learn wrote: > On Saturday, 24 February 2018 at 04:22:12 UTC, Jonathan M Davis > > wrote: > > Why is there anything dodgy going on and why would you need > > contracts? Contracts actually tend to go very badly with > >

Re: Template Constraints

2018-02-23 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, February 24, 2018 04:13:30 psychoticRabbit via Digitalmars-d- learn wrote: > On Saturday, 24 February 2018 at 03:58:48 UTC, Jonathan M Davis > > wrote: > > Whether an implicit cast or an explicit cast makes more sense > > depends entirely on what the code is doing, but either way, the

Re: Template Constraints

2018-02-23 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, February 24, 2018 03:48:44 psychoticRabbit via Digitalmars-d- learn wrote: > On Saturday, 24 February 2018 at 03:43:25 UTC, Jonathan M Davis > > wrote: > > That does not do what the OP requested at all. That tests > > whether T is one of byte, ubyte, short, ushort, int, uint, > >

Re: Template Constraints

2018-02-23 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, February 24, 2018 03:30:45 psychoticRabbit via Digitalmars-d- learn wrote: > On Saturday, 24 February 2018 at 02:54:13 UTC, Jonathan wrote: > > I am having trouble finding many useful explanations of using > > template constraints beyond basic usage. > > > > I would like to have a

Re: Template Constraints

2018-02-23 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, February 24, 2018 03:04:53 psychoticRabbit via Digitalmars-d- learn wrote: > On Saturday, 24 February 2018 at 02:54:13 UTC, Jonathan wrote: > > I am having trouble finding many useful explanations of using > > template constraints beyond basic usage. > > > > I would like to have a

Re: Template Constraints

2018-02-23 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, February 24, 2018 02:54:13 Jonathan via Digitalmars-d-learn wrote: > I am having trouble finding many useful explanations of using > template constraints beyond basic usage. > > I would like to have a template constrant to enforce that a type > can be explicitly cast to another type:

Re: Game and GC

2018-02-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, February 23, 2018 01:54:07 Leonardo via Digitalmars-d-learn wrote: > Hi, I'm new to language and games. > Many people say that GC is bad and can slow down your project in > some moments. > What can happen if I create a game using D without worrying with > memory management? > (using

Re: C++ std::string_view equivalent in D?

2018-02-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, February 21, 2018 10:17:55 0x via Digitalmars-d-learn wrote: > On Wednesday, 21 February 2018 at 09:21:58 UTC, 0x wrote: > > What is the equivalent of C++17 std::string_view (an object > > that can refer to a constant contiguous sequence of char-like > > objects with

Re: C++ std::string_view equivalent in D?

2018-02-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, February 21, 2018 09:21:58 0x via Digitalmars-d-learn wrote: > What is the equivalent of C++17 std::string_view (an object that > can refer to a constant contiguous sequence of char-like objects > with the first element of the sequence at position zero) in D? > > PS: I'm

Re: Manually allocating a File

2018-02-20 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, February 21, 2018 02:59:21 Nicholas Wilson via Digitalmars-d- learn wrote: > On Tuesday, 20 February 2018 at 15:32:45 UTC, Chris M. wrote: > > Thanks for the info, that clears things up. Like I said, it was > > more experimentation rather than me planning to actually use > > it.

Re: countUntil to print all the index of a given string.

2018-02-20 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, February 20, 2018 08:44:37 aberba via Digitalmars-d-learn wrote: > On Sunday, 18 February 2018 at 15:23:14 UTC, Cym13 wrote: > > On Sunday, 18 February 2018 at 14:48:59 UTC, Cym13 wrote: > >> [...] > > > > Just thought of a much better/simpler solution for that last > > case that also

Re: Building from source on FreeBSD

2018-02-19 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, February 19, 2018 14:41:21 Seb via Digitalmars-d-learn wrote: > On Monday, 19 February 2018 at 12:01:31 UTC, Jonathan M Davis > > wrote: > > On Monday, February 19, 2018 11:43:26 psychoticRabbit via > > > > Digitalmars-d- learn wrote: > >> [...] > > > > I've never been able to figure

Re: Building from source on FreeBSD

2018-02-19 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, February 19, 2018 11:43:26 psychoticRabbit via Digitalmars-d- learn wrote: > So I finally got around to building from source. > > I have builds working just fine on a variety of linux machines, > it's just a FreeBSD problem I'm having. > > So, on FreeBSD, I can build the dmd directory,

Re: std.array.array for immutable data types

2018-02-19 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, February 19, 2018 07:25:07 Nicholas Wilson via Digitalmars-d- learn wrote: > On Monday, 19 February 2018 at 07:08:49 UTC, Fra Mecca wrote: > > Is there a way to avoid using to! conversion here? > > > > immutable string[] dst = to!(immutable > > string[])(array(pipe.readEnd.byLineCopy));

Re: isFuture

2018-02-18 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, February 18, 2018 19:10:02 Tofu Ninja via Digitalmars-d-learn wrote: > What is __traits(isFuture)? The language documents says it tests > for @future which doesn't really help as @future is undocumented. https://github.com/dlang/DIPs/blob/master/DIPs/DIP1007.md - Jonathan M Davis

Appending to ddoc macros

2018-02-16 Thread Jonathan M Davis via Digitalmars-d-learn
Does anyone know if there's a way to append to a ddoc macro instead of replacing it? For instance, dlang.org has the EXTRA_HEADERS macro for adding extra stuff to the header of a web page, and it uses that with several pages defining EXTRA_HEADERS to add headers to that specific page. I have

Re: static opSlice is not possible

2018-02-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, February 15, 2018 23:22:17 Adam D. Ruppe via Digitalmars-d- learn wrote: > On Thursday, 15 February 2018 at 23:20:42 UTC, Jonathan M Davis > > wrote: > > The only overloaded operator that I'd expect to work as static > > would be opCall, which I expect works primarily because of > >

Re: static opSlice is not possible

2018-02-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, February 15, 2018 22:49:56 Alex via Digitalmars-d-learn wrote: > Hi all, > a short question about an old bug: > https://issues.dlang.org/show_bug.cgi?id=11877 > > Are there reasons, which speaks against this feature? > > And maybe another one, more general: > Is there any place, where

Re: ubyte[4] to int

2018-02-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, February 15, 2018 18:47:16 Kyle via Digitalmars-d-learn wrote: > I was thinking that the client could determine its own endianness > and either convert the passed int to the other if big, or leave > it alone if little, then send it to the server as little-endian > at that point.

Re: ubyte[4] to int

2018-02-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, February 15, 2018 17:53:54 Kyle via Digitalmars-d-learn wrote: > I want to be able to pass an int to a function, then in the > function ensure that the int is little-endian (whether it starts > out that way or needs to be converted) before additional stuff is > done to the passed int.

Re: ubyte[4] to int

2018-02-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, February 15, 2018 17:21:22 Nicholas Wilson via Digitalmars-d- learn wrote: > On Thursday, 15 February 2018 at 16:51:05 UTC, Kyle wrote: > > Hi. Is there a convenient way to convert a ubyte[4] into a > > signed int? I'm having trouble handling the static arrays > > returned by

Re: ubyte[4] to int

2018-02-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, February 15, 2018 16:51:05 Kyle via Digitalmars-d-learn wrote: > Hi. Is there a convenient way to convert a ubyte[4] into a signed > int? I'm having trouble handling the static arrays returned by > std.bitmanip.nativeToLittleEndian. Is there some magic sauce to > make the static

Re: No error message in DMD 2.078.2

2018-02-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, February 13, 2018 05:51:05 Domain via Digitalmars-d-learn wrote: > module main; > > void main () > { > writeln("Hello"); > } > > Of course, this won't compile, but error message is confused: > > C:\Git\hello\source>dmd app.d > app.d(5): Error: > object.Error@(0): Access Violation

Re: What should I use for concat string into array in loop?

2018-02-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, February 12, 2018 17:56:45 H. S. Teoh via Digitalmars-d-learn wrote: > On Tue, Feb 13, 2018 at 01:58:42AM +, Marc via Digitalmars-d-learn wrote: > > appender doesn't support string[] so in such case: > Why not? This seems to work: > > import std.array; > import std.stdio; >

<    2   3   4   5   6   7   8   9   10   11   >