Re: A couple of questions about arrays and slices

2023-06-24 Thread Jonathan M Davis via Digitalmars-d-learn
(n). But you can only know which is faster by testing it out with the actual data that you're dealing with. Regardless, you need to remember that associative arrays are not arrays in the C sense. Rather, they're hash tables, so they function very differently from dynamic arrays, and the rehash function is the closest that you're going to get to affecting how the elements are laid out internally or how much memory the AA is using. - Jonathan M Davis

Re: A couple of questions about arrays and slices

2023-06-23 Thread Jonathan M Davis via Digitalmars-d-learn
ements, but in general, you don't do much to manage an AA's memory. It's a much more complicated data structure than an array. https://dlang.org/spec/hash-map.html - Jonathan M Davis

Re: A couple of questions about arrays and slices

2023-06-21 Thread Jonathan M Davis via Digitalmars-d-learn
ng to deal with it as properly typed. For it to be otherwise would require @system casts. - Jonathan M Davis

Re: A couple of questions about arrays and slices

2023-06-20 Thread Jonathan M Davis via Digitalmars-d-learn
rectly appending to a dynamic array. Hopefully all of that answers your questions or at least helps clarify things. - Jonathan M Davis

Re: How does D’s ‘import’ work?

2023-06-18 Thread Jonathan M Davis via Digitalmars-d-learn
ast. However, if you want to maximize the efficiency of your code, then you definitely want to be building the binaries that you actually use or release with ldc or gdc. - Jonathan M Davis

Re: C++'s this() equivalent?

2023-06-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, June 15, 2023 7:54:22 PM MDT Jonathan M Davis via Digitalmars-d- learn wrote: > On Thursday, June 15, 2023 7:18:25 PM MDT zjh via Digitalmars-d-learn wrote: > > On Friday, 16 June 2023 at 01:00:05 UTC, Steven Schveighoffer > > > > wrote: > > > B b = B.ma

Re: C++'s this() equivalent?

2023-06-15 Thread Jonathan M Davis via Digitalmars-d-learn
method though is to just use a factory function on a struct. Yes, it's more annoying than proper RAII, but it's a side effect of other benefits that D gives that C++ does not. - Jonathan M Davis

Re: Calling C functions that modify a string

2023-06-15 Thread Jonathan M Davis via Digitalmars-d-learn
way to do this easily in the > library. https://dlang.org/phobos/std_utf.html#toUTFz - Jonathan M Davis

Re: how to assign to shared obj.systime?

2020-07-10 Thread Jonathan M Davis via Digitalmars-d-learn
sing data across threads. So, for the forseeable future, explicit casts are generally going to be required when dealing with shared. - Jonathan M Davis

Re: how to assign to shared obj.systime?

2020-07-10 Thread Jonathan M Davis via Digitalmars-d-learn
he object as thread-local. It's then up to you to ensure that no thread-local references to the shared data escape the section of code protected by the mutex (though scope may help with that if used in conjunction with -dip1000). - Jonathan M Davis

Re: What's the point of static arrays ?

2020-07-09 Thread Jonathan M Davis via Digitalmars-d-learn
xactly what you need. - Jonathan M Davis

Re: called copy constructor in foreach with ref on Range

2020-06-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, June 22, 2020 9:25:55 PM MDT Stanislav Blinov via Digitalmars-d- learn wrote: > On Tuesday, 23 June 2020 at 02:41:55 UTC, Jonathan M Davis wrote: > > As things stand, uncopyable ranges aren't really a thing, and > > common range idiomns rely on ranges being copyable. &

Re: called copy constructor in foreach with ref on Range

2020-06-22 Thread Jonathan M Davis via Digitalmars-d-learn
is set up so that the same code can operate on both basic input and forward ranges, we pretty much inherently have a problem with the copying semantics in ranges being inconsistent - though requiring value semantics for forward ranges would still be a significant improvement. - Jonathan M Davis

Re: called copy constructor in foreach with ref on Range

2020-06-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, June 22, 2020 3:11:07 PM MDT Stanislav Blinov via Digitalmars-d- learn wrote: > On Monday, 22 June 2020 at 20:51:37 UTC, Jonathan M Davis wrote: > > You're unlikely to find much range-based code that does that > > and there really isn't much point in doing that. Again, co

