WPILibC++ 2024.3.2
ADL.h
Go to the documentation of this file.
1//===- llvm/ADT/ADL.h - Argument dependent lookup utilities -----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef WPIUTIL_WPI_ADL_H
10#define WPIUTIL_WPI_ADL_H
11
12#include <type_traits>
13#include <iterator>
14#include <utility>
15
16namespace wpi {
17
18// Only used by compiler if both template types are the same. Useful when
19// using SFINAE to test for the existence of member functions.
20template <typename T, T> struct SameType;
21
22namespace adl_detail {
23
24using std::begin;
25
26template <typename RangeT>
27constexpr auto begin_impl(RangeT &&range)
28 -> decltype(begin(std::forward<RangeT>(range))) {
29 return begin(std::forward<RangeT>(range));
30}
31
32using std::end;
33
34template <typename RangeT>
35constexpr auto end_impl(RangeT &&range)
36 -> decltype(end(std::forward<RangeT>(range))) {
37 return end(std::forward<RangeT>(range));
38}
39
40using std::swap;
41
42template <typename T>
43constexpr void swap_impl(T &&lhs,
44 T &&rhs) noexcept(noexcept(swap(std::declval<T>(),
45 std::declval<T>()))) {
46 swap(std::forward<T>(lhs), std::forward<T>(rhs));
47}
48
49using std::size;
50
51template <typename RangeT>
52constexpr auto size_impl(RangeT &&range)
53 -> decltype(size(std::forward<RangeT>(range))) {
54 return size(std::forward<RangeT>(range));
55}
56
57} // end namespace adl_detail
58
59/// Returns the begin iterator to \p range using `std::begin` and
60/// function found through Argument-Dependent Lookup (ADL).
61template <typename RangeT>
62constexpr auto adl_begin(RangeT &&range)
63 -> decltype(adl_detail::begin_impl(std::forward<RangeT>(range))) {
64 return adl_detail::begin_impl(std::forward<RangeT>(range));
65}
66
67/// Returns the end iterator to \p range using `std::end` and
68/// functions found through Argument-Dependent Lookup (ADL).
69template <typename RangeT>
70constexpr auto adl_end(RangeT &&range)
71 -> decltype(adl_detail::end_impl(std::forward<RangeT>(range))) {
72 return adl_detail::end_impl(std::forward<RangeT>(range));
73}
74
75/// Swaps \p lhs with \p rhs using `std::swap` and functions found through
76/// Argument-Dependent Lookup (ADL).
77template <typename T>
78constexpr void adl_swap(T &&lhs, T &&rhs) noexcept(
79 noexcept(adl_detail::swap_impl(std::declval<T>(), std::declval<T>()))) {
80 adl_detail::swap_impl(std::forward<T>(lhs), std::forward<T>(rhs));
81}
82
83/// Returns the size of \p range using `std::size` and functions found through
84/// Argument-Dependent Lookup (ADL).
85template <typename RangeT>
86constexpr auto adl_size(RangeT &&range)
87 -> decltype(adl_detail::size_impl(std::forward<RangeT>(range))) {
88 return adl_detail::size_impl(std::forward<RangeT>(range));
89}
90
91namespace detail {
92
93template <typename RangeT>
94using IterOfRange = decltype(adl_begin(std::declval<RangeT &>()));
95
96template <typename RangeT>
98 std::remove_reference_t<decltype(*adl_begin(std::declval<RangeT &>()))>;
99
100} // namespace detail
101} // namespace wpi
102
103#endif // WPIUTIL_WPI_ADL_H
detail namespace with internal helper functions
Definition: xchar.h:20
WPI_BASIC_JSON_TPL_DECLARATION void swap(wpi::WPI_BASIC_JSON_TPL &j1, wpi::WPI_BASIC_JSON_TPL &j2) noexcept(//NOLINT(readability-inconsistent-declaration-parameter-name) is_nothrow_move_constructible< wpi::WPI_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression) is_nothrow_move_assignable< wpi::WPI_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects
Definition: json.h:5219
constexpr void swap_impl(T &&lhs, T &&rhs) noexcept(noexcept(swap(std::declval< T >(), std::declval< T >())))
Definition: ADL.h:43
constexpr auto begin_impl(RangeT &&range) -> decltype(begin(std::forward< RangeT >(range)))
Definition: ADL.h:27
constexpr auto size_impl(RangeT &&range) -> decltype(size(std::forward< RangeT >(range)))
Definition: ADL.h:52
constexpr auto end_impl(RangeT &&range) -> decltype(end(std::forward< RangeT >(range)))
Definition: ADL.h:35
decltype(adl_begin(std::declval< RangeT & >())) IterOfRange
Definition: ADL.h:94
std::remove_reference_t< decltype(*adl_begin(std::declval< RangeT & >()))> ValueOfRange
Definition: ADL.h:98
Definition: ntcore_cpp.h:26
constexpr auto adl_size(RangeT &&range) -> decltype(adl_detail::size_impl(std::forward< RangeT >(range)))
Returns the size of range using std::size and functions found through Argument-Dependent Lookup (ADL)...
Definition: ADL.h:86
void swap(expected< T, E > &lhs, expected< T, E > &rhs) noexcept(noexcept(lhs.swap(rhs)))
Definition: expected:2438
constexpr auto adl_end(RangeT &&range) -> decltype(adl_detail::end_impl(std::forward< RangeT >(range)))
Returns the end iterator to range using std::end and functions found through Argument-Dependent Looku...
Definition: ADL.h:70
constexpr void adl_swap(T &&lhs, T &&rhs) noexcept(noexcept(adl_detail::swap_impl(std::declval< T >(), std::declval< T >())))
Swaps lhs with rhs using std::swap and functions found through Argument-Dependent Lookup (ADL).
Definition: ADL.h:78
constexpr auto adl_begin(RangeT &&range) -> decltype(adl_detail::begin_impl(std::forward< RangeT >(range)))
Returns the begin iterator to range using std::begin and function found through Argument-Dependent Lo...
Definition: ADL.h:62
Definition: ADL.h:20