3 // Copyright (C) 2005, 2006 Free Software Foundation, Inc.
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 2, or (at your option)
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.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
30 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
32 // Permission to use, copy, modify, sell, and distribute this software
33 // is hereby granted without fee, provided that the above copyright
34 // notice appears in all copies, and that both that copyright notice and
35 // this permission notice appear in supporting documentation. None of
36 // the above authors, nor IBM Haifa Research Laboratories, make any
37 // representation about the suitability of this software for any
38 // purpose. It is provided "as is" without express or implied warranty.
41 * @file it_value_type_traits.hpp
42 * Contains an adapter of mapping levels.
45 template<class Base
, bool Lowest
>
46 struct base_it_key_type
48 typedef typename
Base::it_key_type type
;
52 struct base_it_key_type
<
56 typedef typename
Base::const_key_reference type
;
59 template<typename Base_Key_
,
64 struct it_value_type_traits_
66 typedef ref_pair
< Base_Key_
, Key_
> key_ref_pair
;
69 typename
Allocator_::template rebind
<
70 key_ref_pair
>::other::const_reference
73 typedef key_ref_pair_val key_type
;
75 typedef ref_pair
< key_ref_pair_val
, Data_
> value_type
;
78 typename
Allocator_::template rebind
<
79 value_type
>::other::reference
83 typename
Allocator_::template rebind
<
84 value_type
>::other::const_reference
88 typename
Allocator_::template rebind
<
89 value_type
>::other::pointer
93 typename
Allocator_::template rebind
<
94 value_type
>::other::const_pointer
97 struct value_type_holder
99 typename
std::tr1::aligned_storage
<sizeof(key_ref_pair
),
100 std::tr1::alignment_of
<key_ref_pair
>::value
>::type m_a_key_buf
;
102 typename
std::tr1::aligned_storage
<sizeof(value_type
),
103 std::tr1::alignment_of
<value_type
>::value
>::type m_a_value_buf
;
107 typename
Allocator_::template rebind
<
108 value_type_holder
>::other::reference
109 value_type_hoder_valerence
;
111 inline static pointer
112 recast(value_type_hoder_valerence r_holder
)
114 return reinterpret_cast<pointer
>(&r_holder
.m_a_value_buf
);
118 make_valid(value_type_hoder_valerence r_holder
, Base_Key_ r_bk
, Value_ r_val
)
121 typename
Allocator_::template rebind
<
122 void* >::other::value_type
125 void_pointer p_target
= &r_holder
.m_a_key_buf
;
127 new (p_target
) key_ref_pair(r_bk
, r_val
.first
);
130 typename
Allocator_::template rebind
<
131 key_ref_pair
>::other::pointer
132 key_ref_pair_pointer
;
134 key_ref_pair_pointer p_key
=
135 reinterpret_cast<key_ref_pair_pointer
>(&r_holder
.m_a_key_buf
);
137 p_target
= &r_holder
.m_a_value_buf
;
139 new (p_target
) value_type(*p_key
, r_val
.second
);
143 template<typename Base_Key_
,
147 struct it_value_type_traits_
<
154 typedef ref_pair
< Base_Key_
, Key_
> key_ref_pair
;
157 typename
Allocator_::template rebind
<
158 key_ref_pair
>::other::const_reference
161 typedef key_ref_pair_val key_type
;
163 typedef key_ref_pair value_type
;
166 typename
Allocator_::template rebind
<
167 value_type
>::other::const_reference
171 typename
Allocator_::template rebind
<
172 value_type
>::other::const_reference
176 typename
Allocator_::template rebind
<
177 value_type
>::other::const_pointer
181 typename
Allocator_::template rebind
<
182 value_type
>::other::const_pointer
185 struct value_type_holder
187 typename
std::tr1::aligned_storage
<sizeof(key_ref_pair
),
188 std::tr1::alignment_of
<key_ref_pair
>::value
>::type m_a_key_buf
;
190 typename
std::tr1::aligned_storage
<sizeof(value_type
),
191 std::tr1::alignment_of
<value_type
>::value
>::type m_a_value_buf
;
195 typename
Allocator_::template rebind
<
196 value_type_holder
>::other::reference
197 value_type_hoder_valerence
;
199 inline static pointer
200 recast(value_type_hoder_valerence r_holder
)
202 return reinterpret_cast<pointer
>(&r_holder
.m_a_value_buf
);
206 make_valid(value_type_hoder_valerence r_holder
, Base_Key_ r_bk
, Value_ r_val
)
209 typename
Allocator_::template rebind
<
210 void* >::other::value_type
213 void_pointer p_target
= &r_holder
.m_a_value_buf
;
215 new (p_target
) key_ref_pair(r_bk
, r_val
.first
);