File: types.pass.cpp

package info (click to toggle)
libpmemobj-cpp 1.12-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 8,388 kB
  • sloc: cpp: 136,076; sh: 1,022; perl: 381; ansic: 163; makefile: 13
file content (184 lines) | stat: -rw-r--r-- 5,054 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Copyright 2020, Intel Corporation
//
// Modified to test pmem::obj containers
//

// <map>

// template <class Key, class T, class Compare = less<Key>,
//           class Allocator = allocator<pair<const Key, T>>>
// class map
// {
// public:
//     // types:
//     typedef Key                                      key_type;
//     typedef T                                        mapped_type;
//     typedef pair<const key_type, mapped_type>        value_type;
//     typedef Compare                                  key_compare;
//     typedef Allocator                                allocator_type;
//     typedef typename allocator_type::reference       reference;
//     typedef typename allocator_type::const_reference const_reference;
//     typedef typename allocator_type::pointer         pointer;
//     typedef typename allocator_type::const_pointer   const_pointer;
//     typedef typename allocator_type::size_type       size_type;
//     typedef typename allocator_type::difference_type difference_type;
//     ...
// };

#include "map_wrapper.hpp"
#include "unittest.hpp"

#include <libpmemobj++/make_persistent.hpp>
#include <libpmemobj++/persistent_ptr.hpp>
#include <libpmemobj++/pool.hpp>
#include <libpmemobj++/transaction.hpp>

namespace nvobj = pmem::obj;
namespace nvobjex = pmem::obj::experimental;

using container = container_t<int, double>;

struct root {
	nvobj::persistent_ptr<container> s;
};

int
run(nvobj::pool<root> &pop)
{
	{
		typedef container C;
		static_assert((std::is_same<C::key_type, int>::value), "");
		static_assert((std::is_same<C::mapped_type, double>::value),
			      "");
		static_assert(
			(std::is_same<
				C::value_type,
				pmem::detail::pair<const int, double>>::value),
			"");
		static_assert(
			(std::is_same<C::key_compare, std::less<int>>::value),
			"");
		static_assert(
			(std::is_same<C::allocator_type,
				      pmem::obj::allocator<pmem::detail::pair<
					      const int, double>>>::value),
			"");
		static_assert(
			(std::is_same<C::reference,
				      pmem::detail::pair<const int, double>
					      &>::value),
			"");
		static_assert(
			(std::is_same<C::const_reference,
				      const pmem::detail::pair<
					      const int, double> &>::value),
			"");
		static_assert(
			(std::is_same<C::pointer,
				      nvobj::persistent_ptr<pmem::detail::pair<
					      const int, double>>>::value),
			"");
		static_assert(
			(std::is_same<
				C::const_pointer,
				nvobj::persistent_ptr<const pmem::detail::pair<
					const int, double>>>::value),
			"");
		static_assert((std::is_same<C::size_type, std::size_t>::value),
			      "");
		static_assert((std::is_same<C::difference_type,
					    std::ptrdiff_t>::value),
			      "");
	}
#ifdef XXX // XXX: Implement min_allocator
	{
		typedef std::map<int, double, std::less<int>,
				 min_allocator<std::pair<const int, double>>>
			C;
		static_assert((std::is_same<C::key_type, int>::value), "");
		static_assert((std::is_same<C::mapped_type, double>::value),
			      "");
		static_assert(
			(std::is_same<C::value_type,
				      std::pair<const int, double>>::value),
			"");
		static_assert(
			(std::is_same<C::key_compare, std::less<int>>::value),
			"");
		static_assert(
			(std::is_same<C::allocator_type,
				      min_allocator<std::pair<const int,
							      double>>>::value),
			"");
		static_assert(
			(std::is_same<C::reference,
				      std::pair<const int, double> &>::value),
			"");
		static_assert(
			(std::is_same<
				C::const_reference,
				const std::pair<const int, double> &>::value),
			"");
		static_assert(
			(std::is_same<C::pointer,
				      min_pointer<std::pair<const int,
							    double>>>::value),
			"");
		static_assert(
			(std::is_same<C::const_pointer,
				      min_pointer<const std::pair<
					      const int, double>>>::value),
			"");
		//  min_allocator doesn't have a size_type, so one gets
		//  synthesized
		static_assert(
			(std::is_same<C::size_type,
				      std::make_unsigned<C::difference_type>::
					      type>::value),
			"");
		static_assert((std::is_same<C::difference_type,
					    std::ptrdiff_t>::value),
			      "");
	}
#endif

	return 0;
}

static void
test(int argc, char *argv[])
{
	if (argc != 2)
		UT_FATAL("usage: %s file-name", argv[0]);

	const char *path = argv[1];

	pmem::obj::pool<root> pop;
	try {
		pop = pmem::obj::pool<root>::create(path, "types.pass",
						    PMEMOBJ_MIN_POOL,
						    S_IWUSR | S_IRUSR);
	} catch (...) {
		UT_FATAL("!pmemobj_create: %s", path);
	}
	try {
		run(pop);
		pop.close();
	} catch (std::exception &e) {
		UT_FATALexc(e);
	}
}

int
main(int argc, char *argv[])
{
	return run_test([&] { test(argc, argv); });
}