STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cast.h
Go to the documentation of this file.
1 // <cast.h> -*- C++ -*-
2 
3 // Copyright (C) 2008-2013 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 
30 #ifndef _GLIBCXX_CAST_H
31 #define _GLIBCXX_CAST_H 1
32 
33 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
34 {
35 _GLIBCXX_BEGIN_NAMESPACE_VERSION
36 
51  template<typename _ToType>
52  struct _Caster
53  { typedef typename _ToType::element_type* type; };
54 
55  template<typename _ToType>
56  struct _Caster<_ToType*>
57  { typedef _ToType* type; };
58 
66  template<typename _ToType, typename _FromType>
67  inline _ToType
68  __static_pointer_cast(const _FromType& __arg)
69  { return _ToType(static_cast<typename _Caster<_ToType>::
70  type>(__arg.get())); }
71 
72  template<typename _ToType, typename _FromType>
73  inline _ToType
74  __dynamic_pointer_cast(const _FromType& __arg)
75  { return _ToType(dynamic_cast<typename _Caster<_ToType>::
76  type>(__arg.get())); }
77 
78  template<typename _ToType, typename _FromType>
79  inline _ToType
80  __const_pointer_cast(const _FromType& __arg)
81  { return _ToType(const_cast<typename _Caster<_ToType>::
82  type>(__arg.get())); }
83 
84  template<typename _ToType, typename _FromType>
85  inline _ToType
86  __reinterpret_pointer_cast(const _FromType& __arg)
87  { return _ToType(reinterpret_cast<typename _Caster<_ToType>::
88  type>(__arg.get())); }
89 
94  template<typename _ToType, typename _FromType>
95  inline _ToType
96  __static_pointer_cast(_FromType* __arg)
97  { return _ToType(static_cast<typename _Caster<_ToType>::
98  type>(__arg)); }
99 
100  template<typename _ToType, typename _FromType>
101  inline _ToType
102  __dynamic_pointer_cast(_FromType* __arg)
103  { return _ToType(dynamic_cast<typename _Caster<_ToType>::
104  type>(__arg)); }
105 
106  template<typename _ToType, typename _FromType>
107  inline _ToType
108  __const_pointer_cast(_FromType* __arg)
109  { return _ToType(const_cast<typename _Caster<_ToType>::
110  type>(__arg)); }
111 
112  template<typename _ToType, typename _FromType>
113  inline _ToType
114  __reinterpret_pointer_cast(_FromType* __arg)
115  { return _ToType(reinterpret_cast<typename _Caster<_ToType>::
116  type>(__arg)); }
117 
118 _GLIBCXX_END_NAMESPACE_VERSION
119 } // namespace
120 
121 #endif // _GLIBCXX_CAST_H
namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
Definition: cast.h:33