OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-dev/] [fsf-gcc-snapshot-1-mar-12/] [or1k-gcc/] [libstdc++-v3/] [include/] [bits/] [ptr_traits.h] - Blame information for rev 783

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 742 jeremybenn
// Pointer Traits -*- C++ -*-
2
 
3
// Copyright (C) 2011 Free Software Foundation, Inc.
4
//
5
// This file is part of the GNU ISO C++ Library.  This library is free
6
// software; you can redistribute it and/or modify it under the
7
// terms of the GNU General Public License as published by the
8
// Free Software Foundation; either version 3, or (at your option)
9
// any later version.
10
 
11
// This library is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
// GNU General Public License for more details.
15
 
16
// Under Section 7 of GPL version 3, you are granted additional
17
// permissions described in the GCC Runtime Library Exception, version
18
// 3.1, as published by the Free Software Foundation.
19
 
20
// You should have received a copy of the GNU General Public License and
21
// a copy of the GCC Runtime Library Exception along with this program;
22
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23
// <http://www.gnu.org/licenses/>.
24
 
25
/** @file bits/ptr_traits.h
26
 *  This is an internal header file, included by other library headers.
27
 *  Do not attempt to use it directly. @headername{memory}
28
 */
29
 
30
#ifndef _PTR_TRAITS_H
31
#define _PTR_TRAITS_H 1
32
 
33
#ifdef __GXX_EXPERIMENTAL_CXX0X__
34
 
35
#include <type_traits> // For _GLIBCXX_HAS_NESTED_TYPE
36
 
37
namespace std _GLIBCXX_VISIBILITY(default)
38
{
39
_GLIBCXX_BEGIN_NAMESPACE_VERSION
40
 
41
_GLIBCXX_HAS_NESTED_TYPE(element_type)
42
_GLIBCXX_HAS_NESTED_TYPE(difference_type)
43
 
44
  template<typename _Tp, bool = __has_element_type<_Tp>::value>
45
    struct __ptrtr_elt_type;
46
 
47
  template<typename _Tp>
48
    struct __ptrtr_elt_type<_Tp, true>
49
    {
50
      typedef typename _Tp::element_type __type;
51
    };
52
 
53
  template<template<typename, typename...> class _SomePtr, typename _Tp,
54
            typename... _Args>
55
    struct __ptrtr_elt_type<_SomePtr<_Tp, _Args...>, false>
56
    {
57
      typedef _Tp __type;
58
    };
59
 
60
  template<typename _Tp, bool = __has_difference_type<_Tp>::value>
61
    struct __ptrtr_diff_type
62
    {
63
      typedef typename _Tp::difference_type __type;
64
    };
65
 
66
  template<typename _Tp>
67
    struct __ptrtr_diff_type<_Tp, false>
68
    {
69
      typedef ptrdiff_t __type;
70
    };
71
 
72
  template<typename _Ptr, typename _Up>
73
    class __ptrtr_rebind_helper
74
    {
75
      template<typename _Ptr2, typename _Up2>
76
        static constexpr bool
77
        _S_chk(typename _Ptr2::template rebind<_Up2>*)
78
        { return true; }
79
 
80
      template<typename, typename>
81
        static constexpr bool
82
        _S_chk(...)
83
        { return false; }
84
 
85
    public:
86
      static const bool __value = _S_chk<_Ptr, _Up>(nullptr);
87
    };
88
 
89
  template<typename _Tp, typename _Up,
90
           bool = __ptrtr_rebind_helper<_Tp, _Up>::__value>
91
    struct __ptrtr_rebind;
92
 
93
  template<typename _Tp, typename _Up>
94
    struct __ptrtr_rebind<_Tp, _Up, true>
95
    {
96
      typedef typename _Tp::template rebind<_Up> __type;
97
    };
98
 
99
  template<template<typename, typename...> class _SomePtr, typename _Up,
100
            typename _Tp, typename... _Args>
101
    struct __ptrtr_rebind<_SomePtr<_Tp, _Args...>, _Up, false>
102
    {
103
      typedef _SomePtr<_Up, _Args...> __type;
104
    };
105
 
106
  template<typename _Tp, typename = typename remove_cv<_Tp>::type>
107
    struct __ptrtr_not_void
108
    {
109
      typedef _Tp __type;
110
    };
111
 
112
  template<typename _Tp>
113
    struct __ptrtr_not_void<_Tp, void>
114
    {
115
      struct __type { };
116
    };
117
 
118
  template<typename _Ptr>
119
    class __ptrtr_pointer_to
120
    {
121
      typedef typename __ptrtr_elt_type<_Ptr>::__type   __orig_type;
122
      typedef typename __ptrtr_not_void<__orig_type>::__type __element_type;
123
 
124
    public:
125
      static _Ptr pointer_to(__element_type& __e)
126
      { return _Ptr::pointer_to(__e); }
127
    };
128
 
129
  /**
130
   * @brief  Uniform interface to all pointer-like types
131
   * @ingroup pointer_abstractions
132
  */
133
  template<typename _Ptr>
134
    struct pointer_traits : __ptrtr_pointer_to<_Ptr>
135
    {
136
      /// The pointer type
137
      typedef _Ptr                                      pointer;
138
      /// The type pointed to
139
      typedef typename __ptrtr_elt_type<_Ptr>::__type   element_type;
140
      /// Type used to represent the difference between two pointers
141
      typedef typename __ptrtr_diff_type<_Ptr>::__type  difference_type;
142
 
143
    private:
144
      template<typename _Up>
145
        using rebind = typename __ptrtr_rebind<_Ptr, _Up>::__type;
146
 
147
      // allocator_traits needs to use __rebind
148
      template<typename> friend struct allocator_traits;
149
      template<typename> friend struct pointer_traits;
150
      template<typename, typename> friend class __ptrtr_rebind_helper2;
151
    };
152
 
153
  /**
154
   * @brief  Partial specialization for built-in pointers.
155
   * @ingroup pointer_abstractions
156
  */
157
  template<typename _Tp>
158
    struct pointer_traits<_Tp*>
159
    {
160
      /// The pointer type
161
      typedef _Tp* pointer;
162
      /// The type pointed to
163
      typedef _Tp  element_type;
164
      /// Type used to represent the difference between two pointers
165
      typedef ptrdiff_t difference_type;
166
 
167
      template<typename _Up>
168
        using rebind = _Up*;
169
 
170
      /**
171
       *  @brief  Obtain a pointer to an object
172
       *  @param  __r  A reference to an object of type @c element_type
173
       *  @return @c addressof(__r)
174
      */
175
      static pointer
176
      pointer_to(typename __ptrtr_not_void<element_type>::__type& __r) noexcept
177
      { return std::addressof(__r); }
178
    };
179
 
180
_GLIBCXX_END_NAMESPACE_VERSION
181
} // namespace std
182
 
183
#endif
184
 
185
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.