Re: called copy constructor in foreach with ref on Range

2020-06-22 Thread Jonathan M Davis via Digitalmars-d-learn
likely that you're going to find much in Phobos that happens to work with them. isForwardRange does outright reject them though. - Jonathan M Davis

Re: Temporary File Creation

2020-06-22 Thread Jonathan M Davis via Digitalmars-d-learn
ee: https://dlang.org/library/std/file/temp_dir.html I created a PR for one a while back that resulted in a surprisingly large amount of arguing. IIRC, there were some tweaks I still needed to make to get it merged, but I keep forgetting to get back to it. - Jonathan M Davis

Re: called copy constructor in foreach with ref on Range

2020-06-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, June 22, 2020 3:10:28 PM MDT kinke via Digitalmars-d-learn wrote: > On Monday, 22 June 2020 at 20:51:37 UTC, Jonathan M Davis wrote: > > [...] > > That's why I put the struct in parantheses. Moving a class ref > makes hardly any sense, but I've also neve

Re: called copy constructor in foreach with ref on Range

2020-06-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, June 22, 2020 1:41:34 PM MDT kinke via Digitalmars-d-learn wrote: > On Monday, 22 June 2020 at 19:03:44 UTC, Jonathan M Davis wrote: > > in practice, that means that generic code cannot use a range > > once it's been copied > > Translating to a simple rule-of-thumb:

Re: called copy constructor in foreach with ref on Range

2020-06-22 Thread Jonathan M Davis via Digitalmars-d-learn
re leeway, because it can rely on the behavior of specific range types, but with generic code, you have to be careful. And foreach is just one of the places where the issue of not using the original after making a copy comes up. - Jonathan M Davis

Re: called copy constructor in foreach with ref on Range

2020-06-22 Thread Jonathan M Davis via Digitalmars-d-learn
each(e; range) { } auto v = range.front; in generic code. It needs to be foreach(e; range.save) { } auto v = range.front; instead. - Jonathan M Davis

Re: final switch problem

2020-06-13 Thread Jonathan M Davis via Digitalmars-d-learn
'll get who-knows-what weird behavior happening if you have a bug with what you pass to the the switch (and of course, you lose assertions in general). It does sound like the problem that's resulting in the compilation error relates to the invisible default case that gets generated without -release though. - Jonathan M Davis

Re: Should opIndex take precedence over pointer indexing?

2020-06-12 Thread Jonathan M Davis via Digitalmars-d-learn
vert expression > `foo[cast(ulong)idx]` of type `Foo` to `float` > > IE, pointer indexing of 'foo' takes precedence over the opIndex > of foo. Is this expected? Yes, it's expected behavior. . is the only operator which implicitly dereferences a pointer. - Jonathan M Davis

Re: What is the current stage of @property ?

2020-06-10 Thread Jonathan M Davis via Digitalmars-d-learn
see @property in quite a lot of D code, but ultimately, all it's really doing is serving as documentation of the author's intent and screwing up metaprogramming. - Jonathan M Davis

Re: Distinguish between a null array and an empty array

2020-05-24 Thread Jonathan M Davis via Digitalmars-d-learn
in a Nullable would be _far_ less error-prone if you need to differentiate between an array that's empty and not having a value. - Jonathan M Davis

Re: opEquals @safe is ignored

2020-05-24 Thread Jonathan M Davis via Digitalmars-d-learn
u're basically forced to use @trusted when comparing class references in @safe code. It's annoying, but because Object's opEquals is @system, we're kind of stuck at the moment. - Jonathan M Davis

Re: Asserting that a base constructor is always called

2020-05-24 Thread Jonathan M Davis via Digitalmars-d-learn
be passed arguments. - Jonathan M Davis

Re: Asserting that a base constructor is always called

2020-05-23 Thread Jonathan M Davis via Digitalmars-d-learn
r base class but no default constructor, then you'd get a compile-time error if your derived class' constructor didn't explicitly call it. - Jonathan M Davis

Re: any chance to get it working on windows xp?

