diff options
author | kan <kan@FreeBSD.org> | 2004-07-28 03:12:05 +0000 |
---|---|---|
committer | kan <kan@FreeBSD.org> | 2004-07-28 03:12:05 +0000 |
commit | 96bad46eee8bf907dceb152bbb9d128bed5a4956 (patch) | |
tree | 75ef0e6da73746d6849e25a0996ae34e1aeff51d /contrib/libstdc++/include/std/std_memory.h | |
parent | 5e00ec74d8ce58f99801200d4d3d0412c7cc1b28 (diff) | |
download | FreeBSD-src-96bad46eee8bf907dceb152bbb9d128bed5a4956.zip FreeBSD-src-96bad46eee8bf907dceb152bbb9d128bed5a4956.tar.gz |
Gcc 3.4.2 20040728 C++ support bits.
Diffstat (limited to 'contrib/libstdc++/include/std/std_memory.h')
-rw-r--r-- | contrib/libstdc++/include/std/std_memory.h | 109 |
1 files changed, 62 insertions, 47 deletions
diff --git a/contrib/libstdc++/include/std/std_memory.h b/contrib/libstdc++/include/std/std_memory.h index 47c3ede..4e6641e 100644 --- a/contrib/libstdc++/include/std/std_memory.h +++ b/contrib/libstdc++/include/std/std_memory.h @@ -1,6 +1,6 @@ // <memory> -*- C++ -*- -// Copyright (C) 2001, 2002 Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc. // // 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 @@ -46,17 +46,18 @@ * in your programs, rather than any of the "st[dl]_*.h" implementation files. */ -#ifndef _CPP_MEMORY -#define _CPP_MEMORY 1 +#ifndef _GLIBCXX_MEMORY +#define _GLIBCXX_MEMORY 1 #pragma GCC system_header #include <bits/stl_algobase.h> -#include <bits/stl_alloc.h> +#include <bits/allocator.h> #include <bits/stl_construct.h> #include <bits/stl_iterator_base_types.h> //for iterator_traits #include <bits/stl_uninitialized.h> #include <bits/stl_raw_storage_iter.h> +#include <debug/debug.h> namespace std { @@ -77,33 +78,36 @@ namespace std while (__len > 0) { - _Tp* __tmp = (_Tp*) std::malloc((std::size_t)__len * sizeof(_Tp)); + _Tp* __tmp = static_cast<_Tp*>(::operator new(__len * sizeof(_Tp), + nothrow)); if (__tmp != 0) return pair<_Tp*, ptrdiff_t>(__tmp, __len); __len /= 2; } - return pair<_Tp*, ptrdiff_t>((_Tp*)0, 0); + return pair<_Tp*, ptrdiff_t>(static_cast<_Tp*>(0), 0); } /** - * @brief This is a mostly-useless wrapper around malloc(). + * @brief Allocates a temporary buffer. * @param len The number of objects of type Tp. - * @return See full description. + * @return See full description. * * Reinventing the wheel, but this time with prettier spokes! * - * This function tries to obtain storage for @c len adjacent Tp objects. - * The objects themselves are not constructed, of course. A pair<> is - * returned containing "the buffer s address and capacity (in the units of - * sizeof(Tp)), or a pair of 0 values if no storage can be obtained." - * Note that the capacity obtained may be less than that requested if the - * memory is unavailable; you should compare len with the .second return - * value. + * This function tries to obtain storage for @c len adjacent Tp + * objects. The objects themselves are not constructed, of course. + * A pair<> is returned containing "the buffer s address and + * capacity (in the units of sizeof(Tp)), or a pair of 0 values if + * no storage can be obtained." Note that the capacity obtained + * may be less than that requested if the memory is unavailable; + * you should compare len with the .second return value. + * + * Provides the nothrow exception guarantee. */ template<typename _Tp> inline pair<_Tp*,ptrdiff_t> get_temporary_buffer(ptrdiff_t __len) - { return __get_temporary_buffer(__len, (_Tp*) 0); } + { return std::__get_temporary_buffer(__len, static_cast<_Tp*>(0)); } /** * @brief The companion to get_temporary_buffer(). @@ -115,12 +119,12 @@ namespace std template<typename _Tp> void return_temporary_buffer(_Tp* __p) - { std::free(__p); } + { ::operator delete(__p, nothrow); } /** - * A wrapper class to provide auto_ptr with reference semantics. For - * example, an auto_ptr can be assigned (or constructed from) the result of - * a function which returns an auto_ptr by value. + * A wrapper class to provide auto_ptr with reference semantics. + * For example, an auto_ptr can be assigned (or constructed from) + * the result of a function which returns an auto_ptr by value. * * All the auto_ptr_ref stuff should happen behind the scenes. */ @@ -139,26 +143,28 @@ namespace std * * The Standard says: * <pre> - * An @c auto_ptr owns the object it holds a pointer to. Copying an - * @c auto_ptr copies the pointer and transfers ownership to the destination. - * If more than one @c auto_ptr owns the same object at the same time the - * behavior of the program is undefined. + * An @c auto_ptr owns the object it holds a pointer to. Copying + * an @c auto_ptr copies the pointer and transfers ownership to the + * destination. If more than one @c auto_ptr owns the same object + * at the same time the behavior of the program is undefined. * - * The uses of @c auto_ptr include providing temporary exception-safety for - * dynamically allocated memory, passing ownership of dynamically allocated - * memory to a function, and returning dynamically allocated memory from a - * function. @c auto_ptr does not meet the CopyConstructible and Assignable - * requirements for Standard Library <a href="tables.html#65">container</a> - * elements and thus instantiating a Standard Library container with an - * @c auto_ptr results in undefined behavior. + * The uses of @c auto_ptr include providing temporary + * exception-safety for dynamically allocated memory, passing + * ownership of dynamically allocated memory to a function, and + * returning dynamically allocated memory from a function. @c + * auto_ptr does not meet the CopyConstructible and Assignable + * requirements for Standard Library <a + * href="tables.html#65">container</a> elements and thus + * instantiating a Standard Library container with an @c auto_ptr + * results in undefined behavior. * </pre> * Quoted from [20.4.5]/3. * - * Good examples of what can and cannot be done with auto_ptr can be found - * in the libstdc++ testsuite. + * Good examples of what can and cannot be done with auto_ptr can + * be found in the libstdc++ testsuite. * * @if maint - * _GLIBCPP_RESOLVE_LIB_DEFECTS + * _GLIBCXX_RESOLVE_LIB_DEFECTS * 127. auto_ptr<> conversion issues * These resolutions have all been incorporated. * @endif @@ -195,7 +201,8 @@ namespace std * @brief An %auto_ptr can be constructed from another %auto_ptr. * @param a Another %auto_ptr of a different but related type. * - * A pointer-to-Tp1 must be convertible to a pointer-to-Tp/element_type. + * A pointer-to-Tp1 must be convertible to a + * pointer-to-Tp/element_type. * * This object now @e owns the object previously owned by @a a, * which has given up ownsership. @@ -237,9 +244,9 @@ namespace std } /** - * When the %auto_ptr goes out of scope, the object it owns is deleted. - * If it no longer owns anything (i.e., @c get() is @c NULL), then this - * has no effect. + * When the %auto_ptr goes out of scope, the object it owns is + * deleted. If it no longer owns anything (i.e., @c get() is + * @c NULL), then this has no effect. * * @if maint * The C++ standard says there is supposed to be an empty throw @@ -259,7 +266,11 @@ namespace std * what happens when you dereference one of those...) */ element_type& - operator*() const throw() { return *_M_ptr; } + operator*() const throw() + { + _GLIBCXX_DEBUG_ASSERT(_M_ptr != 0); + return *_M_ptr; + } /** * @brief Smart pointer dereferencing. @@ -268,15 +279,19 @@ namespace std * automatically cause to be dereferenced. */ element_type* - operator->() const throw() { return _M_ptr; } + operator->() const throw() + { + _GLIBCXX_DEBUG_ASSERT(_M_ptr != 0); + return _M_ptr; + } /** * @brief Bypassing the smart pointer. * @return The raw pointer being managed. * * You can get a copy of the pointer that this object owns, for - * situations such as passing to a function which only accepts a raw - * pointer. + * situations such as passing to a function which only accepts + * a raw pointer. * * @note This %auto_ptr still owns the memory. */ @@ -288,8 +303,8 @@ namespace std * @return The raw pointer being managed. * * You can get a copy of the pointer that this object owns, for - * situations such as passing to a function which only accepts a raw - * pointer. + * situations such as passing to a function which only accepts + * a raw pointer. * * @note This %auto_ptr no longer owns the memory. When this object * goes out of scope, nothing will happen. @@ -306,8 +321,8 @@ namespace std * @brief Forcibly deletes the managed object. * @param p A pointer (defaults to NULL). * - * This object now @e owns the object pointed to by @a p. The previous - * object has been deleted. + * This object now @e owns the object pointed to by @a p. The + * previous object has been deleted. */ void reset(element_type* __p = 0) throw() @@ -355,4 +370,4 @@ namespace std }; } // namespace std -#endif +#endif /* _GLIBCXX_MEMORY */ |