L4Re - L4 Runtime Environment
pair
Go to the documentation of this file.
1 // vi:set ft=cpp: -*- Mode: C++ -*-
6 /*
7  * (c) 2008-2009 Alexander Warg <warg@os.inf.tu-dresden.de>
8  * economic rights: Technische Universität Dresden (Germany)
9  *
10  * This file is part of TUD:OS and distributed under the terms of the
11  * GNU General Public License 2.
12  * Please see the COPYING-GPL-2 file for details.
13  *
14  * As a special exception, you may use this file as part of a free software
15  * library without restriction. Specifically, if other files instantiate
16  * templates or use macros or inline functions from this file, or you compile
17  * this file and link it with other files to produce an executable, this
18  * file does not by itself cause the resulting executable to be covered by
19  * the GNU General Public License. This exception does not however
20  * invalidate any other reasons why the executable file might be covered by
21  * the GNU General Public License.
22  */
23 #pragma once
24 
25 namespace cxx {
26 
35 template< typename First, typename Second >
36 struct Pair
37 {
39  typedef First First_type;
41  typedef Second Second_type;
42 
44  First first;
46  Second second;
47 
53  template<typename A1, typename A2>
54  Pair(A1 &&first, A2 &&second)
55  : first(first), second(second) {}
56 
58  Pair() {}
59 };
60 
61 template< typename F, typename S >
62 Pair<F,S> pair(F const &f, S const &s)
63 { return cxx::Pair<F,S>(f,s); }
64 
65 
74 template< typename Cmp, typename Typ >
76 {
77 private:
78  Cmp const &_cmp;
79 
80 public:
85  Pair_first_compare(Cmp const &cmp = Cmp()) : _cmp(cmp) {}
86 
92  bool operator () (Typ const &l, Typ const &r) const
93  { return _cmp(l.first,r.first); }
94 };
95 
96 }
97 
98 template< typename OS, typename A, typename B >
99 inline
100 OS &operator << (OS &os, cxx::Pair<A,B> const &p)
101 {
102  os << p.first << ';' << p.second;
103  return os;
104 }
105 
Our C++ library.
Definition: arith:22
First First_type
Type of first value.
Definition: pair:39
Second second
Second value.
Definition: pair:46
Pair()
Default construction.
Definition: pair:58
Pair(A1 &&first, A2 &&second)
Create a pair from the two values.
Definition: pair:54
First first
First value.
Definition: pair:44
Second Second_type
Type of second value.
Definition: pair:41
Comparison functor for Pair.
Definition: pair:75
Pair_first_compare(Cmp const &cmp=Cmp())
Construction.
Definition: pair:85
Pair of two values.
Definition: pair:36