2020-05-18 Thread Jonathan M Davis via Digitalmars-d-learn
you're not going to be able to pull in much of anything with dub that way, because the older compiler likely won't be able to compile the newer code, and I don't know if a version of dub that old will ever work with the current dub repository. - Jonathan M Davis

Re: Retrieve the return type of the current function

2020-05-05 Thread Jonathan M Davis via Digitalmars-d-learn
nt i) { return!string(i); } or string bar(string s, int i) { return!(typeof(return))(i); } but you're not going to be have foo figure out anything about its caller on its own. - Jonathan M Davis

Re: How can I check if an element is iterable?

2020-05-03 Thread Jonathan M Davis via Digitalmars-d-learn
uld have to be dealt with at compile time, so all of the checks for whether a type was iteraterable or not would be done at compile time. - Jonathan M Davis

Re: Help, what is the code mean?

2020-04-28 Thread Jonathan M Davis via Digitalmars-d-learn
at has to be examined to make sure that it actually is memory safe and that the programmer didn't use @trusted correctly. - Jonathan M Davis

Re: make dub use my version of dmd

2020-04-16 Thread Jonathan M Davis via Digitalmars-d-learn
y life I've wasted because of my own stupidity with stuff like this... I _was_ going to suggest just building dub yourself, since that's what I have on my system (with it in ~/bin), and I've never had this problem, but clearly, you found the issue. :) - Jonathan M Davis

Re: No implicit opOpAssign for structs with basic types?

2020-04-04 Thread Jonathan M Davis via Digitalmars-d-learn
ly have to write an overloaded operator for such cases? You could just use the constructor syntax. e.g. S a = S(1, 5); S b = S(2, 5); - Jonathan M Davis

Re: OR in version conditional compilation

2020-03-20 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, March 20, 2020 4:33:58 PM MDT jxel via Digitalmars-d-learn wrote: > On Friday, 20 March 2020 at 21:03:55 UTC, Jonathan M Davis wrote: > > On Wednesday, March 18, 2020 10:23:26 AM MDT IGotD- via > > > > Digitalmars-d-learn wrote: > >> I have not seen any exa

Re: OR in version conditional compilation

2020-03-20 Thread Jonathan M Davis via Digitalmars-d-learn
#ifdefs come up with static ifs in generic code (particularly with range-based code that changes what it's doing based on arange's type), but at least those can be found with thorough tests on a single platform, whereas version-related bugs tend to require that you run thorough tests on each platform. - Jonathan M Davis

Re: std.datetime & timzone specifier: 2018-11-06T16:52:03+01:00

