PMDK C++ bindings  1.13.0-git107.g7e59f08f
This is the C++ bindings documentation for PMDK's libpmemobj.
pair.hpp
Go to the documentation of this file.
1 // SPDX-License-Identifier: BSD-3-Clause
2 /* Copyright 2020-2021, Intel Corporation */
3 
9 #ifndef LIBPMEMOBJ_PAIR_HPP
10 #define LIBPMEMOBJ_PAIR_HPP
11 
12 #include <utility>
13 
15 
16 namespace pmem
17 {
18 
19 namespace detail
20 {
21 
22 template <typename F, typename S>
23 struct pair {
24  constexpr pair() : first(), second()
25  {
26  }
27 
28  template <typename... Args1, typename... Args2>
29  pair(std::piecewise_construct_t pc, std::tuple<Args1...> first_args,
30  std::tuple<Args2...> second_args)
31  : pair(pc, first_args, second_args, index_sequence_for<Args1...>{},
32  index_sequence_for<Args2...>{})
33  {
34  }
35 
36  constexpr pair(const F &k, const S &v) : first(k), second(v)
37  {
38  }
39 
40  template <typename K, typename V>
41  constexpr pair(K &&k, V &&v)
42  : first(std::forward<K>(k)), second(std::forward<V>(v))
43  {
44  }
45 
46  template <typename K, typename V>
47  constexpr pair(const std::pair<K, V> &p)
48  : first(p.first), second(p.second)
49  {
50  }
51 
52  template <typename K, typename V>
53  constexpr pair(std::pair<K, V> &&p)
54  : first(std::forward<K>(p.first)), second(std::forward<V>(p.second))
55  {
56  }
57 
58  F first;
59  S second;
60 
61 private:
62  template <typename... Args1, typename... Args2, size_t... I1,
63  size_t... I2>
64  pair(std::piecewise_construct_t, std::tuple<Args1...> &first_args,
65  std::tuple<Args2...> &second_args, index_sequence<I1...>,
66  index_sequence<I2...>)
67  : first(std::forward<Args1>(std::get<I1>(first_args))...),
68  second(std::forward<Args2>(std::get<I2>(second_args))...)
69  {
70  }
71 };
72 
73 template <class T1, class T2>
74 bool
75 operator==(const pair<T1, T2> &lhs, const pair<T1, T2> &rhs)
76 {
77  return lhs.first == rhs.first && lhs.second == rhs.second;
78 }
79 
80 template <class T1, class T2>
81 bool
82 operator!=(const pair<T1, T2> &lhs, const pair<T1, T2> &rhs)
83 {
84  return !(lhs == rhs);
85 }
86 
87 } /* namespace detail */
88 
89 } /* namespace pmem */
90 
91 #endif /* LIBPMEMOBJ_PAIR_HPP */
Create c++14 style index sequence.
Persistent memory namespace.
Definition: allocation_flag.hpp:15