1// -*- C++ -*-
2
3// Copyright (C) 2005-2015 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 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
9// version.
10
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.
15
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/>.
19
20
21// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
22
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
30// warranty.
31
32/**
33 * @file type_trait.hpp
34 * Contains traits for a random regression test
35 *    for a specific container type.
36 */
37
38#ifndef PB_DS_REGRESSION_TEST_TYPE_TRAIT_HPP
39#define PB_DS_REGRESSION_TEST_TYPE_TRAIT_HPP
40
41#include <regression/basic_type.hpp>
42
43namespace __gnu_pbds
44{
45  namespace test
46  {
47    namespace detail
48    {
49      template<typename Cntnr>
50      struct regression_test_type_traits
51      {
52	typedef Cntnr cntnr;
53	typedef typename cntnr::key_type key_type;
54	typedef typename cntnr::key_const_reference key_const_reference;
55	typedef typename cntnr::value_type value_type;
56	typedef typename cntnr::const_reference const_reference;
57	typedef typename cntnr::mapped_type mapped_type;
58	typedef typename cntnr::mapped_const_reference mapped_const_reference;
59
60	template<typename Gen>
61	static key_type
62        generate_key(Gen& r_gen, size_t max)
63	{ return basic_type(r_gen, max); }
64
65	template<typename Gen>
66	static value_type
67        generate_value(Gen& r_gen, size_t max)
68	{ return generate_value(r_gen, max, value_type()); }
69
70	static key_const_reference
71        extract_key(const_reference r_val)
72	{ return extract_key_imp(r_val); }
73
74      private:
75	typedef typename cntnr::allocator_type::template rebind<basic_type>::other
76	basic_type_rebind;
77
78	typedef typename basic_type_rebind::const_reference basic_type_const_reference;
79
80	typedef typename cntnr::allocator_type::template rebind<std::pair<const basic_type, basic_type> >::other pair_type_rebind;
81	typedef typename pair_type_rebind::const_reference pair_type_const_reference;
82
83	template<typename Gen>
84	static value_type
85        generate_value(Gen& r_gen, size_t max, __gnu_pbds::null_type)
86	{ return basic_type(r_gen, max); }
87
88	template<typename Gen>
89	static value_type
90        generate_value(Gen& r_gen, size_t max, basic_type)
91	{ return basic_type(r_gen, max); }
92
93	template<typename Gen>
94	static value_type
95        generate_value(Gen& gen, size_t max,
96		       std::pair<const basic_type, basic_type>)
97	{ return std::make_pair(basic_type(gen, max), basic_type(gen, max)); }
98
99	static key_const_reference
100        extract_key_imp(basic_type_const_reference r_val)
101	{ return r_val; }
102
103	static key_const_reference
104        extract_key_imp(pair_type_const_reference r_val)
105	{ return r_val.first; }
106      };
107    } // namespace detail
108  } // namespace test
109} // namespace __gnu_pbds
110
111#endif
112