2020-03-09 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, March 8, 2020 11:19:33 PM MDT tchaloupka via Digitalmars-d-learn wrote: > On Sunday, 8 March 2020 at 17:28:33 UTC, Robert M. Münch wrote: > > On 2020-03-07 12:10:27 +, Jonathan M Davis said: > > > > DateTime dt = > > DateTime.fromISOExtString(split

Re: std.datetime & timzone specifier: 2018-11-06T16:52:03+01:00

2020-03-07 Thread Jonathan M Davis via Digitalmars-d-learn
o*String functions unless you're just printing to a log or something, and there's no real risk of the string being intepreted as a time value by a program in the future. - Jonathan M Davis

Re: Difference between range `save` and copy constructor

2020-02-16 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, February 16, 2020 12:22:01 PM MST Paul Backus via Digitalmars-d- learn wrote: > On Sunday, 16 February 2020 at 18:11:11 UTC, Jonathan M Davis > > wrote: > > Either way, generic code should never be using a range after > > it's been copied, and copying is a key

Re: Difference between range `save` and copy constructor

2020-02-16 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, February 16, 2020 10:53:36 AM MST Paul Backus via Digitalmars-d- learn wrote: > On Sunday, 16 February 2020 at 17:10:24 UTC, Jonathan M Davis > > wrote: > > On Sunday, February 16, 2020 7:29:11 AM MST uranuz via > > > >> This is working fine with disabl

Re: Difference between range `save` and copy constructor

2020-02-16 Thread Jonathan M Davis via Digitalmars-d-learn
though, any range that is a forward range should have copying it be equivalent to save, and using reference types for forward ranges tends to be inefficient and error-prone even if range-based functions (especially those in Phobos) should be able to handle them correctly. - Jonathan M Davis

Re: Difference between range `save` and copy constructor

2020-02-16 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, February 16, 2020 7:29:11 AM MST uranuz via Digitalmars-d-learn wrote: > On Sunday, 16 February 2020 at 12:38:51 UTC, Jonathan M Davis > > wrote: > > On Sunday, February 16, 2020 3:41:31 AM MST uranuz via > > > > Digitalmars-d-learn wrote: > >> I

Re: Difference between range `save` and copy constructor

2020-02-16 Thread Jonathan M Davis via Digitalmars-d-learn
s which are reference types so that copying them simply results in another reference to the same data such that iterating one copy iterates all copies. - Jonathan M Davis

Re: Difference between range `save` and copy constructor

2020-02-15 Thread Jonathan M Davis via Digitalmars-d-learn
g save on them would requires allocating a now object, and that gets expensive fast. As part of testing dxml, I tested it with forward ranges that were classes in order to make sure that they were handled correctly, and their performance was absolutely terrible in comparison to ranges that were structs or strings. - Jonathan M Davis

Re: Assoc array init

2020-02-04 Thread Jonathan M Davis via Digitalmars-d-learn
hat may or may not be fixed in the future (e.g. originally, it wasn't possible to have class objects transfer from compile-time to runtime, but at some point, that was fixed). Either way, for now, it means that if you want to initialize an AA like the one here, you will need to use a static constructor. - Jonathan M Davis

Re: Empty string vs null

2020-02-04 Thread Jonathan M Davis via Digitalmars-d-learn
either have to make sure that success never resulted in an empty array being returned, or you would have to make it clear in the documentation that the is operator must be used to check for null rather than == and ensure that even if an empty array is returned, it will never null. It can work, but ultimately, for public APIs, it's arguably better to use Nullable from std.typecons to differentiate. It has the downside that the return type is larger, but it's less error-prone. For code that isn't part of a public API (especially code that only you work on), it's less risky to explicitly return null rather than using Nullable, but it's still a risk - especially if the code gets changed over time. - Jonathan M Davis

Re: Cannot implicitly convert expression [[0, -1, 2], [4, 11, 2]] of type int[][] to const(int[2])[]

2020-01-31 Thread Jonathan M Davis via Digitalmars-d-learn
o, neither C/C++ nor D is entirely consistent, but the basic rule is that types are read outwards from the variable name, which is why you get the weirdness with static array dimensions in D. - Jonathan M Davis

Re: auto keyword

2020-01-30 Thread Jonathan M Davis via Digitalmars-d-learn
ost of the time. It can take a bit of getting used to, but ultimately, it actually results in more maintainable code. - Jonathan M Davis

Re: How to convert "string" to const(wchar)* ?

2020-01-29 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, January 29, 2020 12:16:29 AM MST Ferhat Kurtulmuş via Digitalmars-d-learn wrote: > On Wednesday, 29 January 2020 at 06:53:15 UTC, Jonathan M Davis > > wrote: > > On Tuesday, January 28, 2020 10:17:03 PM MST Marcone via > > > > Digitalmars-d-learn wrote: &

Re: How to convert "string" to const(wchar)* ?

2020-01-28 Thread Jonathan M Davis via Digitalmars-d-learn
ns, it's not a problem, but it can definitely be a problem if the C function stores that pointer even after the function has returned. Keeping a pointer to that memory in your D code fixes that problem, because then the D GC can see that that memory is still referenced and thus should not be collected. - Jonathan M Davis

Re: Lexicographic comparison of arrays (of chars)

2020-01-22 Thread Jonathan M Davis via Digitalmars-d-learn
ey could change at any time. In the case of core.internal.array, the only reason that any of it is even exposed is because it had to be when it was changed to a template. - Jonathan M Davis

Re: range algorithms on container class

2020-01-18 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, January 15, 2020 9:13:05 AM MST Paul Backus via Digitalmars-d- learn wrote: > On Thursday, 9 January 2020 at 10:26:07 UTC, Jonathan M Davis > > wrote: > > On Wednesday, January 8, 2020 10:56:20 PM MST rikki cattermole > > > > via Digitalmars-d-le

Re: range algorithms on container class

2020-01-09 Thread Jonathan M Davis via Digitalmars-d-learn
slice the container for you automatically when using it with foreach. - Jonathan M Davis

Re: range algorithms on container class

2020-01-09 Thread Jonathan M Davis via Digitalmars-d-learn
that you can iterate over the container without altering it. And if you use a container with foreach, the compiler will actually insert the opSlice call for you. Alternatively, you can define opApply on the container. Outside of foreach though, you'd have to explicitly slice the container. - Jonathan M Davis

Re: @disable("reason")

2020-01-09 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, January 8, 2020 2:58:59 PM MST Marcel via Digitalmars-d-learn wrote: > On Wednesday, 8 January 2020 at 07:03:26 UTC, Jonathan M Davis > > wrote: > > On Tuesday, January 7, 2020 5:23:48 PM MST Marcel via > > > > Digitalmars-d-learn wrote: > >>

Re: @disable("reason")

2020-01-08 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, January 8, 2020 4:54:06 AM MST Simen Kjærås via Digitalmars-d- learn wrote: > On Wednesday, 8 January 2020 at 07:03:26 UTC, Jonathan M Davis > > wrote: > > you could just document that no one should ever use its init > > value explicitly, and that they will

Re: @disable("reason")

2020-01-07 Thread Jonathan M Davis via Digitalmars-d-learn
hat they shouldn't). It's unlikely that many people will try to use the init value explicitly, but some generic code may do so (e.g. IIRC, std.algorithm's move function uses it on the source variable after moving the value to the target variable). - Jonathan M Davis

Re: @safe std.file.read

2020-01-06 Thread Jonathan M Davis via Digitalmars-d-learn
hould accept void[], because then you can write any binary data to it without casting (including objects which are being serialized), whereas reading should give you ubyte[] or const(ubyte)[], because what you're getting from the OS is bytes of data, and it's up to the program to figure out what to do with them. - Jonathan M Davis

Re: Thin UTF8 string wrapper

2019-12-07 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, December 7, 2019 5:23:30 AM MST Joseph Rushton Wakeling via Digitalmars-d-learn wrote: > On Saturday, 7 December 2019 at 03:23:00 UTC, Jonathan M Davis > > wrote: > > The module to look at here is std.utf, not std.encoding. > > Hmmm, docs may need updating then

Re: Thin UTF8 string wrapper

2019-12-06 Thread Jonathan M Davis via Digitalmars-d-learn
u about the state of the string once you start actually operating on the data, but once you start operating on it, that knowledge is probably no longer valid anyway (especially if you're passing it to a function which is going to return a wrapper range to mutate the elements in the range rather than something like find which just looks at the range). - Jonathan M Davis

Re: opCmp with and without const

2019-12-06 Thread Jonathan M Davis via Digitalmars-d-learn
ate this parameters, so I don't know how well they'll work in this particular case), but ultimately, one way or another, you need to have a non-const opCmp declared for when the wrapped types don't have an opCmp that works with const and a const or inout opCmp for when the wrapped types do have an opCmp that works with const. - Jonathan M Davis

Re: Unexpectedly nice case of auto return type

2019-12-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, December 3, 2019 3:23:20 AM MST Basile B. via Digitalmars-d- learn wrote: > On Tuesday, 3 December 2019 at 10:19:02 UTC, Jonathan M Davis > > wrote: > > On Tuesday, December 3, 2019 3:03:22 AM MST Basile B. via > > > > Digitalmars-d- learn wrote: > >

Re: Unexpectedly nice case of auto return type

2019-12-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, December 3, 2019 3:03:22 AM MST Basile B. via Digitalmars-d- learn wrote: > On Tuesday, 3 December 2019 at 09:58:36 UTC, Jonathan M Davis > > wrote: > > On Tuesday, December 3, 2019 12:12:18 AM MST Basile B. via > > > > Digitalmars-d- learn wrote:

Re: Unexpectedly nice case of auto return type

2019-12-03 Thread Jonathan M Davis via Digitalmars-d-learn
dded to the language, null by itself had no type, since it's just a literal representing the null value for any pointer or class reference. The result was that using null in generic code or with auto could run into issues. typeof(null) was added to solve those problems. - Jonathan M Davis

Re: Building and running DMD tests

2019-12-01 Thread Jonathan M Davis via Digitalmars-d-learn
e, not for running the tests in the test folder. Those are built using the makefile in the test folder or by running the test target from the primary makefile with the target test (which also runs the unittest blocks in the src folder), whereas you're specifically using the makefile in src. - Jonathan M Davis

Re: How to create DDoc for string mixin generated functions?

2019-11-26 Thread Jonathan M Davis via Digitalmars-d-learn
ntly be done with string mixins. There's on open bug report / enhancement request somewhere on bugzilla to fix it so that you can document string mixins, but unless someone has done something to fix that very recently, no one has yet to implement a fix. - Jonathan M Davis

Re: static assert(version(x)) ?

2019-11-26 Thread Jonathan M Davis via Digitalmars-d-learn
or Phobos is for darwin stuff, since darwin isn't a predefined identifier. - Jonathan M Davis

Re: What is the point of a synchronized lock on a single return statement?

2019-11-25 Thread Jonathan M Davis via Digitalmars-d-learn
ething here? It ensures that no other code that locks m_lock is running when m_closed is accessed. I'd have to study std.concurrency in detail to know for sure why that would be needed, but it's not atypical when trying to maintain consistent state when multiple threads are interacting with each other. - Jonathan M Davis

Re: why local variables cannot be ref?

2019-11-25 Thread Jonathan M Davis via Digitalmars-d-learn
hereas pointers still allow for full freedom but in return, they require that certain operations that relate to them be @system (like &, ++, and --). - Jonathan M Davis

Re: Parsing with dxml

2019-11-18 Thread Jonathan M Davis via Digitalmars-d-learn
ed out with -release. On an unrelated note, std.range.primitives.popFrontN (or std.range.popFrontN, since std.range publicly imports std.range.primitives) does what your pops function does - and it does it more efficiently for ranges which have slicing (which dxml's EntityRange doesn't, but either way, you can just use the function from Phobos instead of writing your own). - Jonathan M Davis

Re: Should I stop being interested in D language if I don't like to see template instantiation in my code?

2019-11-13 Thread Jonathan M Davis via Digitalmars-d-learn
C++'s standard library, D's standard library uses templates quite a bit, and it's extremely common for D code in general to use templates. I don't know why you think that using an exclamation point for template instantiations is ugly, but if you can't stand it, you're not going to be happy with D, because you're going to see it quite a lot in typical D code. - Jonathan M Davis

Re: Alias sleep(int) for Thread.sleep(dur!("seconds")( int ));

2019-11-12 Thread Jonathan M Davis via Digitalmars-d-learn
takes a Duration specifically because it makes for clearer code and is less error-prone than using a naked integer (since a naked integer has no units). - Jonathan M Davis

Re: Unexpected aliasing

2019-11-11 Thread Jonathan M Davis via Digitalmars-d-learn
lt-initialized struct of that type will refer to the same dynamic array). Of course, you could always just append values, and the dynamic array will be allocated and grow accordingly, but that's obviously not the same as allocating it up front to have a specific length. - Jonathan M Davis

Re: A question about postblit constructor

2019-11-06 Thread Jonathan M Davis via Digitalmars-d-learn
rstand postblit constructors, any code you're writing now should probably use copy constructors. So, if you have a good understanding of copy constructors and are having trouble with postblit constructors, presumably, that's an improvement for you, though you may still need to deal with postblit constructors in existing code that other people have written. - Jonathan M Davis

Re: No UFCS with nested functions?

2019-11-05 Thread Jonathan M Davis via Digitalmars-d-learn
t; >> } > >> --- > > > > [...] > > > > > > T > > Is this a necessary limitation? It feels inconsistent and clunky. It's explained at the end of this section of the documentation: https://dlang.org/spec/function.html#pseudo-member - Jonathan M Davis

Re: Is there any writeln like functions without GC?

2019-11-02 Thread Jonathan M Davis via Digitalmars-d-learn
e with > other std modules/language features. > > *: > https://www.auburnsounds.com/blog/2016-11-10_Running-D-without-its-runtime > .html You can always just use printf. - Jonathan M Davis

Re: Documentation: is it intentional that template constraints are displayed after the signature?

2019-11-01 Thread Jonathan M Davis via Digitalmars-d-learn
trait is and how old that overload of destroy is, the trait may or may not have been an option when that overload of destroy was written). - Jonathan M Davis

