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_
orfind
itself, 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 namespace
to make it more clear what is used from_Bitmap_details
- Exclude some traits from
_ARM64_EC
and replace byvoid
or 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
bitset
member 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
mismatch
itself. 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
count
itself. 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_of
andbasic_string
members that match against a set of characters. Pre-existing namespace, but reorganized a bit, in particular, someusing namespace
removed. - _Find_seq:
search
,find_end
, andbasic_string
members members that match subsequence. These are distinct enough from_Find
in 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_string
members members that match one character, including single-chararcterfind_meow_not
. They have also much of commonality.search_n
stands 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_ranges
replace
Though I'm sure it is now better with more structure, I'm not sure in particular namespaces usage.