L4Re Operating System Framework
Interface and Usage Documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 * License: see LICENSE.spdx (in this directory or the directories above)
11 */
12#pragma once
13
14#include <l4/cxx/type_traits>
15
16namespace cxx {
17
26template< typename First, typename Second >
27struct Pair
28{
30 typedef First First_type;
32 typedef Second Second_type;
33
35 First first;
37 Second second;
38
44 template<typename A1, typename A2>
45 Pair(A1 &&first, A2 &&second)
46 : first(cxx::forward<A1>(first)), second(cxx::forward<A2>(second)) {}
47
52 template<typename A1>
53 Pair(A1 &&first)
54 : first(cxx::forward<A1>(first)), second() {}
55
57 Pair() = default;
58};
59
60template< typename F, typename S >
61Pair<F,S> pair(F const &f, S const &s)
62{ return cxx::Pair<F,S>(f,s); }
63
64
73template< typename Cmp, typename Typ >
75{
76private:
77 Cmp const &_cmp;
78
79public:
84 Pair_first_compare(Cmp const &cmp = Cmp()) : _cmp(cmp) {}
85
91 bool operator () (Typ const &l, Typ const &r) const
92 { return _cmp(l.first,r.first); }
93};
94
95}
96
97template< typename OS, typename A, typename B >
98inline
99OS &operator << (OS &os, cxx::Pair<A,B> const &p)
100{
101 os << p.first << ';' << p.second;
102 return os;
103}
104
Comparison functor for Pair.
Definition pair:75
bool operator()(Typ const &l, Typ const &r) const
Do the comparison based on the first value.
Definition pair:91
Pair_first_compare(Cmp const &cmp=Cmp())
Construction.
Definition pair:84
Our C++ library.
Definition arith:11
Pair of two values.
Definition pair:28
Second Second_type
Type of second value.
Definition pair:32
Pair(A1 &&first)
Create a pair, default constructing the second value.
Definition pair:53
Second second
Second value.
Definition pair:37
First First_type
Type of first value.
Definition pair:30
Pair()=default
Default construction.
Pair(A1 &&first, A2 &&second)
Create a pair from the two values.
Definition pair:45
First first
First value.
Definition pair:35