mirror of
https://github.com/dlang/phobos.git
synced 2025-04-28 06:00:35 +03:00
The standard library of the D programming language
algorithmsallocatorconcurrencycontainersddlangfunctionalhacktoberfestmathmetaparallelismphobosrangesregexstandard-librarystdiotraitstype-conversionunicode
![]() 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. |
||
---|---|---|
.circleci | ||
.github/workflows | ||
changelog | ||
etc/c | ||
phobos/sys | ||
std | ||
test | ||
tools | ||
.codecov.yml | ||
.dscanner.ini | ||
.editorconfig | ||
.gitignore | ||
CODEOWNERS | ||
CONTRIBUTING.md | ||
dub.sdl | ||
index.dd | ||
LICENSE_1_0.txt | ||
Makefile | ||
posix.mak | ||
project.ddoc | ||
README.md | ||
unittest.d |
Phobos Standard Library
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.