X-Boost  2.3.8
ref.h
Go to the documentation of this file.
1 /******************************************************************************
2 * sprint::container::ref
3 *
4 * Copyright (C) 2005-2014 Paolo Medici <www.pmx.it>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 *******************************************************************************/
21 
22 #ifndef _SPRINT_REF_H
23 #define _SPRINT_REF_H
24 
28 namespace sprint {
29 
30  namespace detail {
31 
33  template<class T>
34  class ref {
35  T & m_ptr;
36  public:
37  ref(T & ptr) : m_ptr(ptr) { }
38 
39  T * operator ->() { return &m_ptr; }
40  const T * operator ->() const { return &m_ptr; }
41  T & operator *() { return m_ptr; }
42  const T & operator *() const { return m_ptr; }
43 
44  operator T& () const { return m_ptr; }
45 
46  };
47 
49  template<class T>
50  class const_ref {
51  const T & m_ptr;
52  public:
53  const_ref(const T & ptr) : m_ptr(ptr) { }
54 
55  const T * operator ->() const { return &m_ptr; }
56  const T & operator *() const { return m_ptr; }
57 
58  operator T& () const { return m_ptr; }
59  };
60 
61  } // detail
62 
64  template<class T>
65  inline sprint::detail::const_ref<T> ref(const T & ptr)
66  {
67  return sprint::detail::const_ref<T>(ptr);
68  }
69 
71  template<class T>
72  inline sprint::detail::const_ref<T> c_ref(const T & ptr)
73  {
74  return sprint::detail::const_ref<T>(ptr);
75  }
76 
78  template<class T>
79  inline sprint::detail::ref<T> ref(T & ptr)
80  {
81  return sprint::detail::ref<T>(ptr);
82  }
83 
84  }
85 
86 #endif
a const reference holder of an object
Definition: ref.h:50
a reference holder of an object
Definition: ref.h:34