PMDK C++ bindings  1.9
This is the C++ bindings documentation for PMDK's libpmemobj.
pair.hpp
1 /*
2  * Copyright 2020, Intel Corporation
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  *
16  * * Neither the name of the copyright holder nor the names of its
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef LIBPMEMOBJ_PAIR_HPP
34 #define LIBPMEMOBJ_PAIR_HPP
35 
36 #include <utility>
37 
39 
40 namespace pmem
41 {
42 
43 namespace detail
44 {
45 
46 template <typename F, typename S>
47 struct pair {
48  constexpr pair() : first(), second()
49  {
50  }
51 
52  template <typename... Args1, typename... Args2>
53  pair(std::piecewise_construct_t pc, std::tuple<Args1...> first_args,
54  std::tuple<Args2...> second_args)
55  : pair(pc, first_args, second_args,
56  typename make_index_sequence<Args1...>::type{},
57  typename make_index_sequence<Args2...>::type{})
58  {
59  }
60 
61  constexpr pair(const F &k, const S &v) : first(k), second(v)
62  {
63  }
64 
65  template <typename K, typename V>
66  constexpr pair(K &&k, V &&v)
67  : first(std::forward<K>(k)), second(std::forward<V>(v))
68  {
69  }
70 
71  template <typename K, typename V>
72  constexpr pair(const std::pair<K, V> &p)
73  : first(p.first), second(p.second)
74  {
75  }
76 
77  template <typename K, typename V>
78  constexpr pair(std::pair<K, V> &&p)
79  : first(std::forward<K>(p.first)), second(std::forward<V>(p.second))
80  {
81  }
82 
83  F first;
84  S second;
85 
86 private:
87  template <typename... Args1, typename... Args2, size_t... I1,
88  size_t... I2>
89  pair(std::piecewise_construct_t, std::tuple<Args1...> &first_args,
90  std::tuple<Args2...> &second_args, index_sequence<I1...>,
91  index_sequence<I2...>)
92  : first(std::forward<Args1>(std::get<I1>(first_args))...),
93  second(std::forward<Args2>(std::get<I2>(second_args))...)
94  {
95  }
96 };
97 
98 } /* namespace detail */
99 
100 } /* namespace pmem */
101 
102 #endif /* LIBPMEMOBJ_PAIR_HPP */
pmem
Persistent memory namespace.
Definition: allocation_flag.hpp:44
integer_sequence.hpp
Create c++14 style index sequence.
pmem::obj::get
T & get(pmem::obj::array< T, N > &a)
Non-member get function.
Definition: array.hpp:923