Re: Using a char value >= 128

2019-10-27 Thread Jonathan M Davis via Digitalmars-d-learn
e). That being said, it doesn't make sense to use startsWith with a single char which isn't ASCII, because no such char would be valid UTF-8 on its own. - Jonathan M Davis

Re: About the in expression, Why can't use with array.

2019-10-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, October 24, 2019 8:40:59 PM MDT lili via Digitalmars-d-learn wrote: > On Thursday, 24 October 2019 at 22:40:31 UTC, Jonathan M Davis > > wrote: > > On Thursday, October 24, 2019 7:04:56 AM MDT Paul Backus via > > > > Digitalmars-d- learn wrote: > >>

Re: About the in expression, Why can't use with array.

2019-10-24 Thread Jonathan M Davis via Digitalmars-d-learn
ry provides functions like canFind or find for finding elements in an array, so having in work with arrays wouldn't add any functionality. It would basically just change the syntax you'd use for finding an element in an array. - Jonathan M Davis

Re: Why isn't skipOver(string, string) nothrow?

2019-10-22 Thread Jonathan M Davis via Digitalmars-d-learn
; But startsWith(string, string) is nothrow so skipOver should be > that too. That's only true with startsWith, because it avoids decoding in the case where the two strings have the same encoding (e.g. it's not nothrow if you compare a dstring and a string). Presumably, skipOver could be made to do the same, but no one has done so. - Jonathan M Davis

