3 // Copyright (C) 2005, 2006, 2009 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 terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 3, or (at your option) any later
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
21 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
23 // Permission to use, copy, modify, sell, and distribute this software
24 // is hereby granted without fee, provided that the above copyright
25 // notice appears in all copies, and that both that copyright notice
26 // and this permission notice appear in supporting documentation. None
27 // of the above authors, nor IBM Haifa Research Laboratories, make any
28 // representation about the suitability of this software for any
29 // purpose. It is provided "as is" without express or implied
33 * @file native_type_trait.hpp
34 * Contains traits for a random regression test
35 * for a specific container type.
38 #ifndef PB_DS_REGRESSION_TEST_NATIVE_TYPE_TRAIT_HPP
39 #define PB_DS_REGRESSION_TEST_NATIVE_TYPE_TRAIT_HPP
50 template<typename Key, class Allocator>
51 struct native_key_type;
53 template<typename Allocator>
54 struct native_key_type<
58 typedef std::string type;
61 native_key(typename Allocator::template rebind<
62 basic_type>::other::const_reference r_key)
64 return (std::string(r_key));
68 template<typename Hd, class Tl, class Allocator>
69 struct native_key_type<
75 typedef typename native_key_type< Hd, Allocator>::type hd_type;
77 typedef typename native_key_type< Tl, Allocator>::type tl_type;
79 typedef std::pair< hd_type, tl_type> type;
82 native_key(typename Allocator::template rebind< std::pair<Hd, Tl> >::other::const_reference r_key)
84 return (std::make_pair(
85 native_key_type<Hd, Allocator>::native_key(r_key.first),
86 native_key_type<Tl, Allocator>::native_key(r_key.second)));
90 template<typename Native_Key_Type,
94 struct native_type_traits_base;
96 template<typename Native_Key_Type, class Key_Type, class Allocator>
97 struct native_type_traits_base<
104 typedef std::map< Native_Key_Type, std::string> type;
107 static const typename type::key_type&
108 extract_key(typename type::const_reference r_val)
110 return (r_val.first);
113 static typename type::value_type
114 native_value(typename Allocator::template rebind< std::pair<Key_Type, basic_type> >::other::const_reference r_val)
116 return (std::make_pair(
117 native_key_type<Key_Type, Allocator>::native_key(r_val.first),
118 std::string(r_val.second)));
122 template<typename Native_Key_Type, class Key_Type, class Allocator>
123 struct native_type_traits_base<
126 __gnu_pbds::null_mapped_type,
130 typedef std::set< Native_Key_Type> type;
133 static const typename type::key_type&
134 extract_key(typename type::const_reference r_val)
139 static typename type::value_type
140 native_value(typename Allocator::template rebind<
141 Key_Type>::other::const_reference r_val)
143 return (native_key_type<Key_Type, Allocator>::native_key(
148 #define PB_DS_NATIVE_KEY_TYPE_C_DEC \
153 #define PB_DS_BASE_C_DEC \
154 native_type_traits_base< \
155 typename PB_DS_NATIVE_KEY_TYPE_C_DEC::type, \
160 template<typename Key_Type, class Data_Type, class Allocator>
161 struct native_type_traits : public PB_DS_BASE_C_DEC
163 typedef typename PB_DS_BASE_C_DEC::type type;
165 typedef typename type::key_type key_type;
167 static typename PB_DS_NATIVE_KEY_TYPE_C_DEC::type
168 native_key(typename Allocator::template rebind<
169 Key_Type>::other::const_reference r_key)
171 return (PB_DS_NATIVE_KEY_TYPE_C_DEC::native_key(r_key));
175 #undef PB_DS_BASE_C_DEC
177 #undef PB_DS_NATIVE_KEY_TYPE_C_DEC
179 } // namespace detail
183 } // namespace __gnu_pbds
185 #endif // #ifndef PB_DS_REGRESSION_TEST_NATIVE_TYPE_TRAIT_HPP