|
16 | 16 |
|
17 | 17 | #include "rapidjson/allocators.h"
|
18 | 18 |
|
| 19 | +#include <map> |
19 | 20 | #include <string>
|
20 |
| -#include <cstring> |
| 21 | +#include <utility> |
| 22 | +#include <functional> |
21 | 23 |
|
22 | 24 | using namespace rapidjson;
|
23 | 25 |
|
@@ -141,12 +143,34 @@ void TestStdAllocator(const Allocator& a) {
|
141 | 143 |
|
142 | 144 | typedef StdAllocator<char, Allocator> CharAllocator;
|
143 | 145 | typedef std::basic_string<char, std::char_traits<char>, CharAllocator> String;
|
| 146 | +#if RAPIDJSON_HAS_CXX11 |
| 147 | + String s(CharAllocator{a}); |
| 148 | +#else |
144 | 149 | CharAllocator ca(a);
|
145 | 150 | String s(ca);
|
| 151 | +#endif |
146 | 152 | for (int i = 0; i < 26; i++) {
|
147 | 153 | s.push_back(static_cast<char>('A' + i));
|
148 | 154 | }
|
149 | 155 | EXPECT_TRUE(s == "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
| 156 | + |
| 157 | + typedef StdAllocator<std::pair<const int, bool>, Allocator> MapAllocator; |
| 158 | + typedef std::map<int, bool, std::less<int>, MapAllocator> Map; |
| 159 | +#if RAPIDJSON_HAS_CXX11 |
| 160 | + Map map(std::less<int>(), MapAllocator{a}); |
| 161 | +#else |
| 162 | + MapAllocator ma(a); |
| 163 | + Map map(std::less<int>(), ma); |
| 164 | +#endif |
| 165 | + for (int i = 0; i < 10; i++) { |
| 166 | + map.insert(std::make_pair(i, (i % 2) == 0)); |
| 167 | + } |
| 168 | + EXPECT_TRUE(map.size() == 10); |
| 169 | + for (int i = 0; i < 10; i++) { |
| 170 | + typename Map::iterator it = map.find(i); |
| 171 | + EXPECT_TRUE(it != map.end()); |
| 172 | + EXPECT_TRUE(it->second == ((i % 2) == 0)); |
| 173 | + } |
150 | 174 | }
|
151 | 175 |
|
152 | 176 | TEST(Allocator, CrtAllocator) {
|
|
0 commit comments