Re: Why isn't skipOver(string, string) nothrow?

2019-10-22 Thread Jonathan M Davis via Digitalmars-d-learn
rappers like byDchar or byCodeUnit if you want much of anything involving strings to be nothrow. - Jonathan M Davis

Re: Some questions about GC

2019-10-18 Thread Jonathan M Davis via Digitalmars-d-learn
with dynamic arrays involving allocation), and if you truly don't want to use the GC for that stuff, it's probably going to be easier to require that your program not use the GC at all than to try to have it just manage cycles. Regardless, if you really want to go forward with something like you're proposing here, you'll probably need to get answers from one of the few GC experts around here. - Jonathan M Davis

Re: How Different Are Templates from Generics

2019-10-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, October 12, 2019 9:48:02 PM MDT jmh530 via Digitalmars-d-learn wrote: > On Saturday, 12 October 2019 at 21:44:57 UTC, Jonathan M Davis > > wrote: > > [snip] > > Thanks for the reply. > > As with most people, I don't write a lot of D code that uses >

Re: How Different Are Templates from Generics

2019-10-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, October 12, 2019 2:11:28 PM MDT jmh530 via Digitalmars-d-learn wrote: > On Friday, 11 October 2019 at 17:50:42 UTC, Jonathan M Davis > > wrote: > > [snip] > > A very thorough explanation! > > One follow-up question: would it be possible to mimic the >

Re: selective tests

2019-10-12 Thread Jonathan M Davis via Digitalmars-d-learn
up. Really, if you want to control which tests get run instead of simply always running them all, then you'll need to use an alternate test runner which supports that. There are a few test runners available on code.dlang.org, and I expect that at least one of them supports that (probably multiple do). - Jonathan M Davis

Re: _getmaxstdio / _setmaxstdio

2019-10-11 Thread Jonathan M Davis via Digitalmars-d-learn
iate library. Given that the header is stdio.h, that would presumably be Microsoft's C runtime library, which probably means that you'd need to tell dmd to use Microsoft's C runtime and not dmc's C runtime. - Jonathan M Davis

Re: How Different Are Templates from Generics

2019-10-11 Thread Jonathan M Davis via Digitalmars-d-learn
int would both be implementing the same interface, because in both cases, it would be ISomeInterface!int. SomeClass!int and SomeOtherClass!float would not be implementing the same interface, because it would be ISomeInterface!int and ISomeInterface!float, but ISomeInterface!int doesn't result in multiple instantiations even if it's used in different parts of the code. - Jonathan M Davis

Re: How Different Are Templates from Generics

2019-10-11 Thread Jonathan M Davis via Digitalmars-d-learn
ates outright generate code, you can do a lot more with them than you could ever do with generics (e.g. making code differ based on the template arguments by using template constraints and/or static if). D's compile-time capabilities actually make it extremely powerful for generating code, and templates are a key part of that. - Jonathan M Davis

