Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef ABSL_TYPES_INTERNAL_SPAN_H_
00017 #define ABSL_TYPES_INTERNAL_SPAN_H_
00018
00019 #include <algorithm>
00020 #include <cstddef>
00021 #include <string>
00022 #include <type_traits>
00023
00024 #include "absl/algorithm/algorithm.h"
00025 #include "absl/base/internal/throw_delegate.h"
00026 #include "absl/meta/type_traits.h"
00027
00028 namespace absl {
00029
00030 namespace span_internal {
00031
00032 constexpr size_t Min(size_t a, size_t b) noexcept { return a < b ? a : b; }
00033
00034
00035 template <typename C>
00036 constexpr auto GetDataImpl(C& c, char) noexcept
00037 -> decltype(c.data()) {
00038 return c.data();
00039 }
00040
00041
00042 inline char* GetDataImpl(std::string& s,
00043 int) noexcept {
00044 return &s[0];
00045 }
00046
00047 template <typename C>
00048 constexpr auto GetData(C& c) noexcept
00049 -> decltype(GetDataImpl(c, 0)) {
00050 return GetDataImpl(c, 0);
00051 }
00052
00053
00054 template <typename C>
00055 using HasSize =
00056 std::is_integral<absl::decay_t<decltype(std::declval<C&>().size())>>;
00057
00058
00059
00060
00061
00062
00063
00064 template <typename T, typename C>
00065 using HasData =
00066 std::is_convertible<absl::decay_t<decltype(GetData(std::declval<C&>()))>*,
00067 T* const*>;
00068
00069
00070 template <typename C>
00071 struct ElementType {
00072 using type = typename absl::remove_reference_t<C>::value_type;
00073 };
00074
00075 template <typename T, size_t N>
00076 struct ElementType<T (&)[N]> {
00077 using type = T;
00078 };
00079
00080 template <typename C>
00081 using ElementT = typename ElementType<C>::type;
00082
00083 template <typename T>
00084 using EnableIfMutable =
00085 typename std::enable_if<!std::is_const<T>::value, int>::type;
00086
00087 template <template <typename> class SpanT, typename T>
00088 bool EqualImpl(SpanT<T> a, SpanT<T> b) {
00089 static_assert(std::is_const<T>::value, "");
00090 return absl::equal(a.begin(), a.end(), b.begin(), b.end());
00091 }
00092
00093 template <template <typename> class SpanT, typename T>
00094 bool LessThanImpl(SpanT<T> a, SpanT<T> b) {
00095
00096
00097 static_assert(std::is_const<T>::value, "");
00098 return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end());
00099 }
00100
00101
00102
00103
00104
00105 template <typename From, typename To>
00106 struct IsConvertibleHelper {
00107 private:
00108 static std::true_type testval(To);
00109 static std::false_type testval(...);
00110
00111 public:
00112 using type = decltype(testval(std::declval<From>()));
00113 };
00114
00115 template <typename From, typename To>
00116 struct IsConvertible : IsConvertibleHelper<From, To>::type {};
00117
00118
00119
00120 template <typename From, typename To>
00121 using EnableIfConvertibleTo =
00122 typename std::enable_if<IsConvertible<From, To>::value>::type;
00123 }
00124 }
00125
00126 #endif // ABSL_TYPES_INTERNAL_SPAN_H_