The standard library of the D programming language
Find a file
Jonathan M Davis ec0857574c
Add isSameSymbol and isSameType to v3 traits and indexOf to v3 meta. (#8960)
indexOf is phobos.sys.meta's version of std.meta's staticIndexOf.

The name was changed to better match our naming scheme. Because the
result of the template is a value and not a type or AliasSeq, it is
correct for it to be camelCased, but we don't normally prepend templates
with static, making it inconsistent to do so in the case of indexOf.

This might result in some symbol conflicts with indexOf from the
algorithm modules (assuming that we retain that function and its name
for Phobos v3), but a quick test showed that importing both
phobos.sys.meta and std.algorithm didn't result in a symbol conflict
when using the one from phobos.sys.meta. And even if we do get symbol
conflicts in some situations, the module system is designed to allow us
to deal with that.

As for the implementation, I've both made indexOf more flexible and more
straightforward.

staticIndexOf looks for an element in the AliasSeq which is "the same"
as the first argument, and that results in a big mess, since what "the
same" is varies considerably depending on what the elements are, and
staticIndexOf makes it even more complicated by evaluating some symbols
at CTFE if it can (e.g. evaluating a no-arg function that returns an int
to try to compare it to an integer literal) while not evaluating them in
other cases. Not only did trying to document the current behavior make
it clear that it's just way too confusing, but even trying to come up
with a sane simplification of how the comparison works was just too
messy, because it's trying to be able to compare just about anything
which you can stick in an AliasSeq. So, I punted on it by taking the
comparison out of the equation entirely.

indexOf now takes a template predicate. So, rather than looking for an
element which is the same, it looks for an element which matches the
predicate. This allows indexOf to be used in more cases than
staticIndexOf can be, _and_ it allows the programmer using it to decide
how the comparison works by choosing a predicate that matches what they
want.

So, in conjuction with that I added isSameSymbol and isSameType to
phobos.sys.traits, since those should correspond to the most common
searches that someone would be trying to do with staticIndexOf, but
since those traits are very specific in what they search for rather than
searching for an element which is "the same" in some nebulous sense, the
code should end up being much clearer and cleaner. And if someone wants
to do something completely different like indexOf!(isInteger, Types),
then they can, unlike with staticIndexOf.
2024-03-27 02:33:54 -07:00
.circleci Merge Makefiles 2023-12-16 22:22:20 +01:00
.github/workflows GHA: Sync main.yml with DMD repo's 2024-03-02 16:18:50 +01:00
changelog Mention improved compile time in changelog 2024-02-27 08:08:35 +08:00
etc/c Sync etc.c.zlib D bindings with updated zlib.h 2024-02-26 13:47:01 +08:00
phobos/sys Add isSameSymbol and isSameType to v3 traits and indexOf to v3 meta. (#8960) 2024-03-27 02:33:54 -07:00
std std/math/hardware.d: use an alternative register naming ... 2024-03-23 23:38:07 +01:00
test Add sumtype to Phobos (#7702) 2021-03-05 12:41:34 +01:00
tools Remove explicit hex string casts 2024-03-19 23:48:15 +01:00
.codecov.yml yaml: make files comply with YAML specification 2021-08-30 14:54:57 +00:00
.dscanner.ini Use static array for table 2024-01-08 00:02:21 +01:00
.editorconfig Fix line endings in .editorconfig 2018-09-16 12:19:04 -07:00
.gitignore Phobos 3 Setup (#8925) 2024-02-28 02:14:35 -08:00
CODEOWNERS Upstream Unicode table generator and update tables to v15 2022-12-12 02:10:14 +13:00
CONTRIBUTING.md Fix IRC link. (Freenode is dead, #d has been on libera for years.) 2024-01-17 15:41:09 +01:00
dub.sdl Rename lib to phobos. (#8953) 2024-03-20 15:12:06 -07:00
index.dd Remove deprecated std.xml module 2022-08-28 11:30:15 +02:00
LICENSE_1_0.txt Changed Phobos to use the Boost license. Currently, all public domain modules and all licensed modules by Walter, Andrei, Bartosz, and Don have been changed to use this license (excepting std.c, for the moment). Ideally, all Phobos modules will eventually be distributed under this license, which means obtaining permission from a few more authors, deleting, or rewriting some modules. 2009-09-16 18:19:51 +00:00
Makefile Fix bugzilla issue 24389 - Make Phobos compile on FreeBSD 14 again. 2024-02-24 06:48:09 +08:00
posix.mak Restore posix.mak, forwarding to generic Makefile 2023-12-16 22:22:20 +01:00
project.ddoc add PROJECT=phobos ddoc macro 2014-01-10 19:16:53 +01:00
README.md Remove no longer available issue stats and add a Buildkite badge 2019-01-04 18:02:28 +01:00
unittest.d Remove deprecated symbols from std.digest.digest 2020-04-09 11:35:23 +02:00

D Logo Phobos Standard Library

GitHub tag Bugzilla Issues CircleCi Buildkite Code coverage license

Phobos is the standard library that comes with the D Programming Language Compiler.

Download

Phobos is packaged together with the compiler. You should download the whole precompiled package.

To build everything yourself, there is a description in the wiki.

Phobos is distributed under Boost Software Licence. See the licence file.

I Want to Contribute

Great! See the CONTRIBUTING.md file.