MorphoGraphX  2.0-1-227
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 {
25  // Code taken from the Boost library !
31  template <typename T, typename U> struct refpair {
32  typedef T first_type;
33  typedef U second_type;
34 
36  refpair(T& x, U& y) : first(x) , second(y) {}
38  refpair(refpair const& rp) : first(rp.first), second(rp.second) {}
39 
41  refpair& operator=(std::pair<T, U> const& p)
42  {
43  first = p.first;
44  second = p.second;
45  return *this;
46  }
47 
49  T& first;
51  U& second;
52  };
53 
67  template <typename T, typename U> inline refpair<T, U> tie(T& x, U& y)
68  {
69  return refpair<T, U>(x, y);
70  }
71 }
72 #endif
mgx::refpair::refpair
refpair(refpair const &rp)
Construct a copy.
Definition: Tie.hpp:38
mgx::refpair::operator=
refpair & operator=(std::pair< T, U > const &p)
Assign the values of p to the references in this pair.
Definition: Tie.hpp:41
mgx
Distributed matrix library.
Definition: Assert.hpp:26
mgx::refpair::second
U & second
The second member of the pair.
Definition: Tie.hpp:51
mgx::refpair::first
T & first
The first member of the pair.
Definition: Tie.hpp:49
mgx::refpair::refpair
refpair(T &x, U &y)
Construct a pair of references to x and y.
Definition: Tie.hpp:36
mgx::tie
refpair< T, U > tie(T &x, U &y)
Tie two variables to the values of a pair.
Definition: Tie.hpp:67
mgx::refpair::second_type
U second_type
Definition: Tie.hpp:33
mgx::refpair
Definition: Tie.hpp:31
mgx::refpair::first_type
T first_type
Definition: Tie.hpp:32