Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
K
KWSys
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Rolf Eike Beer
KWSys
Commits
4022db6d
Commit
4022db6d
authored
18 years ago
by
Brad King
Browse files
Options
Downloads
Patches
Plain Diff
ENH: Enabled support for use_auto_ptr(get_auto_ptr()) syntax on HP compiler.
parent
e44130b9
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
auto_ptr.hxx.in
+47
-19
47 additions, 19 deletions
auto_ptr.hxx.in
testAutoPtr.cxx
+0
-2
0 additions, 2 deletions
testAutoPtr.cxx
with
47 additions
and
21 deletions
auto_ptr.hxx.in
+
47
−
19
View file @
4022db6d
...
...
@@ -16,11 +16,25 @@
#include <@KWSYS_NAMESPACE@/Configure.hxx>
// The HP compiler cannot handle the conversions necessary to use
// auto_ptr_ref to pass an auto_ptr returned from one function
// directly to another function as in use_auto_ptr(get_auto_ptr()).
// We instead use const_cast to achieve the syntax on that platform.
// We do not use const_cast on other platforms to maintain the C++
// standard design and guarantee that if an auto_ptr is bound
// to a reference-to-const then ownership will be maintained.
#if defined(__HP_aCC)
# define @KWSYS_NAMESPACE@_AUTO_PTR_REF 0
#else
# define @KWSYS_NAMESPACE@_AUTO_PTR_REF 1
#endif
namespace @KWSYS_NAMESPACE@
{
template <class X> class auto_ptr;
#if @KWSYS_NAMESPACE@_AUTO_PTR_REF
namespace detail
{
// The auto_ptr_ref template is supposed to be a private member of
...
...
@@ -38,12 +52,24 @@ template <class Y> struct auto_ptr_ref
auto_ptr_ref(Y* p, int): p_(p) {}
};
}
#endif
/** C++98 Standard Section 20.4.5 - Template class auto_ptr. */
template <class X>
class auto_ptr
{
#if @KWSYS_NAMESPACE@_AUTO_PTR_REF
typedef auto_ptr auto_ptr_source;
static inline auto_ptr& cast(auto_ptr_source& a) { return a; }
#else
typedef auto_ptr const auto_ptr_source;
static inline auto_ptr& cast(auto_ptr_source& a)
{ return const_cast<auto_ptr&>(a); }
#endif
/** The pointer to the object held. */
X* x_;
public:
/** The type of object held by the auto_ptr. */
typedef X element_type;
...
...
@@ -73,19 +99,19 @@ public:
explicit auto_ptr(X* p=0) throw(): x_(p)
{
}
/** Construct from another auto_ptr holding an object of the same
type. This transfers ownership to the newly constructed
auto_ptr. */
auto_ptr(auto_ptr& a) throw(): x_(
a
.release())
auto_ptr(auto_ptr
_source
& a) throw(): x_(
cast(a)
.release())
{
}
/** Assign from another auto_ptr holding an object of the same type.
This transfers ownership to the newly constructed auto_ptr. */
auto_ptr& operator=(auto_ptr& a) throw()
auto_ptr& operator=(auto_ptr
_source
& a) throw()
{
this->reset(
a
.release());
this->reset(
cast(a)
.release());
return *this;
}
...
...
@@ -135,21 +161,6 @@ public:
}
}
/** Construct from an auto_ptr_ref. This is used when the
constructor argument is a call to a function returning an
auto_ptr. */
auto_ptr(detail::auto_ptr_ref<X> r) throw(): x_(r.p_)
{
}
/** Convert to an auto_ptr_ref. This is used when a function
returning an auto_ptr is the argument to the constructor of
another auto_ptr. */
template <class Y> operator detail::auto_ptr_ref<Y>() throw()
{
return detail::auto_ptr_ref<Y>(this->release(), 1);
}
/** Convert to an auto_ptr holding an object of a compatible type.
This transfers ownership to the returned auto_ptr. */
template <class Y> operator auto_ptr<Y>() throw()
...
...
@@ -157,6 +168,14 @@ public:
return auto_ptr<Y>(this->release());
}
#if @KWSYS_NAMESPACE@_AUTO_PTR_REF
/** Construct from an auto_ptr_ref. This is used when the
constructor argument is a call to a function returning an
auto_ptr. */
auto_ptr(detail::auto_ptr_ref<X> r) throw(): x_(r.p_)
{
}
/** Assign from an auto_ptr_ref. This is used when a function
returning an auto_ptr is passed on the right-hand-side of an
assignment. */
...
...
@@ -165,6 +184,15 @@ public:
this->reset(r.p_);
return *this;
}
/** Convert to an auto_ptr_ref. This is used when a function
returning an auto_ptr is the argument to the constructor of
another auto_ptr. */
template <class Y> operator detail::auto_ptr_ref<Y>() throw()
{
return detail::auto_ptr_ref<Y>(this->release(), 1);
}
#endif
};
} // namespace @KWSYS_NAMESPACE@
...
...
This diff is collapsed.
Click to expand it.
testAutoPtr.cxx
+
0
−
2
View file @
4022db6d
...
...
@@ -115,14 +115,12 @@ int testAutoPtr(int, char*[])
"auto_ptr did not release ownership to called function"
);
}
#if !defined(__HP_aCC)
{
int
received
=
function_call
(
generate_auto_ptr_A
());
ASSERT
(
received
,
"auto_ptr in called function did not take ownership "
"from factory function"
);
}
#endif
#if 0
// Is this allowed by the standard?
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment