L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
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#include <l4/cxx/type_traits>
26
27namespace cxx {
28
37template< typename First, typename Second >
38struct Pair
39{
41 typedef First First_type;
43 typedef Second Second_type;
44
46 First first;
48 Second second;
49
55 template<typename A1, typename A2>
56 Pair(A1 &&first, A2 &&second)
57 : first(cxx::forward<A1>(first)), second(cxx::forward<A2>(second)) {}
58
63 template<typename A1>
64 Pair(A1 &&first)
65 : first(cxx::forward<A1>(first)), second() {}
66
68 Pair() = default;
69};
70
71template< typename F, typename S >
72Pair<F,S> pair(F const &f, S const &s)
73{ return cxx::Pair<F,S>(f,s); }
74
75
84template< typename Cmp, typename Typ >
86{
87private:
88 Cmp const &_cmp;
89
90public:
95 Pair_first_compare(Cmp const &cmp = Cmp()) : _cmp(cmp) {}
96
102 bool operator () (Typ const &l, Typ const &r) const
103 { return _cmp(l.first,r.first); }
104};
105
106}
107
108template< typename OS, typename A, typename B >
109inline
110OS &operator << (OS &os, cxx::Pair<A,B> const &p)
111{
112 os << p.first << ';' << p.second;
113 return os;
114}
115
Comparison functor for Pair.
Definition pair:86
bool operator()(Typ const &l, Typ const &r) const
Do the comaprison based on the first value.
Definition pair:102
Pair_first_compare(Cmp const &cmp=Cmp())
Construction.
Definition pair:95
Our C++ library.
Definition arith:22
Pair of two values.
Definition pair:39
Second Second_type
Type of second value.
Definition pair:43
Pair(A1 &&first)
Create a pair, default constructing the second value.
Definition pair:64
Second second
Second value.
Definition pair:48
First First_type
Type of first value.
Definition pair:41
Pair()=default
Default construction.
Pair(A1 &&first, A2 &&second)
Create a pair from the two values.
Definition pair:56
First first
First value.
Definition pair:46