MADNESS  version 0.9
move.h
Go to the documentation of this file.
1 /*
2  This file is part of MADNESS.
3 
4  Copyright (C) 2012 Justus Calvin
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program 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
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 
20  For more information please contact:
21 
22  Robert J. Harrison
23  Oak Ridge National Laboratory
24  One Bethel Valley Road
25  P.O. Box 2008, MS-6367
26 
27  email: harrisonrj@ornl.gov
28  tel: 865-241-3937
29  fax: 865-572-0680
30 
31 
32  $Id$
33 */
34 
35 #ifndef MADNESS_WORLD_MOVE_H__INCLUDED
36 #define MADNESS_WORLD_MOVE_H__INCLUDED
37 
38 namespace madness {
39  namespace detail {
40 
42 
46  template <typename T>
47  class MoveWrapper {
48  T* t_;
49 
50  public:
52 
54  MoveWrapper(T& t) : t_(&t) { }
55 
57 
59  MoveWrapper(const MoveWrapper<T>& other) : t_(other.t_) { }
60 
62 
66  t_ = other.t_;
67  return *this;
68  }
69 
71 
73  T& get() const { return *t_; }
74 
76 
78  T* get_pointer() const { return t_; }
79  }; // class MoveWrapper
80 
82 
84  template <typename T>
85  struct is_movable : public std::false_type { };
86 
88 
90  template <typename T>
91  struct is_movable<MoveWrapper<T> > : public std::true_type { };
92 
93  } // namspace detail
94 
96 
101  template <typename T>
103 
105 
110  template <typename T>
111  const T& move(const T& t) { return t; }
112 
114 
118  template <typename T>
119  T& unwrap_move(const detail::MoveWrapper<T>& t) { return t.get(); }
120 
122 
126  template <typename T>
127  typename disable_if<detail::is_movable<T>, T&>::type unwrap_move(T& t) { return t; }
128 
129 } // namespace madness
130 
131 #endif // MADNESS_WORLD_MOVE_H__INCLUDED
MoveWrapper< T > & operator=(const MoveWrapper< T > &other)
Assignment operator.
Definition: move.h:65
T & unwrap_move(const detail::MoveWrapper< T > &t)
Remove move wrapper from a movable object.
Definition: move.h:119
MoveWrapper(const MoveWrapper< T > &other)
Copy constructor.
Definition: move.h:59
bool_constant< true > true_type
Definition: gtest-port.h:1618
disable_if from Boost for conditionally instantiating templates based on type
Definition: enable_if.h:78
bool_constant< false > false_type
Definition: gtest-port.h:1617
Type trait for movable objects.
Definition: move.h:85
const T1 &f1 return GTEST_2_TUPLE_() T(f0, f1)
Wrapper for movable objects.
Definition: move.h:47
detail::MoveWrapper< T > move(T &t)
Move wrapper factory function.
Definition: move.h:102
T & get() const
Get the wrapped object reference.
Definition: move.h:73
MoveWrapper(T &t)
Constructor.
Definition: move.h:54
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45
T * get_pointer() const
Get the wrapped object pointer.
Definition: move.h:78