[libcxx-commits] [PATCH] D65260: [libc++] Consolidate swap, swap_ranges, and iter_swap in <type_traits>. NFC.

Arthur O'Dwyer via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jul 25 09:22:49 PDT 2019


Quuxplusone added a comment.

> I really dislike the general organization (or rather, the lack thereof) in libc++. It's weird to be defining `swap` and `swap_ranges` inside `<type_traits>`, when `swap_ranges` should be part of `<algorithm>` and `swap` should be in `<utility>`.

I'd call that a lack of organization in the //paper// standard, not in the implementation! According to N4810,

- `<concepts>` defines `Swappable` in terms of `ranges::swap`, and defines `ranges::swap` in terms of ADL `swap`
- `<utility>` defines `swap(T&, T&)`, and defines `swap(T (&)[N], T (&)[N])`
- `<type_traits>` defines `is_swappable` in terms of `std::swap` and ADL `swap`
- `<iterator>` defines `ranges::iter_swap` in terms of `ranges::swap` and ADL `iter_swap`(!!)
- `<algorithm>` defines `std::iter_swap` in terms of `std::swap` and (arguably) ADL `swap`; defines `std::swap_ranges` in terms of `std::swap` and (arguably) ADL `swap`; defines `ranges::swap_ranges` in terms of `ranges::iter_swap`

- `<concepts>` includes nothing
- `<utility>` includes only `<initializer_list>`
- `<type_traits>` includes nothing, despite requiring `std::swap` out of `<utility>`
- `<iterator>` includes only `<concepts>`
- `<algorithm>` includes only `<initializer_list>`, despite requiring `std::swap` out of `<utility>` and `ranges::iter_swap` out of `<iterator>`

Taking that spaghetti literally would result in a maintenance nightmare.


Repository:
  rCXX libc++

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65260/new/

https://reviews.llvm.org/D65260





More information about the libcxx-commits mailing list