Orxonox  0.0.5 Codename: Arcturus
RefToValue.h
Go to the documentation of this file.
1 // The Loki Library
3 // Copyright (c) 2006 Richard Sposato
4 // Copyright (c) 2006 Peter Kümmel
5 // Permission to use, copy, modify, distribute and sell this software for any
6 // purpose is hereby granted without fee, provided that the above copyright
7 // notice appear in all copies and that both that copyright notice and this
8 // permission notice appear in supporting documentation.
9 // The authors make no representations about the
10 // suitability of this software for any purpose. It is provided "as is"
11 // without express or implied warranty.
13 #ifndef LOKI_REFTOVALUE_INC_
14 #define LOKI_REFTOVALUE_INC_
15 
16 // $Id: RefToValue.h 751 2006-10-17 19:50:37Z syntheticpp $
17 
18 
19 namespace Loki
20 {
21 
29 
30  template <class T>
31  class RefToValue
32  {
33  public:
34 
35  RefToValue(T& ref) : ref_(ref)
36  {}
37 
38  RefToValue(const RefToValue& rhs) : ref_(rhs.ref_)
39  {}
40 
41  operator T& () const
42  {
43  return ref_;
44  }
45 
46  private:
47  // Disable - not implemented
48  RefToValue();
50 
51  T& ref_;
52  };
53 
54 
59 
60  template <class T>
61  inline RefToValue<T> ByRef(T& t)
62  {
63  return RefToValue<T>(t);
64  }
65 
66 }
67 
68 
69 #endif // end file guardian
70 
Definition: NullType.h:21
RefToValue< T > ByRef(T &t)
RefToValue creator.
Definition: RefToValue.h:61
RefToValue(const RefToValue &rhs)
Definition: RefToValue.h:38
RefToValue(T &ref)
Definition: RefToValue.h:35
RefToValue & operator=(const RefToValue &)
T & ref_
Definition: RefToValue.h:51
Definition: InputPrereqs.h:78
Transports a reference as a value Serves to implement the Colvin/Gibbons trick for SmartPtr/ScopeGuar...
Definition: RefToValue.h:31