PMDK C++ bindings  1.5.2
This is the C++ bindings documentation for PMDK's libpmemobj.
specialization.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2015-2018, 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 
40 #ifndef LIBPMEMOBJ_CPP_SPECIALIZATION_HPP
41 #define LIBPMEMOBJ_CPP_SPECIALIZATION_HPP
42 
43 #include <memory>
44 
45 namespace pmem
46 {
47 
48 namespace detail
49 {
50 /* smart pointer specialization */
51 
52 template <typename T>
53 struct sp_element {
54  typedef T type;
55 };
56 
57 template <typename T>
58 struct sp_element<T[]> {
59  typedef T type;
60 };
61 
62 template <typename T, std::size_t N>
63 struct sp_element<T[N]> {
64  typedef T type;
65 };
66 
67 /* sp_dereference is a return type of operator* */
68 
69 template <typename T>
70 struct sp_dereference {
71  typedef T &type;
72 };
73 
74 template <>
75 struct sp_dereference<void> {
76  typedef void type;
77 };
78 
79 template <>
80 struct sp_dereference<void const> {
81  typedef void type;
82 };
83 
84 template <>
85 struct sp_dereference<void volatile> {
86  typedef void type;
87 };
88 
89 template <>
90 struct sp_dereference<void const volatile> {
91  typedef void type;
92 };
93 
94 template <typename T>
95 struct sp_dereference<T[]> {
96  typedef void type;
97 };
98 
99 template <typename T, std::size_t N>
100 struct sp_dereference<T[N]> {
101  typedef void type;
102 };
103 
104 /* sp_member_access is a return type of operator-> */
105 
106 template <typename T>
107 struct sp_member_access {
108  typedef T *type;
109 };
110 
111 template <typename T>
112 struct sp_member_access<T[]> {
113  typedef void type;
114 };
115 
116 template <typename T, std::size_t N>
117 struct sp_member_access<T[N]> {
118  typedef void type;
119 };
120 
121 /* sp_array_access is a return type of operator[] */
122 
123 template <typename T>
124 struct sp_array_access {
125  typedef T &type;
126 };
127 
128 template <>
129 struct sp_array_access<void> {
130  typedef struct does_not_exist {
131  } & type;
132 };
133 
134 template <typename T>
135 struct sp_array_access<T[]> {
136  typedef T &type;
137 };
138 
139 template <typename T, std::size_t N>
140 struct sp_array_access<T[N]> {
141  typedef T &type;
142 };
143 
144 /* sp_extent is used for operator[] index checking */
145 
146 template <typename T>
147 struct sp_extent {
148  enum _vt { value = 0 };
149 };
150 
151 template <typename T, std::size_t N>
152 struct sp_extent<T[N]> {
153  enum _vt { value = N };
154 };
155 
156 } /* namespace detail */
157 
158 } /* namespace pmem */
159 
160 #endif /* LIBPMEMOBJ_CPP_SPECIALIZATION_HPP */