File: auto_ptr.hxx.in

package info (click to toggle)
cmake 2.4.5-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 16,804 kB
  • ctags: 18,861
  • sloc: cpp: 84,497; ansic: 84,379; yacc: 3,136; sh: 1,970; lex: 1,004; lisp: 119; makefile: 89; xml: 88; perl: 60; tcl: 55; python: 25; php: 25; ruby: 22; java: 20; f90: 19; fortran: 3
file content (58 lines) | stat: -rw-r--r-- 1,992 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*=========================================================================

  Program:   KWSys - Kitware System Library
  Module:    $RCSfile: auto_ptr.hxx.in,v $

  Copyright (c) Kitware, Inc., Insight Consortium.  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#ifndef @KWSYS_NAMESPACE@_auto_ptr_hxx
#define @KWSYS_NAMESPACE@_auto_ptr_hxx

namespace @KWSYS_NAMESPACE@
{

// C++98 Standard Section 20.4.5 - Template class auto_ptr.
template <class X>
class auto_ptr
{
  template <class Y> struct auto_ptr_ref
  {
    auto_ptr<Y>& p_;
    explicit auto_ptr_ref(auto_ptr<Y>& p): p_(p) {}
  };
  X* x_;
public:
  typedef X element_type;

  template <class Y>
  auto_ptr(auto_ptr<Y>& a) throw(): x_(a.release()) {}
  template <class Y>
  auto_ptr& operator=(auto_ptr<Y>& a) throw()
    { reset(a.release()); return *this; }

  explicit auto_ptr(X* p=0) throw(): x_(p) {}
  auto_ptr(auto_ptr& a) throw(): x_(a.release()) {}
  auto_ptr& operator=(auto_ptr& a) throw() { reset(a.release()); return *this; }
  ~auto_ptr() throw() { delete get(); }

  X& operator*() const throw() { return *get(); }
  X* operator->() const throw() { return get(); }
  X* get() const throw() { return x_; }
  X* release() throw() { X* x = x_; x_ = 0; return x; }
  void reset(X* p=0) throw() { if(get() != p) { delete get(); x_ = p; } }

  auto_ptr(auto_ptr_ref<X> r) throw(): x_(r.p_.release()) {}
  template <class Y> operator auto_ptr_ref<Y>() throw() { return *this; }
  template <class Y> operator auto_ptr<Y>() throw() { return release(); }
  auto_ptr& operator=(auto_ptr_ref<X> r) throw() { x_ = r.p_.release(); return *this; }
};

} // namespace @KWSYS_NAMESPACE@

#endif