(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
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
ng to deal with it
as properly typed. For it to be otherwise would require @system casts.
- Jonathan M Davis
rectly appending to a dynamic
array.
Hopefully all of that answers your questions or at least helps clarify
things.
- Jonathan M Davis
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
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
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
way to do this easily in the
> library.
https://dlang.org/phobos/std_utf.html#toUTFz
- Jonathan M Davis
sing data across threads.
So, for the forseeable future, explicit casts are generally going to be
required when dealing with shared.
- Jonathan M Davis
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
xactly what you need.
- Jonathan M Davis
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.
&
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
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
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
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
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
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 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
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
'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
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
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
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
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
be passed arguments.
- Jonathan M Davis
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
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
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
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
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
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
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
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
#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
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
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
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
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
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
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
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
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
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
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
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
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
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:
&
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
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
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
slice the container for you
automatically when using it with foreach.
- Jonathan M Davis
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
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:
> >>
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
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
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
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
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
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
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:
> >
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:
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
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
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
or Phobos is for darwin stuff,
since darwin isn't a predefined identifier.
- Jonathan M Davis
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
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
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
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
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
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
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
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
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
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
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
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:
> >>
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
; 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
rappers like byDchar or byCodeUnit if you want much of anything involving
strings to be nothrow.
- Jonathan M Davis
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
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
>
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
>
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
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
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
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
for
equality (whereas using == with references would compare the objects
themselves for equality).
- Jonathan M Davis
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
'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
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
it slicing were required.
- Jonathan M Davis
rror when accessing the
static array anyway, then you could just forgo all checks entirely and let
druntime throw a RangeError.
- Jonathan M Davis
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
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
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
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
ose member function,
because the module-level function is shadowed by the member function.
- Jonathan M Davis
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
101 - 200 of 4230 matches
Mail list logo