2003-06-11 17:52:11 +02:00
|
|
|
// Allocators -*- C++ -*-
|
|
|
|
|
2008-03-26 07:27:35 +01:00
|
|
|
// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
|
2006-01-04 12:34:45 +01:00
|
|
|
// Free Software Foundation, Inc.
|
2003-06-11 17:52:11 +02:00
|
|
|
//
|
|
|
|
// This file is part of the GNU ISO C++ Library. This library is free
|
|
|
|
// software; you can redistribute it and/or modify it under the
|
|
|
|
// terms of the GNU General Public License as published by the
|
|
|
|
// Free Software Foundation; either version 2, or (at your option)
|
|
|
|
// any later version.
|
|
|
|
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this library; see the file COPYING. If not, write to the Free
|
2005-08-17 04:28:44 +02:00
|
|
|
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
2003-06-11 17:52:11 +02:00
|
|
|
// USA.
|
|
|
|
|
|
|
|
// As a special exception, you may use this file as part of a free software
|
|
|
|
// library without restriction. Specifically, if other files instantiate
|
|
|
|
// templates or use macros or inline functions from this file, or you compile
|
|
|
|
// this file and link it with other files to produce an executable, this
|
|
|
|
// file does not by itself cause the resulting executable to be covered by
|
|
|
|
// the GNU General Public License. This exception does not however
|
|
|
|
// invalidate any other reasons why the executable file might be covered by
|
|
|
|
// the GNU General Public License.
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1996-1997
|
|
|
|
* Silicon Graphics Computer Systems, Inc.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, distribute and sell this software
|
|
|
|
* and its documentation for any purpose is hereby granted without fee,
|
|
|
|
* provided that the above copyright notice appear in all copies and
|
|
|
|
* that both that copyright notice and this permission notice appear
|
|
|
|
* in supporting documentation. Silicon Graphics makes no
|
|
|
|
* representations about the suitability of this software for any
|
|
|
|
* purpose. It is provided "as is" without express or implied warranty.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file allocator.h
|
|
|
|
* This is an internal header file, included by other library headers.
|
|
|
|
* You should not attempt to use it directly.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _ALLOCATOR_H
|
|
|
|
#define _ALLOCATOR_H 1
|
|
|
|
|
2004-02-23 16:41:43 +01:00
|
|
|
// Define the base class to std::allocator.
|
2004-03-13 07:54:25 +01:00
|
|
|
#include <bits/c++allocator.h>
|
2003-06-11 17:52:11 +02:00
|
|
|
|
2005-12-19 01:56:05 +01:00
|
|
|
_GLIBCXX_BEGIN_NAMESPACE(std)
|
|
|
|
|
2004-01-29 01:18:40 +01:00
|
|
|
template<typename _Tp>
|
|
|
|
class allocator;
|
2003-06-11 17:52:11 +02:00
|
|
|
|
2004-11-24 05:11:23 +01:00
|
|
|
/// allocator<void> specialization.
|
2004-01-29 01:18:40 +01:00
|
|
|
template<>
|
|
|
|
class allocator<void>
|
2003-06-11 17:52:11 +02:00
|
|
|
{
|
2004-01-29 01:18:40 +01:00
|
|
|
public:
|
|
|
|
typedef size_t size_type;
|
|
|
|
typedef ptrdiff_t difference_type;
|
|
|
|
typedef void* pointer;
|
|
|
|
typedef const void* const_pointer;
|
|
|
|
typedef void value_type;
|
|
|
|
|
|
|
|
template<typename _Tp1>
|
|
|
|
struct rebind
|
|
|
|
{ typedef allocator<_Tp1> other; };
|
2003-06-11 17:52:11 +02:00
|
|
|
};
|
|
|
|
|
2004-11-24 05:11:23 +01:00
|
|
|
/**
|
|
|
|
* @brief The "standard" allocator, as per [20.4].
|
|
|
|
*
|
|
|
|
* Further details:
|
2008-03-26 07:27:35 +01:00
|
|
|
* http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt04ch11.html
|
2004-11-24 05:11:23 +01:00
|
|
|
*/
|
2003-06-11 17:52:11 +02:00
|
|
|
template<typename _Tp>
|
2005-05-24 22:28:55 +02:00
|
|
|
class allocator: public __glibcxx_base_allocator<_Tp>
|
2003-06-11 17:52:11 +02:00
|
|
|
{
|
2004-01-29 01:18:40 +01:00
|
|
|
public:
|
2003-06-11 17:52:11 +02:00
|
|
|
typedef size_t size_type;
|
|
|
|
typedef ptrdiff_t difference_type;
|
|
|
|
typedef _Tp* pointer;
|
|
|
|
typedef const _Tp* const_pointer;
|
|
|
|
typedef _Tp& reference;
|
|
|
|
typedef const _Tp& const_reference;
|
|
|
|
typedef _Tp value_type;
|
|
|
|
|
|
|
|
template<typename _Tp1>
|
|
|
|
struct rebind
|
|
|
|
{ typedef allocator<_Tp1> other; };
|
|
|
|
|
|
|
|
allocator() throw() { }
|
|
|
|
|
2004-06-25 08:10:44 +02:00
|
|
|
allocator(const allocator& __a) throw()
|
2005-05-24 22:28:55 +02:00
|
|
|
: __glibcxx_base_allocator<_Tp>(__a) { }
|
2003-06-11 17:52:11 +02:00
|
|
|
|
|
|
|
template<typename _Tp1>
|
|
|
|
allocator(const allocator<_Tp1>&) throw() { }
|
|
|
|
|
|
|
|
~allocator() throw() { }
|
|
|
|
|
2004-01-29 01:18:40 +01:00
|
|
|
// Inherit everything else.
|
2003-06-11 17:52:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
template<typename _T1, typename _T2>
|
|
|
|
inline bool
|
|
|
|
operator==(const allocator<_T1>&, const allocator<_T2>&)
|
|
|
|
{ return true; }
|
|
|
|
|
2007-10-18 12:00:18 +02:00
|
|
|
template<typename _Tp>
|
|
|
|
inline bool
|
|
|
|
operator==(const allocator<_Tp>&, const allocator<_Tp>&)
|
|
|
|
{ return true; }
|
|
|
|
|
2003-06-11 17:52:11 +02:00
|
|
|
template<typename _T1, typename _T2>
|
|
|
|
inline bool
|
|
|
|
operator!=(const allocator<_T1>&, const allocator<_T2>&)
|
|
|
|
{ return false; }
|
|
|
|
|
2007-10-18 12:00:18 +02:00
|
|
|
template<typename _Tp>
|
|
|
|
inline bool
|
|
|
|
operator!=(const allocator<_Tp>&, const allocator<_Tp>&)
|
|
|
|
{ return false; }
|
|
|
|
|
2003-06-11 17:52:11 +02:00
|
|
|
// Inhibit implicit instantiations for required instantiations,
|
|
|
|
// which are defined via explicit instantiations elsewhere.
|
|
|
|
// NB: This syntax is a GNU extension.
|
2003-07-05 06:05:45 +02:00
|
|
|
#if _GLIBCXX_EXTERN_TEMPLATE
|
2003-06-11 17:52:11 +02:00
|
|
|
extern template class allocator<char>;
|
|
|
|
extern template class allocator<wchar_t>;
|
|
|
|
#endif
|
2004-01-29 01:18:40 +01:00
|
|
|
|
|
|
|
// Undefine.
|
2005-05-24 22:28:55 +02:00
|
|
|
#undef __glibcxx_base_allocator
|
2005-12-19 01:56:05 +01:00
|
|
|
|
2006-01-04 12:34:45 +01:00
|
|
|
// To implement Option 3 of DR 431.
|
re PR c++/26099 (support for type traits is not available)
gcc/
2007-03-30 Paolo Carlini <pcarlini@suse.de>
PR c++/26099
* c-common.h (enum rid): Add RID_HAS_NOTHROW_ASSIGN,
RID_HAS_NOTHROW_CONSTRUCTOR, RID_HAS_NOTHROW_COPY,
RID_HAS_TRIVIAL_ASSIGN, RID_HAS_TRIVIAL_CONSTRUCTOR,
RID_HAS_TRIVIAL_COPY, RID_HAS_TRIVIAL_DESTRUCTOR,
RID_HAS_VIRTUAL_DESTRUCTOR, RID_IS_ABSTRACT, RID_IS_BASE_OF,
RID_IS_CONVERTIBLE_TO, RID_IS_CLASS, RID_IS_EMPTY, RID_IS_ENUM,
RID_IS_POD, RID_IS_POLYMORPHIC, RID_IS_UNION, as
C++ extensions.
* doc/extend.texi (Extensions to the C++ Language): Add Type Traits.
gcc/cp/
2007-03-30 Paolo Carlini <pcarlini@suse.de>
PR c++/26099
* cp-tree.h (enum cp_trait_kind, struct tree_trait_expr,
TRAIT_EXPR_TYPE1, TRAIT_EXPR_TYPE2, TRAIT_EXPR_KIND): Add.
(enum cp_tree_node_structure_enum, union lang_tree_node): Update.
(CLASS_TYPE_NON_UNION_P): Add.
(struct lang_type_class): Add has_complex_dflt.
(TYPE_HAS_COMPLEX_DFLT, TYPE_HAS_TRIVIAL_DFLT): Add.
(locate_copy, locate_ctor, locate_dtor, finish_trait_expr): Declare.
* cp-tree.def: Add TRAIT_EXPR.
* cp-objcp-common.c (cp_tree_size): Add TRAIT_EXPR case.
* lex.c (struct resword): Add __has_nothrow_assign,
__has_nothrow_constructor, __has_nothrow_copy, __has_trivial_assign,
__has_trivial_constructor, __has_trivial_copy,
__has_trivial_destructor, __has_virtual_destructor, __is_abstract,
__is_base_of, __is_class, __is_convertible_to, __is_empty, __is_enum,
__is_pod, __is_polymorphic, __is_union.
* parser.c (cp_parser_primary_expression): Deal with the new RIDs.
(cp_parser_trait_expr): New.
* semantics.c (finish_trait_expr, trait_expr_value
classtype_has_nothrow_copy_or_assign_p): New.
* method.c (locate_copy, locate_ctor, locate_dtor): Do not define
as static.
* decl.c (cp_tree_node_structure): Add TRAIT_EXPR.
* class.c (check_bases, check_field_decl, check_bases_and_members):
Deal with TYPE_HAS_COMPLEX_DFLT (t) too.
* pt.c (uses_template_parms, tsubst_copy_and_build,
value_dependent_expression_p, type_dependent_expression_p): Deal with
TRAIT_EXPR.
* tree.c (cp_walk_subtrees): Deal with TRAIT_EXPR.
gcc/testsuite/
2007-03-30 Paolo Carlini <pcarlini@suse.de>
PR c++/26099
* g++.dg/ext/is_base_of.C: New.
* g++.dg/ext/has_virtual_destructor.C: New.
* g++.dg/ext/is_polymorphic.C: New.
* g++.dg/ext/is_base_of_diagnostic.C: New.
* g++.dg/ext/is_enum.C: New.
* g++.dg/ext/has_nothrow_assign.C: New.
* g++.dg/ext/has_nothrow_constructor.C: New.
* g++.dg/ext/is_empty.C: New.
* g++.dg/ext/has_trivial_copy.C: New.
* g++.dg/ext/has_trivial_assign.C: New.
* g++.dg/ext/is_abstract.C: New.
* g++.dg/ext/is_pod.C: New.
* g++.dg/ext/has_nothrow_copy.C: New.
* g++.dg/ext/is_class.C: New.
* g++.dg/ext/has_trivial_constructor.C: New.
* g++.dg/ext/is_union.C: New.
* g++.dg/ext/has_trivial_destructor.C: New.
* g++.dg/tree-ssa/pr22444.C: Adjust, avoid __is_pod.
* g++.dg/template/crash43.C: Likewise.
libstdc++-v3/
2007-03-30 Paolo Carlini <pcarlini@suse.de>
PR c++/26099
* include/bits/cpp_type_traits.h (struct __is_pod, struct __is_empty):
Remove.
* include/bits/valarray_array.h: Adjust.
* include/bits/allocator.h: Likewise.
* include/bits/stl_tree.h: Likewise.
From-SVN: r123366
2007-03-30 21:45:57 +02:00
|
|
|
template<typename _Alloc, bool = __is_empty(_Alloc)>
|
2006-01-04 12:34:45 +01:00
|
|
|
struct __alloc_swap
|
|
|
|
{ static void _S_do_it(_Alloc&, _Alloc&) { } };
|
|
|
|
|
|
|
|
template<typename _Alloc>
|
|
|
|
struct __alloc_swap<_Alloc, false>
|
|
|
|
{
|
|
|
|
static void
|
|
|
|
_S_do_it(_Alloc& __one, _Alloc& __two)
|
|
|
|
{
|
|
|
|
// Precondition: swappable allocators.
|
|
|
|
if (__one != __two)
|
|
|
|
swap(__one, __two);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-10-18 21:31:22 +02:00
|
|
|
// Optimize for stateless allocators.
|
|
|
|
template<typename _Alloc, bool = __is_empty(_Alloc)>
|
|
|
|
struct __alloc_neq
|
|
|
|
{
|
|
|
|
static bool
|
|
|
|
_S_do_it(const _Alloc&, const _Alloc&)
|
|
|
|
{ return false; }
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename _Alloc>
|
|
|
|
struct __alloc_neq<_Alloc, false>
|
|
|
|
{
|
|
|
|
static bool
|
|
|
|
_S_do_it(const _Alloc& __one, const _Alloc& __two)
|
|
|
|
{ return __one != __two; }
|
|
|
|
};
|
|
|
|
|
2005-12-19 01:56:05 +01:00
|
|
|
_GLIBCXX_END_NAMESPACE
|
2003-06-11 17:52:11 +02:00
|
|
|
|
|
|
|
#endif
|