1169691Skan// -*- C++ -*-
2169691Skan
3169691Skan// Copyright (C) 2005, 2006, 2007 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 along
17169691Skan// with this library; see the file COPYING.  If not, write to the Free
18169691Skan// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19169691Skan// 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/** @file ext/type_traits.h
32169691Skan *  This file is a GNU extension to the Standard C++ Library.
33169691Skan */
34169691Skan
35169691Skan#ifndef _EXT_TYPE_TRAITS
36169691Skan#define _EXT_TYPE_TRAITS 1
37169691Skan
38169691Skan#pragma GCC system_header
39169691Skan
40169691Skan#include <cstddef>
41169691Skan#include <utility>
42169691Skan#include <bits/cpp_type_traits.h>
43169691Skan
44169691Skan_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
45169691Skan
46169691Skan  // Define a nested type if some predicate holds.
47169691Skan  template<bool, typename>
48169691Skan    struct __enable_if
49169691Skan    { };
50169691Skan
51169691Skan  template<typename _Tp>
52169691Skan    struct __enable_if<true, _Tp>
53169691Skan    { typedef _Tp __type; };
54169691Skan
55169691Skan
56169691Skan  // Conditional expression for types. If true, first, if false, second.
57169691Skan  template<bool _Cond, typename _Iftrue, typename _Iffalse>
58169691Skan    struct __conditional_type
59169691Skan    { typedef _Iftrue __type; };
60169691Skan
61169691Skan  template<typename _Iftrue, typename _Iffalse>
62169691Skan    struct __conditional_type<false, _Iftrue, _Iffalse>
63169691Skan    { typedef _Iffalse __type; };
64169691Skan
65169691Skan
66169691Skan  // Given an integral builtin type, return the corresponding unsigned type.
67169691Skan  template<typename _Tp>
68169691Skan    struct __add_unsigned
69169691Skan    {
70169691Skan    private:
71169691Skan      typedef __enable_if<std::__is_integer<_Tp>::__value, _Tp> __if_type;
72169691Skan
73169691Skan    public:
74169691Skan      typedef typename __if_type::__type __type;
75169691Skan    };
76169691Skan
77169691Skan  template<>
78169691Skan    struct __add_unsigned<char>
79169691Skan    { typedef unsigned char __type; };
80169691Skan
81169691Skan  template<>
82169691Skan    struct __add_unsigned<signed char>
83169691Skan    { typedef unsigned char __type; };
84169691Skan
85169691Skan  template<>
86169691Skan    struct __add_unsigned<short>
87169691Skan    { typedef unsigned short __type; };
88169691Skan
89169691Skan  template<>
90169691Skan    struct __add_unsigned<int>
91169691Skan    { typedef unsigned int __type; };
92169691Skan
93169691Skan  template<>
94169691Skan    struct __add_unsigned<long>
95169691Skan    { typedef unsigned long __type; };
96169691Skan
97169691Skan  template<>
98169691Skan    struct __add_unsigned<long long>
99169691Skan    { typedef unsigned long long __type; };
100169691Skan
101169691Skan  // Declare but don't define.
102169691Skan  template<>
103169691Skan    struct __add_unsigned<bool>;
104169691Skan
105169691Skan  template<>
106169691Skan    struct __add_unsigned<wchar_t>;
107169691Skan
108169691Skan
109169691Skan  // Given an integral builtin type, return the corresponding signed type.
110169691Skan  template<typename _Tp>
111169691Skan    struct __remove_unsigned
112169691Skan    {
113169691Skan    private:
114169691Skan      typedef __enable_if<std::__is_integer<_Tp>::__value, _Tp> __if_type;
115169691Skan
116169691Skan    public:
117169691Skan      typedef typename __if_type::__type __type;
118169691Skan    };
119169691Skan
120169691Skan  template<>
121169691Skan    struct __remove_unsigned<char>
122169691Skan    { typedef signed char __type; };
123169691Skan
124169691Skan  template<>
125169691Skan    struct __remove_unsigned<unsigned char>
126169691Skan    { typedef signed char __type; };
127169691Skan
128169691Skan  template<>
129169691Skan    struct __remove_unsigned<unsigned short>
130169691Skan    { typedef short __type; };
131169691Skan
132169691Skan  template<>
133169691Skan    struct __remove_unsigned<unsigned int>
134169691Skan    { typedef int __type; };
135169691Skan
136169691Skan  template<>
137169691Skan    struct __remove_unsigned<unsigned long>
138169691Skan    { typedef long __type; };
139169691Skan
140169691Skan  template<>
141169691Skan    struct __remove_unsigned<unsigned long long>
142169691Skan    { typedef long long __type; };
143169691Skan
144169691Skan  // Declare but don't define.
145169691Skan  template<>
146169691Skan    struct __remove_unsigned<bool>;
147169691Skan
148169691Skan  template<>
149169691Skan    struct __remove_unsigned<wchar_t>;
150169691Skan
151169691Skan_GLIBCXX_END_NAMESPACE
152169691Skan
153169691Skan#endif
154