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 terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 2, 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 COPYING. If not, write to
18 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19 // MA 02111-1307, USA.
21 // As a special exception, you may use this file as part of a free
22 // software library without restriction. Specifically, if other files
23 // instantiate templates or use macros or inline functions from this
24 // file, or you compile this file and link it with other files to
25 // produce an executable, this file does not by itself cause the
26 // resulting executable to be covered by the GNU General Public
27 // License. This exception does not however invalidate any other
28 // reasons why the executable file might be covered by the GNU General
31 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
33 // Permission to use, copy, modify, sell, and distribute this software
34 // is hereby granted without fee, provided that the above copyright
35 // notice appears in all copies, and that both that copyright notice
36 // and this permission notice appear in supporting documentation. None
37 // of the above authors, nor IBM Haifa Research Laboratories, make any
38 // representation about the suitability of this software for any
39 // purpose. It is provided "as is" without express or implied
43 * @file native_type_trait.hpp
44 * Contains traits for a random regression test
45 * for a specific container type.
48 #ifndef PB_DS_REGRESSION_TEST_NATIVE_TYPE_TRAIT_HPP
49 #define PB_DS_REGRESSION_TEST_NATIVE_TYPE_TRAIT_HPP
60 template<typename Key, class Allocator>
61 struct native_key_type;
63 template<typename Allocator>
64 struct native_key_type<
68 typedef std::string type;
71 native_key(typename Allocator::template rebind<
72 basic_type>::other::const_reference r_key)
74 return (std::string(r_key));
78 template<typename Hd, class Tl, class Allocator>
79 struct native_key_type<
85 typedef typename native_key_type< Hd, Allocator>::type hd_type;
87 typedef typename native_key_type< Tl, Allocator>::type tl_type;
89 typedef std::pair< hd_type, tl_type> type;
92 native_key(typename Allocator::template rebind< std::pair<Hd, Tl> >::other::const_reference r_key)
94 return (std::make_pair(
95 native_key_type<Hd, Allocator>::native_key(r_key.first),
96 native_key_type<Tl, Allocator>::native_key(r_key.second)));
100 template<typename Native_Key_Type,
104 struct native_type_traits_base;
106 template<typename Native_Key_Type, class Key_Type, class Allocator>
107 struct native_type_traits_base<
114 typedef std::map< Native_Key_Type, std::string> type;
117 static const typename type::key_type&
118 extract_key(typename type::const_reference r_val)
120 return (r_val.first);
123 static typename type::value_type
124 native_value(typename Allocator::template rebind< std::pair<Key_Type, basic_type> >::other::const_reference r_val)
126 return (std::make_pair(
127 native_key_type<Key_Type, Allocator>::native_key(r_val.first),
128 std::string(r_val.second)));
132 template<typename Native_Key_Type, class Key_Type, class Allocator>
133 struct native_type_traits_base<
136 __gnu_pbds::null_mapped_type,
140 typedef std::set< Native_Key_Type> type;
143 static const typename type::key_type&
144 extract_key(typename type::const_reference r_val)
149 static typename type::value_type
150 native_value(typename Allocator::template rebind<
151 Key_Type>::other::const_reference r_val)
153 return (native_key_type<Key_Type, Allocator>::native_key(
158 #define PB_DS_NATIVE_KEY_TYPE_C_DEC \
163 #define PB_DS_BASE_C_DEC \
164 native_type_traits_base< \
165 typename PB_DS_NATIVE_KEY_TYPE_C_DEC::type, \
170 template<typename Key_Type, class Data_Type, class Allocator>
171 struct native_type_traits : public PB_DS_BASE_C_DEC
173 typedef typename PB_DS_BASE_C_DEC::type type;
175 typedef typename type::key_type key_type;
177 static typename PB_DS_NATIVE_KEY_TYPE_C_DEC::type
178 native_key(typename Allocator::template rebind<
179 Key_Type>::other::const_reference r_key)
181 return (PB_DS_NATIVE_KEY_TYPE_C_DEC::native_key(r_key));
185 #undef PB_DS_BASE_C_DEC
187 #undef PB_DS_NATIVE_KEY_TYPE_C_DEC
189 } // namespace detail
193 } // namespace __gnu_pbds
195 #endif // #ifndef PB_DS_REGRESSION_TEST_NATIVE_TYPE_TRAIT_HPP