summaryrefslogtreecommitdiffstats
path: root/libcxx/include/iterator
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2019-02-27 02:58:56 +0000
committerMarshall Clow <mclow.lists@gmail.com>2019-02-27 02:58:56 +0000
commit7d3986ea30111015565a3e56530e31aad82dfb6f (patch)
tree8c6b81a15940ea43c3501ac52a838f351e3929ca /libcxx/include/iterator
parentcba6eda15525e8571fcfc874b3496fd3b5ca8ad2 (diff)
downloadbcm5719-llvm-7d3986ea30111015565a3e56530e31aad82dfb6f.tar.gz
bcm5719-llvm-7d3986ea30111015565a3e56530e31aad82dfb6f.zip
Implement the second part of P1227R2 - Signed ssize() functions. Reviewed as https://reviews.llvm.org/D58642
llvm-svn: 354950
Diffstat (limited to 'libcxx/include/iterator')
-rw-r--r--libcxx/include/iterator18
1 files changed, 18 insertions, 0 deletions
diff --git a/libcxx/include/iterator b/libcxx/include/iterator
index ce0be3d5a5c..bce6e90f24b 100644
--- a/libcxx/include/iterator
+++ b/libcxx/include/iterator
@@ -399,6 +399,11 @@ template <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c));
// 24.8, container access:
template <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17
template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
+
+template <class C> constexpr auto ssize(const C& c)
+ -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>; // C++20
+template <class T, ptrdiff_t> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; // C++20
+
template <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17
template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17
template <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17
@@ -1858,6 +1863,19 @@ template <class _Tp, size_t _Sz>
inline _LIBCPP_INLINE_VISIBILITY
constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
+#if _LIBCPP_STD_VER > 17
+template <class _Cont>
+inline _LIBCPP_INLINE_VISIBILITY
+constexpr auto ssize(const _Cont& __c)
+_NOEXCEPT_(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size())))
+-> common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>
+{ return static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()); }
+
+template <class _Tp, ptrdiff_t _Sz>
+inline _LIBCPP_INLINE_VISIBILITY
+constexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; }
+#endif
+
template <class _Cont>
_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY
constexpr auto empty(const _Cont& __c)
OpenPOWER on IntegriCloud