Implement LWG2952: iterator_traits should work for pointers to cv T
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@318119 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -37,16 +37,6 @@ struct iterator_traits<T*>
|
|||||||
typedef random_access_iterator_tag iterator_category;
|
typedef random_access_iterator_tag iterator_category;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T>
|
|
||||||
struct iterator_traits<const T*>
|
|
||||||
{
|
|
||||||
typedef ptrdiff_t difference_type;
|
|
||||||
typedef T value_type;
|
|
||||||
typedef const T* pointer;
|
|
||||||
typedef const T& reference;
|
|
||||||
typedef random_access_iterator_tag iterator_category;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class Category, class T, class Distance = ptrdiff_t,
|
template<class Category, class T, class Distance = ptrdiff_t,
|
||||||
class Pointer = T*, class Reference = T&>
|
class Pointer = T*, class Reference = T&>
|
||||||
struct iterator
|
struct iterator
|
||||||
@@ -494,7 +484,7 @@ template<class _Tp>
|
|||||||
struct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*>
|
struct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*>
|
||||||
{
|
{
|
||||||
typedef ptrdiff_t difference_type;
|
typedef ptrdiff_t difference_type;
|
||||||
typedef typename remove_const<_Tp>::type value_type;
|
typedef typename remove_cv<_Tp>::type value_type;
|
||||||
typedef _Tp* pointer;
|
typedef _Tp* pointer;
|
||||||
typedef _Tp& reference;
|
typedef _Tp& reference;
|
||||||
typedef random_access_iterator_tag iterator_category;
|
typedef random_access_iterator_tag iterator_category;
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||||
|
// Source Licenses. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// <iterator>
|
||||||
|
|
||||||
|
// template<class T>
|
||||||
|
// struct iterator_traits<const T*>
|
||||||
|
|
||||||
|
#include <iterator>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
struct A {};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
typedef std::iterator_traits<volatile A*> It;
|
||||||
|
static_assert((std::is_same<It::difference_type, std::ptrdiff_t>::value), "");
|
||||||
|
static_assert((std::is_same<It::value_type, A>::value), "");
|
||||||
|
static_assert((std::is_same<It::pointer, volatile A*>::value), "");
|
||||||
|
static_assert((std::is_same<It::reference, volatile A&>::value), "");
|
||||||
|
static_assert((std::is_same<It::iterator_category, std::random_access_iterator_tag>::value), "");
|
||||||
|
}
|
||||||
@@ -108,7 +108,7 @@
|
|||||||
<tr><td><a href="https://wg21.link/LWG2945">2945</a></td><td>Order of template parameters in optional comparisons</td><td>Albuquerque</td><td>Complete</td></tr>
|
<tr><td><a href="https://wg21.link/LWG2945">2945</a></td><td>Order of template parameters in optional comparisons</td><td>Albuquerque</td><td>Complete</td></tr>
|
||||||
<tr><td><a href="https://wg21.link/LWG2948">2948</a></td><td>unique_ptr does not define operator<< for stream output</td><td>Albuquerque</td><td></td></tr>
|
<tr><td><a href="https://wg21.link/LWG2948">2948</a></td><td>unique_ptr does not define operator<< for stream output</td><td>Albuquerque</td><td></td></tr>
|
||||||
<tr><td><a href="https://wg21.link/LWG2950">2950</a></td><td>std::byte operations are misspecified</td><td>Albuquerque</td><td></td></tr>
|
<tr><td><a href="https://wg21.link/LWG2950">2950</a></td><td>std::byte operations are misspecified</td><td>Albuquerque</td><td></td></tr>
|
||||||
<tr><td><a href="https://wg21.link/LWG2952">2952</a></td><td>iterator_traits should work for pointers to cv T</td><td>Albuquerque</td><td></td></tr>
|
<tr><td><a href="https://wg21.link/LWG2952">2952</a></td><td>iterator_traits should work for pointers to cv T</td><td>Albuquerque</td><td>Complete</td></tr>
|
||||||
<tr><td><a href="https://wg21.link/LWG2953">2953</a></td><td>LWG 2853 should apply to deque::erase too</td><td>Albuquerque</td><td></td></tr>
|
<tr><td><a href="https://wg21.link/LWG2953">2953</a></td><td>LWG 2853 should apply to deque::erase too</td><td>Albuquerque</td><td></td></tr>
|
||||||
<tr><td><a href="https://wg21.link/LWG2958">2958</a></td><td>Moves improperly defined as deleted</td><td>Albuquerque</td><td></td></tr>
|
<tr><td><a href="https://wg21.link/LWG2958">2958</a></td><td>Moves improperly defined as deleted</td><td>Albuquerque</td><td></td></tr>
|
||||||
<tr><td><a href="https://wg21.link/LWG2964">2964</a></td><td>Apparently redundant requirement for dynamic_pointer_cast</td><td>Albuquerque</td><td></td></tr>
|
<tr><td><a href="https://wg21.link/LWG2964">2964</a></td><td>Apparently redundant requirement for dynamic_pointer_cast</td><td>Albuquerque</td><td></td></tr>
|
||||||
|
|||||||
Reference in New Issue
Block a user