MorphoGraphX
Tie.hpp
Go to the documentation of this file.
1 //
2 // This file is part of MorphoGraphX - http://www.MorphoGraphX.org
3 // Copyright (C) 2012-2015 Richard S. Smith and collaborators.
4 //
5 // If you use MorphoGraphX in your work, please cite:
6 // http://dx.doi.org/10.7554/eLife.05864
7 //
8 // MorphoGraphX is free software, and is licensed under under the terms of the
9 // GNU General (GPL) Public License version 2.0, http://www.gnu.org/licenses.
10 //
11 #ifndef TIE_HPP
12 #define TIE_HPP
13 
19 #include <Config.hpp>
20 
21 #include <utility>
22 
23 namespace mgx {
24 namespace util {
25 
26 // Code taken from the Boost library !
32 template <typename T, typename U> struct refpair {
33  typedef T first_type;
34  typedef U second_type;
35 
37  refpair(T& x, U& y)
38  : first(x)
39  , second(y)
40  {
41  }
43  refpair(refpair const& rp)
44  : first(rp.first)
45  , second(rp.second)
46  {
47  }
48 
50  refpair& operator=(std::pair<T, U> const& p)
51  {
52  first = p.first;
53  second = p.second;
54  return *this;
55  }
56 
58  T& first;
60  U& second;
61 };
62 
76 template <typename T, typename U> inline refpair<T, U> tie(T& x, U& y) {
77  return refpair<T, U>(x, y);
78 }
79 } // namespace util
80 } // namespace mgx
81 #endif
U & second
The second member of the pair.
Definition: Tie.hpp:60
refpair & operator=(std::pair< T, U > const &p)
Assign the values of p to the references in this pair.
Definition: Tie.hpp:50
T & first
The first member of the pair.
Definition: Tie.hpp:58
refpair(refpair const &rp)
Construct a copy.
Definition: Tie.hpp:43
This namespace contains all the API of MorphoGraphX.
Definition: Assert.hpp:26
Class used to hold references for the util::tie() function.
Definition: Tie.hpp:32
refpair< T, U > tie(T &x, U &y)
Tie two variables to the values of a pair.
Definition: Tie.hpp:76
refpair(T &x, U &y)
Construct a pair of references to x and y.
Definition: Tie.hpp:37