1169691Skan// -*- C++ -*-
2169691Skan
3169691Skan// Copyright (C) 2005, 2006 Free Software Foundation, Inc.
4169691Skan//
5169691Skan// This file is part of the GNU ISO C++ Library.  This library is free
6169691Skan// software; you can redistribute it and/or modify it under the terms
7169691Skan// of the GNU General Public License as published by the Free Software
8169691Skan// Foundation; either version 2, or (at your option) any later
9169691Skan// version.
10169691Skan
11169691Skan// This library is distributed in the hope that it will be useful, but
12169691Skan// WITHOUT ANY WARRANTY; without even the implied warranty of
13169691Skan// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14169691Skan// General Public License for more details.
15169691Skan
16169691Skan// You should have received a copy of the GNU General Public License
17169691Skan// along with this library; see the file COPYING.  If not, write to
18169691Skan// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19169691Skan// MA 02111-1307, USA.
20169691Skan
21169691Skan// As a special exception, you may use this file as part of a free
22169691Skan// software library without restriction.  Specifically, if other files
23169691Skan// instantiate templates or use macros or inline functions from this
24169691Skan// file, or you compile this file and link it with other files to
25169691Skan// produce an executable, this file does not by itself cause the
26169691Skan// resulting executable to be covered by the GNU General Public
27169691Skan// License.  This exception does not however invalidate any other
28169691Skan// reasons why the executable file might be covered by the GNU General
29169691Skan// Public License.
30169691Skan
31169691Skan// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
32169691Skan
33169691Skan// Permission to use, copy, modify, sell, and distribute this software
34169691Skan// is hereby granted without fee, provided that the above copyright
35169691Skan// notice appears in all copies, and that both that copyright notice
36169691Skan// and this permission notice appear in supporting documentation. None
37169691Skan// of the above authors, nor IBM Haifa Research Laboratories, make any
38169691Skan// representation about the suitability of this software for any
39169691Skan// purpose. It is provided "as is" without express or implied
40169691Skan// warranty.
41169691Skan
42169691Skan/**
43169691Skan * @file type_utils.hpp
44169691Skan * Contains utilities for handnling types. All of these classes are based on
45169691Skan *    "Modern C++" by Andrei Alxandrescu.
46169691Skan */
47169691Skan
48169691Skan#ifndef PB_DS_TYPE_UTILS_HPP
49169691Skan#define PB_DS_TYPE_UTILS_HPP
50169691Skan
51169691Skan#include <cstddef>
52169691Skan#include <utility>
53169691Skan#include <tr1/type_traits>
54169691Skan#include <ext/type_traits.h>
55169691Skan#include <ext/numeric_traits.h>
56169691Skan
57169691Skannamespace pb_ds
58169691Skan{
59169691Skan  namespace detail
60169691Skan  {
61169691Skan    using std::tr1::is_same;
62169691Skan    using std::tr1::is_const;
63169691Skan    using std::tr1::is_pointer;
64169691Skan    using std::tr1::is_reference;
65169691Skan    using std::tr1::is_fundamental;
66169691Skan    using std::tr1::is_member_object_pointer;
67169691Skan    using std::tr1::is_member_pointer;
68169691Skan    using std::tr1::is_base_of;
69169691Skan    using std::tr1::remove_const;
70169691Skan    using std::tr1::remove_reference;
71169691Skan
72169691Skan    // Need integral_const<bool, true> <-> integral_const<int, 1>, so
73169691Skan    // because of this use the following typedefs instead of importing
74169691Skan    // std::tr1's.
75169691Skan    using std::tr1::integral_constant;
76169691Skan    typedef std::tr1::integral_constant<int, 1> true_type;
77169691Skan    typedef std::tr1::integral_constant<int, 0> false_type;
78169691Skan
79169691Skan    using __gnu_cxx::__conditional_type;
80169691Skan    using __gnu_cxx::__numeric_traits;
81169691Skan
82169691Skan    template<typename T>
83169691Skan    struct is_const_pointer
84169691Skan    {
85169691Skan      enum
86169691Skan	{
87169691Skan	  value = is_const<T>::value && is_pointer<T>::value
88169691Skan	};
89169691Skan    };
90169691Skan
91169691Skan    template<typename T>
92169691Skan    struct is_const_reference
93169691Skan    {
94169691Skan      enum
95169691Skan	{
96169691Skan	  value = is_const<T>::value && is_reference<T>::value
97169691Skan	};
98169691Skan    };
99169691Skan
100169691Skan    template<typename T>
101169691Skan    struct is_simple
102169691Skan    {
103169691Skan      enum
104169691Skan	{
105169691Skan	  value = is_fundamental<typename remove_const<T>::type>::value
106169691Skan	  || is_pointer<typename remove_const<T>::type>::value
107169691Skan	  || is_member_pointer<T>::value
108169691Skan	};
109169691Skan    };
110169691Skan
111169691Skan    template<typename T>
112169691Skan    class is_pair
113169691Skan    {
114169691Skan    private:
115169691Skan      template<typename U>
116169691Skan      struct is_pair_imp
117169691Skan      {
118169691Skan	enum
119169691Skan	  {
120169691Skan	    value = 0
121169691Skan	  };
122169691Skan      };
123169691Skan
124169691Skan      template<typename U, typename V>
125169691Skan      struct is_pair_imp<std::pair<U,V> >
126169691Skan      {
127169691Skan	enum
128169691Skan	  {
129169691Skan	    value = 1
130169691Skan	  };
131169691Skan      };
132169691Skan
133169691Skan    public:
134169691Skan      enum
135169691Skan	{
136169691Skan	  value = is_pair_imp<T>::value
137169691Skan	};
138169691Skan    };
139169691Skan
140169691Skan
141169691Skan    template<bool>
142169691Skan    struct static_assert;
143169691Skan
144169691Skan    template<>
145169691Skan    struct static_assert<true>
146169691Skan    { };
147169691Skan
148169691Skan    template<int>
149169691Skan    struct static_assert_dumclass
150169691Skan    {
151169691Skan      enum
152169691Skan	{
153169691Skan	  v = 1
154169691Skan	};
155169691Skan    };
156169691Skan
157169691Skan    template<typename Type>
158169691Skan    struct type_to_type
159169691Skan    {
160169691Skan      typedef Type type;
161169691Skan    };
162169691Skan  } // namespace detail
163169691Skan} // namespace pb_ds
164169691Skan
165169691Skan#endif
166