vector_algorithms.cpp: introduce namespaces by AlexGuteniev · Pull Request #5450 · microsoft/STL (original) (raw)
Resolves #5418
Why namespaces
The goals were:
- Being able to locate functions using IDE navigation
- Group related stuff to make it clearer what uses what
Both goals are achieved with partial success:
- IDE navigation is way better, but still clobbered with now-empty unnamed namespaces. DevCom-10889095 is about that.
- Grouping works, but some algorithms still use
_Find_trats_orfinditself, now it happens across namespaces
Changes
- Move functions so that the related are grouped and unrelated are ungrouped; each group contains its trait structs, implementation functions, and export functions
- Separate traits from
_Find_traits_where makes sense - Rename existing namespaces and functions to match usual _Naming_style.
- Add new namespaces
- Rename some identifiers to shorter, as they now, in particular
_Predicate - Move comments, change comment, introduce variables to resist silly wrapping
- Remove some
using namespaceto make it more clear what is used from_Bitmap_details - Exclude some traits from
_ARM64_ECand replace byvoidor completely remove
Changes are incremental to enable per-commit review.
(It may be complex to review the whole change, as something is both moved and modified)
Algorithms and namespaces
Namespaces:
- _Bitset_from_string, _Bitset_to_string: contain corresponding
bitsetmember functions implementations. These were fine, just renamed. - _Sorting:
minmax_element,minmax,is_sorted_until. These have obvious commonalities, and even referred by the Standard with this name. - _Removing:
remove,unique,remove_copy,unique_copy: They do the same shuffle and share tables for it. - _Mismatch: only
mismatchitself. Originally was among find-like algorithm due to sharing traits. Decided to move out as it does not resemble find, and re-implmenet similar traits separately, which only need some functions from find traits. The use of traits can be completely avoided for this algorithm, but that's another story. - _Count: only
countitself. As originally implemented, it was seen as find-like algorithm, however later it was re-implemented with a dedicated approach. The traits are its own, but still inherit from_Find_traits_, as all functions from them are needed. - _Find_meow_of:
find_first_ofandbasic_stringmembers that match against a set of characters. Pre-existing namespace, but reorganized a bit, in particular, someusing namespaceremoved. - _Find_seq:
search,find_end, andbasic_stringmembers members that match subsequence. These are distinct enough from_Findin that they use SSE4.2 like_Find_meow_of. They still use_Find_traits_, but only for fallbacks. Although if there would ever be 32 and 64 bit implementation, it will likely use_Find_traits_fully. - _Find:
find,find_last,adjacent_find,search_n, andbasic_stringmembers members that match one character, including single-chararcterfind_meow_not. They have also much of commonality.search_nstands out a bit, but it still uses the same traits, and generally matches a string against a single character, so that is probably fine to keep it here. - _Reversing:
reverse,reverse_copy. The namespace only contains common fallback
The algorithms that don't have traits or common functions don't need namespaces:
swap_rangesreplace
Though I'm sure it is now better with more structure, I'm not sure in particular namespaces usage.