Re: C#'s 'is' equivalent in D

2019-10-10 Thread Jonathan M Davis via Digitalmars-d-learn
for equality (whereas using == with references would compare the objects themselves for equality). - Jonathan M Davis

Re: Dynamic Arrays as Stack and/or Queue

2019-10-08 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, October 8, 2019 2:42:22 PM MDT mipri via Digitalmars-d-learn wrote: > On Tuesday, 8 October 2019 at 10:48:45 UTC, Jonathan M Davis > > wrote: > > The result of this is that code like > > > > stack.popBack(); > > stack ~= foo; > > stack ~= bar

Re: Ranges to deal with corner cases and "random access"

2019-10-08 Thread Jonathan M Davis via Digitalmars-d-learn
's way too easy for a type to pass a template constraint thanks to alias this and then have trouble because it passed based on the implicit conversion, but the conversion wasn't forced in the code using the type. You can get some really subtle problems if the code converts to the alias in some cases but not in others. - Jonathan M Davis

Re: Dynamic Arrays as Stack and/or Queue

2019-10-08 Thread Jonathan M Davis via Digitalmars-d-learn
minimize the number of allocations while still avoiding constantly moving the elements around, but as with a stack, it's the sort of thing where you'd want to wrap the dynamic array in a struct or class to manage all of the logic required for pushing and popping elements instead of using a naked dynamic array. - Jonathan M Davis

Re: How does D distnguish managed pointers from raw pointers?

2019-10-04 Thread Jonathan M Davis via Digitalmars-d-learn
it slicing were required. - Jonathan M Davis

Re: Using enforce or assert to check for fullness when appending to fixed length array container

2019-10-04 Thread Jonathan M Davis via Digitalmars-d-learn
rror when accessing the static array anyway, then you could just forgo all checks entirely and let druntime throw a RangeError. - Jonathan M Davis

Re: Struct initialization has no effect or error?

2019-10-03 Thread Jonathan M Davis via Digitalmars-d-learn
still error-prone, but at least you then eliminate the bugs where you initialize the wrong members and instead just get the ones where new members end up with the default value whether it's appropriate or not. - Jonathan M Davis

Re: C++ base constructor call vs. D's

2019-10-02 Thread Jonathan M Davis via Digitalmars-d-learn
ints "D" class C { string foo() { return "C"; } this() { import std.stdio; writeln(foo()); } } class D : C { override string foo() { return "D"; } } void main() { auto d = new D; } whereas C++ equivalent would likely blow up in your face. - Jonathan M Davis

Re: Why dynamic array is InputRange but static array not.

2019-09-24 Thread Jonathan M Davis via Digitalmars-d-learn
then you need to slice it to get a dynamic array - though when you do that, make sure that the dynamic array is not around longer than the static array, because it's just a slice of the static array, and if the static array goes out of scope, then the dynamic array will then refer to invalid memory. - Jonathan M Davis

Re: wstring comparison is failing

2019-09-23 Thread Jonathan M Davis via Digitalmars-d-learn
oUTFz), and you have to strip it off when getting a string from C code (e.g. with fromStringz). Other than functions specifically designed to convert to and from C strings, D code is going to treat null terminators just like any other character, because D strings are not null-terminated. - Jonathan M Davis

Re: what is the mean that call function start with a dot.

2019-09-22 Thread Jonathan M Davis via Digitalmars-d-learn
ose member function, because the module-level function is shadowed by the member function. - Jonathan M Davis

Re: Looking for a Simple Doubly Linked List Implementation

2019-09-21 Thread Jonathan M Davis via Digitalmars-d-learn
k with, whereas nodes in a linked list are normally private to the list, so it's easy to ensure that they're only ever on the heap even if they're structs). - Jonathan M Davis

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