2003-06-11 15:52:11 +00:00
|
|
|
// Allocators -*- C++ -*-
|
|
|
|
|
2010-01-08 13:01:24 +00:00
|
|
|
// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
|
2006-01-04 11:34:45 +00:00
|
|
|
// Free Software Foundation, Inc.
|
2003-06-11 15:52:11 +00: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
|
2009-04-09 17:00:19 +02:00
|
|
|
// Free Software Foundation; either version 3, or (at your option)
|
2003-06-11 15:52:11 +00:00
|
|
|
// 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.
|
|
|
|
|
2009-04-09 17:00:19 +02:00
|
|
|
// Under Section 7 of GPL version 3, you are granted additional
|
|
|
|
// permissions described in the GCC Runtime Library Exception, version
|
|
|
|
// 3.1, as published by the Free Software Foundation.
|
2003-06-11 15:52:11 +00:00
|
|
|
|
2009-04-09 17:00:19 +02:00
|
|
|
// You should have received a copy of the GNU General Public License and
|
|
|
|
// a copy of the GCC Runtime Library Exception along with this program;
|
|
|
|
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
|
|
// <http://www.gnu.org/licenses/>.
|
2003-06-11 15:52:11 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 15:41:43 +00:00
|
|
|
// Define the base class to std::allocator.
|
2004-03-13 06:54:25 +00:00
|
|
|
#include <bits/c++allocator.h>
|
2003-06-11 15:52:11 +00:00
|
|
|
|
2010-09-27 17:27:43 +00:00
|
|
|
#ifdef __GXX_EXPERIMENTAL_CXX0X__
|
2010-10-05 15:53:35 +00:00
|
|
|
#include <type_traits> // For _GLIBCXX_HAS_NESTED_TYPE
|
2010-09-27 17:27:43 +00:00
|
|
|
#endif
|
|
|
|
|
2005-12-19 00:56:05 +00:00
|
|
|
_GLIBCXX_BEGIN_NAMESPACE(std)
|
|
|
|
|
2009-02-21 00:45:21 +00:00
|
|
|
/**
|
|
|
|
* @defgroup allocators Allocators
|
|
|
|
* @ingroup memory
|
|
|
|
*
|
|
|
|
* Classes encapsulating memory operations.
|
|
|
|
*/
|
|
|
|
|
2004-01-29 00:18:40 +00:00
|
|
|
template<typename _Tp>
|
|
|
|
class allocator;
|
2003-06-11 15:52:11 +00:00
|
|
|
|
2004-11-24 04:11:23 +00:00
|
|
|
/// allocator<void> specialization.
|
2004-01-29 00:18:40 +00:00
|
|
|
template<>
|
|
|
|
class allocator<void>
|
2003-06-11 15:52:11 +00:00
|
|
|
{
|
2004-01-29 00:18:40 +00: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 15:52:11 +00:00
|
|
|
};
|
|
|
|
|
2004-11-24 04:11:23 +00:00
|
|
|
/**
|
2010-02-04 18:20:34 +00:00
|
|
|
* @brief The @a standard allocator, as per [20.4].
|
2009-02-21 00:45:21 +00:00
|
|
|
* @ingroup allocators
|
2004-11-24 04:11:23 +00:00
|
|
|
*
|
|
|
|
* Further details:
|
2008-03-26 06:27:35 +00:00
|
|
|
* http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt04ch11.html
|
2004-11-24 04:11:23 +00:00
|
|
|
*/
|
2003-06-11 15:52:11 +00:00
|
|
|
template<typename _Tp>
|
2005-05-24 20:28:55 +00:00
|
|
|
class allocator: public __glibcxx_base_allocator<_Tp>
|
2003-06-11 15:52:11 +00:00
|
|
|
{
|
2004-01-29 00:18:40 +00:00
|
|
|
public:
|
2003-06-11 15:52:11 +00: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 06:10:44 +00:00
|
|
|
allocator(const allocator& __a) throw()
|
2005-05-24 20:28:55 +00:00
|
|
|
: __glibcxx_base_allocator<_Tp>(__a) { }
|
2003-06-11 15:52:11 +00:00
|
|
|
|
|
|
|
template<typename _Tp1>
|
|
|
|
allocator(const allocator<_Tp1>&) throw() { }
|
|
|
|
|
|
|
|
~allocator() throw() { }
|
|
|
|
|
2004-01-29 00:18:40 +00:00
|
|
|
// Inherit everything else.
|
2003-06-11 15:52:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template<typename _T1, typename _T2>
|
|
|
|
inline bool
|
|
|
|
operator==(const allocator<_T1>&, const allocator<_T2>&)
|
|
|
|
{ return true; }
|
|
|
|
|
2007-10-18 10:00:18 +00:00
|
|
|
template<typename _Tp>
|
|
|
|
inline bool
|
|
|
|
operator==(const allocator<_Tp>&, const allocator<_Tp>&)
|
|
|
|
{ return true; }
|
|
|
|
|
2003-06-11 15:52:11 +00:00
|
|
|
template<typename _T1, typename _T2>
|
|
|
|
inline bool
|
|
|
|
operator!=(const allocator<_T1>&, const allocator<_T2>&)
|
|
|
|
{ return false; }
|
|
|
|
|
2007-10-18 10:00:18 +00:00
|
|
|
template<typename _Tp>
|
|
|
|
inline bool
|
|
|
|
operator!=(const allocator<_Tp>&, const allocator<_Tp>&)
|
|
|
|
{ return false; }
|
|
|
|
|
2003-06-11 15:52:11 +00:00
|
|
|
// Inhibit implicit instantiations for required instantiations,
|
|
|
|
// which are defined via explicit instantiations elsewhere.
|
|
|
|
// NB: This syntax is a GNU extension.
|
2003-07-05 04:05:45 +00:00
|
|
|
#if _GLIBCXX_EXTERN_TEMPLATE
|
2003-06-11 15:52:11 +00:00
|
|
|
extern template class allocator<char>;
|
|
|
|
extern template class allocator<wchar_t>;
|
|
|
|
#endif
|
2004-01-29 00:18:40 +00:00
|
|
|
|
|
|
|
// Undefine.
|
2005-05-24 20:28:55 +00:00
|
|
|
#undef __glibcxx_base_allocator
|
2005-12-19 00:56:05 +00:00
|
|
|
|
2006-01-04 11:34:45 +00: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 19:45:57 +00:00
|
|
|
template<typename _Alloc, bool = __is_empty(_Alloc)>
|
2006-01-04 11:34:45 +00: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 19:31:22 +00: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; }
|
|
|
|
};
|
|
|
|
|
2010-01-08 13:01:24 +00:00
|
|
|
#ifdef __GXX_EXPERIMENTAL_CXX0X__
|
2010-09-27 17:27:43 +00:00
|
|
|
// A very basic implementation for now. In general we have to wait for
|
|
|
|
// the availability of the infrastructure described in N2983: we should
|
|
|
|
// try when either T has a move constructor which cannot throw or T is
|
|
|
|
// CopyContructible.
|
|
|
|
// NB: This code doesn't properly belong here, we should find a more
|
|
|
|
// suited place common to std::vector and std::deque.
|
|
|
|
template<typename _Tp,
|
|
|
|
bool = __has_trivial_copy(typename _Tp::value_type)>
|
|
|
|
struct __shrink_to_fit
|
|
|
|
{ static void _S_do_it(_Tp&) { } };
|
|
|
|
|
|
|
|
template<typename _Tp>
|
|
|
|
struct __shrink_to_fit<_Tp, true>
|
|
|
|
{
|
|
|
|
static void
|
|
|
|
_S_do_it(_Tp& __v)
|
|
|
|
{
|
|
|
|
__try
|
|
|
|
{ _Tp(__v).swap(__v); }
|
|
|
|
__catch(...) { }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// [allocator.tag]
|
|
|
|
struct allocator_arg_t { };
|
|
|
|
|
2010-11-02 02:35:28 +00:00
|
|
|
constexpr allocator_arg_t allocator_arg = allocator_arg_t();
|
2010-09-27 17:27:43 +00:00
|
|
|
|
2010-10-05 15:53:35 +00:00
|
|
|
_GLIBCXX_HAS_NESTED_TYPE(allocator_type)
|
2010-09-27 17:27:43 +00:00
|
|
|
|
|
|
|
template<typename _Tp, typename _Alloc,
|
2010-10-05 15:53:35 +00:00
|
|
|
bool = __has_allocator_type<_Tp>::value>
|
2010-09-27 17:27:43 +00:00
|
|
|
struct __uses_allocator_helper
|
|
|
|
: public false_type { };
|
|
|
|
|
|
|
|
template<typename _Tp, typename _Alloc>
|
|
|
|
struct __uses_allocator_helper<_Tp, _Alloc, true>
|
|
|
|
: public integral_constant<bool, is_convertible<_Alloc,
|
|
|
|
typename _Tp::allocator_type>::value>
|
|
|
|
{ };
|
|
|
|
|
|
|
|
/// [allocator.uses.trait]
|
|
|
|
template<typename _Tp, typename _Alloc>
|
|
|
|
struct uses_allocator
|
|
|
|
: public integral_constant<bool,
|
|
|
|
__uses_allocator_helper<_Tp, _Alloc>::value>
|
|
|
|
{ };
|
|
|
|
|
2010-01-08 13:01:24 +00:00
|
|
|
#endif
|
|
|
|
|
2005-12-19 00:56:05 +00:00
|
|
|
_GLIBCXX_END_NAMESPACE
|
2003-06-11 15:52:11 +00:00
|
|
|
|
|
|
|
#endif
|