Bug Summary

File:src/gnu/usr.bin/clang/liblldbPluginPlatform/../../../llvm/lldb/source/Plugins/Platform/Android/AdbClient.cpp
Warning:line 633, column 5
1st function call argument is an uninitialized value

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name AdbClient.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model static -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/gnu/usr.bin/clang/liblldbPluginPlatform/obj -resource-dir /usr/local/lib/clang/13.0.0 -I /usr/src/gnu/usr.bin/clang/liblldbPluginPlatform/../../../llvm/llvm/include -I /usr/src/gnu/usr.bin/clang/liblldbPluginPlatform/../include -I /usr/src/gnu/usr.bin/clang/liblldbPluginPlatform/obj -I /usr/src/gnu/usr.bin/clang/liblldbPluginPlatform/obj/../include -D NDEBUG -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D LLVM_PREFIX="/usr" -I /usr/src/gnu/usr.bin/clang/liblldbPluginPlatform/../../../llvm/lldb/include -I /usr/src/gnu/usr.bin/clang/liblldbPluginPlatform/../../../llvm/lldb/source -I /usr/src/gnu/usr.bin/clang/liblldbPluginPlatform/../../../llvm/clang/include -internal-isystem /usr/include/c++/v1 -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-comment -std=c++14 -fdeprecated-macro -fdebug-compilation-dir=/usr/src/gnu/usr.bin/clang/liblldbPluginPlatform/obj -ferror-limit 19 -fvisibility-inlines-hidden -fwrapv -stack-protector 2 -fno-rtti -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c++ /usr/src/gnu/usr.bin/clang/liblldbPluginPlatform/../../../llvm/lldb/source/Plugins/Platform/Android/AdbClient.cpp

/usr/src/gnu/usr.bin/clang/liblldbPluginPlatform/../../../llvm/lldb/source/Plugins/Platform/Android/AdbClient.cpp

1//===-- AdbClient.cpp -----------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "AdbClient.h"
10
11#include "llvm/ADT/STLExtras.h"
12#include "llvm/ADT/SmallVector.h"
13#include "llvm/ADT/StringRef.h"
14#include "llvm/Support/FileUtilities.h"
15
16#include "lldb/Host/ConnectionFileDescriptor.h"
17#include "lldb/Host/FileSystem.h"
18#include "lldb/Host/PosixApi.h"
19#include "lldb/Utility/DataBuffer.h"
20#include "lldb/Utility/DataBufferHeap.h"
21#include "lldb/Utility/DataEncoder.h"
22#include "lldb/Utility/DataExtractor.h"
23#include "lldb/Utility/FileSpec.h"
24#include "lldb/Utility/StreamString.h"
25#include "lldb/Utility/Timeout.h"
26
27#include <climits>
28
29#include <algorithm>
30#include <cstdlib>
31#include <fstream>
32#include <sstream>
33
34// On Windows, transitive dependencies pull in <Windows.h>, which defines a
35// macro that clashes with a method name.
36#ifdef SendMessage
37#undef SendMessage
38#endif
39
40using namespace lldb;
41using namespace lldb_private;
42using namespace lldb_private::platform_android;
43using namespace std::chrono;
44
45namespace {
46
47const seconds kReadTimeout(20);
48const char *kOKAY = "OKAY";
49const char *kFAIL = "FAIL";
50const char *kDATA = "DATA";
51const char *kDONE = "DONE";
52
53const char *kSEND = "SEND";
54const char *kRECV = "RECV";
55const char *kSTAT = "STAT";
56
57const size_t kSyncPacketLen = 8;
58// Maximum size of a filesync DATA packet.
59const size_t kMaxPushData = 2 * 1024;
60// Default mode for pushed files.
61const uint32_t kDefaultMode = 0100770; // S_IFREG | S_IRWXU | S_IRWXG
62
63const char *kSocketNamespaceAbstract = "localabstract";
64const char *kSocketNamespaceFileSystem = "localfilesystem";
65
66Status ReadAllBytes(Connection &conn, void *buffer, size_t size) {
67
68 Status error;
69 ConnectionStatus status;
70 char *read_buffer = static_cast<char *>(buffer);
71
72 auto now = steady_clock::now();
73 const auto deadline = now + kReadTimeout;
74 size_t total_read_bytes = 0;
75 while (total_read_bytes < size && now < deadline) {
76 auto read_bytes =
77 conn.Read(read_buffer + total_read_bytes, size - total_read_bytes,
78 duration_cast<microseconds>(deadline - now), status, &error);
79 if (error.Fail())
80 return error;
81 total_read_bytes += read_bytes;
82 if (status != eConnectionStatusSuccess)
83 break;
84 now = steady_clock::now();
85 }
86 if (total_read_bytes < size)
87 error = Status(
88 "Unable to read requested number of bytes. Connection status: %d.",
89 status);
90 return error;
91}
92
93} // namespace
94
95Status AdbClient::CreateByDeviceID(const std::string &device_id,
96 AdbClient &adb) {
97 Status error;
98 std::string android_serial;
99 if (!device_id.empty())
100 android_serial = device_id;
101 else if (const char *env_serial = std::getenv("ANDROID_SERIAL"))
102 android_serial = env_serial;
103
104 if (android_serial.empty()) {
105 DeviceIDList connected_devices;
106 error = adb.GetDevices(connected_devices);
107 if (error.Fail())
108 return error;
109
110 if (connected_devices.size() != 1)
111 return Status("Expected a single connected device, got instead %zu - try "
112 "setting 'ANDROID_SERIAL'",
113 connected_devices.size());
114 adb.SetDeviceID(connected_devices.front());
115 } else {
116 adb.SetDeviceID(android_serial);
117 }
118 return error;
119}
120
121AdbClient::AdbClient() = default;
122
123AdbClient::AdbClient(const std::string &device_id) : m_device_id(device_id) {}
124
125AdbClient::~AdbClient() = default;
126
127void AdbClient::SetDeviceID(const std::string &device_id) {
128 m_device_id = device_id;
129}
130
131const std::string &AdbClient::GetDeviceID() const { return m_device_id; }
132
133Status AdbClient::Connect() {
134 Status error;
135 m_conn = std::make_unique<ConnectionFileDescriptor>();
136 std::string port = "5037";
137 if (const char *env_port = std::getenv("ANDROID_ADB_SERVER_PORT")) {
138 port = env_port;
139 }
140 std::string uri = "connect://127.0.0.1:" + port;
141 m_conn->Connect(uri.c_str(), &error);
142
143 return error;
144}
145
146Status AdbClient::GetDevices(DeviceIDList &device_list) {
147 device_list.clear();
148
149 auto error = SendMessage("host:devices");
150 if (error.Fail())
151 return error;
152
153 error = ReadResponseStatus();
154 if (error.Fail())
155 return error;
156
157 std::vector<char> in_buffer;
158 error = ReadMessage(in_buffer);
159
160 llvm::StringRef response(&in_buffer[0], in_buffer.size());
161 llvm::SmallVector<llvm::StringRef, 4> devices;
162 response.split(devices, "\n", -1, false);
163
164 for (const auto &device : devices)
165 device_list.push_back(std::string(device.split('\t').first));
166
167 // Force disconnect since ADB closes connection after host:devices response
168 // is sent.
169 m_conn.reset();
170 return error;
171}
172
173Status AdbClient::SetPortForwarding(const uint16_t local_port,
174 const uint16_t remote_port) {
175 char message[48];
176 snprintf(message, sizeof(message), "forward:tcp:%d;tcp:%d", local_port,
177 remote_port);
178
179 const auto error = SendDeviceMessage(message);
180 if (error.Fail())
181 return error;
182
183 return ReadResponseStatus();
184}
185
186Status
187AdbClient::SetPortForwarding(const uint16_t local_port,
188 llvm::StringRef remote_socket_name,
189 const UnixSocketNamespace socket_namespace) {
190 char message[PATH_MAX1024];
191 const char *sock_namespace_str =
192 (socket_namespace == UnixSocketNamespaceAbstract)
193 ? kSocketNamespaceAbstract
194 : kSocketNamespaceFileSystem;
195 snprintf(message, sizeof(message), "forward:tcp:%d;%s:%s", local_port,
196 sock_namespace_str, remote_socket_name.str().c_str());
197
198 const auto error = SendDeviceMessage(message);
199 if (error.Fail())
200 return error;
201
202 return ReadResponseStatus();
203}
204
205Status AdbClient::DeletePortForwarding(const uint16_t local_port) {
206 char message[32];
207 snprintf(message, sizeof(message), "killforward:tcp:%d", local_port);
208
209 const auto error = SendDeviceMessage(message);
210 if (error.Fail())
211 return error;
212
213 return ReadResponseStatus();
214}
215
216Status AdbClient::SendMessage(const std::string &packet, const bool reconnect) {
217 Status error;
218 if (!m_conn || reconnect) {
219 error = Connect();
220 if (error.Fail())
221 return error;
222 }
223
224 char length_buffer[5];
225 snprintf(length_buffer, sizeof(length_buffer), "%04x",
226 static_cast<int>(packet.size()));
227
228 ConnectionStatus status;
229
230 m_conn->Write(length_buffer, 4, status, &error);
231 if (error.Fail())
232 return error;
233
234 m_conn->Write(packet.c_str(), packet.size(), status, &error);
235 return error;
236}
237
238Status AdbClient::SendDeviceMessage(const std::string &packet) {
239 std::ostringstream msg;
240 msg << "host-serial:" << m_device_id << ":" << packet;
241 return SendMessage(msg.str());
242}
243
244Status AdbClient::ReadMessage(std::vector<char> &message) {
245 message.clear();
246
247 char buffer[5];
248 buffer[4] = 0;
249
250 auto error = ReadAllBytes(buffer, 4);
251 if (error.Fail())
252 return error;
253
254 unsigned int packet_len = 0;
255 sscanf(buffer, "%x", &packet_len);
256
257 message.resize(packet_len, 0);
258 error = ReadAllBytes(&message[0], packet_len);
259 if (error.Fail())
260 message.clear();
261
262 return error;
263}
264
265Status AdbClient::ReadMessageStream(std::vector<char> &message,
266 milliseconds timeout) {
267 auto start = steady_clock::now();
268 message.clear();
269
270 Status error;
271 lldb::ConnectionStatus status = lldb::eConnectionStatusSuccess;
272 char buffer[1024];
273 while (error.Success() && status == lldb::eConnectionStatusSuccess) {
274 auto end = steady_clock::now();
275 auto elapsed = end - start;
276 if (elapsed >= timeout)
277 return Status("Timed out");
278
279 size_t n = m_conn->Read(buffer, sizeof(buffer),
280 duration_cast<microseconds>(timeout - elapsed),
281 status, &error);
282 if (n > 0)
283 message.insert(message.end(), &buffer[0], &buffer[n]);
284 }
285 return error;
286}
287
288Status AdbClient::ReadResponseStatus() {
289 char response_id[5];
290
291 static const size_t packet_len = 4;
292 response_id[packet_len] = 0;
293
294 auto error = ReadAllBytes(response_id, packet_len);
295 if (error.Fail())
296 return error;
297
298 if (strncmp(response_id, kOKAY, packet_len) != 0)
299 return GetResponseError(response_id);
300
301 return error;
302}
303
304Status AdbClient::GetResponseError(const char *response_id) {
305 if (strcmp(response_id, kFAIL) != 0)
306 return Status("Got unexpected response id from adb: \"%s\"", response_id);
307
308 std::vector<char> error_message;
309 auto error = ReadMessage(error_message);
310 if (error.Success())
311 error.SetErrorString(
312 std::string(&error_message[0], error_message.size()).c_str());
313
314 return error;
315}
316
317Status AdbClient::SwitchDeviceTransport() {
318 std::ostringstream msg;
319 msg << "host:transport:" << m_device_id;
320
321 auto error = SendMessage(msg.str());
322 if (error.Fail())
323 return error;
324
325 return ReadResponseStatus();
326}
327
328Status AdbClient::StartSync() {
329 auto error = SwitchDeviceTransport();
330 if (error.Fail())
331 return Status("Failed to switch to device transport: %s",
332 error.AsCString());
333
334 error = Sync();
335 if (error.Fail())
336 return Status("Sync failed: %s", error.AsCString());
337
338 return error;
339}
340
341Status AdbClient::Sync() {
342 auto error = SendMessage("sync:", false);
343 if (error.Fail())
344 return error;
345
346 return ReadResponseStatus();
347}
348
349Status AdbClient::ReadAllBytes(void *buffer, size_t size) {
350 return ::ReadAllBytes(*m_conn, buffer, size);
351}
352
353Status AdbClient::internalShell(const char *command, milliseconds timeout,
354 std::vector<char> &output_buf) {
355 output_buf.clear();
356
357 auto error = SwitchDeviceTransport();
358 if (error.Fail())
359 return Status("Failed to switch to device transport: %s",
360 error.AsCString());
361
362 StreamString adb_command;
363 adb_command.Printf("shell:%s", command);
364 error = SendMessage(std::string(adb_command.GetString()), false);
365 if (error.Fail())
366 return error;
367
368 error = ReadResponseStatus();
369 if (error.Fail())
370 return error;
371
372 error = ReadMessageStream(output_buf, timeout);
373 if (error.Fail())
374 return error;
375
376 // ADB doesn't propagate return code of shell execution - if
377 // output starts with /system/bin/sh: most likely command failed.
378 static const char *kShellPrefix = "/system/bin/sh:";
379 if (output_buf.size() > strlen(kShellPrefix)) {
380 if (!memcmp(&output_buf[0], kShellPrefix, strlen(kShellPrefix)))
381 return Status("Shell command %s failed: %s", command,
382 std::string(output_buf.begin(), output_buf.end()).c_str());
383 }
384
385 return Status();
386}
387
388Status AdbClient::Shell(const char *command, milliseconds timeout,
389 std::string *output) {
390 std::vector<char> output_buffer;
391 auto error = internalShell(command, timeout, output_buffer);
392 if (error.Fail())
393 return error;
394
395 if (output)
396 output->assign(output_buffer.begin(), output_buffer.end());
397 return error;
398}
399
400Status AdbClient::ShellToFile(const char *command, milliseconds timeout,
401 const FileSpec &output_file_spec) {
402 std::vector<char> output_buffer;
403 auto error = internalShell(command, timeout, output_buffer);
404 if (error.Fail())
405 return error;
406
407 const auto output_filename = output_file_spec.GetPath();
408 std::error_code EC;
409 llvm::raw_fd_ostream dst(output_filename, EC, llvm::sys::fs::OF_None);
410 if (EC)
411 return Status("Unable to open local file %s", output_filename.c_str());
412
413 dst.write(&output_buffer[0], output_buffer.size());
414 dst.close();
415 if (dst.has_error())
416 return Status("Failed to write file %s", output_filename.c_str());
417 return Status();
418}
419
420std::unique_ptr<AdbClient::SyncService>
421AdbClient::GetSyncService(Status &error) {
422 std::unique_ptr<SyncService> sync_service;
423 error = StartSync();
424 if (error.Success())
425 sync_service.reset(new SyncService(std::move(m_conn)));
426
427 return sync_service;
428}
429
430Status AdbClient::SyncService::internalPullFile(const FileSpec &remote_file,
431 const FileSpec &local_file) {
432 const auto local_file_path = local_file.GetPath();
433 llvm::FileRemover local_file_remover(local_file_path);
434
435 std::error_code EC;
436 llvm::raw_fd_ostream dst(local_file_path, EC, llvm::sys::fs::OF_None);
437 if (EC)
12
Taking false branch
438 return Status("Unable to open local file %s", local_file_path.c_str());
439
440 const auto remote_file_path = remote_file.GetPath(false);
441 auto error = SendSyncRequest(kRECV, remote_file_path.length(),
442 remote_file_path.c_str());
443 if (error.Fail())
13
Assuming the condition is false
14
Taking false branch
444 return error;
445
446 std::vector<char> chunk;
447 bool eof = false;
448 while (!eof) {
15
Loop condition is true. Entering loop body
449 error = PullFileChunk(chunk, eof);
16
Calling 'SyncService::PullFileChunk'
450 if (error.Fail())
451 return error;
452 if (!eof)
453 dst.write(&chunk[0], chunk.size());
454 }
455 dst.close();
456 if (dst.has_error())
457 return Status("Failed to write file %s", local_file_path.c_str());
458
459 local_file_remover.releaseFile();
460 return error;
461}
462
463Status AdbClient::SyncService::internalPushFile(const FileSpec &local_file,
464 const FileSpec &remote_file) {
465 const auto local_file_path(local_file.GetPath());
466 std::ifstream src(local_file_path.c_str(), std::ios::in | std::ios::binary);
467 if (!src.is_open())
468 return Status("Unable to open local file %s", local_file_path.c_str());
469
470 std::stringstream file_description;
471 file_description << remote_file.GetPath(false).c_str() << "," << kDefaultMode;
472 std::string file_description_str = file_description.str();
473 auto error = SendSyncRequest(kSEND, file_description_str.length(),
474 file_description_str.c_str());
475 if (error.Fail())
476 return error;
477
478 char chunk[kMaxPushData];
479 while (!src.eof() && !src.read(chunk, kMaxPushData).bad()) {
480 size_t chunk_size = src.gcount();
481 error = SendSyncRequest(kDATA, chunk_size, chunk);
482 if (error.Fail())
483 return Status("Failed to send file chunk: %s", error.AsCString());
484 }
485 error = SendSyncRequest(
486 kDONE, llvm::sys::toTimeT(FileSystem::Instance().GetModificationTime(local_file)),
487 nullptr);
488 if (error.Fail())
489 return error;
490
491 std::string response_id;
492 uint32_t data_len;
493 error = ReadSyncHeader(response_id, data_len);
494 if (error.Fail())
495 return Status("Failed to read DONE response: %s", error.AsCString());
496 if (response_id == kFAIL) {
497 std::string error_message(data_len, 0);
498 error = ReadAllBytes(&error_message[0], data_len);
499 if (error.Fail())
500 return Status("Failed to read DONE error message: %s", error.AsCString());
501 return Status("Failed to push file: %s", error_message.c_str());
502 } else if (response_id != kOKAY)
503 return Status("Got unexpected DONE response: %s", response_id.c_str());
504
505 // If there was an error reading the source file, finish the adb file
506 // transfer first so that adb isn't expecting any more data.
507 if (src.bad())
508 return Status("Failed read on %s", local_file_path.c_str());
509 return error;
510}
511
512Status AdbClient::SyncService::internalStat(const FileSpec &remote_file,
513 uint32_t &mode, uint32_t &size,
514 uint32_t &mtime) {
515 const std::string remote_file_path(remote_file.GetPath(false));
516 auto error = SendSyncRequest(kSTAT, remote_file_path.length(),
517 remote_file_path.c_str());
518 if (error.Fail())
519 return Status("Failed to send request: %s", error.AsCString());
520
521 static const size_t stat_len = strlen(kSTAT);
522 static const size_t response_len = stat_len + (sizeof(uint32_t) * 3);
523
524 std::vector<char> buffer(response_len);
525 error = ReadAllBytes(&buffer[0], buffer.size());
526 if (error.Fail())
527 return Status("Failed to read response: %s", error.AsCString());
528
529 DataExtractor extractor(&buffer[0], buffer.size(), eByteOrderLittle,
530 sizeof(void *));
531 offset_t offset = 0;
532
533 const void *command = extractor.GetData(&offset, stat_len);
534 if (!command)
535 return Status("Failed to get response command");
536 const char *command_str = static_cast<const char *>(command);
537 if (strncmp(command_str, kSTAT, stat_len))
538 return Status("Got invalid stat command: %s", command_str);
539
540 mode = extractor.GetU32(&offset);
541 size = extractor.GetU32(&offset);
542 mtime = extractor.GetU32(&offset);
543 return Status();
544}
545
546Status AdbClient::SyncService::PullFile(const FileSpec &remote_file,
547 const FileSpec &local_file) {
548 return executeCommand([this, &remote_file, &local_file]() {
1
Calling 'SyncService::executeCommand'
549 return internalPullFile(remote_file, local_file);
11
Calling 'SyncService::internalPullFile'
550 });
551}
552
553Status AdbClient::SyncService::PushFile(const FileSpec &local_file,
554 const FileSpec &remote_file) {
555 return executeCommand([this, &local_file, &remote_file]() {
556 return internalPushFile(local_file, remote_file);
557 });
558}
559
560Status AdbClient::SyncService::Stat(const FileSpec &remote_file, uint32_t &mode,
561 uint32_t &size, uint32_t &mtime) {
562 return executeCommand([this, &remote_file, &mode, &size, &mtime]() {
563 return internalStat(remote_file, mode, size, mtime);
564 });
565}
566
567bool AdbClient::SyncService::IsConnected() const {
568 return m_conn && m_conn->IsConnected();
569}
570
571AdbClient::SyncService::SyncService(std::unique_ptr<Connection> &&conn)
572 : m_conn(std::move(conn)) {}
573
574Status
575AdbClient::SyncService::executeCommand(const std::function<Status()> &cmd) {
576 if (!m_conn)
2
Taking false branch
577 return Status("SyncService is disconnected");
578
579 const auto error = cmd();
3
Calling 'function::operator()'
580 if (error.Fail())
581 m_conn.reset();
582
583 return error;
584}
585
586AdbClient::SyncService::~SyncService() = default;
587
588Status AdbClient::SyncService::SendSyncRequest(const char *request_id,
589 const uint32_t data_len,
590 const void *data) {
591 const DataBufferSP data_sp(new DataBufferHeap(kSyncPacketLen, 0));
592 DataEncoder encoder(data_sp, eByteOrderLittle, sizeof(void *));
593 auto offset = encoder.PutData(0, request_id, strlen(request_id));
594 encoder.PutUnsigned(offset, 4, data_len);
595
596 Status error;
597 ConnectionStatus status;
598 m_conn->Write(data_sp->GetBytes(), kSyncPacketLen, status, &error);
599 if (error.Fail())
600 return error;
601
602 if (data)
603 m_conn->Write(data, data_len, status, &error);
604 return error;
605}
606
607Status AdbClient::SyncService::ReadSyncHeader(std::string &response_id,
608 uint32_t &data_len) {
609 char buffer[kSyncPacketLen];
610
611 auto error = ReadAllBytes(buffer, kSyncPacketLen);
612 if (error.Success()) {
19
Assuming the condition is false
20
Taking false branch
613 response_id.assign(&buffer[0], 4);
614 DataExtractor extractor(&buffer[4], 4, eByteOrderLittle, sizeof(void *));
615 offset_t offset = 0;
616 data_len = extractor.GetU32(&offset);
617 }
618
619 return error;
21
Returning without writing to 'data_len'
620}
621
622Status AdbClient::SyncService::PullFileChunk(std::vector<char> &buffer,
623 bool &eof) {
624 buffer.clear();
625
626 std::string response_id;
627 uint32_t data_len;
17
'data_len' declared without an initial value
628 auto error = ReadSyncHeader(response_id, data_len);
18
Calling 'SyncService::ReadSyncHeader'
22
Returning from 'SyncService::ReadSyncHeader'
629 if (error.Fail())
23
Assuming the condition is false
24
Taking false branch
630 return error;
631
632 if (response_id == kDATA) {
25
Calling 'operator==<char, std::char_traits<char>, std::allocator<char>>'
30
Returning from 'operator==<char, std::char_traits<char>, std::allocator<char>>'
31
Taking true branch
633 buffer.resize(data_len, 0);
32
1st function call argument is an uninitialized value
634 error = ReadAllBytes(&buffer[0], data_len);
635 if (error.Fail())
636 buffer.clear();
637 } else if (response_id == kDONE) {
638 eof = true;
639 } else if (response_id == kFAIL) {
640 std::string error_message(data_len, 0);
641 error = ReadAllBytes(&error_message[0], data_len);
642 if (error.Fail())
643 return Status("Failed to read pull error message: %s", error.AsCString());
644 return Status("Failed to pull file: %s", error_message.c_str());
645 } else
646 return Status("Pull failed with unknown response: %s", response_id.c_str());
647
648 return Status();
649}
650
651Status AdbClient::SyncService::ReadAllBytes(void *buffer, size_t size) {
652 return ::ReadAllBytes(*m_conn, buffer, size);
653}

/usr/include/c++/v1/__functional/function.h

1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___FUNCTIONAL_FUNCTION_H
11#define _LIBCPP___FUNCTIONAL_FUNCTION_H
12
13#include <__config>
14#include <__functional/binary_function.h>
15#include <__functional/invoke.h>
16#include <__functional/unary_function.h>
17#include <__iterator/iterator_traits.h>
18#include <__memory/allocator_traits.h>
19#include <__memory/compressed_pair.h>
20#include <__memory/shared_ptr.h>
21#include <exception>
22#include <memory> // TODO: replace with <__memory/__builtin_new_allocator.h>
23#include <type_traits>
24#include <utility>
25
26#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
27#pragma GCC system_header
28#endif
29
30_LIBCPP_BEGIN_NAMESPACE_STDnamespace std { inline namespace __1 {
31
32// bad_function_call
33
34class _LIBCPP_EXCEPTION_ABI__attribute__ ((__visibility__("default"))) bad_function_call
35 : public exception
36{
37#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
38public:
39 virtual ~bad_function_call() _NOEXCEPTnoexcept;
40
41 virtual const char* what() const _NOEXCEPTnoexcept;
42#endif
43};
44
45_LIBCPP_NORETURN[[noreturn]] inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
46void __throw_bad_function_call()
47{
48#ifndef _LIBCPP_NO_EXCEPTIONS
49 throw bad_function_call();
50#else
51 _VSTDstd::__1::abort();
52#endif
53}
54
55#if defined(_LIBCPP_CXX03_LANG) && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) && __has_attribute(deprecated)1
56# define _LIBCPP_DEPRECATED_CXX03_FUNCTION \
57 __attribute__((deprecated("Using std::function in C++03 is not supported anymore. Please upgrade to C++11 or later, or use a different type")))
58#else
59# define _LIBCPP_DEPRECATED_CXX03_FUNCTION /* nothing */
60#endif
61
62template<class _Fp> class _LIBCPP_DEPRECATED_CXX03_FUNCTION _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) function; // undefined
63
64namespace __function
65{
66
67template<class _Rp>
68struct __maybe_derive_from_unary_function
69{
70};
71
72template<class _Rp, class _A1>
73struct __maybe_derive_from_unary_function<_Rp(_A1)>
74 : public unary_function<_A1, _Rp>
75{
76};
77
78template<class _Rp>
79struct __maybe_derive_from_binary_function
80{
81};
82
83template<class _Rp, class _A1, class _A2>
84struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
85 : public binary_function<_A1, _A2, _Rp>
86{
87};
88
89template <class _Fp>
90_LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
91bool __not_null(_Fp const&) { return true; }
92
93template <class _Fp>
94_LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
95bool __not_null(_Fp* __ptr) { return __ptr; }
96
97template <class _Ret, class _Class>
98_LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
99bool __not_null(_Ret _Class::*__ptr) { return __ptr; }
100
101template <class _Fp>
102_LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
103bool __not_null(function<_Fp> const& __f) { return !!__f; }
104
105#ifdef _LIBCPP_HAS_EXTENSION_BLOCKS
106template <class _Rp, class ..._Args>
107_LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
108bool __not_null(_Rp (^__p)(_Args...)) { return __p; }
109#endif
110
111} // namespace __function
112
113#ifndef _LIBCPP_CXX03_LANG
114
115namespace __function {
116
117// __alloc_func holds a functor and an allocator.
118
119template <class _Fp, class _Ap, class _FB> class __alloc_func;
120template <class _Fp, class _FB>
121class __default_alloc_func;
122
123template <class _Fp, class _Ap, class _Rp, class... _ArgTypes>
124class __alloc_func<_Fp, _Ap, _Rp(_ArgTypes...)>
125{
126 __compressed_pair<_Fp, _Ap> __f_;
127
128 public:
129 typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) _Fp _Target;
130 typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) _Ap _Alloc;
131
132 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
133 const _Target& __target() const { return __f_.first(); }
134
135 // WIN32 APIs may define __allocator, so use __get_allocator instead.
136 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
137 const _Alloc& __get_allocator() const { return __f_.second(); }
138
139 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
140 explicit __alloc_func(_Target&& __f)
141 : __f_(piecewise_construct, _VSTDstd::__1::forward_as_tuple(_VSTDstd::__1::move(__f)),
142 _VSTDstd::__1::forward_as_tuple())
143 {
144 }
145
146 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
147 explicit __alloc_func(const _Target& __f, const _Alloc& __a)
148 : __f_(piecewise_construct, _VSTDstd::__1::forward_as_tuple(__f),
149 _VSTDstd::__1::forward_as_tuple(__a))
150 {
151 }
152
153 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
154 explicit __alloc_func(const _Target& __f, _Alloc&& __a)
155 : __f_(piecewise_construct, _VSTDstd::__1::forward_as_tuple(__f),
156 _VSTDstd::__1::forward_as_tuple(_VSTDstd::__1::move(__a)))
157 {
158 }
159
160 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
161 explicit __alloc_func(_Target&& __f, _Alloc&& __a)
162 : __f_(piecewise_construct, _VSTDstd::__1::forward_as_tuple(_VSTDstd::__1::move(__f)),
163 _VSTDstd::__1::forward_as_tuple(_VSTDstd::__1::move(__a)))
164 {
165 }
166
167 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
168 _Rp operator()(_ArgTypes&&... __arg)
169 {
170 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
171 return _Invoker::__call(__f_.first(),
8
Calling '__invoke_void_return_wrapper::__call'
172 _VSTDstd::__1::forward<_ArgTypes>(__arg)...);
173 }
174
175 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
176 __alloc_func* __clone() const
177 {
178 typedef allocator_traits<_Alloc> __alloc_traits;
179 typedef
180 typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type
181 _AA;
182 _AA __a(__f_.second());
183 typedef __allocator_destructor<_AA> _Dp;
184 unique_ptr<__alloc_func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
185 ::new ((void*)__hold.get()) __alloc_func(__f_.first(), _Alloc(__a));
186 return __hold.release();
187 }
188
189 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
190 void destroy() _NOEXCEPTnoexcept { __f_.~__compressed_pair<_Target, _Alloc>(); }
191
192 static void __destroy_and_delete(__alloc_func* __f) {
193 typedef allocator_traits<_Alloc> __alloc_traits;
194 typedef typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type
195 _FunAlloc;
196 _FunAlloc __a(__f->__get_allocator());
197 __f->destroy();
198 __a.deallocate(__f, 1);
199 }
200};
201
202template <class _Fp, class _Rp, class... _ArgTypes>
203class __default_alloc_func<_Fp, _Rp(_ArgTypes...)> {
204 _Fp __f_;
205
206public:
207 typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) _Fp _Target;
208
209 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
210 const _Target& __target() const { return __f_; }
211
212 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
213 explicit __default_alloc_func(_Target&& __f) : __f_(_VSTDstd::__1::move(__f)) {}
214
215 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
216 explicit __default_alloc_func(const _Target& __f) : __f_(__f) {}
217
218 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
219 _Rp operator()(_ArgTypes&&... __arg) {
220 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
221 return _Invoker::__call(__f_, _VSTDstd::__1::forward<_ArgTypes>(__arg)...);
222 }
223
224 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
225 __default_alloc_func* __clone() const {
226 __builtin_new_allocator::__holder_t __hold =
227 __builtin_new_allocator::__allocate_type<__default_alloc_func>(1);
228 __default_alloc_func* __res =
229 ::new ((void*)__hold.get()) __default_alloc_func(__f_);
230 (void)__hold.release();
231 return __res;
232 }
233
234 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
235 void destroy() _NOEXCEPTnoexcept { __f_.~_Target(); }
236
237 static void __destroy_and_delete(__default_alloc_func* __f) {
238 __f->destroy();
239 __builtin_new_allocator::__deallocate_type<__default_alloc_func>(__f, 1);
240 }
241};
242
243// __base provides an abstract interface for copyable functors.
244
245template<class _Fp> class _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) __base;
246
247template<class _Rp, class ..._ArgTypes>
248class __base<_Rp(_ArgTypes...)>
249{
250 __base(const __base&);
251 __base& operator=(const __base&);
252public:
253 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
__base() {}
254 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
virtual ~__base() {}
255 virtual __base* __clone() const = 0;
256 virtual void __clone(__base*) const = 0;
257 virtual void destroy() _NOEXCEPTnoexcept = 0;
258 virtual void destroy_deallocate() _NOEXCEPTnoexcept = 0;
259 virtual _Rp operator()(_ArgTypes&& ...) = 0;
260#ifndef _LIBCPP_NO_RTTI
261 virtual const void* target(const type_info&) const _NOEXCEPTnoexcept = 0;
262 virtual const std::type_info& target_type() const _NOEXCEPTnoexcept = 0;
263#endif // _LIBCPP_NO_RTTI
264};
265
266// __func implements __base for a given functor type.
267
268template<class _FD, class _Alloc, class _FB> class __func;
269
270template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
271class __func<_Fp, _Alloc, _Rp(_ArgTypes...)>
272 : public __base<_Rp(_ArgTypes...)>
273{
274 __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> __f_;
275public:
276 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
277 explicit __func(_Fp&& __f)
278 : __f_(_VSTDstd::__1::move(__f)) {}
279
280 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
281 explicit __func(const _Fp& __f, const _Alloc& __a)
282 : __f_(__f, __a) {}
283
284 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
285 explicit __func(const _Fp& __f, _Alloc&& __a)
286 : __f_(__f, _VSTDstd::__1::move(__a)) {}
287
288 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
289 explicit __func(_Fp&& __f, _Alloc&& __a)
290 : __f_(_VSTDstd::__1::move(__f), _VSTDstd::__1::move(__a)) {}
291
292 virtual __base<_Rp(_ArgTypes...)>* __clone() const;
293 virtual void __clone(__base<_Rp(_ArgTypes...)>*) const;
294 virtual void destroy() _NOEXCEPTnoexcept;
295 virtual void destroy_deallocate() _NOEXCEPTnoexcept;
296 virtual _Rp operator()(_ArgTypes&&... __arg);
297#ifndef _LIBCPP_NO_RTTI
298 virtual const void* target(const type_info&) const _NOEXCEPTnoexcept;
299 virtual const std::type_info& target_type() const _NOEXCEPTnoexcept;
300#endif // _LIBCPP_NO_RTTI
301};
302
303template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
304__base<_Rp(_ArgTypes...)>*
305__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const
306{
307 typedef allocator_traits<_Alloc> __alloc_traits;
308 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
309 _Ap __a(__f_.__get_allocator());
310 typedef __allocator_destructor<_Ap> _Dp;
311 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
312 ::new ((void*)__hold.get()) __func(__f_.__target(), _Alloc(__a));
313 return __hold.release();
314}
315
316template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
317void
318__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const
319{
320 ::new ((void*)__p) __func(__f_.__target(), __f_.__get_allocator());
321}
322
323template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
324void
325__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPTnoexcept
326{
327 __f_.destroy();
328}
329
330template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
331void
332__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPTnoexcept
333{
334 typedef allocator_traits<_Alloc> __alloc_traits;
335 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
336 _Ap __a(__f_.__get_allocator());
337 __f_.destroy();
338 __a.deallocate(this, 1);
339}
340
341template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
342_Rp
343__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
344{
345 return __f_(_VSTDstd::__1::forward<_ArgTypes>(__arg)...);
7
Calling '__alloc_func::operator()'
346}
347
348#ifndef _LIBCPP_NO_RTTI
349
350template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
351const void*
352__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPTnoexcept
353{
354 if (__ti == typeid(_Fp))
355 return &__f_.__target();
356 return nullptr;
357}
358
359template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
360const std::type_info&
361__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPTnoexcept
362{
363 return typeid(_Fp);
364}
365
366#endif // _LIBCPP_NO_RTTI
367
368// __value_func creates a value-type from a __func.
369
370template <class _Fp> class __value_func;
371
372template <class _Rp, class... _ArgTypes> class __value_func<_Rp(_ArgTypes...)>
373{
374 typename aligned_storage<3 * sizeof(void*)>::type __buf_;
375
376 typedef __base<_Rp(_ArgTypes...)> __func;
377 __func* __f_;
378
379 _LIBCPP_NO_CFI__attribute__((__no_sanitize__("cfi"))) static __func* __as_base(void* p)
380 {
381 return reinterpret_cast<__func*>(p);
382 }
383
384 public:
385 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
386 __value_func() _NOEXCEPTnoexcept : __f_(nullptr) {}
387
388 template <class _Fp, class _Alloc>
389 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
__value_func(_Fp&& __f, const _Alloc& __a)
390 : __f_(nullptr)
391 {
392 typedef allocator_traits<_Alloc> __alloc_traits;
393 typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun;
394 typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type
395 _FunAlloc;
396
397 if (__function::__not_null(__f))
398 {
399 _FunAlloc __af(__a);
400 if (sizeof(_Fun) <= sizeof(__buf_) &&
401 is_nothrow_copy_constructible<_Fp>::value &&
402 is_nothrow_copy_constructible<_FunAlloc>::value)
403 {
404 __f_ =
405 ::new ((void*)&__buf_) _Fun(_VSTDstd::__1::move(__f), _Alloc(__af));
406 }
407 else
408 {
409 typedef __allocator_destructor<_FunAlloc> _Dp;
410 unique_ptr<__func, _Dp> __hold(__af.allocate(1), _Dp(__af, 1));
411 ::new ((void*)__hold.get()) _Fun(_VSTDstd::__1::move(__f), _Alloc(__a));
412 __f_ = __hold.release();
413 }
414 }
415 }
416
417 template <class _Fp,
418 class = typename enable_if<!is_same<typename decay<_Fp>::type, __value_func>::value>::type>
419 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
explicit __value_func(_Fp&& __f)
420 : __value_func(_VSTDstd::__1::forward<_Fp>(__f), allocator<_Fp>()) {}
421
422 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
423 __value_func(const __value_func& __f)
424 {
425 if (__f.__f_ == nullptr)
426 __f_ = nullptr;
427 else if ((void*)__f.__f_ == &__f.__buf_)
428 {
429 __f_ = __as_base(&__buf_);
430 __f.__f_->__clone(__f_);
431 }
432 else
433 __f_ = __f.__f_->__clone();
434 }
435
436 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
437 __value_func(__value_func&& __f) _NOEXCEPTnoexcept
438 {
439 if (__f.__f_ == nullptr)
440 __f_ = nullptr;
441 else if ((void*)__f.__f_ == &__f.__buf_)
442 {
443 __f_ = __as_base(&__buf_);
444 __f.__f_->__clone(__f_);
445 }
446 else
447 {
448 __f_ = __f.__f_;
449 __f.__f_ = nullptr;
450 }
451 }
452
453 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
454 ~__value_func()
455 {
456 if ((void*)__f_ == &__buf_)
457 __f_->destroy();
458 else if (__f_)
459 __f_->destroy_deallocate();
460 }
461
462 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
463 __value_func& operator=(__value_func&& __f)
464 {
465 *this = nullptr;
466 if (__f.__f_ == nullptr)
467 __f_ = nullptr;
468 else if ((void*)__f.__f_ == &__f.__buf_)
469 {
470 __f_ = __as_base(&__buf_);
471 __f.__f_->__clone(__f_);
472 }
473 else
474 {
475 __f_ = __f.__f_;
476 __f.__f_ = nullptr;
477 }
478 return *this;
479 }
480
481 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
482 __value_func& operator=(nullptr_t)
483 {
484 __func* __f = __f_;
485 __f_ = nullptr;
486 if ((void*)__f == &__buf_)
487 __f->destroy();
488 else if (__f)
489 __f->destroy_deallocate();
490 return *this;
491 }
492
493 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
494 _Rp operator()(_ArgTypes&&... __args) const
495 {
496 if (__f_ == nullptr)
5
Taking false branch
497 __throw_bad_function_call();
498 return (*__f_)(_VSTDstd::__1::forward<_ArgTypes>(__args)...);
6
Calling '__func::operator()'
499 }
500
501 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
502 void swap(__value_func& __f) _NOEXCEPTnoexcept
503 {
504 if (&__f == this)
505 return;
506 if ((void*)__f_ == &__buf_ && (void*)__f.__f_ == &__f.__buf_)
507 {
508 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
509 __func* __t = __as_base(&__tempbuf);
510 __f_->__clone(__t);
511 __f_->destroy();
512 __f_ = nullptr;
513 __f.__f_->__clone(__as_base(&__buf_));
514 __f.__f_->destroy();
515 __f.__f_ = nullptr;
516 __f_ = __as_base(&__buf_);
517 __t->__clone(__as_base(&__f.__buf_));
518 __t->destroy();
519 __f.__f_ = __as_base(&__f.__buf_);
520 }
521 else if ((void*)__f_ == &__buf_)
522 {
523 __f_->__clone(__as_base(&__f.__buf_));
524 __f_->destroy();
525 __f_ = __f.__f_;
526 __f.__f_ = __as_base(&__f.__buf_);
527 }
528 else if ((void*)__f.__f_ == &__f.__buf_)
529 {
530 __f.__f_->__clone(__as_base(&__buf_));
531 __f.__f_->destroy();
532 __f.__f_ = __f_;
533 __f_ = __as_base(&__buf_);
534 }
535 else
536 _VSTDstd::__1::swap(__f_, __f.__f_);
537 }
538
539 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
540 explicit operator bool() const _NOEXCEPTnoexcept { return __f_ != nullptr; }
541
542#ifndef _LIBCPP_NO_RTTI
543 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
544 const std::type_info& target_type() const _NOEXCEPTnoexcept
545 {
546 if (__f_ == nullptr)
547 return typeid(void);
548 return __f_->target_type();
549 }
550
551 template <typename _Tp>
552 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
const _Tp* target() const _NOEXCEPTnoexcept
553 {
554 if (__f_ == nullptr)
555 return nullptr;
556 return (const _Tp*)__f_->target(typeid(_Tp));
557 }
558#endif // _LIBCPP_NO_RTTI
559};
560
561// Storage for a functor object, to be used with __policy to manage copy and
562// destruction.
563union __policy_storage
564{
565 mutable char __small[sizeof(void*) * 2];
566 void* __large;
567};
568
569// True if _Fun can safely be held in __policy_storage.__small.
570template <typename _Fun>
571struct __use_small_storage
572 : public integral_constant<
573 bool, sizeof(_Fun) <= sizeof(__policy_storage) &&
574 _LIBCPP_ALIGNOF(_Fun)alignof(_Fun) <= _LIBCPP_ALIGNOF(__policy_storage)alignof(__policy_storage) &&
575 is_trivially_copy_constructible<_Fun>::value &&
576 is_trivially_destructible<_Fun>::value> {};
577
578// Policy contains information about how to copy, destroy, and move the
579// underlying functor. You can think of it as a vtable of sorts.
580struct __policy
581{
582 // Used to copy or destroy __large values. null for trivial objects.
583 void* (*const __clone)(const void*);
584 void (*const __destroy)(void*);
585
586 // True if this is the null policy (no value).
587 const bool __is_null;
588
589 // The target type. May be null if RTTI is disabled.
590 const std::type_info* const __type_info;
591
592 // Returns a pointer to a static policy object suitable for the functor
593 // type.
594 template <typename _Fun>
595 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
static const __policy* __create()
596 {
597 return __choose_policy<_Fun>(__use_small_storage<_Fun>());
598 }
599
600 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
601 static const __policy* __create_empty()
602 {
603 static const _LIBCPP_CONSTEXPRconstexpr __policy __policy_ = {nullptr, nullptr,
604 true,
605#ifndef _LIBCPP_NO_RTTI
606 &typeid(void)
607#else
608 nullptr
609#endif
610 };
611 return &__policy_;
612 }
613
614 private:
615 template <typename _Fun> static void* __large_clone(const void* __s)
616 {
617 const _Fun* __f = static_cast<const _Fun*>(__s);
618 return __f->__clone();
619 }
620
621 template <typename _Fun>
622 static void __large_destroy(void* __s) {
623 _Fun::__destroy_and_delete(static_cast<_Fun*>(__s));
624 }
625
626 template <typename _Fun>
627 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
static const __policy*
628 __choose_policy(/* is_small = */ false_type) {
629 static const _LIBCPP_CONSTEXPRconstexpr __policy __policy_ = {
630 &__large_clone<_Fun>, &__large_destroy<_Fun>, false,
631#ifndef _LIBCPP_NO_RTTI
632 &typeid(typename _Fun::_Target)
633#else
634 nullptr
635#endif
636 };
637 return &__policy_;
638 }
639
640 template <typename _Fun>
641 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
static const __policy*
642 __choose_policy(/* is_small = */ true_type)
643 {
644 static const _LIBCPP_CONSTEXPRconstexpr __policy __policy_ = {
645 nullptr, nullptr, false,
646#ifndef _LIBCPP_NO_RTTI
647 &typeid(typename _Fun::_Target)
648#else
649 nullptr
650#endif
651 };
652 return &__policy_;
653 }
654};
655
656// Used to choose between perfect forwarding or pass-by-value. Pass-by-value is
657// faster for types that can be passed in registers.
658template <typename _Tp>
659using __fast_forward =
660 typename conditional<is_scalar<_Tp>::value, _Tp, _Tp&&>::type;
661
662// __policy_invoker calls an instance of __alloc_func held in __policy_storage.
663
664template <class _Fp> struct __policy_invoker;
665
666template <class _Rp, class... _ArgTypes>
667struct __policy_invoker<_Rp(_ArgTypes...)>
668{
669 typedef _Rp (*__Call)(const __policy_storage*,
670 __fast_forward<_ArgTypes>...);
671
672 __Call __call_;
673
674 // Creates an invoker that throws bad_function_call.
675 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
676 __policy_invoker() : __call_(&__call_empty) {}
677
678 // Creates an invoker that calls the given instance of __func.
679 template <typename _Fun>
680 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
static __policy_invoker __create()
681 {
682 return __policy_invoker(&__call_impl<_Fun>);
683 }
684
685 private:
686 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
687 explicit __policy_invoker(__Call __c) : __call_(__c) {}
688
689 static _Rp __call_empty(const __policy_storage*,
690 __fast_forward<_ArgTypes>...)
691 {
692 __throw_bad_function_call();
693 }
694
695 template <typename _Fun>
696 static _Rp __call_impl(const __policy_storage* __buf,
697 __fast_forward<_ArgTypes>... __args)
698 {
699 _Fun* __f = reinterpret_cast<_Fun*>(__use_small_storage<_Fun>::value
700 ? &__buf->__small
701 : __buf->__large);
702 return (*__f)(_VSTDstd::__1::forward<_ArgTypes>(__args)...);
703 }
704};
705
706// __policy_func uses a __policy and __policy_invoker to create a type-erased,
707// copyable functor.
708
709template <class _Fp> class __policy_func;
710
711template <class _Rp, class... _ArgTypes> class __policy_func<_Rp(_ArgTypes...)>
712{
713 // Inline storage for small objects.
714 __policy_storage __buf_;
715
716 // Calls the value stored in __buf_. This could technically be part of
717 // policy, but storing it here eliminates a level of indirection inside
718 // operator().
719 typedef __function::__policy_invoker<_Rp(_ArgTypes...)> __invoker;
720 __invoker __invoker_;
721
722 // The policy that describes how to move / copy / destroy __buf_. Never
723 // null, even if the function is empty.
724 const __policy* __policy_;
725
726 public:
727 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
728 __policy_func() : __policy_(__policy::__create_empty()) {}
729
730 template <class _Fp, class _Alloc>
731 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
__policy_func(_Fp&& __f, const _Alloc& __a)
732 : __policy_(__policy::__create_empty())
733 {
734 typedef __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun;
735 typedef allocator_traits<_Alloc> __alloc_traits;
736 typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type
737 _FunAlloc;
738
739 if (__function::__not_null(__f))
740 {
741 __invoker_ = __invoker::template __create<_Fun>();
742 __policy_ = __policy::__create<_Fun>();
743
744 _FunAlloc __af(__a);
745 if (__use_small_storage<_Fun>())
746 {
747 ::new ((void*)&__buf_.__small)
748 _Fun(_VSTDstd::__1::move(__f), _Alloc(__af));
749 }
750 else
751 {
752 typedef __allocator_destructor<_FunAlloc> _Dp;
753 unique_ptr<_Fun, _Dp> __hold(__af.allocate(1), _Dp(__af, 1));
754 ::new ((void*)__hold.get())
755 _Fun(_VSTDstd::__1::move(__f), _Alloc(__af));
756 __buf_.__large = __hold.release();
757 }
758 }
759 }
760
761 template <class _Fp, class = typename enable_if<!is_same<typename decay<_Fp>::type, __policy_func>::value>::type>
762 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
explicit __policy_func(_Fp&& __f)
763 : __policy_(__policy::__create_empty()) {
764 typedef __default_alloc_func<_Fp, _Rp(_ArgTypes...)> _Fun;
765
766 if (__function::__not_null(__f)) {
767 __invoker_ = __invoker::template __create<_Fun>();
768 __policy_ = __policy::__create<_Fun>();
769 if (__use_small_storage<_Fun>()) {
770 ::new ((void*)&__buf_.__small) _Fun(_VSTDstd::__1::move(__f));
771 } else {
772 __builtin_new_allocator::__holder_t __hold =
773 __builtin_new_allocator::__allocate_type<_Fun>(1);
774 __buf_.__large = ::new ((void*)__hold.get()) _Fun(_VSTDstd::__1::move(__f));
775 (void)__hold.release();
776 }
777 }
778 }
779
780 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
781 __policy_func(const __policy_func& __f)
782 : __buf_(__f.__buf_), __invoker_(__f.__invoker_),
783 __policy_(__f.__policy_)
784 {
785 if (__policy_->__clone)
786 __buf_.__large = __policy_->__clone(__f.__buf_.__large);
787 }
788
789 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
790 __policy_func(__policy_func&& __f)
791 : __buf_(__f.__buf_), __invoker_(__f.__invoker_),
792 __policy_(__f.__policy_)
793 {
794 if (__policy_->__destroy)
795 {
796 __f.__policy_ = __policy::__create_empty();
797 __f.__invoker_ = __invoker();
798 }
799 }
800
801 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
802 ~__policy_func()
803 {
804 if (__policy_->__destroy)
805 __policy_->__destroy(__buf_.__large);
806 }
807
808 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
809 __policy_func& operator=(__policy_func&& __f)
810 {
811 *this = nullptr;
812 __buf_ = __f.__buf_;
813 __invoker_ = __f.__invoker_;
814 __policy_ = __f.__policy_;
815 __f.__policy_ = __policy::__create_empty();
816 __f.__invoker_ = __invoker();
817 return *this;
818 }
819
820 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
821 __policy_func& operator=(nullptr_t)
822 {
823 const __policy* __p = __policy_;
824 __policy_ = __policy::__create_empty();
825 __invoker_ = __invoker();
826 if (__p->__destroy)
827 __p->__destroy(__buf_.__large);
828 return *this;
829 }
830
831 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
832 _Rp operator()(_ArgTypes&&... __args) const
833 {
834 return __invoker_.__call_(_VSTDstd::__1::addressof(__buf_),
835 _VSTDstd::__1::forward<_ArgTypes>(__args)...);
836 }
837
838 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
839 void swap(__policy_func& __f)
840 {
841 _VSTDstd::__1::swap(__invoker_, __f.__invoker_);
842 _VSTDstd::__1::swap(__policy_, __f.__policy_);
843 _VSTDstd::__1::swap(__buf_, __f.__buf_);
844 }
845
846 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
847 explicit operator bool() const _NOEXCEPTnoexcept
848 {
849 return !__policy_->__is_null;
850 }
851
852#ifndef _LIBCPP_NO_RTTI
853 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
854 const std::type_info& target_type() const _NOEXCEPTnoexcept
855 {
856 return *__policy_->__type_info;
857 }
858
859 template <typename _Tp>
860 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
const _Tp* target() const _NOEXCEPTnoexcept
861 {
862 if (__policy_->__is_null || typeid(_Tp) != *__policy_->__type_info)
863 return nullptr;
864 if (__policy_->__clone) // Out of line storage.
865 return reinterpret_cast<const _Tp*>(__buf_.__large);
866 else
867 return reinterpret_cast<const _Tp*>(&__buf_.__small);
868 }
869#endif // _LIBCPP_NO_RTTI
870};
871
872#if defined(_LIBCPP_HAS_BLOCKS_RUNTIME) && !defined(_LIBCPP_HAS_OBJC_ARC)
873
874extern "C" void *_Block_copy(const void *);
875extern "C" void _Block_release(const void *);
876
877template<class _Rp1, class ..._ArgTypes1, class _Alloc, class _Rp, class ..._ArgTypes>
878class __func<_Rp1(^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)>
879 : public __base<_Rp(_ArgTypes...)>
880{
881 typedef _Rp1(^__block_type)(_ArgTypes1...);
882 __block_type __f_;
883
884public:
885 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
886 explicit __func(__block_type const& __f)
887 : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr))
888 { }
889
890 // [TODO] add && to save on a retain
891
892 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
893 explicit __func(__block_type __f, const _Alloc& /* unused */)
894 : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr))
895 { }
896
897 virtual __base<_Rp(_ArgTypes...)>* __clone() const {
898 _LIBCPP_ASSERT(false,((void)0)
899 "Block pointers are just pointers, so they should always fit into "((void)0)
900 "std::function's small buffer optimization. This function should "((void)0)
901 "never be invoked.")((void)0);
902 return nullptr;
903 }
904
905 virtual void __clone(__base<_Rp(_ArgTypes...)>* __p) const {
906 ::new ((void*)__p) __func(__f_);
907 }
908
909 virtual void destroy() _NOEXCEPTnoexcept {
910 if (__f_)
911 _Block_release(__f_);
912 __f_ = 0;
913 }
914
915 virtual void destroy_deallocate() _NOEXCEPTnoexcept {
916 _LIBCPP_ASSERT(false,((void)0)
917 "Block pointers are just pointers, so they should always fit into "((void)0)
918 "std::function's small buffer optimization. This function should "((void)0)
919 "never be invoked.")((void)0);
920 }
921
922 virtual _Rp operator()(_ArgTypes&& ... __arg) {
923 return _VSTDstd::__1::__invoke(__f_, _VSTDstd::__1::forward<_ArgTypes>(__arg)...);
924 }
925
926#ifndef _LIBCPP_NO_RTTI
927 virtual const void* target(type_info const& __ti) const _NOEXCEPTnoexcept {
928 if (__ti == typeid(__func::__block_type))
929 return &__f_;
930 return (const void*)nullptr;
931 }
932
933 virtual const std::type_info& target_type() const _NOEXCEPTnoexcept {
934 return typeid(__func::__block_type);
935 }
936#endif // _LIBCPP_NO_RTTI
937};
938
939#endif // _LIBCPP_HAS_EXTENSION_BLOCKS && !_LIBCPP_HAS_OBJC_ARC
940
941} // __function
942
943template<class _Rp, class ..._ArgTypes>
944class _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) function<_Rp(_ArgTypes...)>
945#if _LIBCPP_STD_VER14 <= 17 || !defined(_LIBCPP_ABI_NO_BINDER_BASES)
946 : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
947 public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
948#endif
949{
950#ifndef _LIBCPP_ABI_OPTIMIZED_FUNCTION
951 typedef __function::__value_func<_Rp(_ArgTypes...)> __func;
952#else
953 typedef __function::__policy_func<_Rp(_ArgTypes...)> __func;
954#endif
955
956 __func __f_;
957
958 template <class _Fp, bool = _And<
959 _IsNotSame<__uncvref_t<_Fp>, function>,
960 __invokable<_Fp, _ArgTypes...>
961 >::value>
962 struct __callable;
963 template <class _Fp>
964 struct __callable<_Fp, true>
965 {
966 static const bool value = is_void<_Rp>::value ||
967 __is_core_convertible<typename __invoke_of<_Fp, _ArgTypes...>::type,
968 _Rp>::value;
969 };
970 template <class _Fp>
971 struct __callable<_Fp, false>
972 {
973 static const bool value = false;
974 };
975
976 template <class _Fp>
977 using _EnableIfLValueCallable = typename enable_if<__callable<_Fp&>::value>::type;
978public:
979 typedef _Rp result_type;
980
981 // construct/copy/destroy:
982 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
983 function() _NOEXCEPTnoexcept { }
984 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
985 function(nullptr_t) _NOEXCEPTnoexcept {}
986 function(const function&);
987 function(function&&) _NOEXCEPTnoexcept;
988 template<class _Fp, class = _EnableIfLValueCallable<_Fp>>
989 function(_Fp);
990
991#if _LIBCPP_STD_VER14 <= 14
992 template<class _Alloc>
993 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
994 function(allocator_arg_t, const _Alloc&) _NOEXCEPTnoexcept {}
995 template<class _Alloc>
996 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
997 function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPTnoexcept {}
998 template<class _Alloc>
999 function(allocator_arg_t, const _Alloc&, const function&);
1000 template<class _Alloc>
1001 function(allocator_arg_t, const _Alloc&, function&&);
1002 template<class _Fp, class _Alloc, class = _EnableIfLValueCallable<_Fp>>
1003 function(allocator_arg_t, const _Alloc& __a, _Fp __f);
1004#endif
1005
1006 function& operator=(const function&);
1007 function& operator=(function&&) _NOEXCEPTnoexcept;
1008 function& operator=(nullptr_t) _NOEXCEPTnoexcept;
1009 template<class _Fp, class = _EnableIfLValueCallable<typename decay<_Fp>::type>>
1010 function& operator=(_Fp&&);
1011
1012 ~function();
1013
1014 // function modifiers:
1015 void swap(function&) _NOEXCEPTnoexcept;
1016
1017#if _LIBCPP_STD_VER14 <= 14
1018 template<class _Fp, class _Alloc>
1019 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1020 void assign(_Fp&& __f, const _Alloc& __a)
1021 {function(allocator_arg, __a, _VSTDstd::__1::forward<_Fp>(__f)).swap(*this);}
1022#endif
1023
1024 // function capacity:
1025 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1026 explicit operator bool() const _NOEXCEPTnoexcept {
1027 return static_cast<bool>(__f_);
1028 }
1029
1030 // deleted overloads close possible hole in the type system
1031 template<class _R2, class... _ArgTypes2>
1032 bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
1033 template<class _R2, class... _ArgTypes2>
1034 bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
1035public:
1036 // function invocation:
1037 _Rp operator()(_ArgTypes...) const;
1038
1039#ifndef _LIBCPP_NO_RTTI
1040 // function target access:
1041 const std::type_info& target_type() const _NOEXCEPTnoexcept;
1042 template <typename _Tp> _Tp* target() _NOEXCEPTnoexcept;
1043 template <typename _Tp> const _Tp* target() const _NOEXCEPTnoexcept;
1044#endif // _LIBCPP_NO_RTTI
1045};
1046
1047#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1048template<class _Rp, class ..._Ap>
1049function(_Rp(*)(_Ap...)) -> function<_Rp(_Ap...)>;
1050
1051template<class _Fp>
1052struct __strip_signature;
1053
1054template<class _Rp, class _Gp, class ..._Ap>
1055struct __strip_signature<_Rp (_Gp::*) (_Ap...)> { using type = _Rp(_Ap...); };
1056template<class _Rp, class _Gp, class ..._Ap>
1057struct __strip_signature<_Rp (_Gp::*) (_Ap...) const> { using type = _Rp(_Ap...); };
1058template<class _Rp, class _Gp, class ..._Ap>
1059struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile> { using type = _Rp(_Ap...); };
1060template<class _Rp, class _Gp, class ..._Ap>
1061struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile> { using type = _Rp(_Ap...); };
1062
1063template<class _Rp, class _Gp, class ..._Ap>
1064struct __strip_signature<_Rp (_Gp::*) (_Ap...) &> { using type = _Rp(_Ap...); };
1065template<class _Rp, class _Gp, class ..._Ap>
1066struct __strip_signature<_Rp (_Gp::*) (_Ap...) const &> { using type = _Rp(_Ap...); };
1067template<class _Rp, class _Gp, class ..._Ap>
1068struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile &> { using type = _Rp(_Ap...); };
1069template<class _Rp, class _Gp, class ..._Ap>
1070struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile &> { using type = _Rp(_Ap...); };
1071
1072template<class _Rp, class _Gp, class ..._Ap>
1073struct __strip_signature<_Rp (_Gp::*) (_Ap...) noexcept> { using type = _Rp(_Ap...); };
1074template<class _Rp, class _Gp, class ..._Ap>
1075struct __strip_signature<_Rp (_Gp::*) (_Ap...) const noexcept> { using type = _Rp(_Ap...); };
1076template<class _Rp, class _Gp, class ..._Ap>
1077struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile noexcept> { using type = _Rp(_Ap...); };
1078template<class _Rp, class _Gp, class ..._Ap>
1079struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile noexcept> { using type = _Rp(_Ap...); };
1080
1081template<class _Rp, class _Gp, class ..._Ap>
1082struct __strip_signature<_Rp (_Gp::*) (_Ap...) & noexcept> { using type = _Rp(_Ap...); };
1083template<class _Rp, class _Gp, class ..._Ap>
1084struct __strip_signature<_Rp (_Gp::*) (_Ap...) const & noexcept> { using type = _Rp(_Ap...); };
1085template<class _Rp, class _Gp, class ..._Ap>
1086struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile & noexcept> { using type = _Rp(_Ap...); };
1087template<class _Rp, class _Gp, class ..._Ap>
1088struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile & noexcept> { using type = _Rp(_Ap...); };
1089
1090template<class _Fp, class _Stripped = typename __strip_signature<decltype(&_Fp::operator())>::type>
1091function(_Fp) -> function<_Stripped>;
1092#endif // !_LIBCPP_HAS_NO_DEDUCTION_GUIDES
1093
1094template<class _Rp, class ..._ArgTypes>
1095function<_Rp(_ArgTypes...)>::function(const function& __f) : __f_(__f.__f_) {}
1096
1097#if _LIBCPP_STD_VER14 <= 14
1098template<class _Rp, class ..._ArgTypes>
1099template <class _Alloc>
1100function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
1101 const function& __f) : __f_(__f.__f_) {}
1102#endif
1103
1104template <class _Rp, class... _ArgTypes>
1105function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPTnoexcept
1106 : __f_(_VSTDstd::__1::move(__f.__f_)) {}
1107
1108#if _LIBCPP_STD_VER14 <= 14
1109template<class _Rp, class ..._ArgTypes>
1110template <class _Alloc>
1111function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
1112 function&& __f)
1113 : __f_(_VSTDstd::__1::move(__f.__f_)) {}
1114#endif
1115
1116template <class _Rp, class... _ArgTypes>
1117template <class _Fp, class>
1118function<_Rp(_ArgTypes...)>::function(_Fp __f) : __f_(_VSTDstd::__1::move(__f)) {}
1119
1120#if _LIBCPP_STD_VER14 <= 14
1121template <class _Rp, class... _ArgTypes>
1122template <class _Fp, class _Alloc, class>
1123function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a,
1124 _Fp __f)
1125 : __f_(_VSTDstd::__1::move(__f), __a) {}
1126#endif
1127
1128template<class _Rp, class ..._ArgTypes>
1129function<_Rp(_ArgTypes...)>&
1130function<_Rp(_ArgTypes...)>::operator=(const function& __f)
1131{
1132 function(__f).swap(*this);
1133 return *this;
1134}
1135
1136template<class _Rp, class ..._ArgTypes>
1137function<_Rp(_ArgTypes...)>&
1138function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPTnoexcept
1139{
1140 __f_ = _VSTDstd::__1::move(__f.__f_);
1141 return *this;
1142}
1143
1144template<class _Rp, class ..._ArgTypes>
1145function<_Rp(_ArgTypes...)>&
1146function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPTnoexcept
1147{
1148 __f_ = nullptr;
1149 return *this;
1150}
1151
1152template<class _Rp, class ..._ArgTypes>
1153template <class _Fp, class>
1154function<_Rp(_ArgTypes...)>&
1155function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
1156{
1157 function(_VSTDstd::__1::forward<_Fp>(__f)).swap(*this);
1158 return *this;
1159}
1160
1161template<class _Rp, class ..._ArgTypes>
1162function<_Rp(_ArgTypes...)>::~function() {}
1163
1164template<class _Rp, class ..._ArgTypes>
1165void
1166function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPTnoexcept
1167{
1168 __f_.swap(__f.__f_);
1169}
1170
1171template<class _Rp, class ..._ArgTypes>
1172_Rp
1173function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
1174{
1175 return __f_(_VSTDstd::__1::forward<_ArgTypes>(__arg)...);
4
Calling '__value_func::operator()'
1176}
1177
1178#ifndef _LIBCPP_NO_RTTI
1179
1180template<class _Rp, class ..._ArgTypes>
1181const std::type_info&
1182function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPTnoexcept
1183{
1184 return __f_.target_type();
1185}
1186
1187template<class _Rp, class ..._ArgTypes>
1188template <typename _Tp>
1189_Tp*
1190function<_Rp(_ArgTypes...)>::target() _NOEXCEPTnoexcept
1191{
1192 return (_Tp*)(__f_.template target<_Tp>());
1193}
1194
1195template<class _Rp, class ..._ArgTypes>
1196template <typename _Tp>
1197const _Tp*
1198function<_Rp(_ArgTypes...)>::target() const _NOEXCEPTnoexcept
1199{
1200 return __f_.template target<_Tp>();
1201}
1202
1203#endif // _LIBCPP_NO_RTTI
1204
1205template <class _Rp, class... _ArgTypes>
1206inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1207bool
1208operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPTnoexcept {return !__f;}
1209
1210template <class _Rp, class... _ArgTypes>
1211inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1212bool
1213operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPTnoexcept {return !__f;}
1214
1215template <class _Rp, class... _ArgTypes>
1216inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1217bool
1218operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPTnoexcept {return (bool)__f;}
1219
1220template <class _Rp, class... _ArgTypes>
1221inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1222bool
1223operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPTnoexcept {return (bool)__f;}
1224
1225template <class _Rp, class... _ArgTypes>
1226inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1227void
1228swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPTnoexcept
1229{return __x.swap(__y);}
1230
1231#else // _LIBCPP_CXX03_LANG
1232
1233namespace __function {
1234
1235template<class _Fp> class __base;
1236
1237template<class _Rp>
1238class __base<_Rp()>
1239{
1240 __base(const __base&);
1241 __base& operator=(const __base&);
1242public:
1243 __base() {}
1244 virtual ~__base() {}
1245 virtual __base* __clone() const = 0;
1246 virtual void __clone(__base*) const = 0;
1247 virtual void destroy() = 0;
1248 virtual void destroy_deallocate() = 0;
1249 virtual _Rp operator()() = 0;
1250#ifndef _LIBCPP_NO_RTTI
1251 virtual const void* target(const type_info&) const = 0;
1252 virtual const std::type_info& target_type() const = 0;
1253#endif // _LIBCPP_NO_RTTI
1254};
1255
1256template<class _Rp, class _A0>
1257class __base<_Rp(_A0)>
1258{
1259 __base(const __base&);
1260 __base& operator=(const __base&);
1261public:
1262 __base() {}
1263 virtual ~__base() {}
1264 virtual __base* __clone() const = 0;
1265 virtual void __clone(__base*) const = 0;
1266 virtual void destroy() = 0;
1267 virtual void destroy_deallocate() = 0;
1268 virtual _Rp operator()(_A0) = 0;
1269#ifndef _LIBCPP_NO_RTTI
1270 virtual const void* target(const type_info&) const = 0;
1271 virtual const std::type_info& target_type() const = 0;
1272#endif // _LIBCPP_NO_RTTI
1273};
1274
1275template<class _Rp, class _A0, class _A1>
1276class __base<_Rp(_A0, _A1)>
1277{
1278 __base(const __base&);
1279 __base& operator=(const __base&);
1280public:
1281 __base() {}
1282 virtual ~__base() {}
1283 virtual __base* __clone() const = 0;
1284 virtual void __clone(__base*) const = 0;
1285 virtual void destroy() = 0;
1286 virtual void destroy_deallocate() = 0;
1287 virtual _Rp operator()(_A0, _A1) = 0;
1288#ifndef _LIBCPP_NO_RTTI
1289 virtual const void* target(const type_info&) const = 0;
1290 virtual const std::type_info& target_type() const = 0;
1291#endif // _LIBCPP_NO_RTTI
1292};
1293
1294template<class _Rp, class _A0, class _A1, class _A2>
1295class __base<_Rp(_A0, _A1, _A2)>
1296{
1297 __base(const __base&);
1298 __base& operator=(const __base&);
1299public:
1300 __base() {}
1301 virtual ~__base() {}
1302 virtual __base* __clone() const = 0;
1303 virtual void __clone(__base*) const = 0;
1304 virtual void destroy() = 0;
1305 virtual void destroy_deallocate() = 0;
1306 virtual _Rp operator()(_A0, _A1, _A2) = 0;
1307#ifndef _LIBCPP_NO_RTTI
1308 virtual const void* target(const type_info&) const = 0;
1309 virtual const std::type_info& target_type() const = 0;
1310#endif // _LIBCPP_NO_RTTI
1311};
1312
1313template<class _FD, class _Alloc, class _FB> class __func;
1314
1315template<class _Fp, class _Alloc, class _Rp>
1316class __func<_Fp, _Alloc, _Rp()>
1317 : public __base<_Rp()>
1318{
1319 __compressed_pair<_Fp, _Alloc> __f_;
1320public:
1321 explicit __func(_Fp __f) : __f_(_VSTDstd::__1::move(__f), __default_init_tag()) {}
1322 explicit __func(_Fp __f, _Alloc __a) : __f_(_VSTDstd::__1::move(__f), _VSTDstd::__1::move(__a)) {}
1323 virtual __base<_Rp()>* __clone() const;
1324 virtual void __clone(__base<_Rp()>*) const;
1325 virtual void destroy();
1326 virtual void destroy_deallocate();
1327 virtual _Rp operator()();
1328#ifndef _LIBCPP_NO_RTTI
1329 virtual const void* target(const type_info&) const;
1330 virtual const std::type_info& target_type() const;
1331#endif // _LIBCPP_NO_RTTI
1332};
1333
1334template<class _Fp, class _Alloc, class _Rp>
1335__base<_Rp()>*
1336__func<_Fp, _Alloc, _Rp()>::__clone() const
1337{
1338 typedef allocator_traits<_Alloc> __alloc_traits;
1339 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
1340 _Ap __a(__f_.second());
1341 typedef __allocator_destructor<_Ap> _Dp;
1342 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1343 ::new ((void*)__hold.get()) __func(__f_.first(), _Alloc(__a));
1344 return __hold.release();
1345}
1346
1347template<class _Fp, class _Alloc, class _Rp>
1348void
1349__func<_Fp, _Alloc, _Rp()>::__clone(__base<_Rp()>* __p) const
1350{
1351 ::new ((void*)__p) __func(__f_.first(), __f_.second());
1352}
1353
1354template<class _Fp, class _Alloc, class _Rp>
1355void
1356__func<_Fp, _Alloc, _Rp()>::destroy()
1357{
1358 __f_.~__compressed_pair<_Fp, _Alloc>();
1359}
1360
1361template<class _Fp, class _Alloc, class _Rp>
1362void
1363__func<_Fp, _Alloc, _Rp()>::destroy_deallocate()
1364{
1365 typedef allocator_traits<_Alloc> __alloc_traits;
1366 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
1367 _Ap __a(__f_.second());
1368 __f_.~__compressed_pair<_Fp, _Alloc>();
1369 __a.deallocate(this, 1);
1370}
1371
1372template<class _Fp, class _Alloc, class _Rp>
1373_Rp
1374__func<_Fp, _Alloc, _Rp()>::operator()()
1375{
1376 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
1377 return _Invoker::__call(__f_.first());
1378}
1379
1380#ifndef _LIBCPP_NO_RTTI
1381
1382template<class _Fp, class _Alloc, class _Rp>
1383const void*
1384__func<_Fp, _Alloc, _Rp()>::target(const type_info& __ti) const
1385{
1386 if (__ti == typeid(_Fp))
1387 return &__f_.first();
1388 return (const void*)0;
1389}
1390
1391template<class _Fp, class _Alloc, class _Rp>
1392const std::type_info&
1393__func<_Fp, _Alloc, _Rp()>::target_type() const
1394{
1395 return typeid(_Fp);
1396}
1397
1398#endif // _LIBCPP_NO_RTTI
1399
1400template<class _Fp, class _Alloc, class _Rp, class _A0>
1401class __func<_Fp, _Alloc, _Rp(_A0)>
1402 : public __base<_Rp(_A0)>
1403{
1404 __compressed_pair<_Fp, _Alloc> __f_;
1405public:
1406 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
explicit __func(_Fp __f) : __f_(_VSTDstd::__1::move(__f), __default_init_tag()) {}
1407 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
explicit __func(_Fp __f, _Alloc __a)
1408 : __f_(_VSTDstd::__1::move(__f), _VSTDstd::__1::move(__a)) {}
1409 virtual __base<_Rp(_A0)>* __clone() const;
1410 virtual void __clone(__base<_Rp(_A0)>*) const;
1411 virtual void destroy();
1412 virtual void destroy_deallocate();
1413 virtual _Rp operator()(_A0);
1414#ifndef _LIBCPP_NO_RTTI
1415 virtual const void* target(const type_info&) const;
1416 virtual const std::type_info& target_type() const;
1417#endif // _LIBCPP_NO_RTTI
1418};
1419
1420template<class _Fp, class _Alloc, class _Rp, class _A0>
1421__base<_Rp(_A0)>*
1422__func<_Fp, _Alloc, _Rp(_A0)>::__clone() const
1423{
1424 typedef allocator_traits<_Alloc> __alloc_traits;
1425 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
1426 _Ap __a(__f_.second());
1427 typedef __allocator_destructor<_Ap> _Dp;
1428 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1429 ::new ((void*)__hold.get()) __func(__f_.first(), _Alloc(__a));
1430 return __hold.release();
1431}
1432
1433template<class _Fp, class _Alloc, class _Rp, class _A0>
1434void
1435__func<_Fp, _Alloc, _Rp(_A0)>::__clone(__base<_Rp(_A0)>* __p) const
1436{
1437 ::new ((void*)__p) __func(__f_.first(), __f_.second());
1438}
1439
1440template<class _Fp, class _Alloc, class _Rp, class _A0>
1441void
1442__func<_Fp, _Alloc, _Rp(_A0)>::destroy()
1443{
1444 __f_.~__compressed_pair<_Fp, _Alloc>();
1445}
1446
1447template<class _Fp, class _Alloc, class _Rp, class _A0>
1448void
1449__func<_Fp, _Alloc, _Rp(_A0)>::destroy_deallocate()
1450{
1451 typedef allocator_traits<_Alloc> __alloc_traits;
1452 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
1453 _Ap __a(__f_.second());
1454 __f_.~__compressed_pair<_Fp, _Alloc>();
1455 __a.deallocate(this, 1);
1456}
1457
1458template<class _Fp, class _Alloc, class _Rp, class _A0>
1459_Rp
1460__func<_Fp, _Alloc, _Rp(_A0)>::operator()(_A0 __a0)
1461{
1462 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
1463 return _Invoker::__call(__f_.first(), __a0);
1464}
1465
1466#ifndef _LIBCPP_NO_RTTI
1467
1468template<class _Fp, class _Alloc, class _Rp, class _A0>
1469const void*
1470__func<_Fp, _Alloc, _Rp(_A0)>::target(const type_info& __ti) const
1471{
1472 if (__ti == typeid(_Fp))
1473 return &__f_.first();
1474 return (const void*)0;
1475}
1476
1477template<class _Fp, class _Alloc, class _Rp, class _A0>
1478const std::type_info&
1479__func<_Fp, _Alloc, _Rp(_A0)>::target_type() const
1480{
1481 return typeid(_Fp);
1482}
1483
1484#endif // _LIBCPP_NO_RTTI
1485
1486template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1>
1487class __func<_Fp, _Alloc, _Rp(_A0, _A1)>
1488 : public __base<_Rp(_A0, _A1)>
1489{
1490 __compressed_pair<_Fp, _Alloc> __f_;
1491public:
1492 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
explicit __func(_Fp __f) : __f_(_VSTDstd::__1::move(__f), __default_init_tag()) {}
1493 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
explicit __func(_Fp __f, _Alloc __a)
1494 : __f_(_VSTDstd::__1::move(__f), _VSTDstd::__1::move(__a)) {}
1495 virtual __base<_Rp(_A0, _A1)>* __clone() const;
1496 virtual void __clone(__base<_Rp(_A0, _A1)>*) const;
1497 virtual void destroy();
1498 virtual void destroy_deallocate();
1499 virtual _Rp operator()(_A0, _A1);
1500#ifndef _LIBCPP_NO_RTTI
1501 virtual const void* target(const type_info&) const;
1502 virtual const std::type_info& target_type() const;
1503#endif // _LIBCPP_NO_RTTI
1504};
1505
1506template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1>
1507__base<_Rp(_A0, _A1)>*
1508__func<_Fp, _Alloc, _Rp(_A0, _A1)>::__clone() const
1509{
1510 typedef allocator_traits<_Alloc> __alloc_traits;
1511 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
1512 _Ap __a(__f_.second());
1513 typedef __allocator_destructor<_Ap> _Dp;
1514 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1515 ::new ((void*)__hold.get()) __func(__f_.first(), _Alloc(__a));
1516 return __hold.release();
1517}
1518
1519template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1>
1520void
1521__func<_Fp, _Alloc, _Rp(_A0, _A1)>::__clone(__base<_Rp(_A0, _A1)>* __p) const
1522{
1523 ::new ((void*)__p) __func(__f_.first(), __f_.second());
1524}
1525
1526template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1>
1527void
1528__func<_Fp, _Alloc, _Rp(_A0, _A1)>::destroy()
1529{
1530 __f_.~__compressed_pair<_Fp, _Alloc>();
1531}
1532
1533template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1>
1534void
1535__func<_Fp, _Alloc, _Rp(_A0, _A1)>::destroy_deallocate()
1536{
1537 typedef allocator_traits<_Alloc> __alloc_traits;
1538 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
1539 _Ap __a(__f_.second());
1540 __f_.~__compressed_pair<_Fp, _Alloc>();
1541 __a.deallocate(this, 1);
1542}
1543
1544template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1>
1545_Rp
1546__func<_Fp, _Alloc, _Rp(_A0, _A1)>::operator()(_A0 __a0, _A1 __a1)
1547{
1548 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
1549 return _Invoker::__call(__f_.first(), __a0, __a1);
1550}
1551
1552#ifndef _LIBCPP_NO_RTTI
1553
1554template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1>
1555const void*
1556__func<_Fp, _Alloc, _Rp(_A0, _A1)>::target(const type_info& __ti) const
1557{
1558 if (__ti == typeid(_Fp))
1559 return &__f_.first();
1560 return (const void*)0;
1561}
1562
1563template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1>
1564const std::type_info&
1565__func<_Fp, _Alloc, _Rp(_A0, _A1)>::target_type() const
1566{
1567 return typeid(_Fp);
1568}
1569
1570#endif // _LIBCPP_NO_RTTI
1571
1572template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2>
1573class __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>
1574 : public __base<_Rp(_A0, _A1, _A2)>
1575{
1576 __compressed_pair<_Fp, _Alloc> __f_;
1577public:
1578 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
explicit __func(_Fp __f) : __f_(_VSTDstd::__1::move(__f), __default_init_tag()) {}
1579 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
explicit __func(_Fp __f, _Alloc __a)
1580 : __f_(_VSTDstd::__1::move(__f), _VSTDstd::__1::move(__a)) {}
1581 virtual __base<_Rp(_A0, _A1, _A2)>* __clone() const;
1582 virtual void __clone(__base<_Rp(_A0, _A1, _A2)>*) const;
1583 virtual void destroy();
1584 virtual void destroy_deallocate();
1585 virtual _Rp operator()(_A0, _A1, _A2);
1586#ifndef _LIBCPP_NO_RTTI
1587 virtual const void* target(const type_info&) const;
1588 virtual const std::type_info& target_type() const;
1589#endif // _LIBCPP_NO_RTTI
1590};
1591
1592template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2>
1593__base<_Rp(_A0, _A1, _A2)>*
1594__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::__clone() const
1595{
1596 typedef allocator_traits<_Alloc> __alloc_traits;
1597 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
1598 _Ap __a(__f_.second());
1599 typedef __allocator_destructor<_Ap> _Dp;
1600 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1601 ::new ((void*)__hold.get()) __func(__f_.first(), _Alloc(__a));
1602 return __hold.release();
1603}
1604
1605template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2>
1606void
1607__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::__clone(__base<_Rp(_A0, _A1, _A2)>* __p) const
1608{
1609 ::new ((void*)__p) __func(__f_.first(), __f_.second());
1610}
1611
1612template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2>
1613void
1614__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::destroy()
1615{
1616 __f_.~__compressed_pair<_Fp, _Alloc>();
1617}
1618
1619template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2>
1620void
1621__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::destroy_deallocate()
1622{
1623 typedef allocator_traits<_Alloc> __alloc_traits;
1624 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
1625 _Ap __a(__f_.second());
1626 __f_.~__compressed_pair<_Fp, _Alloc>();
1627 __a.deallocate(this, 1);
1628}
1629
1630template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2>
1631_Rp
1632__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::operator()(_A0 __a0, _A1 __a1, _A2 __a2)
1633{
1634 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
1635 return _Invoker::__call(__f_.first(), __a0, __a1, __a2);
1636}
1637
1638#ifndef _LIBCPP_NO_RTTI
1639
1640template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2>
1641const void*
1642__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::target(const type_info& __ti) const
1643{
1644 if (__ti == typeid(_Fp))
1645 return &__f_.first();
1646 return (const void*)0;
1647}
1648
1649template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2>
1650const std::type_info&
1651__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::target_type() const
1652{
1653 return typeid(_Fp);
1654}
1655
1656#endif // _LIBCPP_NO_RTTI
1657
1658} // __function
1659
1660template<class _Rp>
1661class _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) function<_Rp()>
1662{
1663 typedef __function::__base<_Rp()> __base;
1664 aligned_storage<3*sizeof(void*)>::type __buf_;
1665 __base* __f_;
1666
1667public:
1668 typedef _Rp result_type;
1669
1670 // 20.7.16.2.1, construct/copy/destroy:
1671 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
explicit function() : __f_(0) {}
1672 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
function(nullptr_t) : __f_(0) {}
1673 function(const function&);
1674 template<class _Fp>
1675 function(_Fp,
1676 typename enable_if<!is_integral<_Fp>::value>::type* = 0);
1677
1678 template<class _Alloc>
1679 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1680 function(allocator_arg_t, const _Alloc&) : __f_(0) {}
1681 template<class _Alloc>
1682 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1683 function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {}
1684 template<class _Alloc>
1685 function(allocator_arg_t, const _Alloc&, const function&);
1686 template<class _Fp, class _Alloc>
1687 function(allocator_arg_t, const _Alloc& __a, _Fp __f,
1688 typename enable_if<!is_integral<_Fp>::value>::type* = 0);
1689
1690 function& operator=(const function&);
1691 function& operator=(nullptr_t);
1692 template<class _Fp>
1693 typename enable_if
1694 <
1695 !is_integral<_Fp>::value,
1696 function&
1697 >::type
1698 operator=(_Fp);
1699
1700 ~function();
1701
1702 // 20.7.16.2.2, function modifiers:
1703 void swap(function&);
1704 template<class _Fp, class _Alloc>
1705 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1706 void assign(_Fp __f, const _Alloc& __a)
1707 {function(allocator_arg, __a, __f).swap(*this);}
1708
1709 // 20.7.16.2.3, function capacity:
1710 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
explicit operator bool() const {return __f_;}
1711
1712private:
1713 // deleted overloads close possible hole in the type system
1714 template<class _R2>
1715 bool operator==(const function<_R2()>&) const;// = delete;
1716 template<class _R2>
1717 bool operator!=(const function<_R2()>&) const;// = delete;
1718public:
1719 // 20.7.16.2.4, function invocation:
1720 _Rp operator()() const;
1721
1722#ifndef _LIBCPP_NO_RTTI
1723 // 20.7.16.2.5, function target access:
1724 const std::type_info& target_type() const;
1725 template <typename _Tp> _Tp* target();
1726 template <typename _Tp> const _Tp* target() const;
1727#endif // _LIBCPP_NO_RTTI
1728};
1729
1730template<class _Rp>
1731function<_Rp()>::function(const function& __f)
1732{
1733 if (__f.__f_ == 0)
1734 __f_ = 0;
1735 else if (__f.__f_ == (const __base*)&__f.__buf_)
1736 {
1737 __f_ = (__base*)&__buf_;
1738 __f.__f_->__clone(__f_);
1739 }
1740 else
1741 __f_ = __f.__f_->__clone();
1742}
1743
1744template<class _Rp>
1745template<class _Alloc>
1746function<_Rp()>::function(allocator_arg_t, const _Alloc&, const function& __f)
1747{
1748 if (__f.__f_ == 0)
1749 __f_ = 0;
1750 else if (__f.__f_ == (const __base*)&__f.__buf_)
1751 {
1752 __f_ = (__base*)&__buf_;
1753 __f.__f_->__clone(__f_);
1754 }
1755 else
1756 __f_ = __f.__f_->__clone();
1757}
1758
1759template<class _Rp>
1760template <class _Fp>
1761function<_Rp()>::function(_Fp __f,
1762 typename enable_if<!is_integral<_Fp>::value>::type*)
1763 : __f_(0)
1764{
1765 if (__function::__not_null(__f))
1766 {
1767 typedef __function::__func<_Fp, allocator<_Fp>, _Rp()> _FF;
1768 if (sizeof(_FF) <= sizeof(__buf_))
1769 {
1770 __f_ = (__base*)&__buf_;
1771 ::new ((void*)__f_) _FF(__f);
1772 }
1773 else
1774 {
1775 typedef allocator<_FF> _Ap;
1776 _Ap __a;
1777 typedef __allocator_destructor<_Ap> _Dp;
1778 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1779 ::new ((void*)__hold.get()) _FF(__f, allocator<_Fp>(__a));
1780 __f_ = __hold.release();
1781 }
1782 }
1783}
1784
1785template<class _Rp>
1786template <class _Fp, class _Alloc>
1787function<_Rp()>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f,
1788 typename enable_if<!is_integral<_Fp>::value>::type*)
1789 : __f_(0)
1790{
1791 typedef allocator_traits<_Alloc> __alloc_traits;
1792 if (__function::__not_null(__f))
1793 {
1794 typedef __function::__func<_Fp, _Alloc, _Rp()> _FF;
1795 if (sizeof(_FF) <= sizeof(__buf_))
1796 {
1797 __f_ = (__base*)&__buf_;
1798 ::new ((void*)__f_) _FF(__f, __a0);
1799 }
1800 else
1801 {
1802 typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap;
1803 _Ap __a(__a0);
1804 typedef __allocator_destructor<_Ap> _Dp;
1805 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1806 ::new ((void*)__hold.get()) _FF(__f, _Alloc(__a));
1807 __f_ = __hold.release();
1808 }
1809 }
1810}
1811
1812template<class _Rp>
1813function<_Rp()>&
1814function<_Rp()>::operator=(const function& __f)
1815{
1816 if (__f)
1817 function(__f).swap(*this);
1818 else
1819 *this = nullptr;
1820 return *this;
1821}
1822
1823template<class _Rp>
1824function<_Rp()>&
1825function<_Rp()>::operator=(nullptr_t)
1826{
1827 __base* __t = __f_;
1828 __f_ = 0;
1829 if (__t == (__base*)&__buf_)
1830 __t->destroy();
1831 else if (__t)
1832 __t->destroy_deallocate();
1833 return *this;
1834}
1835
1836template<class _Rp>
1837template <class _Fp>
1838typename enable_if
1839<
1840 !is_integral<_Fp>::value,
1841 function<_Rp()>&
1842>::type
1843function<_Rp()>::operator=(_Fp __f)
1844{
1845 function(_VSTDstd::__1::move(__f)).swap(*this);
1846 return *this;
1847}
1848
1849template<class _Rp>
1850function<_Rp()>::~function()
1851{
1852 if (__f_ == (__base*)&__buf_)
1853 __f_->destroy();
1854 else if (__f_)
1855 __f_->destroy_deallocate();
1856}
1857
1858template<class _Rp>
1859void
1860function<_Rp()>::swap(function& __f)
1861{
1862 if (_VSTDstd::__1::addressof(__f) == this)
1863 return;
1864 if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
1865 {
1866 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
1867 __base* __t = (__base*)&__tempbuf;
1868 __f_->__clone(__t);
1869 __f_->destroy();
1870 __f_ = 0;
1871 __f.__f_->__clone((__base*)&__buf_);
1872 __f.__f_->destroy();
1873 __f.__f_ = 0;
1874 __f_ = (__base*)&__buf_;
1875 __t->__clone((__base*)&__f.__buf_);
1876 __t->destroy();
1877 __f.__f_ = (__base*)&__f.__buf_;
1878 }
1879 else if (__f_ == (__base*)&__buf_)
1880 {
1881 __f_->__clone((__base*)&__f.__buf_);
1882 __f_->destroy();
1883 __f_ = __f.__f_;
1884 __f.__f_ = (__base*)&__f.__buf_;
1885 }
1886 else if (__f.__f_ == (__base*)&__f.__buf_)
1887 {
1888 __f.__f_->__clone((__base*)&__buf_);
1889 __f.__f_->destroy();
1890 __f.__f_ = __f_;
1891 __f_ = (__base*)&__buf_;
1892 }
1893 else
1894 _VSTDstd::__1::swap(__f_, __f.__f_);
1895}
1896
1897template<class _Rp>
1898_Rp
1899function<_Rp()>::operator()() const
1900{
1901 if (__f_ == 0)
1902 __throw_bad_function_call();
1903 return (*__f_)();
1904}
1905
1906#ifndef _LIBCPP_NO_RTTI
1907
1908template<class _Rp>
1909const std::type_info&
1910function<_Rp()>::target_type() const
1911{
1912 if (__f_ == 0)
1913 return typeid(void);
1914 return __f_->target_type();
1915}
1916
1917template<class _Rp>
1918template <typename _Tp>
1919_Tp*
1920function<_Rp()>::target()
1921{
1922 if (__f_ == 0)
1923 return (_Tp*)0;
1924 return (_Tp*) const_cast<void *>(__f_->target(typeid(_Tp)));
1925}
1926
1927template<class _Rp>
1928template <typename _Tp>
1929const _Tp*
1930function<_Rp()>::target() const
1931{
1932 if (__f_ == 0)
1933 return (const _Tp*)0;
1934 return (const _Tp*)__f_->target(typeid(_Tp));
1935}
1936
1937#endif // _LIBCPP_NO_RTTI
1938
1939template<class _Rp, class _A0>
1940class _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) function<_Rp(_A0)>
1941 : public unary_function<_A0, _Rp>
1942{
1943 typedef __function::__base<_Rp(_A0)> __base;
1944 aligned_storage<3*sizeof(void*)>::type __buf_;
1945 __base* __f_;
1946
1947public:
1948 typedef _Rp result_type;
1949
1950 // 20.7.16.2.1, construct/copy/destroy:
1951 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
explicit function() : __f_(0) {}
1952 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
function(nullptr_t) : __f_(0) {}
1953 function(const function&);
1954 template<class _Fp>
1955 function(_Fp,
1956 typename enable_if<!is_integral<_Fp>::value>::type* = 0);
1957
1958 template<class _Alloc>
1959 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1960 function(allocator_arg_t, const _Alloc&) : __f_(0) {}
1961 template<class _Alloc>
1962 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1963 function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {}
1964 template<class _Alloc>
1965 function(allocator_arg_t, const _Alloc&, const function&);
1966 template<class _Fp, class _Alloc>
1967 function(allocator_arg_t, const _Alloc& __a, _Fp __f,
1968 typename enable_if<!is_integral<_Fp>::value>::type* = 0);
1969
1970 function& operator=(const function&);
1971 function& operator=(nullptr_t);
1972 template<class _Fp>
1973 typename enable_if
1974 <
1975 !is_integral<_Fp>::value,
1976 function&
1977 >::type
1978 operator=(_Fp);
1979
1980 ~function();
1981
1982 // 20.7.16.2.2, function modifiers:
1983 void swap(function&);
1984 template<class _Fp, class _Alloc>
1985 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1986 void assign(_Fp __f, const _Alloc& __a)
1987 {function(allocator_arg, __a, __f).swap(*this);}
1988
1989 // 20.7.16.2.3, function capacity:
1990 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
explicit operator bool() const {return __f_;}
1991
1992private:
1993 // deleted overloads close possible hole in the type system
1994 template<class _R2, class _B0>
1995 bool operator==(const function<_R2(_B0)>&) const;// = delete;
1996 template<class _R2, class _B0>
1997 bool operator!=(const function<_R2(_B0)>&) const;// = delete;
1998public:
1999 // 20.7.16.2.4, function invocation:
2000 _Rp operator()(_A0) const;
2001
2002#ifndef _LIBCPP_NO_RTTI
2003 // 20.7.16.2.5, function target access:
2004 const std::type_info& target_type() const;
2005 template <typename _Tp> _Tp* target();
2006 template <typename _Tp> const _Tp* target() const;
2007#endif // _LIBCPP_NO_RTTI
2008};
2009
2010template<class _Rp, class _A0>
2011function<_Rp(_A0)>::function(const function& __f)
2012{
2013 if (__f.__f_ == 0)
2014 __f_ = 0;
2015 else if (__f.__f_ == (const __base*)&__f.__buf_)
2016 {
2017 __f_ = (__base*)&__buf_;
2018 __f.__f_->__clone(__f_);
2019 }
2020 else
2021 __f_ = __f.__f_->__clone();
2022}
2023
2024template<class _Rp, class _A0>
2025template<class _Alloc>
2026function<_Rp(_A0)>::function(allocator_arg_t, const _Alloc&, const function& __f)
2027{
2028 if (__f.__f_ == 0)
2029 __f_ = 0;
2030 else if (__f.__f_ == (const __base*)&__f.__buf_)
2031 {
2032 __f_ = (__base*)&__buf_;
2033 __f.__f_->__clone(__f_);
2034 }
2035 else
2036 __f_ = __f.__f_->__clone();
2037}
2038
2039template<class _Rp, class _A0>
2040template <class _Fp>
2041function<_Rp(_A0)>::function(_Fp __f,
2042 typename enable_if<!is_integral<_Fp>::value>::type*)
2043 : __f_(0)
2044{
2045 if (__function::__not_null(__f))
2046 {
2047 typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0)> _FF;
2048 if (sizeof(_FF) <= sizeof(__buf_))
2049 {
2050 __f_ = (__base*)&__buf_;
2051 ::new ((void*)__f_) _FF(__f);
2052 }
2053 else
2054 {
2055 typedef allocator<_FF> _Ap;
2056 _Ap __a;
2057 typedef __allocator_destructor<_Ap> _Dp;
2058 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
2059 ::new ((void*)__hold.get()) _FF(__f, allocator<_Fp>(__a));
2060 __f_ = __hold.release();
2061 }
2062 }
2063}
2064
2065template<class _Rp, class _A0>
2066template <class _Fp, class _Alloc>
2067function<_Rp(_A0)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f,
2068 typename enable_if<!is_integral<_Fp>::value>::type*)
2069 : __f_(0)
2070{
2071 typedef allocator_traits<_Alloc> __alloc_traits;
2072 if (__function::__not_null(__f))
2073 {
2074 typedef __function::__func<_Fp, _Alloc, _Rp(_A0)> _FF;
2075 if (sizeof(_FF) <= sizeof(__buf_))
2076 {
2077 __f_ = (__base*)&__buf_;
2078 ::new ((void*)__f_) _FF(__f, __a0);
2079 }
2080 else
2081 {
2082 typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap;
2083 _Ap __a(__a0);
2084 typedef __allocator_destructor<_Ap> _Dp;
2085 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
2086 ::new ((void*)__hold.get()) _FF(__f, _Alloc(__a));
2087 __f_ = __hold.release();
2088 }
2089 }
2090}
2091
2092template<class _Rp, class _A0>
2093function<_Rp(_A0)>&
2094function<_Rp(_A0)>::operator=(const function& __f)
2095{
2096 if (__f)
2097 function(__f).swap(*this);
2098 else
2099 *this = nullptr;
2100 return *this;
2101}
2102
2103template<class _Rp, class _A0>
2104function<_Rp(_A0)>&
2105function<_Rp(_A0)>::operator=(nullptr_t)
2106{
2107 __base* __t = __f_;
2108 __f_ = 0;
2109 if (__t == (__base*)&__buf_)
2110 __t->destroy();
2111 else if (__t)
2112 __t->destroy_deallocate();
2113 return *this;
2114}
2115
2116template<class _Rp, class _A0>
2117template <class _Fp>
2118typename enable_if
2119<
2120 !is_integral<_Fp>::value,
2121 function<_Rp(_A0)>&
2122>::type
2123function<_Rp(_A0)>::operator=(_Fp __f)
2124{
2125 function(_VSTDstd::__1::move(__f)).swap(*this);
2126 return *this;
2127}
2128
2129template<class _Rp, class _A0>
2130function<_Rp(_A0)>::~function()
2131{
2132 if (__f_ == (__base*)&__buf_)
2133 __f_->destroy();
2134 else if (__f_)
2135 __f_->destroy_deallocate();
2136}
2137
2138template<class _Rp, class _A0>
2139void
2140function<_Rp(_A0)>::swap(function& __f)
2141{
2142 if (_VSTDstd::__1::addressof(__f) == this)
2143 return;
2144 if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
2145 {
2146 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
2147 __base* __t = (__base*)&__tempbuf;
2148 __f_->__clone(__t);
2149 __f_->destroy();
2150 __f_ = 0;
2151 __f.__f_->__clone((__base*)&__buf_);
2152 __f.__f_->destroy();
2153 __f.__f_ = 0;
2154 __f_ = (__base*)&__buf_;
2155 __t->__clone((__base*)&__f.__buf_);
2156 __t->destroy();
2157 __f.__f_ = (__base*)&__f.__buf_;
2158 }
2159 else if (__f_ == (__base*)&__buf_)
2160 {
2161 __f_->__clone((__base*)&__f.__buf_);
2162 __f_->destroy();
2163 __f_ = __f.__f_;
2164 __f.__f_ = (__base*)&__f.__buf_;
2165 }
2166 else if (__f.__f_ == (__base*)&__f.__buf_)
2167 {
2168 __f.__f_->__clone((__base*)&__buf_);
2169 __f.__f_->destroy();
2170 __f.__f_ = __f_;
2171 __f_ = (__base*)&__buf_;
2172 }
2173 else
2174 _VSTDstd::__1::swap(__f_, __f.__f_);
2175}
2176
2177template<class _Rp, class _A0>
2178_Rp
2179function<_Rp(_A0)>::operator()(_A0 __a0) const
2180{
2181 if (__f_ == 0)
2182 __throw_bad_function_call();
2183 return (*__f_)(__a0);
2184}
2185
2186#ifndef _LIBCPP_NO_RTTI
2187
2188template<class _Rp, class _A0>
2189const std::type_info&
2190function<_Rp(_A0)>::target_type() const
2191{
2192 if (__f_ == 0)
2193 return typeid(void);
2194 return __f_->target_type();
2195}
2196
2197template<class _Rp, class _A0>
2198template <typename _Tp>
2199_Tp*
2200function<_Rp(_A0)>::target()
2201{
2202 if (__f_ == 0)
2203 return (_Tp*)0;
2204 return (_Tp*) const_cast<void *>(__f_->target(typeid(_Tp)));
2205}
2206
2207template<class _Rp, class _A0>
2208template <typename _Tp>
2209const _Tp*
2210function<_Rp(_A0)>::target() const
2211{
2212 if (__f_ == 0)
2213 return (const _Tp*)0;
2214 return (const _Tp*)__f_->target(typeid(_Tp));
2215}
2216
2217#endif // _LIBCPP_NO_RTTI
2218
2219template<class _Rp, class _A0, class _A1>
2220class _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) function<_Rp(_A0, _A1)>
2221 : public binary_function<_A0, _A1, _Rp>
2222{
2223 typedef __function::__base<_Rp(_A0, _A1)> __base;
2224 aligned_storage<3*sizeof(void*)>::type __buf_;
2225 __base* __f_;
2226
2227public:
2228 typedef _Rp result_type;
2229
2230 // 20.7.16.2.1, construct/copy/destroy:
2231 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
explicit function() : __f_(0) {}
2232 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
function(nullptr_t) : __f_(0) {}
2233 function(const function&);
2234 template<class _Fp>
2235 function(_Fp,
2236 typename enable_if<!is_integral<_Fp>::value>::type* = 0);
2237
2238 template<class _Alloc>
2239 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
2240 function(allocator_arg_t, const _Alloc&) : __f_(0) {}
2241 template<class _Alloc>
2242 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
2243 function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {}
2244 template<class _Alloc>
2245 function(allocator_arg_t, const _Alloc&, const function&);
2246 template<class _Fp, class _Alloc>
2247 function(allocator_arg_t, const _Alloc& __a, _Fp __f,
2248 typename enable_if<!is_integral<_Fp>::value>::type* = 0);
2249
2250 function& operator=(const function&);
2251 function& operator=(nullptr_t);
2252 template<class _Fp>
2253 typename enable_if
2254 <
2255 !is_integral<_Fp>::value,
2256 function&
2257 >::type
2258 operator=(_Fp);
2259
2260 ~function();
2261
2262 // 20.7.16.2.2, function modifiers:
2263 void swap(function&);
2264 template<class _Fp, class _Alloc>
2265 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
2266 void assign(_Fp __f, const _Alloc& __a)
2267 {function(allocator_arg, __a, __f).swap(*this);}
2268
2269 // 20.7.16.2.3, function capacity:
2270 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
explicit operator bool() const {return __f_;}
2271
2272private:
2273 // deleted overloads close possible hole in the type system
2274 template<class _R2, class _B0, class _B1>
2275 bool operator==(const function<_R2(_B0, _B1)>&) const;// = delete;
2276 template<class _R2, class _B0, class _B1>
2277 bool operator!=(const function<_R2(_B0, _B1)>&) const;// = delete;
2278public:
2279 // 20.7.16.2.4, function invocation:
2280 _Rp operator()(_A0, _A1) const;
2281
2282#ifndef _LIBCPP_NO_RTTI
2283 // 20.7.16.2.5, function target access:
2284 const std::type_info& target_type() const;
2285 template <typename _Tp> _Tp* target();
2286 template <typename _Tp> const _Tp* target() const;
2287#endif // _LIBCPP_NO_RTTI
2288};
2289
2290template<class _Rp, class _A0, class _A1>
2291function<_Rp(_A0, _A1)>::function(const function& __f)
2292{
2293 if (__f.__f_ == 0)
2294 __f_ = 0;
2295 else if (__f.__f_ == (const __base*)&__f.__buf_)
2296 {
2297 __f_ = (__base*)&__buf_;
2298 __f.__f_->__clone(__f_);
2299 }
2300 else
2301 __f_ = __f.__f_->__clone();
2302}
2303
2304template<class _Rp, class _A0, class _A1>
2305template<class _Alloc>
2306function<_Rp(_A0, _A1)>::function(allocator_arg_t, const _Alloc&, const function& __f)
2307{
2308 if (__f.__f_ == 0)
2309 __f_ = 0;
2310 else if (__f.__f_ == (const __base*)&__f.__buf_)
2311 {
2312 __f_ = (__base*)&__buf_;
2313 __f.__f_->__clone(__f_);
2314 }
2315 else
2316 __f_ = __f.__f_->__clone();
2317}
2318
2319template<class _Rp, class _A0, class _A1>
2320template <class _Fp>
2321function<_Rp(_A0, _A1)>::function(_Fp __f,
2322 typename enable_if<!is_integral<_Fp>::value>::type*)
2323 : __f_(0)
2324{
2325 if (__function::__not_null(__f))
2326 {
2327 typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0, _A1)> _FF;
2328 if (sizeof(_FF) <= sizeof(__buf_))
2329 {
2330 __f_ = (__base*)&__buf_;
2331 ::new ((void*)__f_) _FF(__f);
2332 }
2333 else
2334 {
2335 typedef allocator<_FF> _Ap;
2336 _Ap __a;
2337 typedef __allocator_destructor<_Ap> _Dp;
2338 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
2339 ::new ((void*)__hold.get()) _FF(__f, allocator<_Fp>(__a));
2340 __f_ = __hold.release();
2341 }
2342 }
2343}
2344
2345template<class _Rp, class _A0, class _A1>
2346template <class _Fp, class _Alloc>
2347function<_Rp(_A0, _A1)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f,
2348 typename enable_if<!is_integral<_Fp>::value>::type*)
2349 : __f_(0)
2350{
2351 typedef allocator_traits<_Alloc> __alloc_traits;
2352 if (__function::__not_null(__f))
2353 {
2354 typedef __function::__func<_Fp, _Alloc, _Rp(_A0, _A1)> _FF;
2355 if (sizeof(_FF) <= sizeof(__buf_))
2356 {
2357 __f_ = (__base*)&__buf_;
2358 ::new ((void*)__f_) _FF(__f, __a0);
2359 }
2360 else
2361 {
2362 typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap;
2363 _Ap __a(__a0);
2364 typedef __allocator_destructor<_Ap> _Dp;
2365 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
2366 ::new ((void*)__hold.get()) _FF(__f, _Alloc(__a));
2367 __f_ = __hold.release();
2368 }
2369 }
2370}
2371
2372template<class _Rp, class _A0, class _A1>
2373function<_Rp(_A0, _A1)>&
2374function<_Rp(_A0, _A1)>::operator=(const function& __f)
2375{
2376 if (__f)
2377 function(__f).swap(*this);
2378 else
2379 *this = nullptr;
2380 return *this;
2381}
2382
2383template<class _Rp, class _A0, class _A1>
2384function<_Rp(_A0, _A1)>&
2385function<_Rp(_A0, _A1)>::operator=(nullptr_t)
2386{
2387 __base* __t = __f_;
2388 __f_ = 0;
2389 if (__t == (__base*)&__buf_)
2390 __t->destroy();
2391 else if (__t)
2392 __t->destroy_deallocate();
2393 return *this;
2394}
2395
2396template<class _Rp, class _A0, class _A1>
2397template <class _Fp>
2398typename enable_if
2399<
2400 !is_integral<_Fp>::value,
2401 function<_Rp(_A0, _A1)>&
2402>::type
2403function<_Rp(_A0, _A1)>::operator=(_Fp __f)
2404{
2405 function(_VSTDstd::__1::move(__f)).swap(*this);
2406 return *this;
2407}
2408
2409template<class _Rp, class _A0, class _A1>
2410function<_Rp(_A0, _A1)>::~function()
2411{
2412 if (__f_ == (__base*)&__buf_)
2413 __f_->destroy();
2414 else if (__f_)
2415 __f_->destroy_deallocate();
2416}
2417
2418template<class _Rp, class _A0, class _A1>
2419void
2420function<_Rp(_A0, _A1)>::swap(function& __f)
2421{
2422 if (_VSTDstd::__1::addressof(__f) == this)
2423 return;
2424 if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
2425 {
2426 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
2427 __base* __t = (__base*)&__tempbuf;
2428 __f_->__clone(__t);
2429 __f_->destroy();
2430 __f_ = 0;
2431 __f.__f_->__clone((__base*)&__buf_);
2432 __f.__f_->destroy();
2433 __f.__f_ = 0;
2434 __f_ = (__base*)&__buf_;
2435 __t->__clone((__base*)&__f.__buf_);
2436 __t->destroy();
2437 __f.__f_ = (__base*)&__f.__buf_;
2438 }
2439 else if (__f_ == (__base*)&__buf_)
2440 {
2441 __f_->__clone((__base*)&__f.__buf_);
2442 __f_->destroy();
2443 __f_ = __f.__f_;
2444 __f.__f_ = (__base*)&__f.__buf_;
2445 }
2446 else if (__f.__f_ == (__base*)&__f.__buf_)
2447 {
2448 __f.__f_->__clone((__base*)&__buf_);
2449 __f.__f_->destroy();
2450 __f.__f_ = __f_;
2451 __f_ = (__base*)&__buf_;
2452 }
2453 else
2454 _VSTDstd::__1::swap(__f_, __f.__f_);
2455}
2456
2457template<class _Rp, class _A0, class _A1>
2458_Rp
2459function<_Rp(_A0, _A1)>::operator()(_A0 __a0, _A1 __a1) const
2460{
2461 if (__f_ == 0)
2462 __throw_bad_function_call();
2463 return (*__f_)(__a0, __a1);
2464}
2465
2466#ifndef _LIBCPP_NO_RTTI
2467
2468template<class _Rp, class _A0, class _A1>
2469const std::type_info&
2470function<_Rp(_A0, _A1)>::target_type() const
2471{
2472 if (__f_ == 0)
2473 return typeid(void);
2474 return __f_->target_type();
2475}
2476
2477template<class _Rp, class _A0, class _A1>
2478template <typename _Tp>
2479_Tp*
2480function<_Rp(_A0, _A1)>::target()
2481{
2482 if (__f_ == 0)
2483 return (_Tp*)0;
2484 return (_Tp*) const_cast<void *>(__f_->target(typeid(_Tp)));
2485}
2486
2487template<class _Rp, class _A0, class _A1>
2488template <typename _Tp>
2489const _Tp*
2490function<_Rp(_A0, _A1)>::target() const
2491{
2492 if (__f_ == 0)
2493 return (const _Tp*)0;
2494 return (const _Tp*)__f_->target(typeid(_Tp));
2495}
2496
2497#endif // _LIBCPP_NO_RTTI
2498
2499template<class _Rp, class _A0, class _A1, class _A2>
2500class _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) function<_Rp(_A0, _A1, _A2)>
2501{
2502 typedef __function::__base<_Rp(_A0, _A1, _A2)> __base;
2503 aligned_storage<3*sizeof(void*)>::type __buf_;
2504 __base* __f_;
2505
2506public:
2507 typedef _Rp result_type;
2508
2509 // 20.7.16.2.1, construct/copy/destroy:
2510 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
explicit function() : __f_(0) {}
2511 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
function(nullptr_t) : __f_(0) {}
2512 function(const function&);
2513 template<class _Fp>
2514 function(_Fp,
2515 typename enable_if<!is_integral<_Fp>::value>::type* = 0);
2516
2517 template<class _Alloc>
2518 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
2519 function(allocator_arg_t, const _Alloc&) : __f_(0) {}
2520 template<class _Alloc>
2521 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
2522 function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {}
2523 template<class _Alloc>
2524 function(allocator_arg_t, const _Alloc&, const function&);
2525 template<class _Fp, class _Alloc>
2526 function(allocator_arg_t, const _Alloc& __a, _Fp __f,
2527 typename enable_if<!is_integral<_Fp>::value>::type* = 0);
2528
2529 function& operator=(const function&);
2530 function& operator=(nullptr_t);
2531 template<class _Fp>
2532 typename enable_if
2533 <
2534 !is_integral<_Fp>::value,
2535 function&
2536 >::type
2537 operator=(_Fp);
2538
2539 ~function();
2540
2541 // 20.7.16.2.2, function modifiers:
2542 void swap(function&);
2543 template<class _Fp, class _Alloc>
2544 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
2545 void assign(_Fp __f, const _Alloc& __a)
2546 {function(allocator_arg, __a, __f).swap(*this);}
2547
2548 // 20.7.16.2.3, function capacity:
2549 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
explicit operator bool() const {return __f_;}
2550
2551private:
2552 // deleted overloads close possible hole in the type system
2553 template<class _R2, class _B0, class _B1, class _B2>
2554 bool operator==(const function<_R2(_B0, _B1, _B2)>&) const;// = delete;
2555 template<class _R2, class _B0, class _B1, class _B2>
2556 bool operator!=(const function<_R2(_B0, _B1, _B2)>&) const;// = delete;
2557public:
2558 // 20.7.16.2.4, function invocation:
2559 _Rp operator()(_A0, _A1, _A2) const;
2560
2561#ifndef _LIBCPP_NO_RTTI
2562 // 20.7.16.2.5, function target access:
2563 const std::type_info& target_type() const;
2564 template <typename _Tp> _Tp* target();
2565 template <typename _Tp> const _Tp* target() const;
2566#endif // _LIBCPP_NO_RTTI
2567};
2568
2569template<class _Rp, class _A0, class _A1, class _A2>
2570function<_Rp(_A0, _A1, _A2)>::function(const function& __f)
2571{
2572 if (__f.__f_ == 0)
2573 __f_ = 0;
2574 else if (__f.__f_ == (const __base*)&__f.__buf_)
2575 {
2576 __f_ = (__base*)&__buf_;
2577 __f.__f_->__clone(__f_);
2578 }
2579 else
2580 __f_ = __f.__f_->__clone();
2581}
2582
2583template<class _Rp, class _A0, class _A1, class _A2>
2584template<class _Alloc>
2585function<_Rp(_A0, _A1, _A2)>::function(allocator_arg_t, const _Alloc&,
2586 const function& __f)
2587{
2588 if (__f.__f_ == 0)
2589 __f_ = 0;
2590 else if (__f.__f_ == (const __base*)&__f.__buf_)
2591 {
2592 __f_ = (__base*)&__buf_;
2593 __f.__f_->__clone(__f_);
2594 }
2595 else
2596 __f_ = __f.__f_->__clone();
2597}
2598
2599template<class _Rp, class _A0, class _A1, class _A2>
2600template <class _Fp>
2601function<_Rp(_A0, _A1, _A2)>::function(_Fp __f,
2602 typename enable_if<!is_integral<_Fp>::value>::type*)
2603 : __f_(0)
2604{
2605 if (__function::__not_null(__f))
2606 {
2607 typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0, _A1, _A2)> _FF;
2608 if (sizeof(_FF) <= sizeof(__buf_))
2609 {
2610 __f_ = (__base*)&__buf_;
2611 ::new ((void*)__f_) _FF(__f);
2612 }
2613 else
2614 {
2615 typedef allocator<_FF> _Ap;
2616 _Ap __a;
2617 typedef __allocator_destructor<_Ap> _Dp;
2618 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
2619 ::new ((void*)__hold.get()) _FF(__f, allocator<_Fp>(__a));
2620 __f_ = __hold.release();
2621 }
2622 }
2623}
2624
2625template<class _Rp, class _A0, class _A1, class _A2>
2626template <class _Fp, class _Alloc>
2627function<_Rp(_A0, _A1, _A2)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f,
2628 typename enable_if<!is_integral<_Fp>::value>::type*)
2629 : __f_(0)
2630{
2631 typedef allocator_traits<_Alloc> __alloc_traits;
2632 if (__function::__not_null(__f))
2633 {
2634 typedef __function::__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)> _FF;
2635 if (sizeof(_FF) <= sizeof(__buf_))
2636 {
2637 __f_ = (__base*)&__buf_;
2638 ::new ((void*)__f_) _FF(__f, __a0);
2639 }
2640 else
2641 {
2642 typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap;
2643 _Ap __a(__a0);
2644 typedef __allocator_destructor<_Ap> _Dp;
2645 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
2646 ::new ((void*)__hold.get()) _FF(__f, _Alloc(__a));
2647 __f_ = __hold.release();
2648 }
2649 }
2650}
2651
2652template<class _Rp, class _A0, class _A1, class _A2>
2653function<_Rp(_A0, _A1, _A2)>&
2654function<_Rp(_A0, _A1, _A2)>::operator=(const function& __f)
2655{
2656 if (__f)
2657 function(__f).swap(*this);
2658 else
2659 *this = nullptr;
2660 return *this;
2661}
2662
2663template<class _Rp, class _A0, class _A1, class _A2>
2664function<_Rp(_A0, _A1, _A2)>&
2665function<_Rp(_A0, _A1, _A2)>::operator=(nullptr_t)
2666{
2667 __base* __t = __f_;
2668 __f_ = 0;
2669 if (__t == (__base*)&__buf_)
2670 __t->destroy();
2671 else if (__t)
2672 __t->destroy_deallocate();
2673 return *this;
2674}
2675
2676template<class _Rp, class _A0, class _A1, class _A2>
2677template <class _Fp>
2678typename enable_if
2679<
2680 !is_integral<_Fp>::value,
2681 function<_Rp(_A0, _A1, _A2)>&
2682>::type
2683function<_Rp(_A0, _A1, _A2)>::operator=(_Fp __f)
2684{
2685 function(_VSTDstd::__1::move(__f)).swap(*this);
2686 return *this;
2687}
2688
2689template<class _Rp, class _A0, class _A1, class _A2>
2690function<_Rp(_A0, _A1, _A2)>::~function()
2691{
2692 if (__f_ == (__base*)&__buf_)
2693 __f_->destroy();
2694 else if (__f_)
2695 __f_->destroy_deallocate();
2696}
2697
2698template<class _Rp, class _A0, class _A1, class _A2>
2699void
2700function<_Rp(_A0, _A1, _A2)>::swap(function& __f)
2701{
2702 if (_VSTDstd::__1::addressof(__f) == this)
2703 return;
2704 if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
2705 {
2706 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
2707 __base* __t = (__base*)&__tempbuf;
2708 __f_->__clone(__t);
2709 __f_->destroy();
2710 __f_ = 0;
2711 __f.__f_->__clone((__base*)&__buf_);
2712 __f.__f_->destroy();
2713 __f.__f_ = 0;
2714 __f_ = (__base*)&__buf_;
2715 __t->__clone((__base*)&__f.__buf_);
2716 __t->destroy();
2717 __f.__f_ = (__base*)&__f.__buf_;
2718 }
2719 else if (__f_ == (__base*)&__buf_)
2720 {
2721 __f_->__clone((__base*)&__f.__buf_);
2722 __f_->destroy();
2723 __f_ = __f.__f_;
2724 __f.__f_ = (__base*)&__f.__buf_;
2725 }
2726 else if (__f.__f_ == (__base*)&__f.__buf_)
2727 {
2728 __f.__f_->__clone((__base*)&__buf_);
2729 __f.__f_->destroy();
2730 __f.__f_ = __f_;
2731 __f_ = (__base*)&__buf_;
2732 }
2733 else
2734 _VSTDstd::__1::swap(__f_, __f.__f_);
2735}
2736
2737template<class _Rp, class _A0, class _A1, class _A2>
2738_Rp
2739function<_Rp(_A0, _A1, _A2)>::operator()(_A0 __a0, _A1 __a1, _A2 __a2) const
2740{
2741 if (__f_ == 0)
2742 __throw_bad_function_call();
2743 return (*__f_)(__a0, __a1, __a2);
2744}
2745
2746#ifndef _LIBCPP_NO_RTTI
2747
2748template<class _Rp, class _A0, class _A1, class _A2>
2749const std::type_info&
2750function<_Rp(_A0, _A1, _A2)>::target_type() const
2751{
2752 if (__f_ == 0)
2753 return typeid(void);
2754 return __f_->target_type();
2755}
2756
2757template<class _Rp, class _A0, class _A1, class _A2>
2758template <typename _Tp>
2759_Tp*
2760function<_Rp(_A0, _A1, _A2)>::target()
2761{
2762 if (__f_ == 0)
2763 return (_Tp*)0;
2764 return (_Tp*) const_cast<void *>(__f_->target(typeid(_Tp)));
2765}
2766
2767template<class _Rp, class _A0, class _A1, class _A2>
2768template <typename _Tp>
2769const _Tp*
2770function<_Rp(_A0, _A1, _A2)>::target() const
2771{
2772 if (__f_ == 0)
2773 return (const _Tp*)0;
2774 return (const _Tp*)__f_->target(typeid(_Tp));
2775}
2776
2777#endif // _LIBCPP_NO_RTTI
2778
2779template <class _Fp>
2780inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
2781bool
2782operator==(const function<_Fp>& __f, nullptr_t) {return !__f;}
2783
2784template <class _Fp>
2785inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
2786bool
2787operator==(nullptr_t, const function<_Fp>& __f) {return !__f;}
2788
2789template <class _Fp>
2790inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
2791bool
2792operator!=(const function<_Fp>& __f, nullptr_t) {return (bool)__f;}
2793
2794template <class _Fp>
2795inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
2796bool
2797operator!=(nullptr_t, const function<_Fp>& __f) {return (bool)__f;}
2798
2799template <class _Fp>
2800inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
2801void
2802swap(function<_Fp>& __x, function<_Fp>& __y)
2803{return __x.swap(__y);}
2804
2805#endif
2806
2807_LIBCPP_END_NAMESPACE_STD} }
2808
2809#endif // _LIBCPP___FUNCTIONAL_FUNCTION_H

/usr/include/c++/v1/__functional/invoke.h

1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP___FUNCTIONAL_INVOKE_H
11#define _LIBCPP___FUNCTIONAL_INVOKE_H
12
13#include <__config>
14#include <__functional/weak_result_type.h>
15#include <__utility/forward.h>
16#include <type_traits>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19#pragma GCC system_header
20#endif
21
22_LIBCPP_BEGIN_NAMESPACE_STDnamespace std { inline namespace __1 {
23
24template <class _Ret, bool = is_void<_Ret>::value>
25struct __invoke_void_return_wrapper
26{
27#ifndef _LIBCPP_CXX03_LANG
28 template <class ..._Args>
29 static _Ret __call(_Args&&... __args) {
30 return _VSTDstd::__1::__invoke(_VSTDstd::__1::forward<_Args>(__args)...);
9
Calling '__invoke<(lambda at /usr/src/gnu/usr.bin/clang/liblldbPluginPlatform/../../../llvm/lldb/source/Plugins/Platform/Android/AdbClient.cpp:548:25) &, >'
31 }
32#else
33 template <class _Fn>
34 static _Ret __call(_Fn __f) {
35 return _VSTDstd::__1::__invoke(__f);
36 }
37
38 template <class _Fn, class _A0>
39 static _Ret __call(_Fn __f, _A0& __a0) {
40 return _VSTDstd::__1::__invoke(__f, __a0);
41 }
42
43 template <class _Fn, class _A0, class _A1>
44 static _Ret __call(_Fn __f, _A0& __a0, _A1& __a1) {
45 return _VSTDstd::__1::__invoke(__f, __a0, __a1);
46 }
47
48 template <class _Fn, class _A0, class _A1, class _A2>
49 static _Ret __call(_Fn __f, _A0& __a0, _A1& __a1, _A2& __a2){
50 return _VSTDstd::__1::__invoke(__f, __a0, __a1, __a2);
51 }
52#endif
53};
54
55template <class _Ret>
56struct __invoke_void_return_wrapper<_Ret, true>
57{
58#ifndef _LIBCPP_CXX03_LANG
59 template <class ..._Args>
60 static void __call(_Args&&... __args) {
61 _VSTDstd::__1::__invoke(_VSTDstd::__1::forward<_Args>(__args)...);
62 }
63#else
64 template <class _Fn>
65 static void __call(_Fn __f) {
66 _VSTDstd::__1::__invoke(__f);
67 }
68
69 template <class _Fn, class _A0>
70 static void __call(_Fn __f, _A0& __a0) {
71 _VSTDstd::__1::__invoke(__f, __a0);
72 }
73
74 template <class _Fn, class _A0, class _A1>
75 static void __call(_Fn __f, _A0& __a0, _A1& __a1) {
76 _VSTDstd::__1::__invoke(__f, __a0, __a1);
77 }
78
79 template <class _Fn, class _A0, class _A1, class _A2>
80 static void __call(_Fn __f, _A0& __a0, _A1& __a1, _A2& __a2) {
81 _VSTDstd::__1::__invoke(__f, __a0, __a1, __a2);
82 }
83#endif
84};
85
86#if _LIBCPP_STD_VER14 > 14
87
88template <class _Fn, class ..._Args>
89_LIBCPP_CONSTEXPR_AFTER_CXX17 invoke_result_t<_Fn, _Args...>
90invoke(_Fn&& __f, _Args&&... __args)
91 noexcept(is_nothrow_invocable_v<_Fn, _Args...>)
92{
93 return _VSTDstd::__1::__invoke(_VSTDstd::__1::forward<_Fn>(__f), _VSTDstd::__1::forward<_Args>(__args)...);
94}
95
96#endif // _LIBCPP_STD_VER > 14
97
98_LIBCPP_END_NAMESPACE_STD} }
99
100#endif // _LIBCPP___FUNCTIONAL_INVOKE_H

/usr/include/c++/v1/type_traits

1// -*- C++ -*-
2//===------------------------ type_traits ---------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_TYPE_TRAITS
11#define _LIBCPP_TYPE_TRAITS
12
13/*
14 type_traits synopsis
15
16namespace std
17{
18
19 // helper class:
20 template <class T, T v> struct integral_constant;
21 typedef integral_constant<bool, true> true_type; // C++11
22 typedef integral_constant<bool, false> false_type; // C++11
23
24 template <bool B> // C++14
25 using bool_constant = integral_constant<bool, B>; // C++14
26 typedef bool_constant<true> true_type; // C++14
27 typedef bool_constant<false> false_type; // C++14
28
29 // helper traits
30 template <bool, class T = void> struct enable_if;
31 template <bool, class T, class F> struct conditional;
32
33 // Primary classification traits:
34 template <class T> struct is_void;
35 template <class T> struct is_null_pointer; // C++14
36 template <class T> struct is_integral;
37 template <class T> struct is_floating_point;
38 template <class T> struct is_array;
39 template <class T> struct is_pointer;
40 template <class T> struct is_lvalue_reference;
41 template <class T> struct is_rvalue_reference;
42 template <class T> struct is_member_object_pointer;
43 template <class T> struct is_member_function_pointer;
44 template <class T> struct is_enum;
45 template <class T> struct is_union;
46 template <class T> struct is_class;
47 template <class T> struct is_function;
48
49 // Secondary classification traits:
50 template <class T> struct is_reference;
51 template <class T> struct is_arithmetic;
52 template <class T> struct is_fundamental;
53 template <class T> struct is_member_pointer;
54 template <class T> struct is_scoped_enum; // C++2b
55 template <class T> struct is_scalar;
56 template <class T> struct is_object;
57 template <class T> struct is_compound;
58
59 // Const-volatile properties and transformations:
60 template <class T> struct is_const;
61 template <class T> struct is_volatile;
62 template <class T> struct remove_const;
63 template <class T> struct remove_volatile;
64 template <class T> struct remove_cv;
65 template <class T> struct add_const;
66 template <class T> struct add_volatile;
67 template <class T> struct add_cv;
68
69 // Reference transformations:
70 template <class T> struct remove_reference;
71 template <class T> struct add_lvalue_reference;
72 template <class T> struct add_rvalue_reference;
73
74 // Pointer transformations:
75 template <class T> struct remove_pointer;
76 template <class T> struct add_pointer;
77
78 template<class T> struct type_identity; // C++20
79 template<class T>
80 using type_identity_t = typename type_identity<T>::type; // C++20
81
82 // Integral properties:
83 template <class T> struct is_signed;
84 template <class T> struct is_unsigned;
85 template <class T> struct make_signed;
86 template <class T> struct make_unsigned;
87
88 // Array properties and transformations:
89 template <class T> struct rank;
90 template <class T, unsigned I = 0> struct extent;
91 template <class T> struct remove_extent;
92 template <class T> struct remove_all_extents;
93
94 template <class T> struct is_bounded_array; // C++20
95 template <class T> struct is_unbounded_array; // C++20
96
97 // Member introspection:
98 template <class T> struct is_pod;
99 template <class T> struct is_trivial;
100 template <class T> struct is_trivially_copyable;
101 template <class T> struct is_standard_layout;
102 template <class T> struct is_literal_type; // Deprecated in C++17; removed in C++20
103 template <class T> struct is_empty;
104 template <class T> struct is_polymorphic;
105 template <class T> struct is_abstract;
106 template <class T> struct is_final; // C++14
107 template <class T> struct is_aggregate; // C++17
108
109 template <class T, class... Args> struct is_constructible;
110 template <class T> struct is_default_constructible;
111 template <class T> struct is_copy_constructible;
112 template <class T> struct is_move_constructible;
113 template <class T, class U> struct is_assignable;
114 template <class T> struct is_copy_assignable;
115 template <class T> struct is_move_assignable;
116 template <class T, class U> struct is_swappable_with; // C++17
117 template <class T> struct is_swappable; // C++17
118 template <class T> struct is_destructible;
119
120 template <class T, class... Args> struct is_trivially_constructible;
121 template <class T> struct is_trivially_default_constructible;
122 template <class T> struct is_trivially_copy_constructible;
123 template <class T> struct is_trivially_move_constructible;
124 template <class T, class U> struct is_trivially_assignable;
125 template <class T> struct is_trivially_copy_assignable;
126 template <class T> struct is_trivially_move_assignable;
127 template <class T> struct is_trivially_destructible;
128
129 template <class T, class... Args> struct is_nothrow_constructible;
130 template <class T> struct is_nothrow_default_constructible;
131 template <class T> struct is_nothrow_copy_constructible;
132 template <class T> struct is_nothrow_move_constructible;
133 template <class T, class U> struct is_nothrow_assignable;
134 template <class T> struct is_nothrow_copy_assignable;
135 template <class T> struct is_nothrow_move_assignable;
136 template <class T, class U> struct is_nothrow_swappable_with; // C++17
137 template <class T> struct is_nothrow_swappable; // C++17
138 template <class T> struct is_nothrow_destructible;
139
140 template <class T> struct has_virtual_destructor;
141
142 template<class T> struct has_unique_object_representations; // C++17
143
144 // Relationships between types:
145 template <class T, class U> struct is_same;
146 template <class Base, class Derived> struct is_base_of;
147
148 template <class From, class To> struct is_convertible;
149 template <typename From, typename To> struct is_nothrow_convertible; // C++20
150 template <typename From, typename To> inline constexpr bool is_nothrow_convertible_v; // C++20
151
152 template <class Fn, class... ArgTypes> struct is_invocable;
153 template <class R, class Fn, class... ArgTypes> struct is_invocable_r;
154
155 template <class Fn, class... ArgTypes> struct is_nothrow_invocable;
156 template <class R, class Fn, class... ArgTypes> struct is_nothrow_invocable_r;
157
158 // Alignment properties and transformations:
159 template <class T> struct alignment_of;
160 template <size_t Len, size_t Align = most_stringent_alignment_requirement>
161 struct aligned_storage;
162 template <size_t Len, class... Types> struct aligned_union;
163 template <class T> struct remove_cvref; // C++20
164
165 template <class T> struct decay;
166 template <class... T> struct common_type;
167 template <class T> struct underlying_type;
168 template <class> class result_of; // undefined; deprecated in C++17; removed in C++20
169 template <class Fn, class... ArgTypes> class result_of<Fn(ArgTypes...)>; // deprecated in C++17; removed in C++20
170 template <class Fn, class... ArgTypes> struct invoke_result; // C++17
171
172 // const-volatile modifications:
173 template <class T>
174 using remove_const_t = typename remove_const<T>::type; // C++14
175 template <class T>
176 using remove_volatile_t = typename remove_volatile<T>::type; // C++14
177 template <class T>
178 using remove_cv_t = typename remove_cv<T>::type; // C++14
179 template <class T>
180 using add_const_t = typename add_const<T>::type; // C++14
181 template <class T>
182 using add_volatile_t = typename add_volatile<T>::type; // C++14
183 template <class T>
184 using add_cv_t = typename add_cv<T>::type; // C++14
185
186 // reference modifications:
187 template <class T>
188 using remove_reference_t = typename remove_reference<T>::type; // C++14
189 template <class T>
190 using add_lvalue_reference_t = typename add_lvalue_reference<T>::type; // C++14
191 template <class T>
192 using add_rvalue_reference_t = typename add_rvalue_reference<T>::type; // C++14
193
194 // sign modifications:
195 template <class T>
196 using make_signed_t = typename make_signed<T>::type; // C++14
197 template <class T>
198 using make_unsigned_t = typename make_unsigned<T>::type; // C++14
199
200 // array modifications:
201 template <class T>
202 using remove_extent_t = typename remove_extent<T>::type; // C++14
203 template <class T>
204 using remove_all_extents_t = typename remove_all_extents<T>::type; // C++14
205
206 template <class T>
207 inline constexpr bool is_bounded_array_v
208 = is_bounded_array<T>::value; // C++20
209 inline constexpr bool is_unbounded_array_v
210 = is_unbounded_array<T>::value; // C++20
211
212 // pointer modifications:
213 template <class T>
214 using remove_pointer_t = typename remove_pointer<T>::type; // C++14
215 template <class T>
216 using add_pointer_t = typename add_pointer<T>::type; // C++14
217
218 // other transformations:
219 template <size_t Len, size_t Align=default-alignment>
220 using aligned_storage_t = typename aligned_storage<Len,Align>::type; // C++14
221 template <size_t Len, class... Types>
222 using aligned_union_t = typename aligned_union<Len,Types...>::type; // C++14
223 template <class T>
224 using remove_cvref_t = typename remove_cvref<T>::type; // C++20
225 template <class T>
226 using decay_t = typename decay<T>::type; // C++14
227 template <bool b, class T=void>
228 using enable_if_t = typename enable_if<b,T>::type; // C++14
229 template <bool b, class T, class F>
230 using conditional_t = typename conditional<b,T,F>::type; // C++14
231 template <class... T>
232 using common_type_t = typename common_type<T...>::type; // C++14
233 template <class T>
234 using underlying_type_t = typename underlying_type<T>::type; // C++14
235 template <class T>
236 using result_of_t = typename result_of<T>::type; // C++14; deprecated in C++17; removed in C++20
237 template <class Fn, class... ArgTypes>
238 using invoke_result_t = typename invoke_result<Fn, ArgTypes...>::type; // C++17
239
240 template <class...>
241 using void_t = void; // C++17
242
243 // See C++14 20.10.4.1, primary type categories
244 template <class T> inline constexpr bool is_void_v
245 = is_void<T>::value; // C++17
246 template <class T> inline constexpr bool is_null_pointer_v
247 = is_null_pointer<T>::value; // C++17
248 template <class T> inline constexpr bool is_integral_v
249 = is_integral<T>::value; // C++17
250 template <class T> inline constexpr bool is_floating_point_v
251 = is_floating_point<T>::value; // C++17
252 template <class T> inline constexpr bool is_array_v
253 = is_array<T>::value; // C++17
254 template <class T> inline constexpr bool is_pointer_v
255 = is_pointer<T>::value; // C++17
256 template <class T> inline constexpr bool is_lvalue_reference_v
257 = is_lvalue_reference<T>::value; // C++17
258 template <class T> inline constexpr bool is_rvalue_reference_v
259 = is_rvalue_reference<T>::value; // C++17
260 template <class T> inline constexpr bool is_member_object_pointer_v
261 = is_member_object_pointer<T>::value; // C++17
262 template <class T> inline constexpr bool is_member_function_pointer_v
263 = is_member_function_pointer<T>::value; // C++17
264 template <class T> inline constexpr bool is_enum_v
265 = is_enum<T>::value; // C++17
266 template <class T> inline constexpr bool is_union_v
267 = is_union<T>::value; // C++17
268 template <class T> inline constexpr bool is_class_v
269 = is_class<T>::value; // C++17
270 template <class T> inline constexpr bool is_function_v
271 = is_function<T>::value; // C++17
272
273 // See C++14 20.10.4.2, composite type categories
274 template <class T> inline constexpr bool is_reference_v
275 = is_reference<T>::value; // C++17
276 template <class T> inline constexpr bool is_arithmetic_v
277 = is_arithmetic<T>::value; // C++17
278 template <class T> inline constexpr bool is_fundamental_v
279 = is_fundamental<T>::value; // C++17
280 template <class T> inline constexpr bool is_object_v
281 = is_object<T>::value; // C++17
282 template <class T> inline constexpr bool is_scalar_v
283 = is_scalar<T>::value; // C++17
284 template <class T> inline constexpr bool is_compound_v
285 = is_compound<T>::value; // C++17
286 template <class T> inline constexpr bool is_member_pointer_v
287 = is_member_pointer<T>::value; // C++17
288 template <class T> inline constexpr bool is_scoped_enum_v
289 = is_scoped_enum<T>::value; // C++2b
290
291 // See C++14 20.10.4.3, type properties
292 template <class T> inline constexpr bool is_const_v
293 = is_const<T>::value; // C++17
294 template <class T> inline constexpr bool is_volatile_v
295 = is_volatile<T>::value; // C++17
296 template <class T> inline constexpr bool is_trivial_v
297 = is_trivial<T>::value; // C++17
298 template <class T> inline constexpr bool is_trivially_copyable_v
299 = is_trivially_copyable<T>::value; // C++17
300 template <class T> inline constexpr bool is_standard_layout_v
301 = is_standard_layout<T>::value; // C++17
302 template <class T> inline constexpr bool is_pod_v
303 = is_pod<T>::value; // C++17
304 template <class T> inline constexpr bool is_literal_type_v
305 = is_literal_type<T>::value; // C++17; deprecated in C++17; removed in C++20
306 template <class T> inline constexpr bool is_empty_v
307 = is_empty<T>::value; // C++17
308 template <class T> inline constexpr bool is_polymorphic_v
309 = is_polymorphic<T>::value; // C++17
310 template <class T> inline constexpr bool is_abstract_v
311 = is_abstract<T>::value; // C++17
312 template <class T> inline constexpr bool is_final_v
313 = is_final<T>::value; // C++17
314 template <class T> inline constexpr bool is_aggregate_v
315 = is_aggregate<T>::value; // C++17
316 template <class T> inline constexpr bool is_signed_v
317 = is_signed<T>::value; // C++17
318 template <class T> inline constexpr bool is_unsigned_v
319 = is_unsigned<T>::value; // C++17
320 template <class T, class... Args> inline constexpr bool is_constructible_v
321 = is_constructible<T, Args...>::value; // C++17
322 template <class T> inline constexpr bool is_default_constructible_v
323 = is_default_constructible<T>::value; // C++17
324 template <class T> inline constexpr bool is_copy_constructible_v
325 = is_copy_constructible<T>::value; // C++17
326 template <class T> inline constexpr bool is_move_constructible_v
327 = is_move_constructible<T>::value; // C++17
328 template <class T, class U> inline constexpr bool is_assignable_v
329 = is_assignable<T, U>::value; // C++17
330 template <class T> inline constexpr bool is_copy_assignable_v
331 = is_copy_assignable<T>::value; // C++17
332 template <class T> inline constexpr bool is_move_assignable_v
333 = is_move_assignable<T>::value; // C++17
334 template <class T, class U> inline constexpr bool is_swappable_with_v
335 = is_swappable_with<T, U>::value; // C++17
336 template <class T> inline constexpr bool is_swappable_v
337 = is_swappable<T>::value; // C++17
338 template <class T> inline constexpr bool is_destructible_v
339 = is_destructible<T>::value; // C++17
340 template <class T, class... Args> inline constexpr bool is_trivially_constructible_v
341 = is_trivially_constructible<T, Args...>::value; // C++17
342 template <class T> inline constexpr bool is_trivially_default_constructible_v
343 = is_trivially_default_constructible<T>::value; // C++17
344 template <class T> inline constexpr bool is_trivially_copy_constructible_v
345 = is_trivially_copy_constructible<T>::value; // C++17
346 template <class T> inline constexpr bool is_trivially_move_constructible_v
347 = is_trivially_move_constructible<T>::value; // C++17
348 template <class T, class U> inline constexpr bool is_trivially_assignable_v
349 = is_trivially_assignable<T, U>::value; // C++17
350 template <class T> inline constexpr bool is_trivially_copy_assignable_v
351 = is_trivially_copy_assignable<T>::value; // C++17
352 template <class T> inline constexpr bool is_trivially_move_assignable_v
353 = is_trivially_move_assignable<T>::value; // C++17
354 template <class T> inline constexpr bool is_trivially_destructible_v
355 = is_trivially_destructible<T>::value; // C++17
356 template <class T, class... Args> inline constexpr bool is_nothrow_constructible_v
357 = is_nothrow_constructible<T, Args...>::value; // C++17
358 template <class T> inline constexpr bool is_nothrow_default_constructible_v
359 = is_nothrow_default_constructible<T>::value; // C++17
360 template <class T> inline constexpr bool is_nothrow_copy_constructible_v
361 = is_nothrow_copy_constructible<T>::value; // C++17
362 template <class T> inline constexpr bool is_nothrow_move_constructible_v
363 = is_nothrow_move_constructible<T>::value; // C++17
364 template <class T, class U> inline constexpr bool is_nothrow_assignable_v
365 = is_nothrow_assignable<T, U>::value; // C++17
366 template <class T> inline constexpr bool is_nothrow_copy_assignable_v
367 = is_nothrow_copy_assignable<T>::value; // C++17
368 template <class T> inline constexpr bool is_nothrow_move_assignable_v
369 = is_nothrow_move_assignable<T>::value; // C++17
370 template <class T, class U> inline constexpr bool is_nothrow_swappable_with_v
371 = is_nothrow_swappable_with<T, U>::value; // C++17
372 template <class T> inline constexpr bool is_nothrow_swappable_v
373 = is_nothrow_swappable<T>::value; // C++17
374 template <class T> inline constexpr bool is_nothrow_destructible_v
375 = is_nothrow_destructible<T>::value; // C++17
376 template <class T> inline constexpr bool has_virtual_destructor_v
377 = has_virtual_destructor<T>::value; // C++17
378 template<class T> inline constexpr bool has_unique_object_representations_v // C++17
379 = has_unique_object_representations<T>::value;
380
381 // See C++14 20.10.5, type property queries
382 template <class T> inline constexpr size_t alignment_of_v
383 = alignment_of<T>::value; // C++17
384 template <class T> inline constexpr size_t rank_v
385 = rank<T>::value; // C++17
386 template <class T, unsigned I = 0> inline constexpr size_t extent_v
387 = extent<T, I>::value; // C++17
388
389 // See C++14 20.10.6, type relations
390 template <class T, class U> inline constexpr bool is_same_v
391 = is_same<T, U>::value; // C++17
392 template <class Base, class Derived> inline constexpr bool is_base_of_v
393 = is_base_of<Base, Derived>::value; // C++17
394 template <class From, class To> inline constexpr bool is_convertible_v
395 = is_convertible<From, To>::value; // C++17
396 template <class Fn, class... ArgTypes> inline constexpr bool is_invocable_v
397 = is_invocable<Fn, ArgTypes...>::value; // C++17
398 template <class R, class Fn, class... ArgTypes> inline constexpr bool is_invocable_r_v
399 = is_invocable_r<R, Fn, ArgTypes...>::value; // C++17
400 template <class Fn, class... ArgTypes> inline constexpr bool is_nothrow_invocable_v
401 = is_nothrow_invocable<Fn, ArgTypes...>::value; // C++17
402 template <class R, class Fn, class... ArgTypes> inline constexpr bool is_nothrow_invocable_r_v
403 = is_nothrow_invocable_r<R, Fn, ArgTypes...>::value; // C++17
404
405 // [meta.logical], logical operator traits:
406 template<class... B> struct conjunction; // C++17
407 template<class... B>
408 inline constexpr bool conjunction_v = conjunction<B...>::value; // C++17
409 template<class... B> struct disjunction; // C++17
410 template<class... B>
411 inline constexpr bool disjunction_v = disjunction<B...>::value; // C++17
412 template<class B> struct negation; // C++17
413 template<class B>
414 inline constexpr bool negation_v = negation<B>::value; // C++17
415
416}
417
418*/
419#include <__config>
420#include <cstddef>
421#include <version>
422
423#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
424#pragma GCC system_header
425#endif
426
427_LIBCPP_BEGIN_NAMESPACE_STDnamespace std { inline namespace __1 {
428
429template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) pair;
430template <class _Tp> class _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) reference_wrapper;
431template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) hash;
432
433template <class _Tp, _Tp __v>
434struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) integral_constant
435{
436 static _LIBCPP_CONSTEXPRconstexpr const _Tp value = __v;
437 typedef _Tp value_type;
438 typedef integral_constant type;
439 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
440 _LIBCPP_CONSTEXPRconstexpr operator value_type() const _NOEXCEPTnoexcept {return value;}
441#if _LIBCPP_STD_VER14 > 11
442 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
443 constexpr value_type operator ()() const _NOEXCEPTnoexcept {return value;}
444#endif
445};
446
447template <class _Tp, _Tp __v>
448_LIBCPP_CONSTEXPRconstexpr const _Tp integral_constant<_Tp, __v>::value;
449
450#if _LIBCPP_STD_VER14 > 14
451template <bool __b>
452using bool_constant = integral_constant<bool, __b>;
453#define _LIBCPP_BOOL_CONSTANT(__b)integral_constant<bool,(__b)> bool_constant<(__b)>
454#else
455#define _LIBCPP_BOOL_CONSTANT(__b)integral_constant<bool,(__b)> integral_constant<bool,(__b)>
456#endif
457
458typedef _LIBCPP_BOOL_CONSTANT(true)integral_constant<bool,(true)> true_type;
459typedef _LIBCPP_BOOL_CONSTANT(false)integral_constant<bool,(false)> false_type;
460
461template <bool _Val>
462using _BoolConstant _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = integral_constant<bool, _Val>;
463
464template <bool> struct _MetaBase;
465template <>
466struct _MetaBase<true> {
467 template <class _Tp, class _Up>
468 using _SelectImpl _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = _Tp;
469 template <template <class...> class _FirstFn, template <class...> class, class ..._Args>
470 using _SelectApplyImpl _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = _FirstFn<_Args...>;
471 template <class _First, class...>
472 using _FirstImpl _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = _First;
473 template <class, class _Second, class...>
474 using _SecondImpl _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = _Second;
475 template <class _Tp = void>
476 using _EnableIfImpl _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = _Tp;
477 template <class _Result, class _First, class ..._Rest>
478 using _OrImpl _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = typename _MetaBase<_First::value != true && sizeof...(_Rest) != 0>::template _OrImpl<_First, _Rest...>;
479};
480
481template <>
482struct _MetaBase<false> {
483 template <class _Tp, class _Up>
484 using _SelectImpl _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = _Up;
485 template <template <class...> class, template <class...> class _SecondFn, class ..._Args>
486 using _SelectApplyImpl _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = _SecondFn<_Args...>;
487 template <class _Result, class ...>
488 using _OrImpl _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = _Result;
489};
490template <bool _Cond, class _Ret = void>
491using _EnableIf _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = typename _MetaBase<_Cond>::template _EnableIfImpl<_Ret>;
492template <bool _Cond, class _IfRes, class _ElseRes>
493using _If _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = typename _MetaBase<_Cond>::template _SelectImpl<_IfRes, _ElseRes>;
494template <class ..._Rest>
495using _Or _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = typename _MetaBase< sizeof...(_Rest) != 0 >::template _OrImpl<false_type, _Rest...>;
496template <class _Pred>
497struct _Not : _BoolConstant<!_Pred::value> {};
498template <class ..._Args>
499using _FirstType _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = typename _MetaBase<(sizeof...(_Args) >= 1)>::template _FirstImpl<_Args...>;
500template <class ..._Args>
501using _SecondType _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = typename _MetaBase<(sizeof...(_Args) >= 2)>::template _SecondImpl<_Args...>;
502
503template <class ...> using __expand_to_true = true_type;
504template <class ..._Pred>
505__expand_to_true<_EnableIf<_Pred::value>...> __and_helper(int);
506template <class ...>
507false_type __and_helper(...);
508template <class ..._Pred>
509using _And _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = decltype(__and_helper<_Pred...>(0));
510
511template <template <class...> class _Func, class ..._Args>
512struct _Lazy : _Func<_Args...> {};
513
514// Member detector base
515
516template <template <class...> class _Templ, class ..._Args, class = _Templ<_Args...> >
517true_type __sfinae_test_impl(int);
518template <template <class...> class, class ...>
519false_type __sfinae_test_impl(...);
520
521template <template <class ...> class _Templ, class ..._Args>
522using _IsValidExpansion _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = decltype(__sfinae_test_impl<_Templ, _Args...>(0));
523
524template <class>
525struct __void_t { typedef void type; };
526
527template <class _Tp>
528struct __identity { typedef _Tp type; };
529
530template <class _Tp>
531using __identity_t _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = typename __identity<_Tp>::type;
532
533template <class _Tp, bool>
534struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) __dependent_type : public _Tp {};
535
536
537template <bool _Bp, class _If, class _Then>
538 struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) conditional {typedef _If type;};
539template <class _If, class _Then>
540 struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) conditional<false, _If, _Then> {typedef _Then type;};
541
542#if _LIBCPP_STD_VER14 > 11
543template <bool _Bp, class _If, class _Then> using conditional_t = typename conditional<_Bp, _If, _Then>::type;
544#endif
545
546template <bool, class _Tp = void> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) enable_if {};
547template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) enable_if<true, _Tp> {typedef _Tp type;};
548
549#if _LIBCPP_STD_VER14 > 11
550template <bool _Bp, class _Tp = void> using enable_if_t = typename enable_if<_Bp, _Tp>::type;
551#endif
552
553// is_same
554
555#if __has_keyword(__is_same)!(0)
556
557template <class _Tp, class _Up>
558struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_same : _BoolConstant<__is_same(_Tp, _Up)> { };
559
560#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
561template <class _Tp, class _Up>
562_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_same_v = __is_same(_Tp, _Up);
563#endif
564
565#else
566
567template <class _Tp, class _Up> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_same : public false_type {};
568template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_same<_Tp, _Tp> : public true_type {};
569
570#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
571template <class _Tp, class _Up>
572_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_same_v
573 = is_same<_Tp, _Up>::value;
574#endif
575
576#endif // __is_same
577
578template <class _Tp, class _Up>
579using _IsSame = _BoolConstant<
580#ifdef __clang__1
581 __is_same(_Tp, _Up)
582#else
583 is_same<_Tp, _Up>::value
584#endif
585>;
586
587template <class _Tp, class _Up>
588using _IsNotSame = _BoolConstant<
589#ifdef __clang__1
590 !__is_same(_Tp, _Up)
591#else
592 !is_same<_Tp, _Up>::value
593#endif
594>;
595
596
597template <class _Tp>
598using __test_for_primary_template = _EnableIf<
599 _IsSame<_Tp, typename _Tp::__primary_template>::value
600 >;
601template <class _Tp>
602using __is_primary_template = _IsValidExpansion<
603 __test_for_primary_template, _Tp
604 >;
605
606struct __two {char __lx[2];};
607
608// helper class:
609
610// is_const
611
612#if __has_keyword(__is_const)!(0)
613
614template <class _Tp>
615struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_const : _BoolConstant<__is_const(_Tp)> { };
616
617#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
618template <class _Tp>
619_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_const_v = __is_const(_Tp);
620#endif
621
622#else
623
624template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_const : public false_type {};
625template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_const<_Tp const> : public true_type {};
626
627#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
628template <class _Tp>
629_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_const_v
630 = is_const<_Tp>::value;
631#endif
632
633#endif // __has_keyword(__is_const)
634
635// is_volatile
636
637#if __has_keyword(__is_volatile)!(0)
638
639template <class _Tp>
640struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_volatile : _BoolConstant<__is_volatile(_Tp)> { };
641
642#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
643template <class _Tp>
644_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_volatile_v = __is_volatile(_Tp);
645#endif
646
647#else
648
649template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_volatile : public false_type {};
650template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_volatile<_Tp volatile> : public true_type {};
651
652#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
653template <class _Tp>
654_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_volatile_v
655 = is_volatile<_Tp>::value;
656#endif
657
658#endif // __has_keyword(__is_volatile)
659
660// remove_const
661
662#if __has_keyword(__remove_const)!(1)
663
664template <class _Tp>
665struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_const {typedef __remove_const(_Tp) type;};
666
667#if _LIBCPP_STD_VER14 > 11
668template <class _Tp> using remove_const_t = __remove_const(_Tp);
669#endif
670
671#else
672
673template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_const {typedef _Tp type;};
674template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_const<const _Tp> {typedef _Tp type;};
675#if _LIBCPP_STD_VER14 > 11
676template <class _Tp> using remove_const_t = typename remove_const<_Tp>::type;
677#endif
678
679#endif // __has_keyword(__remove_const)
680
681// remove_volatile
682
683#if __has_keyword(__remove_volatile)!(1)
684
685template <class _Tp>
686struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_volatile {typedef __remove_volatile(_Tp) type;};
687
688#if _LIBCPP_STD_VER14 > 11
689template <class _Tp> using remove_volatile_t = __remove_volatile(_Tp);
690#endif
691
692#else
693
694template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_volatile {typedef _Tp type;};
695template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_volatile<volatile _Tp> {typedef _Tp type;};
696#if _LIBCPP_STD_VER14 > 11
697template <class _Tp> using remove_volatile_t = typename remove_volatile<_Tp>::type;
698#endif
699
700#endif // __has_keyword(__remove_volatile)
701
702// remove_cv
703
704#if __has_keyword(__remove_cv)!(1)
705
706template <class _Tp>
707struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_cv {typedef __remove_cv(_Tp) type;};
708
709#if _LIBCPP_STD_VER14 > 11
710template <class _Tp> using remove_cv_t = __remove_cv(_Tp);
711#endif
712
713#else
714
715template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_cv
716{typedef typename remove_volatile<typename remove_const<_Tp>::type>::type type;};
717#if _LIBCPP_STD_VER14 > 11
718template <class _Tp> using remove_cv_t = typename remove_cv<_Tp>::type;
719#endif
720
721#endif // __has_keyword(__remove_cv)
722
723// is_void
724
725#if __has_keyword(__is_void)!(0)
726
727template <class _Tp>
728struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_void : _BoolConstant<__is_void(_Tp)> { };
729
730#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
731template <class _Tp>
732_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_void_v = __is_void(_Tp);
733#endif
734
735#else
736
737template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_void
738 : public is_same<typename remove_cv<_Tp>::type, void> {};
739
740#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
741template <class _Tp>
742_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_void_v
743 = is_void<_Tp>::value;
744#endif
745
746#endif // __has_keyword(__is_void)
747
748// __is_nullptr_t
749
750template <class _Tp> struct __is_nullptr_t_impl : public false_type {};
751template <> struct __is_nullptr_t_impl<nullptr_t> : public true_type {};
752
753template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) __is_nullptr_t
754 : public __is_nullptr_t_impl<typename remove_cv<_Tp>::type> {};
755
756#if _LIBCPP_STD_VER14 > 11
757template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_null_pointer
758 : public __is_nullptr_t_impl<typename remove_cv<_Tp>::type> {};
759
760#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
761template <class _Tp>
762_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_null_pointer_v
763 = is_null_pointer<_Tp>::value;
764#endif
765#endif // _LIBCPP_STD_VER > 11
766
767// is_integral
768
769#if __has_keyword(__is_integral)!(0)
770
771template <class _Tp>
772struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_integral : _BoolConstant<__is_integral(_Tp)> { };
773
774#if _LIBCPP_STD_VER14 > 14
775template <class _Tp>
776_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_integral_v = __is_integral(_Tp);
777#endif
778
779#else
780
781template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_integral
782 : public _BoolConstant<__libcpp_is_integral<typename remove_cv<_Tp>::type>::value> {};
783
784#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
785template <class _Tp>
786_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_integral_v
787 = is_integral<_Tp>::value;
788#endif
789
790#endif // __has_keyword(__is_integral)
791
792// __libcpp_is_signed_integer, __libcpp_is_unsigned_integer
793
794// [basic.fundamental] defines five standard signed integer types;
795// __int128_t is an extended signed integer type.
796// The signed and unsigned integer types, plus bool and the
797// five types with "char" in their name, compose the "integral" types.
798
799template <class _Tp> struct __libcpp_is_signed_integer : public false_type {};
800template <> struct __libcpp_is_signed_integer<signed char> : public true_type {};
801template <> struct __libcpp_is_signed_integer<signed short> : public true_type {};
802template <> struct __libcpp_is_signed_integer<signed int> : public true_type {};
803template <> struct __libcpp_is_signed_integer<signed long> : public true_type {};
804template <> struct __libcpp_is_signed_integer<signed long long> : public true_type {};
805#ifndef _LIBCPP_HAS_NO_INT128
806template <> struct __libcpp_is_signed_integer<__int128_t> : public true_type {};
807#endif
808
809template <class _Tp> struct __libcpp_is_unsigned_integer : public false_type {};
810template <> struct __libcpp_is_unsigned_integer<unsigned char> : public true_type {};
811template <> struct __libcpp_is_unsigned_integer<unsigned short> : public true_type {};
812template <> struct __libcpp_is_unsigned_integer<unsigned int> : public true_type {};
813template <> struct __libcpp_is_unsigned_integer<unsigned long> : public true_type {};
814template <> struct __libcpp_is_unsigned_integer<unsigned long long> : public true_type {};
815#ifndef _LIBCPP_HAS_NO_INT128
816template <> struct __libcpp_is_unsigned_integer<__uint128_t> : public true_type {};
817#endif
818
819// is_floating_point
820
821template <class _Tp> struct __libcpp_is_floating_point : public false_type {};
822template <> struct __libcpp_is_floating_point<float> : public true_type {};
823template <> struct __libcpp_is_floating_point<double> : public true_type {};
824template <> struct __libcpp_is_floating_point<long double> : public true_type {};
825
826template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_floating_point
827 : public __libcpp_is_floating_point<typename remove_cv<_Tp>::type> {};
828
829#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
830template <class _Tp>
831_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_floating_point_v
832 = is_floating_point<_Tp>::value;
833#endif
834
835// is_array
836
837#if __has_keyword(__is_array)!(0)
838
839template <class _Tp>
840struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_array : _BoolConstant<__is_array(_Tp)> { };
841
842#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
843template <class _Tp>
844_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_array_v = __is_array(_Tp);
845#endif
846
847#else
848
849template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_array
850 : public false_type {};
851template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_array<_Tp[]>
852 : public true_type {};
853template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_array<_Tp[_Np]>
854 : public true_type {};
855
856#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
857template <class _Tp>
858_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_array_v
859 = is_array<_Tp>::value;
860#endif
861
862#endif // __has_keyword(__is_array)
863
864// is_pointer
865
866// Before Clang 11 / AppleClang 12.0.5, __is_pointer didn't work for Objective-C types.
867#if __has_keyword(__is_pointer)!(0) && \
868 !(defined(_LIBCPP_CLANG_VER(13 * 100 + 0)) && _LIBCPP_CLANG_VER(13 * 100 + 0) < 1100) && \
869 !(defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER < 1205)
870
871template<class _Tp>
872struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_pointer : _BoolConstant<__is_pointer(_Tp)> { };
873
874#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
875template <class _Tp>
876_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_pointer_v = __is_pointer(_Tp);
877#endif
878
879#else // __has_keyword(__is_pointer)
880
881template <class _Tp> struct __libcpp_is_pointer : public false_type {};
882template <class _Tp> struct __libcpp_is_pointer<_Tp*> : public true_type {};
883
884template <class _Tp> struct __libcpp_remove_objc_qualifiers { typedef _Tp type; };
885#if defined(_LIBCPP_HAS_OBJC_ARC)
886template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __strong> { typedef _Tp type; };
887template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __weak> { typedef _Tp type; };
888template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __autoreleasing> { typedef _Tp type; };
889template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __unsafe_unretained> { typedef _Tp type; };
890#endif
891
892template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_pointer
893 : public __libcpp_is_pointer<typename __libcpp_remove_objc_qualifiers<typename remove_cv<_Tp>::type>::type> {};
894
895#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
896template <class _Tp>
897_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_pointer_v
898 = is_pointer<_Tp>::value;
899#endif
900
901#endif // __has_keyword(__is_pointer)
902
903// is_reference
904
905#if __has_keyword(__is_lvalue_reference)!(0) && \
906 __has_keyword(__is_rvalue_reference)!(0) && \
907 __has_keyword(__is_reference)!(0)
908
909template<class _Tp>
910struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_lvalue_reference : _BoolConstant<__is_lvalue_reference(_Tp)> { };
911
912template<class _Tp>
913struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_rvalue_reference : _BoolConstant<__is_rvalue_reference(_Tp)> { };
914
915template<class _Tp>
916struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_reference : _BoolConstant<__is_reference(_Tp)> { };
917
918#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
919template <class _Tp>
920_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_reference_v = __is_reference(_Tp);
921
922template <class _Tp>
923_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_lvalue_reference_v = __is_lvalue_reference(_Tp);
924
925template <class _Tp>
926_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_rvalue_reference_v = __is_rvalue_reference(_Tp);
927#endif
928
929#else // __has_keyword(__is_lvalue_reference) && etc...
930
931template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_lvalue_reference : public false_type {};
932template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_lvalue_reference<_Tp&> : public true_type {};
933
934template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_rvalue_reference : public false_type {};
935template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_rvalue_reference<_Tp&&> : public true_type {};
936
937template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_reference : public false_type {};
938template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_reference<_Tp&> : public true_type {};
939template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_reference<_Tp&&> : public true_type {};
940
941#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
942template <class _Tp>
943_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_reference_v
944 = is_reference<_Tp>::value;
945
946template <class _Tp>
947_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_lvalue_reference_v
948 = is_lvalue_reference<_Tp>::value;
949
950template <class _Tp>
951_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_rvalue_reference_v
952 = is_rvalue_reference<_Tp>::value;
953#endif
954
955#endif // __has_keyword(__is_lvalue_reference) && etc...
956
957// is_union
958
959#if __has_feature(is_union)1 || defined(_LIBCPP_COMPILER_GCC)
960
961template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_union
962 : public integral_constant<bool, __is_union(_Tp)> {};
963
964#else
965
966template <class _Tp> struct __libcpp_union : public false_type {};
967template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_union
968 : public __libcpp_union<typename remove_cv<_Tp>::type> {};
969
970#endif
971
972#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
973template <class _Tp>
974_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_union_v
975 = is_union<_Tp>::value;
976#endif
977
978// is_class
979
980#if __has_feature(is_class)1 || defined(_LIBCPP_COMPILER_GCC)
981
982template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_class
983 : public integral_constant<bool, __is_class(_Tp)> {};
984
985#else
986
987namespace __is_class_imp
988{
989template <class _Tp> char __test(int _Tp::*);
990template <class _Tp> __two __test(...);
991}
992
993template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_class
994 : public integral_constant<bool, sizeof(__is_class_imp::__test<_Tp>(0)) == 1 && !is_union<_Tp>::value> {};
995
996#endif
997
998#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
999template <class _Tp>
1000_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_class_v
1001 = is_class<_Tp>::value;
1002#endif
1003
1004// is_function
1005
1006template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_function
1007 : public _BoolConstant<
1008#ifdef __clang__1
1009 __is_function(_Tp)
1010#else
1011 !(is_reference<_Tp>::value || is_const<const _Tp>::value)
1012#endif
1013 > {};
1014
1015
1016#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1017template <class _Tp>
1018_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_function_v
1019 = is_function<_Tp>::value;
1020#endif
1021
1022template <class _Tp> struct __libcpp_is_member_pointer {
1023 enum {
1024 __is_member = false,
1025 __is_func = false,
1026 __is_obj = false
1027 };
1028};
1029template <class _Tp, class _Up> struct __libcpp_is_member_pointer<_Tp _Up::*> {
1030 enum {
1031 __is_member = true,
1032 __is_func = is_function<_Tp>::value,
1033 __is_obj = !__is_func,
1034 };
1035};
1036
1037#if __has_keyword(__is_member_function_pointer)!(0)
1038
1039template<class _Tp>
1040struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_member_function_pointer
1041 : _BoolConstant<__is_member_function_pointer(_Tp)> { };
1042
1043#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1044template <class _Tp>
1045_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_member_function_pointer_v
1046 = __is_member_function_pointer(_Tp);
1047#endif
1048
1049#else // __has_keyword(__is_member_function_pointer)
1050
1051template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_member_function_pointer
1052 : public _BoolConstant< __libcpp_is_member_pointer<typename remove_cv<_Tp>::type>::__is_func > {};
1053
1054#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1055template <class _Tp>
1056_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_member_function_pointer_v
1057 = is_member_function_pointer<_Tp>::value;
1058#endif
1059
1060#endif // __has_keyword(__is_member_function_pointer)
1061
1062// is_member_pointer
1063
1064#if __has_keyword(__is_member_pointer)!(0)
1065
1066template<class _Tp>
1067struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_member_pointer : _BoolConstant<__is_member_pointer(_Tp)> { };
1068
1069#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1070template <class _Tp>
1071_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_member_pointer_v = __is_member_pointer(_Tp);
1072#endif
1073
1074#else // __has_keyword(__is_member_pointer)
1075
1076template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_member_pointer
1077 : public _BoolConstant< __libcpp_is_member_pointer<typename remove_cv<_Tp>::type>::__is_member > {};
1078
1079#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1080template <class _Tp>
1081_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_member_pointer_v
1082 = is_member_pointer<_Tp>::value;
1083#endif
1084
1085#endif // __has_keyword(__is_member_pointer)
1086
1087// is_member_object_pointer
1088
1089#if __has_keyword(__is_member_object_pointer)!(0)
1090
1091template<class _Tp>
1092struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_member_object_pointer
1093 : _BoolConstant<__is_member_object_pointer(_Tp)> { };
1094
1095#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1096template <class _Tp>
1097_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_member_object_pointer_v
1098 = __is_member_object_pointer(_Tp);
1099#endif
1100
1101#else // __has_keyword(__is_member_object_pointer)
1102
1103template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_member_object_pointer
1104 : public _BoolConstant< __libcpp_is_member_pointer<typename remove_cv<_Tp>::type>::__is_obj > {};
1105
1106#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1107template <class _Tp>
1108_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_member_object_pointer_v
1109 = is_member_object_pointer<_Tp>::value;
1110#endif
1111
1112#endif // __has_keyword(__is_member_object_pointer)
1113
1114// is_enum
1115
1116#if __has_feature(is_enum)1 || defined(_LIBCPP_COMPILER_GCC)
1117
1118template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_enum
1119 : public integral_constant<bool, __is_enum(_Tp)> {};
1120
1121#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1122template <class _Tp>
1123_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_enum_v = __is_enum(_Tp);
1124#endif
1125
1126#else
1127
1128template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_enum
1129 : public integral_constant<bool, !is_void<_Tp>::value &&
1130 !is_integral<_Tp>::value &&
1131 !is_floating_point<_Tp>::value &&
1132 !is_array<_Tp>::value &&
1133 !is_pointer<_Tp>::value &&
1134 !is_reference<_Tp>::value &&
1135 !is_member_pointer<_Tp>::value &&
1136 !is_union<_Tp>::value &&
1137 !is_class<_Tp>::value &&
1138 !is_function<_Tp>::value > {};
1139
1140#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1141template <class _Tp>
1142_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_enum_v
1143 = is_enum<_Tp>::value;
1144#endif
1145
1146#endif // __has_feature(is_enum) || defined(_LIBCPP_COMPILER_GCC)
1147
1148// is_arithmetic
1149
1150
1151template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_arithmetic
1152 : public integral_constant<bool, is_integral<_Tp>::value ||
1153 is_floating_point<_Tp>::value> {};
1154
1155#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1156template <class _Tp>
1157_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_arithmetic_v
1158 = is_arithmetic<_Tp>::value;
1159#endif
1160
1161// is_fundamental
1162
1163// Before Clang 10, __is_fundamental didn't work for nullptr_t.
1164// In C++03 nullptr_t is library-provided but must still count as "fundamental."
1165#if __has_keyword(__is_fundamental)!(0) && \
1166 !(defined(_LIBCPP_CLANG_VER(13 * 100 + 0)) && _LIBCPP_CLANG_VER(13 * 100 + 0) < 1000) && \
1167 !defined(_LIBCPP_CXX03_LANG)
1168
1169template<class _Tp>
1170struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_fundamental : _BoolConstant<__is_fundamental(_Tp)> { };
1171
1172#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1173template <class _Tp>
1174_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_fundamental_v = __is_fundamental(_Tp);
1175#endif
1176
1177#else // __has_keyword(__is_fundamental)
1178
1179template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_fundamental
1180 : public integral_constant<bool, is_void<_Tp>::value ||
1181 __is_nullptr_t<_Tp>::value ||
1182 is_arithmetic<_Tp>::value> {};
1183
1184#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1185template <class _Tp>
1186_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_fundamental_v
1187 = is_fundamental<_Tp>::value;
1188#endif
1189
1190#endif // __has_keyword(__is_fundamental)
1191
1192// is_scalar
1193
1194// In C++03 nullptr_t is library-provided but must still count as "scalar."
1195#if __has_keyword(__is_scalar)!(0) && !defined(_LIBCPP_CXX03_LANG)
1196
1197template<class _Tp>
1198struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_scalar : _BoolConstant<__is_scalar(_Tp)> { };
1199
1200#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1201template <class _Tp>
1202_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_scalar_v = __is_scalar(_Tp);
1203#endif
1204
1205#else // __has_keyword(__is_scalar)
1206
1207template <class _Tp> struct __is_block : false_type {};
1208#if defined(_LIBCPP_HAS_EXTENSION_BLOCKS)
1209template <class _Rp, class ..._Args> struct __is_block<_Rp (^)(_Args...)> : true_type {};
1210#endif
1211
1212template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_scalar
1213 : public integral_constant<bool, is_arithmetic<_Tp>::value ||
1214 is_member_pointer<_Tp>::value ||
1215 is_pointer<_Tp>::value ||
1216 __is_nullptr_t<_Tp>::value ||
1217 __is_block<_Tp>::value ||
1218 is_enum<_Tp>::value > {};
1219
1220template <> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_scalar<nullptr_t> : public true_type {};
1221
1222#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1223template <class _Tp>
1224_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_scalar_v
1225 = is_scalar<_Tp>::value;
1226#endif
1227
1228#endif // __has_keyword(__is_scalar)
1229
1230// is_object
1231
1232#if __has_keyword(__is_object)!(0)
1233
1234template<class _Tp>
1235struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_object : _BoolConstant<__is_object(_Tp)> { };
1236
1237#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1238template <class _Tp>
1239_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_object_v = __is_object(_Tp);
1240#endif
1241
1242#else // __has_keyword(__is_object)
1243
1244template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_object
1245 : public integral_constant<bool, is_scalar<_Tp>::value ||
1246 is_array<_Tp>::value ||
1247 is_union<_Tp>::value ||
1248 is_class<_Tp>::value > {};
1249
1250#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1251template <class _Tp>
1252_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_object_v
1253 = is_object<_Tp>::value;
1254#endif
1255
1256#endif // __has_keyword(__is_object)
1257
1258// is_compound
1259
1260// >= 11 because in C++03 nullptr isn't actually nullptr
1261#if __has_keyword(__is_compound)!(0) && !defined(_LIBCPP_CXX03_LANG)
1262
1263template<class _Tp>
1264struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_compound : _BoolConstant<__is_compound(_Tp)> { };
1265
1266#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1267template <class _Tp>
1268_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_compound_v = __is_compound(_Tp);
1269#endif
1270
1271#else // __has_keyword(__is_compound)
1272
1273template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_compound
1274 : public integral_constant<bool, !is_fundamental<_Tp>::value> {};
1275
1276#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1277template <class _Tp>
1278_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_compound_v
1279 = is_compound<_Tp>::value;
1280#endif
1281
1282#endif // __has_keyword(__is_compound)
1283
1284// __is_referenceable [defns.referenceable]
1285
1286struct __is_referenceable_impl {
1287 template <class _Tp> static _Tp& __test(int);
1288 template <class _Tp> static __two __test(...);
1289};
1290
1291template <class _Tp>
1292struct __is_referenceable : integral_constant<bool,
1293 _IsNotSame<decltype(__is_referenceable_impl::__test<_Tp>(0)), __two>::value> {};
1294
1295
1296// add_const
1297
1298template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) add_const {
1299 typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) const _Tp type;
1300};
1301
1302#if _LIBCPP_STD_VER14 > 11
1303template <class _Tp> using add_const_t = typename add_const<_Tp>::type;
1304#endif
1305
1306// add_volatile
1307
1308template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) add_volatile {
1309 typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) volatile _Tp type;
1310};
1311
1312#if _LIBCPP_STD_VER14 > 11
1313template <class _Tp> using add_volatile_t = typename add_volatile<_Tp>::type;
1314#endif
1315
1316// add_cv
1317template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) add_cv {
1318 typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) const volatile _Tp type;
1319};
1320
1321#if _LIBCPP_STD_VER14 > 11
1322template <class _Tp> using add_cv_t = typename add_cv<_Tp>::type;
1323#endif
1324
1325// remove_reference
1326
1327#if __has_keyword(__remove_reference)!(1)
1328
1329template<class _Tp>
1330struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_reference { typedef __remove_reference(_Tp) type; };
1331
1332#else // __has_keyword(__remove_reference)
1333
1334template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_reference {typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) _Tp type;};
1335template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_reference<_Tp&> {typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) _Tp type;};
1336template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_reference<_Tp&&> {typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) _Tp type;};
1337
1338#if _LIBCPP_STD_VER14 > 11
1339template <class _Tp> using remove_reference_t = typename remove_reference<_Tp>::type;
1340#endif
1341
1342#endif // __has_keyword(__remove_reference)
1343
1344// add_lvalue_reference
1345
1346template <class _Tp, bool = __is_referenceable<_Tp>::value> struct __add_lvalue_reference_impl { typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) _Tp type; };
1347template <class _Tp > struct __add_lvalue_reference_impl<_Tp, true> { typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) _Tp& type; };
1348
1349template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) add_lvalue_reference
1350{typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) typename __add_lvalue_reference_impl<_Tp>::type type;};
1351
1352#if _LIBCPP_STD_VER14 > 11
1353template <class _Tp> using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type;
1354#endif
1355
1356template <class _Tp, bool = __is_referenceable<_Tp>::value> struct __add_rvalue_reference_impl { typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) _Tp type; };
1357template <class _Tp > struct __add_rvalue_reference_impl<_Tp, true> { typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) _Tp&& type; };
1358
1359template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) add_rvalue_reference
1360{typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) typename __add_rvalue_reference_impl<_Tp>::type type;};
1361
1362#if _LIBCPP_STD_VER14 > 11
1363template <class _Tp> using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type;
1364#endif
1365
1366// Suppress deprecation notice for volatile-qualified return type resulting
1367// from volatile-qualified types _Tp.
1368_LIBCPP_SUPPRESS_DEPRECATED_PUSHGCC diagnostic push GCC diagnostic ignored "-Wdeprecated" GCC
diagnostic ignored "-Wdeprecated-declarations"
1369template <class _Tp> _Tp&& __declval(int);
1370template <class _Tp> _Tp __declval(long);
1371_LIBCPP_SUPPRESS_DEPRECATED_POPGCC diagnostic pop
1372
1373template <class _Tp>
1374decltype(__declval<_Tp>(0))
1375declval() _NOEXCEPTnoexcept;
1376
1377// __uncvref
1378
1379template <class _Tp>
1380struct __uncvref {
1381 typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) typename remove_cv<typename remove_reference<_Tp>::type>::type type;
1382};
1383
1384template <class _Tp>
1385struct __unconstref {
1386 typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) typename remove_const<typename remove_reference<_Tp>::type>::type type;
1387};
1388
1389#ifndef _LIBCPP_CXX03_LANG
1390template <class _Tp>
1391using __uncvref_t _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = typename __uncvref<_Tp>::type;
1392#endif
1393
1394// __is_same_uncvref
1395
1396template <class _Tp, class _Up>
1397struct __is_same_uncvref : _IsSame<typename __uncvref<_Tp>::type,
1398 typename __uncvref<_Up>::type> {};
1399
1400#if _LIBCPP_STD_VER14 > 17
1401// remove_cvref - same as __uncvref
1402template <class _Tp>
1403struct remove_cvref : public __uncvref<_Tp> {};
1404
1405template <class _Tp> using remove_cvref_t = typename remove_cvref<_Tp>::type;
1406#endif
1407
1408
1409struct __any
1410{
1411 __any(...);
1412};
1413
1414// remove_pointer
1415
1416template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_pointer {typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) _Tp type;};
1417template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_pointer<_Tp*> {typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) _Tp type;};
1418template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_pointer<_Tp* const> {typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) _Tp type;};
1419template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_pointer<_Tp* volatile> {typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) _Tp type;};
1420template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_pointer<_Tp* const volatile> {typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) _Tp type;};
1421
1422#if _LIBCPP_STD_VER14 > 11
1423template <class _Tp> using remove_pointer_t = typename remove_pointer<_Tp>::type;
1424#endif
1425
1426// add_pointer
1427
1428template <class _Tp,
1429 bool = __is_referenceable<_Tp>::value ||
1430 _IsSame<typename remove_cv<_Tp>::type, void>::value>
1431struct __add_pointer_impl
1432 {typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) typename remove_reference<_Tp>::type* type;};
1433template <class _Tp> struct __add_pointer_impl<_Tp, false>
1434 {typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) _Tp type;};
1435
1436template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) add_pointer
1437 {typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) typename __add_pointer_impl<_Tp>::type type;};
1438
1439#if _LIBCPP_STD_VER14 > 11
1440template <class _Tp> using add_pointer_t = typename add_pointer<_Tp>::type;
1441#endif
1442
1443// type_identity
1444#if _LIBCPP_STD_VER14 > 17
1445template<class _Tp> struct type_identity { typedef _Tp type; };
1446template<class _Tp> using type_identity_t = typename type_identity<_Tp>::type;
1447#endif
1448
1449// is_signed
1450
1451// Before Clang 10, __is_signed didn't work for floating-point types or enums.
1452#if __has_keyword(__is_signed)!(0) && \
1453 !(defined(_LIBCPP_CLANG_VER(13 * 100 + 0)) && _LIBCPP_CLANG_VER(13 * 100 + 0) < 1000)
1454
1455template<class _Tp>
1456struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_signed : _BoolConstant<__is_signed(_Tp)> { };
1457
1458#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1459template <class _Tp>
1460_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_signed_v = __is_signed(_Tp);
1461#endif
1462
1463#else // __has_keyword(__is_signed)
1464
1465template <class _Tp, bool = is_integral<_Tp>::value>
1466struct __libcpp_is_signed_impl : public _LIBCPP_BOOL_CONSTANT(_Tp(-1) < _Tp(0))integral_constant<bool,(_Tp(-1) < _Tp(0))> {};
1467
1468template <class _Tp>
1469struct __libcpp_is_signed_impl<_Tp, false> : public true_type {}; // floating point
1470
1471template <class _Tp, bool = is_arithmetic<_Tp>::value>
1472struct __libcpp_is_signed : public __libcpp_is_signed_impl<_Tp> {};
1473
1474template <class _Tp> struct __libcpp_is_signed<_Tp, false> : public false_type {};
1475
1476template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_signed : public __libcpp_is_signed<_Tp> {};
1477
1478#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1479template <class _Tp>
1480_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_signed_v
1481 = is_signed<_Tp>::value;
1482#endif
1483
1484#endif // __has_keyword(__is_signed)
1485
1486// is_unsigned
1487
1488// Before Clang 13, __is_unsigned returned true for enums with signed underlying type.
1489// No currently-released version of AppleClang contains the fixed intrinsic.
1490#if __has_keyword(__is_unsigned)!(0) && \
1491 !(defined(_LIBCPP_CLANG_VER(13 * 100 + 0)) && _LIBCPP_CLANG_VER(13 * 100 + 0) < 1300) && \
1492 !defined(_LIBCPP_APPLE_CLANG_VER)
1493
1494template<class _Tp>
1495struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_unsigned : _BoolConstant<__is_unsigned(_Tp)> { };
1496
1497#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1498template <class _Tp>
1499_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_unsigned_v = __is_unsigned(_Tp);
1500#endif
1501
1502#else // __has_keyword(__is_unsigned)
1503
1504template <class _Tp, bool = is_integral<_Tp>::value>
1505struct __libcpp_is_unsigned_impl : public _LIBCPP_BOOL_CONSTANT(_Tp(0) < _Tp(-1))integral_constant<bool,(_Tp(0) < _Tp(-1))> {};
1506
1507template <class _Tp>
1508struct __libcpp_is_unsigned_impl<_Tp, false> : public false_type {}; // floating point
1509
1510template <class _Tp, bool = is_arithmetic<_Tp>::value>
1511struct __libcpp_is_unsigned : public __libcpp_is_unsigned_impl<_Tp> {};
1512
1513template <class _Tp> struct __libcpp_is_unsigned<_Tp, false> : public false_type {};
1514
1515template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_unsigned : public __libcpp_is_unsigned<_Tp> {};
1516
1517#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1518template <class _Tp>
1519_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_unsigned_v
1520 = is_unsigned<_Tp>::value;
1521#endif
1522
1523#endif // __has_keyword(__is_unsigned)
1524
1525// rank
1526
1527template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) rank
1528 : public integral_constant<size_t, 0> {};
1529template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) rank<_Tp[]>
1530 : public integral_constant<size_t, rank<_Tp>::value + 1> {};
1531template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) rank<_Tp[_Np]>
1532 : public integral_constant<size_t, rank<_Tp>::value + 1> {};
1533
1534#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1535template <class _Tp>
1536_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr size_t rank_v
1537 = rank<_Tp>::value;
1538#endif
1539
1540// extent
1541
1542#if __has_keyword(__array_extent)!(0)
1543
1544template<class _Tp, size_t _Dim = 0>
1545struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) extent
1546 : integral_constant<size_t, __array_extent(_Tp, _Dim)> { };
1547
1548#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1549template <class _Tp, unsigned _Ip = 0>
1550_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr size_t extent_v = __array_extent(_Tp, _Ip);
1551#endif
1552
1553#else // __has_keyword(__array_extent)
1554
1555template <class _Tp, unsigned _Ip = 0> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) extent
1556 : public integral_constant<size_t, 0> {};
1557template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) extent<_Tp[], 0>
1558 : public integral_constant<size_t, 0> {};
1559template <class _Tp, unsigned _Ip> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) extent<_Tp[], _Ip>
1560 : public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {};
1561template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) extent<_Tp[_Np], 0>
1562 : public integral_constant<size_t, _Np> {};
1563template <class _Tp, size_t _Np, unsigned _Ip> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) extent<_Tp[_Np], _Ip>
1564 : public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {};
1565
1566#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1567template <class _Tp, unsigned _Ip = 0>
1568_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr size_t extent_v
1569 = extent<_Tp, _Ip>::value;
1570#endif
1571
1572#endif // __has_keyword(__array_extent)
1573
1574// remove_extent
1575
1576template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_extent
1577 {typedef _Tp type;};
1578template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_extent<_Tp[]>
1579 {typedef _Tp type;};
1580template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_extent<_Tp[_Np]>
1581 {typedef _Tp type;};
1582
1583#if _LIBCPP_STD_VER14 > 11
1584template <class _Tp> using remove_extent_t = typename remove_extent<_Tp>::type;
1585#endif
1586
1587// remove_all_extents
1588
1589template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_all_extents
1590 {typedef _Tp type;};
1591template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_all_extents<_Tp[]>
1592 {typedef typename remove_all_extents<_Tp>::type type;};
1593template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_all_extents<_Tp[_Np]>
1594 {typedef typename remove_all_extents<_Tp>::type type;};
1595
1596#if _LIBCPP_STD_VER14 > 11
1597template <class _Tp> using remove_all_extents_t = typename remove_all_extents<_Tp>::type;
1598#endif
1599
1600#if _LIBCPP_STD_VER14 > 17
1601// is_bounded_array
1602
1603template <class> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_bounded_array : false_type {};
1604template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_bounded_array<_Tp[_Np]> : true_type {};
1605
1606template <class _Tp>
1607_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr
1608bool is_bounded_array_v = is_bounded_array<_Tp>::value;
1609
1610// is_unbounded_array
1611
1612template <class> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_unbounded_array : false_type {};
1613template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_unbounded_array<_Tp[]> : true_type {};
1614
1615template <class _Tp>
1616_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr
1617bool is_unbounded_array_v = is_unbounded_array<_Tp>::value;
1618#endif
1619
1620// decay
1621
1622template <class _Up, bool>
1623struct __decay {
1624 typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) typename remove_cv<_Up>::type type;
1625};
1626
1627template <class _Up>
1628struct __decay<_Up, true> {
1629public:
1630 typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) typename conditional
1631 <
1632 is_array<_Up>::value,
1633 typename remove_extent<_Up>::type*,
1634 typename conditional
1635 <
1636 is_function<_Up>::value,
1637 typename add_pointer<_Up>::type,
1638 typename remove_cv<_Up>::type
1639 >::type
1640 >::type type;
1641};
1642
1643template <class _Tp>
1644struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) decay
1645{
1646private:
1647 typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) typename remove_reference<_Tp>::type _Up;
1648public:
1649 typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) typename __decay<_Up, __is_referenceable<_Up>::value>::type type;
1650};
1651
1652#if _LIBCPP_STD_VER14 > 11
1653template <class _Tp> using decay_t = typename decay<_Tp>::type;
1654#endif
1655
1656// is_abstract
1657
1658template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_abstract
1659 : public integral_constant<bool, __is_abstract(_Tp)> {};
1660
1661#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1662template <class _Tp>
1663_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_abstract_v
1664 = is_abstract<_Tp>::value;
1665#endif
1666
1667// is_final
1668
1669template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default")))
1670__libcpp_is_final : public integral_constant<bool, __is_final(_Tp)> {};
1671
1672#if _LIBCPP_STD_VER14 > 11
1673template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default")))
1674is_final : public integral_constant<bool, __is_final(_Tp)> {};
1675#endif
1676
1677#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1678template <class _Tp>
1679_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_final_v
1680 = is_final<_Tp>::value;
1681#endif
1682
1683// is_aggregate
1684#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_IS_AGGREGATE)
1685
1686template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default")))
1687is_aggregate : public integral_constant<bool, __is_aggregate(_Tp)> {};
1688
1689#if !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1690template <class _Tp>
1691_LIBCPP_INLINE_VAR constexpr bool is_aggregate_v
1692 = is_aggregate<_Tp>::value;
1693#endif
1694
1695#endif // _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_IS_AGGREGATE)
1696
1697// is_base_of
1698
1699template <class _Bp, class _Dp>
1700struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_base_of
1701 : public integral_constant<bool, __is_base_of(_Bp, _Dp)> {};
1702
1703#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1704template <class _Bp, class _Dp>
1705_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_base_of_v
1706 = is_base_of<_Bp, _Dp>::value;
1707#endif
1708
1709// __is_core_convertible
1710
1711// [conv.general]/3 says "E is convertible to T" whenever "T t=E;" is well-formed.
1712// We can't test for that, but we can test implicit convertibility by passing it
1713// to a function. Notice that __is_core_convertible<void,void> is false,
1714// and __is_core_convertible<immovable-type,immovable-type> is true in C++17 and later.
1715
1716template <class _Tp, class _Up, class = void>
1717struct __is_core_convertible : public false_type {};
1718
1719template <class _Tp, class _Up>
1720struct __is_core_convertible<_Tp, _Up, decltype(
1721 static_cast<void(*)(_Up)>(0) ( static_cast<_Tp(*)()>(0)() )
1722)> : public true_type {};
1723
1724// is_convertible
1725
1726#if __has_feature(is_convertible_to)1 && !defined(_LIBCPP_USE_IS_CONVERTIBLE_FALLBACK)
1727
1728template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_convertible
1729 : public integral_constant<bool, __is_convertible_to(_T1, _T2)> {};
1730
1731#else // __has_feature(is_convertible_to)
1732
1733namespace __is_convertible_imp
1734{
1735template <class _Tp> void __test_convert(_Tp);
1736
1737template <class _From, class _To, class = void>
1738struct __is_convertible_test : public false_type {};
1739
1740template <class _From, class _To>
1741struct __is_convertible_test<_From, _To,
1742 decltype(__is_convertible_imp::__test_convert<_To>(declval<_From>()))> : public true_type
1743{};
1744
1745template <class _Tp, bool _IsArray = is_array<_Tp>::value,
1746 bool _IsFunction = is_function<_Tp>::value,
1747 bool _IsVoid = is_void<_Tp>::value>
1748 struct __is_array_function_or_void {enum {value = 0};};
1749template <class _Tp> struct __is_array_function_or_void<_Tp, true, false, false> {enum {value = 1};};
1750template <class _Tp> struct __is_array_function_or_void<_Tp, false, true, false> {enum {value = 2};};
1751template <class _Tp> struct __is_array_function_or_void<_Tp, false, false, true> {enum {value = 3};};
1752}
1753
1754template <class _Tp,
1755 unsigned = __is_convertible_imp::__is_array_function_or_void<typename remove_reference<_Tp>::type>::value>
1756struct __is_convertible_check
1757{
1758 static const size_t __v = 0;
1759};
1760
1761template <class _Tp>
1762struct __is_convertible_check<_Tp, 0>
1763{
1764 static const size_t __v = sizeof(_Tp);
1765};
1766
1767template <class _T1, class _T2,
1768 unsigned _T1_is_array_function_or_void = __is_convertible_imp::__is_array_function_or_void<_T1>::value,
1769 unsigned _T2_is_array_function_or_void = __is_convertible_imp::__is_array_function_or_void<_T2>::value>
1770struct __is_convertible
1771 : public integral_constant<bool,
1772 __is_convertible_imp::__is_convertible_test<_T1, _T2>::value
1773 >
1774{};
1775
1776template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 1> : public false_type {};
1777template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 1> : public false_type {};
1778template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 1> : public false_type {};
1779template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 1> : public false_type {};
1780
1781template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 2> : public false_type {};
1782template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 2> : public false_type {};
1783template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 2> : public false_type {};
1784template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 2> : public false_type {};
1785
1786template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 3> : public false_type {};
1787template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 3> : public false_type {};
1788template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 3> : public false_type {};
1789template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 3> : public true_type {};
1790
1791template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_convertible
1792 : public __is_convertible<_T1, _T2>
1793{
1794 static const size_t __complete_check1 = __is_convertible_check<_T1>::__v;
1795 static const size_t __complete_check2 = __is_convertible_check<_T2>::__v;
1796};
1797
1798#endif // __has_feature(is_convertible_to)
1799
1800#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1801template <class _From, class _To>
1802_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_convertible_v
1803 = is_convertible<_From, _To>::value;
1804#endif
1805
1806// is_nothrow_convertible
1807
1808#if _LIBCPP_STD_VER14 > 17
1809
1810template <typename _Tp>
1811static void __test_noexcept(_Tp) noexcept;
1812
1813template<typename _Fm, typename _To>
1814static bool_constant<noexcept(_VSTDstd::__1::__test_noexcept<_To>(declval<_Fm>()))>
1815__is_nothrow_convertible_test();
1816
1817template <typename _Fm, typename _To>
1818struct __is_nothrow_convertible_helper: decltype(__is_nothrow_convertible_test<_Fm, _To>())
1819{ };
1820
1821template <typename _Fm, typename _To>
1822struct is_nothrow_convertible : _Or<
1823 _And<is_void<_To>, is_void<_Fm>>,
1824 _Lazy<_And, is_convertible<_Fm, _To>, __is_nothrow_convertible_helper<_Fm, _To>>
1825>::type { };
1826
1827template <typename _Fm, typename _To>
1828inline constexpr bool is_nothrow_convertible_v = is_nothrow_convertible<_Fm, _To>::value;
1829
1830#endif // _LIBCPP_STD_VER > 17
1831
1832// is_empty
1833
1834#if __has_feature(is_empty)1 || defined(_LIBCPP_COMPILER_GCC)
1835
1836template <class _Tp>
1837struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_empty
1838 : public integral_constant<bool, __is_empty(_Tp)> {};
1839
1840#else // __has_feature(is_empty)
1841
1842template <class _Tp>
1843struct __is_empty1
1844 : public _Tp
1845{
1846 double __lx;
1847};
1848
1849struct __is_empty2
1850{
1851 double __lx;
1852};
1853
1854template <class _Tp, bool = is_class<_Tp>::value>
1855struct __libcpp_empty : public integral_constant<bool, sizeof(__is_empty1<_Tp>) == sizeof(__is_empty2)> {};
1856
1857template <class _Tp> struct __libcpp_empty<_Tp, false> : public false_type {};
1858
1859template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_empty : public __libcpp_empty<_Tp> {};
1860
1861#endif // __has_feature(is_empty)
1862
1863#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1864template <class _Tp>
1865_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_empty_v
1866 = is_empty<_Tp>::value;
1867#endif
1868
1869// is_polymorphic
1870
1871#if __has_feature(is_polymorphic)1 || defined(_LIBCPP_COMPILER_MSVC)
1872
1873template <class _Tp>
1874struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_polymorphic
1875 : public integral_constant<bool, __is_polymorphic(_Tp)> {};
1876
1877#else
1878
1879template<typename _Tp> char &__is_polymorphic_impl(
1880 typename enable_if<sizeof((_Tp*)dynamic_cast<const volatile void*>(declval<_Tp*>())) != 0,
1881 int>::type);
1882template<typename _Tp> __two &__is_polymorphic_impl(...);
1883
1884template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_polymorphic
1885 : public integral_constant<bool, sizeof(__is_polymorphic_impl<_Tp>(0)) == 1> {};
1886
1887#endif // __has_feature(is_polymorphic)
1888
1889#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1890template <class _Tp>
1891_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_polymorphic_v
1892 = is_polymorphic<_Tp>::value;
1893#endif
1894
1895// has_virtual_destructor
1896
1897#if __has_feature(has_virtual_destructor)1 || defined(_LIBCPP_COMPILER_GCC)
1898
1899template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) has_virtual_destructor
1900 : public integral_constant<bool, __has_virtual_destructor(_Tp)> {};
1901
1902#else
1903
1904template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) has_virtual_destructor
1905 : public false_type {};
1906
1907#endif
1908
1909#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1910template <class _Tp>
1911_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool has_virtual_destructor_v
1912 = has_virtual_destructor<_Tp>::value;
1913#endif
1914
1915// has_unique_object_representations
1916
1917#if _LIBCPP_STD_VER14 > 14 && defined(_LIBCPP_HAS_UNIQUE_OBJECT_REPRESENTATIONS)
1918
1919template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) has_unique_object_representations
1920 : public integral_constant<bool,
1921 __has_unique_object_representations(remove_cv_t<remove_all_extents_t<_Tp>>)> {};
1922
1923#if !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1924template <class _Tp>
1925_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool has_unique_object_representations_v
1926 = has_unique_object_representations<_Tp>::value;
1927#endif
1928
1929#endif
1930
1931// alignment_of
1932
1933template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) alignment_of
1934 : public integral_constant<size_t, _LIBCPP_ALIGNOF(_Tp)alignof(_Tp)> {};
1935
1936#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
1937template <class _Tp>
1938_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr size_t alignment_of_v
1939 = alignment_of<_Tp>::value;
1940#endif
1941
1942// aligned_storage
1943
1944template <class _Hp, class _Tp>
1945struct __type_list
1946{
1947 typedef _Hp _Head;
1948 typedef _Tp _Tail;
1949};
1950
1951struct __nat
1952{
1953#ifndef _LIBCPP_CXX03_LANG
1954 __nat() = delete;
1955 __nat(const __nat&) = delete;
1956 __nat& operator=(const __nat&) = delete;
1957 ~__nat() = delete;
1958#endif
1959};
1960
1961template <class _Tp>
1962struct __align_type
1963{
1964 static const size_t value = _LIBCPP_PREFERRED_ALIGNOF(_Tp)__alignof(_Tp);
1965 typedef _Tp type;
1966};
1967
1968struct __struct_double {long double __lx;};
1969struct __struct_double4 {double __lx[4];};
1970
1971typedef
1972 __type_list<__align_type<unsigned char>,
1973 __type_list<__align_type<unsigned short>,
1974 __type_list<__align_type<unsigned int>,
1975 __type_list<__align_type<unsigned long>,
1976 __type_list<__align_type<unsigned long long>,
1977 __type_list<__align_type<double>,
1978 __type_list<__align_type<long double>,
1979 __type_list<__align_type<__struct_double>,
1980 __type_list<__align_type<__struct_double4>,
1981 __type_list<__align_type<int*>,
1982 __nat
1983 > > > > > > > > > > __all_types;
1984
1985template <size_t _Align>
1986struct _ALIGNAS(_Align)alignas(_Align) __fallback_overaligned {};
1987
1988template <class _TL, size_t _Align> struct __find_pod;
1989
1990template <class _Hp, size_t _Align>
1991struct __find_pod<__type_list<_Hp, __nat>, _Align>
1992{
1993 typedef typename conditional<
1994 _Align == _Hp::value,
1995 typename _Hp::type,
1996 __fallback_overaligned<_Align>
1997 >::type type;
1998};
1999
2000template <class _Hp, class _Tp, size_t _Align>
2001struct __find_pod<__type_list<_Hp, _Tp>, _Align>
2002{
2003 typedef typename conditional<
2004 _Align == _Hp::value,
2005 typename _Hp::type,
2006 typename __find_pod<_Tp, _Align>::type
2007 >::type type;
2008};
2009
2010template <class _TL, size_t _Len> struct __find_max_align;
2011
2012template <class _Hp, size_t _Len>
2013struct __find_max_align<__type_list<_Hp, __nat>, _Len> : public integral_constant<size_t, _Hp::value> {};
2014
2015template <size_t _Len, size_t _A1, size_t _A2>
2016struct __select_align
2017{
2018private:
2019 static const size_t __min = _A2 < _A1 ? _A2 : _A1;
2020 static const size_t __max = _A1 < _A2 ? _A2 : _A1;
2021public:
2022 static const size_t value = _Len < __max ? __min : __max;
2023};
2024
2025template <class _Hp, class _Tp, size_t _Len>
2026struct __find_max_align<__type_list<_Hp, _Tp>, _Len>
2027 : public integral_constant<size_t, __select_align<_Len, _Hp::value, __find_max_align<_Tp, _Len>::value>::value> {};
2028
2029template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value>
2030struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) aligned_storage
2031{
2032 typedef typename __find_pod<__all_types, _Align>::type _Aligner;
2033 union type
2034 {
2035 _Aligner __align;
2036 unsigned char __data[(_Len + _Align - 1)/_Align * _Align];
2037 };
2038};
2039
2040#if _LIBCPP_STD_VER14 > 11
2041template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value>
2042 using aligned_storage_t = typename aligned_storage<_Len, _Align>::type;
2043#endif
2044
2045#define _CREATE_ALIGNED_STORAGE_SPECIALIZATION(n) \
2046template <size_t _Len>\
2047struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) aligned_storage<_Len, n>\
2048{\
2049 struct _ALIGNAS(n)alignas(n) type\
2050 {\
2051 unsigned char __lx[(_Len + n - 1)/n * n];\
2052 };\
2053}
2054
2055_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1);
2056_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2);
2057_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4);
2058_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x8);
2059_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x10);
2060_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x20);
2061_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x40);
2062_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x80);
2063_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x100);
2064_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x200);
2065_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x400);
2066_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x800);
2067_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1000);
2068_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2000);
2069// PE/COFF does not support alignment beyond 8192 (=0x2000)
2070#if !defined(_LIBCPP_OBJECT_FORMAT_COFF)
2071_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4000);
2072#endif // !defined(_LIBCPP_OBJECT_FORMAT_COFF)
2073
2074#undef _CREATE_ALIGNED_STORAGE_SPECIALIZATION
2075
2076
2077// aligned_union
2078
2079template <size_t _I0, size_t ..._In>
2080struct __static_max;
2081
2082template <size_t _I0>
2083struct __static_max<_I0>
2084{
2085 static const size_t value = _I0;
2086};
2087
2088template <size_t _I0, size_t _I1, size_t ..._In>
2089struct __static_max<_I0, _I1, _In...>
2090{
2091 static const size_t value = _I0 >= _I1 ? __static_max<_I0, _In...>::value :
2092 __static_max<_I1, _In...>::value;
2093};
2094
2095template <size_t _Len, class _Type0, class ..._Types>
2096struct aligned_union
2097{
2098 static const size_t alignment_value = __static_max<_LIBCPP_PREFERRED_ALIGNOF(_Type0)__alignof(_Type0),
2099 _LIBCPP_PREFERRED_ALIGNOF(_Types)__alignof(_Types)...>::value;
2100 static const size_t __len = __static_max<_Len, sizeof(_Type0),
2101 sizeof(_Types)...>::value;
2102 typedef typename aligned_storage<__len, alignment_value>::type type;
2103};
2104
2105#if _LIBCPP_STD_VER14 > 11
2106template <size_t _Len, class ..._Types> using aligned_union_t = typename aligned_union<_Len, _Types...>::type;
2107#endif
2108
2109template <class _Tp>
2110struct __numeric_type
2111{
2112 static void __test(...);
2113 static float __test(float);
2114 static double __test(char);
2115 static double __test(int);
2116 static double __test(unsigned);
2117 static double __test(long);
2118 static double __test(unsigned long);
2119 static double __test(long long);
2120 static double __test(unsigned long long);
2121 static double __test(double);
2122 static long double __test(long double);
2123
2124 typedef decltype(__test(declval<_Tp>())) type;
2125 static const bool value = _IsNotSame<type, void>::value;
2126};
2127
2128template <>
2129struct __numeric_type<void>
2130{
2131 static const bool value = true;
2132};
2133
2134// __promote
2135
2136template <class _A1, class _A2 = void, class _A3 = void,
2137 bool = __numeric_type<_A1>::value &&
2138 __numeric_type<_A2>::value &&
2139 __numeric_type<_A3>::value>
2140class __promote_imp
2141{
2142public:
2143 static const bool value = false;
2144};
2145
2146template <class _A1, class _A2, class _A3>
2147class __promote_imp<_A1, _A2, _A3, true>
2148{
2149private:
2150 typedef typename __promote_imp<_A1>::type __type1;
2151 typedef typename __promote_imp<_A2>::type __type2;
2152 typedef typename __promote_imp<_A3>::type __type3;
2153public:
2154 typedef decltype(__type1() + __type2() + __type3()) type;
2155 static const bool value = true;
2156};
2157
2158template <class _A1, class _A2>
2159class __promote_imp<_A1, _A2, void, true>
2160{
2161private:
2162 typedef typename __promote_imp<_A1>::type __type1;
2163 typedef typename __promote_imp<_A2>::type __type2;
2164public:
2165 typedef decltype(__type1() + __type2()) type;
2166 static const bool value = true;
2167};
2168
2169template <class _A1>
2170class __promote_imp<_A1, void, void, true>
2171{
2172public:
2173 typedef typename __numeric_type<_A1>::type type;
2174 static const bool value = true;
2175};
2176
2177template <class _A1, class _A2 = void, class _A3 = void>
2178class __promote : public __promote_imp<_A1, _A2, _A3> {};
2179
2180// make_signed / make_unsigned
2181
2182typedef
2183 __type_list<signed char,
2184 __type_list<signed short,
2185 __type_list<signed int,
2186 __type_list<signed long,
2187 __type_list<signed long long,
2188#ifndef _LIBCPP_HAS_NO_INT128
2189 __type_list<__int128_t,
2190#endif
2191 __nat
2192#ifndef _LIBCPP_HAS_NO_INT128
2193 >
2194#endif
2195 > > > > > __signed_types;
2196
2197typedef
2198 __type_list<unsigned char,
2199 __type_list<unsigned short,
2200 __type_list<unsigned int,
2201 __type_list<unsigned long,
2202 __type_list<unsigned long long,
2203#ifndef _LIBCPP_HAS_NO_INT128
2204 __type_list<__uint128_t,
2205#endif
2206 __nat
2207#ifndef _LIBCPP_HAS_NO_INT128
2208 >
2209#endif
2210 > > > > > __unsigned_types;
2211
2212template <class _TypeList, size_t _Size, bool = _Size <= sizeof(typename _TypeList::_Head)> struct __find_first;
2213
2214template <class _Hp, class _Tp, size_t _Size>
2215struct __find_first<__type_list<_Hp, _Tp>, _Size, true>
2216{
2217 typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) _Hp type;
2218};
2219
2220template <class _Hp, class _Tp, size_t _Size>
2221struct __find_first<__type_list<_Hp, _Tp>, _Size, false>
2222{
2223 typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) typename __find_first<_Tp, _Size>::type type;
2224};
2225
2226template <class _Tp, class _Up, bool = is_const<typename remove_reference<_Tp>::type>::value,
2227 bool = is_volatile<typename remove_reference<_Tp>::type>::value>
2228struct __apply_cv
2229{
2230 typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) _Up type;
2231};
2232
2233template <class _Tp, class _Up>
2234struct __apply_cv<_Tp, _Up, true, false>
2235{
2236 typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) const _Up type;
2237};
2238
2239template <class _Tp, class _Up>
2240struct __apply_cv<_Tp, _Up, false, true>
2241{
2242 typedef volatile _Up type;
2243};
2244
2245template <class _Tp, class _Up>
2246struct __apply_cv<_Tp, _Up, true, true>
2247{
2248 typedef const volatile _Up type;
2249};
2250
2251template <class _Tp, class _Up>
2252struct __apply_cv<_Tp&, _Up, false, false>
2253{
2254 typedef _Up& type;
2255};
2256
2257template <class _Tp, class _Up>
2258struct __apply_cv<_Tp&, _Up, true, false>
2259{
2260 typedef const _Up& type;
2261};
2262
2263template <class _Tp, class _Up>
2264struct __apply_cv<_Tp&, _Up, false, true>
2265{
2266 typedef volatile _Up& type;
2267};
2268
2269template <class _Tp, class _Up>
2270struct __apply_cv<_Tp&, _Up, true, true>
2271{
2272 typedef const volatile _Up& type;
2273};
2274
2275template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
2276struct __make_signed {};
2277
2278template <class _Tp>
2279struct __make_signed<_Tp, true>
2280{
2281 typedef typename __find_first<__signed_types, sizeof(_Tp)>::type type;
2282};
2283
2284template <> struct __make_signed<bool, true> {};
2285template <> struct __make_signed< signed short, true> {typedef short type;};
2286template <> struct __make_signed<unsigned short, true> {typedef short type;};
2287template <> struct __make_signed< signed int, true> {typedef int type;};
2288template <> struct __make_signed<unsigned int, true> {typedef int type;};
2289template <> struct __make_signed< signed long, true> {typedef long type;};
2290template <> struct __make_signed<unsigned long, true> {typedef long type;};
2291template <> struct __make_signed< signed long long, true> {typedef long long type;};
2292template <> struct __make_signed<unsigned long long, true> {typedef long long type;};
2293#ifndef _LIBCPP_HAS_NO_INT128
2294template <> struct __make_signed<__int128_t, true> {typedef __int128_t type;};
2295template <> struct __make_signed<__uint128_t, true> {typedef __int128_t type;};
2296#endif
2297
2298template <class _Tp>
2299struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) make_signed
2300{
2301 typedef typename __apply_cv<_Tp, typename __make_signed<typename remove_cv<_Tp>::type>::type>::type type;
2302};
2303
2304#if _LIBCPP_STD_VER14 > 11
2305template <class _Tp> using make_signed_t = typename make_signed<_Tp>::type;
2306#endif
2307
2308template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
2309struct __make_unsigned {};
2310
2311template <class _Tp>
2312struct __make_unsigned<_Tp, true>
2313{
2314 typedef typename __find_first<__unsigned_types, sizeof(_Tp)>::type type;
2315};
2316
2317template <> struct __make_unsigned<bool, true> {};
2318template <> struct __make_unsigned< signed short, true> {typedef unsigned short type;};
2319template <> struct __make_unsigned<unsigned short, true> {typedef unsigned short type;};
2320template <> struct __make_unsigned< signed int, true> {typedef unsigned int type;};
2321template <> struct __make_unsigned<unsigned int, true> {typedef unsigned int type;};
2322template <> struct __make_unsigned< signed long, true> {typedef unsigned long type;};
2323template <> struct __make_unsigned<unsigned long, true> {typedef unsigned long type;};
2324template <> struct __make_unsigned< signed long long, true> {typedef unsigned long long type;};
2325template <> struct __make_unsigned<unsigned long long, true> {typedef unsigned long long type;};
2326#ifndef _LIBCPP_HAS_NO_INT128
2327template <> struct __make_unsigned<__int128_t, true> {typedef __uint128_t type;};
2328template <> struct __make_unsigned<__uint128_t, true> {typedef __uint128_t type;};
2329#endif
2330
2331template <class _Tp>
2332struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) make_unsigned
2333{
2334 typedef typename __apply_cv<_Tp, typename __make_unsigned<typename remove_cv<_Tp>::type>::type>::type type;
2335};
2336
2337#if _LIBCPP_STD_VER14 > 11
2338template <class _Tp> using make_unsigned_t = typename make_unsigned<_Tp>::type;
2339#endif
2340
2341#ifndef _LIBCPP_CXX03_LANG
2342template <class _Tp>
2343_LIBCPP_NODISCARD_ATTRIBUTE[[nodiscard]] _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
constexpr
2344typename make_unsigned<_Tp>::type __to_unsigned_like(_Tp __x) noexcept {
2345 return static_cast<typename make_unsigned<_Tp>::type>(__x);
2346}
2347#endif
2348
2349#if _LIBCPP_STD_VER14 > 14
2350template <class...> using void_t = void;
2351#endif
2352
2353#if _LIBCPP_STD_VER14 > 17
2354// Let COND_RES(X, Y) be:
2355template <class _Tp, class _Up>
2356using __cond_type = decltype(false ? declval<_Tp>() : declval<_Up>());
2357
2358template <class _Tp, class _Up, class = void>
2359struct __common_type3 {};
2360
2361// sub-bullet 4 - "if COND_RES(CREF(D1), CREF(D2)) denotes a type..."
2362template <class _Tp, class _Up>
2363struct __common_type3<_Tp, _Up, void_t<__cond_type<const _Tp&, const _Up&>>>
2364{
2365 using type = remove_cvref_t<__cond_type<const _Tp&, const _Up&>>;
2366};
2367
2368template <class _Tp, class _Up, class = void>
2369struct __common_type2_imp : __common_type3<_Tp, _Up> {};
2370#else
2371template <class _Tp, class _Up, class = void>
2372struct __common_type2_imp {};
2373#endif
2374
2375// sub-bullet 3 - "if decay_t<decltype(false ? declval<D1>() : declval<D2>())> ..."
2376template <class _Tp, class _Up>
2377struct __common_type2_imp<_Tp, _Up,
2378 typename __void_t<decltype(
2379 true ? declval<_Tp>() : declval<_Up>()
2380 )>::type>
2381{
2382 typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) typename decay<decltype(
2383 true ? declval<_Tp>() : declval<_Up>()
2384 )>::type type;
2385};
2386
2387template <class, class = void>
2388struct __common_type_impl {};
2389
2390// Clang provides variadic templates in C++03 as an extension.
2391#if !defined(_LIBCPP_CXX03_LANG) || defined(__clang__1)
2392# define _LIBCPP_OPTIONAL_PACK(...) , __VA_ARGS__
2393template <class... Tp>
2394struct __common_types;
2395template <class... _Tp>
2396struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) common_type;
2397#else
2398# define _LIBCPP_OPTIONAL_PACK(...)
2399struct __no_arg;
2400template <class _Tp, class _Up, class = __no_arg>
2401struct __common_types;
2402template <class _Tp = __no_arg, class _Up = __no_arg, class _Vp = __no_arg,
2403 class _Unused = __no_arg>
2404struct common_type {
2405 static_assert(sizeof(_Unused) == 0,
2406 "common_type accepts at most 3 arguments in C++03");
2407};
2408#endif // _LIBCPP_CXX03_LANG
2409
2410template <class _Tp, class _Up>
2411struct __common_type_impl<
2412 __common_types<_Tp, _Up>,
2413 typename __void_t<typename common_type<_Tp, _Up>::type>::type>
2414{
2415 typedef typename common_type<_Tp, _Up>::type type;
2416};
2417
2418template <class _Tp, class _Up, class _Vp _LIBCPP_OPTIONAL_PACK(class... _Rest)>
2419struct __common_type_impl<
2420 __common_types<_Tp, _Up, _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)>,
2421 typename __void_t<typename common_type<_Tp, _Up>::type>::type>
2422 : __common_type_impl<__common_types<typename common_type<_Tp, _Up>::type,
2423 _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)> > {
2424};
2425
2426// bullet 1 - sizeof...(Tp) == 0
2427
2428template <>
2429struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) common_type<> {};
2430
2431// bullet 2 - sizeof...(Tp) == 1
2432
2433template <class _Tp>
2434struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) common_type<_Tp>
2435 : public common_type<_Tp, _Tp> {};
2436
2437// bullet 3 - sizeof...(Tp) == 2
2438
2439// sub-bullet 1 - "If is_same_v<T1, D1> is false or ..."
2440template <class _Tp, class _Up>
2441struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) common_type<_Tp, _Up>
2442 : conditional<
2443 _IsSame<_Tp, typename decay<_Tp>::type>::value && _IsSame<_Up, typename decay<_Up>::type>::value,
2444 __common_type2_imp<_Tp, _Up>,
2445 common_type<typename decay<_Tp>::type, typename decay<_Up>::type>
2446 >::type
2447{};
2448
2449// bullet 4 - sizeof...(Tp) > 2
2450
2451template <class _Tp, class _Up, class _Vp _LIBCPP_OPTIONAL_PACK(class... _Rest)>
2452struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default")))
2453 common_type<_Tp, _Up, _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)>
2454 : __common_type_impl<
2455 __common_types<_Tp, _Up, _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)> > {};
2456
2457#undef _LIBCPP_OPTIONAL_PACK
2458
2459#if _LIBCPP_STD_VER14 > 11
2460template <class ..._Tp> using common_type_t = typename common_type<_Tp...>::type;
2461#endif
2462
2463#if _LIBCPP_STD_VER14 > 11
2464// Let COPYCV(FROM, TO) be an alias for type TO with the addition of FROM's
2465// top-level cv-qualifiers.
2466template <class _From, class _To>
2467struct __copy_cv
2468{
2469 using type = _To;
2470};
2471
2472template <class _From, class _To>
2473struct __copy_cv<const _From, _To>
2474{
2475 using type = add_const_t<_To>;
2476};
2477
2478template <class _From, class _To>
2479struct __copy_cv<volatile _From, _To>
2480{
2481 using type = add_volatile_t<_To>;
2482};
2483
2484template <class _From, class _To>
2485struct __copy_cv<const volatile _From, _To>
2486{
2487 using type = add_cv_t<_To>;
2488};
2489
2490template <class _From, class _To>
2491using __copy_cv_t = typename __copy_cv<_From, _To>::type;
2492
2493template <class _From, class _To>
2494struct __copy_cvref
2495{
2496 using type = __copy_cv_t<_From, _To>;
2497};
2498
2499template <class _From, class _To>
2500struct __copy_cvref<_From&, _To>
2501{
2502 using type = add_lvalue_reference_t<__copy_cv_t<_From, _To>>;
2503};
2504
2505template <class _From, class _To>
2506struct __copy_cvref<_From&&, _To>
2507{
2508 using type = add_rvalue_reference_t<__copy_cv_t<_From, _To>>;
2509};
2510
2511template <class _From, class _To>
2512using __copy_cvref_t = typename __copy_cvref<_From, _To>::type;
2513
2514#endif // _LIBCPP_STD_VER > 11
2515
2516// common_reference
2517#if _LIBCPP_STD_VER14 > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
2518// Let COND_RES(X, Y) be:
2519template <class _Xp, class _Yp>
2520using __cond_res =
2521 decltype(false ? declval<_Xp(&)()>()() : declval<_Yp(&)()>()());
2522
2523// Let `XREF(A)` denote a unary alias template `T` such that `T<U>` denotes the same type as `U`
2524// with the addition of `A`'s cv and reference qualifiers, for a non-reference cv-unqualified type
2525// `U`.
2526// [Note: `XREF(A)` is `__xref<A>::template __apply`]
2527template <class _Tp>
2528struct __xref {
2529 template<class _Up>
2530 using __apply = __copy_cvref_t<_Tp, _Up>;
2531};
2532
2533// Given types A and B, let X be remove_reference_t<A>, let Y be remove_reference_t<B>,
2534// and let COMMON-REF(A, B) be:
2535template<class _Ap, class _Bp, class _Xp = remove_reference_t<_Ap>, class _Yp = remove_reference_t<_Bp>>
2536struct __common_ref;
2537
2538template<class _Xp, class _Yp>
2539using __common_ref_t = typename __common_ref<_Xp, _Yp>::__type;
2540
2541template<class _Xp, class _Yp>
2542using __cv_cond_res = __cond_res<__copy_cv_t<_Xp, _Yp>&, __copy_cv_t<_Yp, _Xp>&>;
2543
2544
2545// If A and B are both lvalue reference types, COMMON-REF(A, B) is
2546// COND-RES(COPYCV(X, Y)&, COPYCV(Y, X)&) if that type exists and is a reference type.
2547template<class _Ap, class _Bp, class _Xp, class _Yp>
2548requires requires { typename __cv_cond_res<_Xp, _Yp>; } && is_reference_v<__cv_cond_res<_Xp, _Yp>>
2549struct __common_ref<_Ap&, _Bp&, _Xp, _Yp>
2550{
2551 using __type = __cv_cond_res<_Xp, _Yp>;
2552};
2553
2554// Otherwise, let C be remove_reference_t<COMMON-REF(X&, Y&)>&&. ...
2555template <class _Xp, class _Yp>
2556using __common_ref_C = remove_reference_t<__common_ref_t<_Xp&, _Yp&>>&&;
2557
2558
2559// .... If A and B are both rvalue reference types, C is well-formed, and
2560// is_convertible_v<A, C> && is_convertible_v<B, C> is true, then COMMON-REF(A, B) is C.
2561template<class _Ap, class _Bp, class _Xp, class _Yp>
2562requires
2563 requires { typename __common_ref_C<_Xp, _Yp>; } &&
2564 is_convertible_v<_Ap&&, __common_ref_C<_Xp, _Yp>> &&
2565 is_convertible_v<_Bp&&, __common_ref_C<_Xp, _Yp>>
2566struct __common_ref<_Ap&&, _Bp&&, _Xp, _Yp>
2567{
2568 using __type = __common_ref_C<_Xp, _Yp>;
2569};
2570
2571// Otherwise, let D be COMMON-REF(const X&, Y&). ...
2572template <class _Tp, class _Up>
2573using __common_ref_D = __common_ref_t<const _Tp&, _Up&>;
2574
2575// ... If A is an rvalue reference and B is an lvalue reference and D is well-formed and
2576// is_convertible_v<A, D> is true, then COMMON-REF(A, B) is D.
2577template<class _Ap, class _Bp, class _Xp, class _Yp>
2578requires requires { typename __common_ref_D<_Xp, _Yp>; } &&
2579 is_convertible_v<_Ap&&, __common_ref_D<_Xp, _Yp>>
2580struct __common_ref<_Ap&&, _Bp&, _Xp, _Yp>
2581{
2582 using __type = __common_ref_D<_Xp, _Yp>;
2583};
2584
2585// Otherwise, if A is an lvalue reference and B is an rvalue reference, then
2586// COMMON-REF(A, B) is COMMON-REF(B, A).
2587template<class _Ap, class _Bp, class _Xp, class _Yp>
2588struct __common_ref<_Ap&, _Bp&&, _Xp, _Yp> : __common_ref<_Bp&&, _Ap&> {};
2589
2590// Otherwise, COMMON-REF(A, B) is ill-formed.
2591template<class _Ap, class _Bp, class _Xp, class _Yp>
2592struct __common_ref {};
2593
2594// Note C: For the common_reference trait applied to a parameter pack [...]
2595
2596template <class...>
2597struct common_reference;
2598
2599template <class... _Types>
2600using common_reference_t = typename common_reference<_Types...>::type;
2601
2602// bullet 1 - sizeof...(T) == 0
2603template<>
2604struct common_reference<> {};
2605
2606// bullet 2 - sizeof...(T) == 1
2607template <class _Tp>
2608struct common_reference<_Tp>
2609{
2610 using type = _Tp;
2611};
2612
2613// bullet 3 - sizeof...(T) == 2
2614template <class _Tp, class _Up> struct __common_reference_sub_bullet3;
2615template <class _Tp, class _Up> struct __common_reference_sub_bullet2 : __common_reference_sub_bullet3<_Tp, _Up> {};
2616template <class _Tp, class _Up> struct __common_reference_sub_bullet1 : __common_reference_sub_bullet2<_Tp, _Up> {};
2617
2618// sub-bullet 1 - If T1 and T2 are reference types and COMMON-REF(T1, T2) is well-formed, then
2619// the member typedef `type` denotes that type.
2620template <class _Tp, class _Up> struct common_reference<_Tp, _Up> : __common_reference_sub_bullet1<_Tp, _Up> {};
2621
2622template <class _Tp, class _Up>
2623requires is_reference_v<_Tp> && is_reference_v<_Up> && requires { typename __common_ref_t<_Tp, _Up>; }
2624struct __common_reference_sub_bullet1<_Tp, _Up>
2625{
2626 using type = __common_ref_t<_Tp, _Up>;
2627};
2628
2629// sub-bullet 2 - Otherwise, if basic_common_reference<remove_cvref_t<T1>, remove_cvref_t<T2>, XREF(T1), XREF(T2)>::type
2630// is well-formed, then the member typedef `type` denotes that type.
2631template <class, class, template <class> class, template <class> class> struct basic_common_reference {};
2632
2633template <class _Tp, class _Up>
2634using __basic_common_reference_t = typename basic_common_reference<
2635 remove_cvref_t<_Tp>, remove_cvref_t<_Up>,
2636 __xref<_Tp>::template __apply, __xref<_Up>::template __apply>::type;
2637
2638template <class _Tp, class _Up>
2639requires requires { typename __basic_common_reference_t<_Tp, _Up>; }
2640struct __common_reference_sub_bullet2<_Tp, _Up>
2641{
2642 using type = __basic_common_reference_t<_Tp, _Up>;
2643};
2644
2645// sub-bullet 3 - Otherwise, if COND-RES(T1, T2) is well-formed,
2646// then the member typedef `type` denotes that type.
2647template <class _Tp, class _Up>
2648requires requires { typename __cond_res<_Tp, _Up>; }
2649struct __common_reference_sub_bullet3<_Tp, _Up>
2650{
2651 using type = __cond_res<_Tp, _Up>;
2652};
2653
2654
2655// sub-bullet 4 & 5 - Otherwise, if common_type_t<T1, T2> is well-formed,
2656// then the member typedef `type` denotes that type.
2657// - Otherwise, there shall be no member `type`.
2658template <class _Tp, class _Up> struct __common_reference_sub_bullet3 : common_type<_Tp, _Up> {};
2659
2660// bullet 4 - If there is such a type `C`, the member typedef type shall denote the same type, if
2661// any, as `common_reference_t<C, Rest...>`.
2662template <class _Tp, class _Up, class _Vp, class... _Rest>
2663requires requires { typename common_reference_t<_Tp, _Up>; }
2664struct common_reference<_Tp, _Up, _Vp, _Rest...>
2665 : common_reference<common_reference_t<_Tp, _Up>, _Vp, _Rest...>
2666{};
2667
2668// bullet 5 - Otherwise, there shall be no member `type`.
2669template <class...> struct common_reference {};
2670
2671#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
2672
2673// is_assignable
2674
2675template<typename, typename _Tp> struct __select_2nd { typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) _Tp type; };
2676
2677#if __has_keyword(__is_assignable)!(0)
2678
2679template<class _Tp, class _Up>
2680struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_assignable : _BoolConstant<__is_assignable(_Tp, _Up)> { };
2681
2682#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
2683template <class _Tp, class _Arg>
2684_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_assignable_v = __is_assignable(_Tp, _Arg);
2685#endif
2686
2687#else // __has_keyword(__is_assignable)
2688
2689template <class _Tp, class _Arg>
2690typename __select_2nd<decltype((declval<_Tp>() = declval<_Arg>())), true_type>::type
2691__is_assignable_test(int);
2692
2693template <class, class>
2694false_type __is_assignable_test(...);
2695
2696
2697template <class _Tp, class _Arg, bool = is_void<_Tp>::value || is_void<_Arg>::value>
2698struct __is_assignable_imp
2699 : public decltype((_VSTDstd::__1::__is_assignable_test<_Tp, _Arg>(0))) {};
2700
2701template <class _Tp, class _Arg>
2702struct __is_assignable_imp<_Tp, _Arg, true>
2703 : public false_type
2704{
2705};
2706
2707template <class _Tp, class _Arg>
2708struct is_assignable
2709 : public __is_assignable_imp<_Tp, _Arg> {};
2710
2711#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
2712template <class _Tp, class _Arg>
2713_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_assignable_v
2714 = is_assignable<_Tp, _Arg>::value;
2715#endif
2716
2717#endif // __has_keyword(__is_assignable)
2718
2719// is_copy_assignable
2720
2721template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_copy_assignable
2722 : public is_assignable<typename add_lvalue_reference<_Tp>::type,
2723 typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
2724
2725#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
2726template <class _Tp>
2727_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_copy_assignable_v
2728 = is_copy_assignable<_Tp>::value;
2729#endif
2730
2731// is_move_assignable
2732
2733template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_move_assignable
2734 : public is_assignable<typename add_lvalue_reference<_Tp>::type,
2735 typename add_rvalue_reference<_Tp>::type> {};
2736
2737#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
2738template <class _Tp>
2739_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_move_assignable_v
2740 = is_move_assignable<_Tp>::value;
2741#endif
2742
2743// is_destructible
2744
2745#if __has_keyword(__is_destructible)!(1)
2746
2747template<class _Tp>
2748struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_destructible : _BoolConstant<__is_destructible(_Tp)> { };
2749
2750#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
2751template <class _Tp>
2752_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_destructible_v = __is_destructible(_Tp);
2753#endif
2754
2755#else // __has_keyword(__is_destructible)
2756
2757// if it's a reference, return true
2758// if it's a function, return false
2759// if it's void, return false
2760// if it's an array of unknown bound, return false
2761// Otherwise, return "declval<_Up&>().~_Up()" is well-formed
2762// where _Up is remove_all_extents<_Tp>::type
2763
2764template <class>
2765struct __is_destructible_apply { typedef int type; };
2766
2767template <typename _Tp>
2768struct __is_destructor_wellformed {
2769 template <typename _Tp1>
2770 static char __test (
2771 typename __is_destructible_apply<decltype(declval<_Tp1&>().~_Tp1())>::type
2772 );
2773
2774 template <typename _Tp1>
2775 static __two __test (...);
2776
2777 static const bool value = sizeof(__test<_Tp>(12)) == sizeof(char);
2778};
2779
2780template <class _Tp, bool>
2781struct __destructible_imp;
2782
2783template <class _Tp>
2784struct __destructible_imp<_Tp, false>
2785 : public integral_constant<bool,
2786 __is_destructor_wellformed<typename remove_all_extents<_Tp>::type>::value> {};
2787
2788template <class _Tp>
2789struct __destructible_imp<_Tp, true>
2790 : public true_type {};
2791
2792template <class _Tp, bool>
2793struct __destructible_false;
2794
2795template <class _Tp>
2796struct __destructible_false<_Tp, false> : public __destructible_imp<_Tp, is_reference<_Tp>::value> {};
2797
2798template <class _Tp>
2799struct __destructible_false<_Tp, true> : public false_type {};
2800
2801template <class _Tp>
2802struct is_destructible
2803 : public __destructible_false<_Tp, is_function<_Tp>::value> {};
2804
2805template <class _Tp>
2806struct is_destructible<_Tp[]>
2807 : public false_type {};
2808
2809template <>
2810struct is_destructible<void>
2811 : public false_type {};
2812
2813#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
2814template <class _Tp>
2815_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_destructible_v
2816 = is_destructible<_Tp>::value;
2817#endif
2818
2819#endif // __has_keyword(__is_destructible)
2820
2821template <class _MP, bool _IsMemberFunctionPtr, bool _IsMemberObjectPtr>
2822struct __member_pointer_traits_imp
2823{
2824};
2825
2826template <class _Rp, class _Class, class ..._Param>
2827struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...), true, false>
2828{
2829 typedef _Class _ClassType;
2830 typedef _Rp _ReturnType;
2831 typedef _Rp (_FnType) (_Param...);
2832};
2833
2834template <class _Rp, class _Class, class ..._Param>
2835struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...), true, false>
2836{
2837 typedef _Class _ClassType;
2838 typedef _Rp _ReturnType;
2839 typedef _Rp (_FnType) (_Param..., ...);
2840};
2841
2842template <class _Rp, class _Class, class ..._Param>
2843struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const, true, false>
2844{
2845 typedef _Class const _ClassType;
2846 typedef _Rp _ReturnType;
2847 typedef _Rp (_FnType) (_Param...);
2848};
2849
2850template <class _Rp, class _Class, class ..._Param>
2851struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const, true, false>
2852{
2853 typedef _Class const _ClassType;
2854 typedef _Rp _ReturnType;
2855 typedef _Rp (_FnType) (_Param..., ...);
2856};
2857
2858template <class _Rp, class _Class, class ..._Param>
2859struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile, true, false>
2860{
2861 typedef _Class volatile _ClassType;
2862 typedef _Rp _ReturnType;
2863 typedef _Rp (_FnType) (_Param...);
2864};
2865
2866template <class _Rp, class _Class, class ..._Param>
2867struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) volatile, true, false>
2868{
2869 typedef _Class volatile _ClassType;
2870 typedef _Rp _ReturnType;
2871 typedef _Rp (_FnType) (_Param..., ...);
2872};
2873
2874template <class _Rp, class _Class, class ..._Param>
2875struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile, true, false>
2876{
2877 typedef _Class const volatile _ClassType;
2878 typedef _Rp _ReturnType;
2879 typedef _Rp (_FnType) (_Param...);
2880};
2881
2882template <class _Rp, class _Class, class ..._Param>
2883struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatile, true, false>
2884{
2885 typedef _Class const volatile _ClassType;
2886 typedef _Rp _ReturnType;
2887 typedef _Rp (_FnType) (_Param..., ...);
2888};
2889
2890#if __has_feature(cxx_reference_qualified_functions)1 || defined(_LIBCPP_COMPILER_GCC)
2891
2892template <class _Rp, class _Class, class ..._Param>
2893struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) &, true, false>
2894{
2895 typedef _Class& _ClassType;
2896 typedef _Rp _ReturnType;
2897 typedef _Rp (_FnType) (_Param...);
2898};
2899
2900template <class _Rp, class _Class, class ..._Param>
2901struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) &, true, false>
2902{
2903 typedef _Class& _ClassType;
2904 typedef _Rp _ReturnType;
2905 typedef _Rp (_FnType) (_Param..., ...);
2906};
2907
2908template <class _Rp, class _Class, class ..._Param>
2909struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const&, true, false>
2910{
2911 typedef _Class const& _ClassType;
2912 typedef _Rp _ReturnType;
2913 typedef _Rp (_FnType) (_Param...);
2914};
2915
2916template <class _Rp, class _Class, class ..._Param>
2917struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const&, true, false>
2918{
2919 typedef _Class const& _ClassType;
2920 typedef _Rp _ReturnType;
2921 typedef _Rp (_FnType) (_Param..., ...);
2922};
2923
2924template <class _Rp, class _Class, class ..._Param>
2925struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile&, true, false>
2926{
2927 typedef _Class volatile& _ClassType;
2928 typedef _Rp _ReturnType;
2929 typedef _Rp (_FnType) (_Param...);
2930};
2931
2932template <class _Rp, class _Class, class ..._Param>
2933struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) volatile&, true, false>
2934{
2935 typedef _Class volatile& _ClassType;
2936 typedef _Rp _ReturnType;
2937 typedef _Rp (_FnType) (_Param..., ...);
2938};
2939
2940template <class _Rp, class _Class, class ..._Param>
2941struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile&, true, false>
2942{
2943 typedef _Class const volatile& _ClassType;
2944 typedef _Rp _ReturnType;
2945 typedef _Rp (_FnType) (_Param...);
2946};
2947
2948template <class _Rp, class _Class, class ..._Param>
2949struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatile&, true, false>
2950{
2951 typedef _Class const volatile& _ClassType;
2952 typedef _Rp _ReturnType;
2953 typedef _Rp (_FnType) (_Param..., ...);
2954};
2955
2956template <class _Rp, class _Class, class ..._Param>
2957struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) &&, true, false>
2958{
2959 typedef _Class&& _ClassType;
2960 typedef _Rp _ReturnType;
2961 typedef _Rp (_FnType) (_Param...);
2962};
2963
2964template <class _Rp, class _Class, class ..._Param>
2965struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) &&, true, false>
2966{
2967 typedef _Class&& _ClassType;
2968 typedef _Rp _ReturnType;
2969 typedef _Rp (_FnType) (_Param..., ...);
2970};
2971
2972template <class _Rp, class _Class, class ..._Param>
2973struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const&&, true, false>
2974{
2975 typedef _Class const&& _ClassType;
2976 typedef _Rp _ReturnType;
2977 typedef _Rp (_FnType) (_Param...);
2978};
2979
2980template <class _Rp, class _Class, class ..._Param>
2981struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const&&, true, false>
2982{
2983 typedef _Class const&& _ClassType;
2984 typedef _Rp _ReturnType;
2985 typedef _Rp (_FnType) (_Param..., ...);
2986};
2987
2988template <class _Rp, class _Class, class ..._Param>
2989struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile&&, true, false>
2990{
2991 typedef _Class volatile&& _ClassType;
2992 typedef _Rp _ReturnType;
2993 typedef _Rp (_FnType) (_Param...);
2994};
2995
2996template <class _Rp, class _Class, class ..._Param>
2997struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) volatile&&, true, false>
2998{
2999 typedef _Class volatile&& _ClassType;
3000 typedef _Rp _ReturnType;
3001 typedef _Rp (_FnType) (_Param..., ...);
3002};
3003
3004template <class _Rp, class _Class, class ..._Param>
3005struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile&&, true, false>
3006{
3007 typedef _Class const volatile&& _ClassType;
3008 typedef _Rp _ReturnType;
3009 typedef _Rp (_FnType) (_Param...);
3010};
3011
3012template <class _Rp, class _Class, class ..._Param>
3013struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatile&&, true, false>
3014{
3015 typedef _Class const volatile&& _ClassType;
3016 typedef _Rp _ReturnType;
3017 typedef _Rp (_FnType) (_Param..., ...);
3018};
3019
3020#endif // __has_feature(cxx_reference_qualified_functions) || defined(_LIBCPP_COMPILER_GCC)
3021
3022
3023template <class _Rp, class _Class>
3024struct __member_pointer_traits_imp<_Rp _Class::*, false, true>
3025{
3026 typedef _Class _ClassType;
3027 typedef _Rp _ReturnType;
3028};
3029
3030template <class _MP>
3031struct __member_pointer_traits
3032 : public __member_pointer_traits_imp<typename remove_cv<_MP>::type,
3033 is_member_function_pointer<_MP>::value,
3034 is_member_object_pointer<_MP>::value>
3035{
3036// typedef ... _ClassType;
3037// typedef ... _ReturnType;
3038// typedef ... _FnType;
3039};
3040
3041
3042template <class _DecayedFp>
3043struct __member_pointer_class_type {};
3044
3045template <class _Ret, class _ClassType>
3046struct __member_pointer_class_type<_Ret _ClassType::*> {
3047 typedef _ClassType type;
3048};
3049
3050// template <class T, class... Args> struct is_constructible;
3051
3052#if defined(_LIBCPP_COMPILER_GCC) && _GNUC_VER_NEW((4 * 100 + 2) * 10 + 1) >= 10000
3053# define _LIBCPP_GCC_SUPPORTS_IS_CONSTRUCTIBLE
3054#endif
3055
3056#if !defined(_LIBCPP_CXX03_LANG) && !__has_feature(is_constructible)1 && !defined(_LIBCPP_GCC_SUPPORTS_IS_CONSTRUCTIBLE)
3057
3058template <class _Tp, class... _Args>
3059struct __libcpp_is_constructible;
3060
3061template <class _To, class _From>
3062struct __is_invalid_base_to_derived_cast {
3063 static_assert(is_reference<_To>::value, "Wrong specialization");
3064 using _RawFrom = __uncvref_t<_From>;
3065 using _RawTo = __uncvref_t<_To>;
3066 static const bool value = _And<
3067 _IsNotSame<_RawFrom, _RawTo>,
3068 is_base_of<_RawFrom, _RawTo>,
3069 _Not<__libcpp_is_constructible<_RawTo, _From>>
3070 >::value;
3071};
3072
3073template <class _To, class _From>
3074struct __is_invalid_lvalue_to_rvalue_cast : false_type {
3075 static_assert(is_reference<_To>::value, "Wrong specialization");
3076};
3077
3078template <class _ToRef, class _FromRef>
3079struct __is_invalid_lvalue_to_rvalue_cast<_ToRef&&, _FromRef&> {
3080 using _RawFrom = __uncvref_t<_FromRef>;
3081 using _RawTo = __uncvref_t<_ToRef>;
3082 static const bool value = _And<
3083 _Not<is_function<_RawTo>>,
3084 _Or<
3085 _IsSame<_RawFrom, _RawTo>,
3086 is_base_of<_RawTo, _RawFrom>>
3087 >::value;
3088};
3089
3090struct __is_constructible_helper
3091{
3092 template <class _To>
3093 static void __eat(_To);
3094
3095 // This overload is needed to work around a Clang bug that disallows
3096 // static_cast<T&&>(e) for non-reference-compatible types.
3097 // Example: static_cast<int&&>(declval<double>());
3098 // NOTE: The static_cast implementation below is required to support
3099 // classes with explicit conversion operators.
3100 template <class _To, class _From,
3101 class = decltype(__eat<_To>(declval<_From>()))>
3102 static true_type __test_cast(int);
3103
3104 template <class _To, class _From,
3105 class = decltype(static_cast<_To>(declval<_From>()))>
3106 static integral_constant<bool,
3107 !__is_invalid_base_to_derived_cast<_To, _From>::value &&
3108 !__is_invalid_lvalue_to_rvalue_cast<_To, _From>::value
3109 > __test_cast(long);
3110
3111 template <class, class>
3112 static false_type __test_cast(...);
3113
3114 template <class _Tp, class ..._Args,
3115 class = decltype(_Tp(declval<_Args>()...))>
3116 static true_type __test_nary(int);
3117 template <class _Tp, class...>
3118 static false_type __test_nary(...);
3119
3120 template <class _Tp, class _A0, class = decltype(::new _Tp(declval<_A0>()))>
3121 static is_destructible<_Tp> __test_unary(int);
3122 template <class, class>
3123 static false_type __test_unary(...);
3124};
3125
3126template <class _Tp, bool = is_void<_Tp>::value>
3127struct __is_default_constructible
3128 : decltype(__is_constructible_helper::__test_nary<_Tp>(0))
3129{};
3130
3131template <class _Tp>
3132struct __is_default_constructible<_Tp, true> : false_type {};
3133
3134template <class _Tp>
3135struct __is_default_constructible<_Tp[], false> : false_type {};
3136
3137template <class _Tp, size_t _Nx>
3138struct __is_default_constructible<_Tp[_Nx], false>
3139 : __is_default_constructible<typename remove_all_extents<_Tp>::type> {};
3140
3141template <class _Tp, class... _Args>
3142struct __libcpp_is_constructible
3143{
3144 static_assert(sizeof...(_Args) > 1, "Wrong specialization");
3145 typedef decltype(__is_constructible_helper::__test_nary<_Tp, _Args...>(0))
3146 type;
3147};
3148
3149template <class _Tp>
3150struct __libcpp_is_constructible<_Tp> : __is_default_constructible<_Tp> {};
3151
3152template <class _Tp, class _A0>
3153struct __libcpp_is_constructible<_Tp, _A0>
3154 : public decltype(__is_constructible_helper::__test_unary<_Tp, _A0>(0))
3155{};
3156
3157template <class _Tp, class _A0>
3158struct __libcpp_is_constructible<_Tp&, _A0>
3159 : public decltype(__is_constructible_helper::
3160 __test_cast<_Tp&, _A0>(0))
3161{};
3162
3163template <class _Tp, class _A0>
3164struct __libcpp_is_constructible<_Tp&&, _A0>
3165 : public decltype(__is_constructible_helper::
3166 __test_cast<_Tp&&, _A0>(0))
3167{};
3168
3169#endif
3170
3171#if __has_feature(is_constructible)1 || defined(_LIBCPP_GCC_SUPPORTS_IS_CONSTRUCTIBLE)
3172template <class _Tp, class ..._Args>
3173struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_constructible
3174 : public integral_constant<bool, __is_constructible(_Tp, _Args...)>
3175 {};
3176#else
3177template <class _Tp, class... _Args>
3178struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_constructible
3179 : public __libcpp_is_constructible<_Tp, _Args...>::type {};
3180#endif
3181
3182#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3183template <class _Tp, class ..._Args>
3184_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_constructible_v
3185 = is_constructible<_Tp, _Args...>::value;
3186#endif
3187
3188// is_default_constructible
3189
3190template <class _Tp>
3191struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_default_constructible
3192 : public is_constructible<_Tp>
3193 {};
3194
3195#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3196template <class _Tp>
3197_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_default_constructible_v
3198 = is_default_constructible<_Tp>::value;
3199#endif
3200
3201#ifndef _LIBCPP_CXX03_LANG
3202// First of all, we can't implement this check in C++03 mode because the {}
3203// default initialization syntax isn't valid.
3204// Second, we implement the trait in a funny manner with two defaulted template
3205// arguments to workaround Clang's PR43454.
3206template <class _Tp>
3207void __test_implicit_default_constructible(_Tp);
3208
3209template <class _Tp, class = void, class = typename is_default_constructible<_Tp>::type>
3210struct __is_implicitly_default_constructible
3211 : false_type
3212{ };
3213
3214template <class _Tp>
3215struct __is_implicitly_default_constructible<_Tp, decltype(__test_implicit_default_constructible<_Tp const&>({})), true_type>
3216 : true_type
3217{ };
3218
3219template <class _Tp>
3220struct __is_implicitly_default_constructible<_Tp, decltype(__test_implicit_default_constructible<_Tp const&>({})), false_type>
3221 : false_type
3222{ };
3223#endif // !C++03
3224
3225// is_copy_constructible
3226
3227template <class _Tp>
3228struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_copy_constructible
3229 : public is_constructible<_Tp,
3230 typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
3231
3232#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3233template <class _Tp>
3234_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_copy_constructible_v
3235 = is_copy_constructible<_Tp>::value;
3236#endif
3237
3238// is_move_constructible
3239
3240template <class _Tp>
3241struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_move_constructible
3242 : public is_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
3243 {};
3244
3245#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3246template <class _Tp>
3247_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_move_constructible_v
3248 = is_move_constructible<_Tp>::value;
3249#endif
3250
3251// is_trivially_constructible
3252
3253#if __has_feature(is_trivially_constructible)1 || _GNUC_VER(4 * 100 + 2) >= 501
3254
3255template <class _Tp, class... _Args>
3256struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_trivially_constructible
3257 : integral_constant<bool, __is_trivially_constructible(_Tp, _Args...)>
3258{
3259};
3260
3261#else // !__has_feature(is_trivially_constructible)
3262
3263template <class _Tp, class... _Args>
3264struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_trivially_constructible
3265 : false_type
3266{
3267};
3268
3269template <class _Tp>
3270struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_trivially_constructible<_Tp>
3271#if __has_feature(has_trivial_constructor)1 || defined(_LIBCPP_COMPILER_GCC)
3272 : integral_constant<bool, __has_trivial_constructor(_Tp)>
3273#else
3274 : integral_constant<bool, is_scalar<_Tp>::value>
3275#endif
3276{
3277};
3278
3279template <class _Tp>
3280struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_trivially_constructible<_Tp, _Tp&&>
3281 : integral_constant<bool, is_scalar<_Tp>::value>
3282{
3283};
3284
3285template <class _Tp>
3286struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_trivially_constructible<_Tp, const _Tp&>
3287 : integral_constant<bool, is_scalar<_Tp>::value>
3288{
3289};
3290
3291template <class _Tp>
3292struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_trivially_constructible<_Tp, _Tp&>
3293 : integral_constant<bool, is_scalar<_Tp>::value>
3294{
3295};
3296
3297#endif // !__has_feature(is_trivially_constructible)
3298
3299
3300#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3301template <class _Tp, class... _Args>
3302_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_trivially_constructible_v
3303 = is_trivially_constructible<_Tp, _Args...>::value;
3304#endif
3305
3306// is_trivially_default_constructible
3307
3308template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_trivially_default_constructible
3309 : public is_trivially_constructible<_Tp>
3310 {};
3311
3312#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3313template <class _Tp>
3314_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_trivially_default_constructible_v
3315 = is_trivially_default_constructible<_Tp>::value;
3316#endif
3317
3318// is_trivially_copy_constructible
3319
3320template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_trivially_copy_constructible
3321 : public is_trivially_constructible<_Tp, typename add_lvalue_reference<const _Tp>::type>
3322 {};
3323
3324#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3325template <class _Tp>
3326_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_trivially_copy_constructible_v
3327 = is_trivially_copy_constructible<_Tp>::value;
3328#endif
3329
3330// is_trivially_move_constructible
3331
3332template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_trivially_move_constructible
3333 : public is_trivially_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
3334 {};
3335
3336#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3337template <class _Tp>
3338_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_trivially_move_constructible_v
3339 = is_trivially_move_constructible<_Tp>::value;
3340#endif
3341
3342// is_trivially_assignable
3343
3344#if __has_feature(is_trivially_assignable)1 || _GNUC_VER(4 * 100 + 2) >= 501
3345
3346template <class _Tp, class _Arg>
3347struct is_trivially_assignable
3348 : integral_constant<bool, __is_trivially_assignable(_Tp, _Arg)>
3349{
3350};
3351
3352#else // !__has_feature(is_trivially_assignable)
3353
3354template <class _Tp, class _Arg>
3355struct is_trivially_assignable
3356 : public false_type {};
3357
3358template <class _Tp>
3359struct is_trivially_assignable<_Tp&, _Tp>
3360 : integral_constant<bool, is_scalar<_Tp>::value> {};
3361
3362template <class _Tp>
3363struct is_trivially_assignable<_Tp&, _Tp&>
3364 : integral_constant<bool, is_scalar<_Tp>::value> {};
3365
3366template <class _Tp>
3367struct is_trivially_assignable<_Tp&, const _Tp&>
3368 : integral_constant<bool, is_scalar<_Tp>::value> {};
3369
3370template <class _Tp>
3371struct is_trivially_assignable<_Tp&, _Tp&&>
3372 : integral_constant<bool, is_scalar<_Tp>::value> {};
3373
3374#endif // !__has_feature(is_trivially_assignable)
3375
3376#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3377template <class _Tp, class _Arg>
3378_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_trivially_assignable_v
3379 = is_trivially_assignable<_Tp, _Arg>::value;
3380#endif
3381
3382// is_trivially_copy_assignable
3383
3384template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_trivially_copy_assignable
3385 : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
3386 typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
3387
3388#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3389template <class _Tp>
3390_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_trivially_copy_assignable_v
3391 = is_trivially_copy_assignable<_Tp>::value;
3392#endif
3393
3394// is_trivially_move_assignable
3395
3396template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_trivially_move_assignable
3397 : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
3398 typename add_rvalue_reference<_Tp>::type>
3399 {};
3400
3401#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3402template <class _Tp>
3403_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_trivially_move_assignable_v
3404 = is_trivially_move_assignable<_Tp>::value;
3405#endif
3406
3407// is_trivially_destructible
3408
3409#if __has_keyword(__is_trivially_destructible)!(0)
3410
3411template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_trivially_destructible
3412 : public integral_constant<bool, __is_trivially_destructible(_Tp)> {};
3413
3414#elif __has_feature(has_trivial_destructor)1 || defined(_LIBCPP_COMPILER_GCC)
3415
3416template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_trivially_destructible
3417 : public integral_constant<bool, is_destructible<_Tp>::value && __has_trivial_destructor(_Tp)> {};
3418
3419#else
3420
3421template <class _Tp> struct __libcpp_trivial_destructor
3422 : public integral_constant<bool, is_scalar<_Tp>::value ||
3423 is_reference<_Tp>::value> {};
3424
3425template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_trivially_destructible
3426 : public __libcpp_trivial_destructor<typename remove_all_extents<_Tp>::type> {};
3427
3428template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_trivially_destructible<_Tp[]>
3429 : public false_type {};
3430
3431#endif
3432
3433#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3434template <class _Tp>
3435_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_trivially_destructible_v
3436 = is_trivially_destructible<_Tp>::value;
3437#endif
3438
3439// is_nothrow_constructible
3440
3441#if __has_keyword(__is_nothrow_constructible)!(0)
3442
3443template <class _Tp, class... _Args>
3444struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_nothrow_constructible
3445 : public integral_constant<bool, __is_nothrow_constructible(_Tp, _Args...)> {};
3446
3447#else
3448
3449template <bool, bool, class _Tp, class... _Args> struct __libcpp_is_nothrow_constructible;
3450
3451template <class _Tp, class... _Args>
3452struct __libcpp_is_nothrow_constructible</*is constructible*/true, /*is reference*/false, _Tp, _Args...>
3453 : public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))>
3454{
3455};
3456
3457template <class _Tp>
3458void __implicit_conversion_to(_Tp) noexcept { }
3459
3460template <class _Tp, class _Arg>
3461struct __libcpp_is_nothrow_constructible</*is constructible*/true, /*is reference*/true, _Tp, _Arg>
3462 : public integral_constant<bool, noexcept(_VSTDstd::__1::__implicit_conversion_to<_Tp>(declval<_Arg>()))>
3463{
3464};
3465
3466template <class _Tp, bool _IsReference, class... _Args>
3467struct __libcpp_is_nothrow_constructible</*is constructible*/false, _IsReference, _Tp, _Args...>
3468 : public false_type
3469{
3470};
3471
3472template <class _Tp, class... _Args>
3473struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_nothrow_constructible
3474 : __libcpp_is_nothrow_constructible<is_constructible<_Tp, _Args...>::value, is_reference<_Tp>::value, _Tp, _Args...>
3475{
3476};
3477
3478template <class _Tp, size_t _Ns>
3479struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_nothrow_constructible<_Tp[_Ns]>
3480 : __libcpp_is_nothrow_constructible<is_constructible<_Tp>::value, is_reference<_Tp>::value, _Tp>
3481{
3482};
3483
3484#endif // _LIBCPP_HAS_NO_NOEXCEPT
3485
3486
3487#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3488template <class _Tp, class ..._Args>
3489_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_nothrow_constructible_v
3490 = is_nothrow_constructible<_Tp, _Args...>::value;
3491#endif
3492
3493// is_nothrow_default_constructible
3494
3495template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_nothrow_default_constructible
3496 : public is_nothrow_constructible<_Tp>
3497 {};
3498
3499#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3500template <class _Tp>
3501_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_nothrow_default_constructible_v
3502 = is_nothrow_default_constructible<_Tp>::value;
3503#endif
3504
3505// is_nothrow_copy_constructible
3506
3507template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_nothrow_copy_constructible
3508 : public is_nothrow_constructible<_Tp,
3509 typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
3510
3511#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3512template <class _Tp>
3513_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_nothrow_copy_constructible_v
3514 = is_nothrow_copy_constructible<_Tp>::value;
3515#endif
3516
3517// is_nothrow_move_constructible
3518
3519template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_nothrow_move_constructible
3520 : public is_nothrow_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
3521 {};
3522
3523#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3524template <class _Tp>
3525_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_nothrow_move_constructible_v
3526 = is_nothrow_move_constructible<_Tp>::value;
3527#endif
3528
3529// is_nothrow_assignable
3530
3531#if __has_keyword(__is_nothrow_assignable)!(0)
3532
3533template <class _Tp, class _Arg>
3534struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_nothrow_assignable
3535 : public integral_constant<bool, __is_nothrow_assignable(_Tp, _Arg)> {};
3536
3537#else
3538
3539template <bool, class _Tp, class _Arg> struct __libcpp_is_nothrow_assignable;
3540
3541template <class _Tp, class _Arg>
3542struct __libcpp_is_nothrow_assignable<false, _Tp, _Arg>
3543 : public false_type
3544{
3545};
3546
3547template <class _Tp, class _Arg>
3548struct __libcpp_is_nothrow_assignable<true, _Tp, _Arg>
3549 : public integral_constant<bool, noexcept(declval<_Tp>() = declval<_Arg>()) >
3550{
3551};
3552
3553template <class _Tp, class _Arg>
3554struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_nothrow_assignable
3555 : public __libcpp_is_nothrow_assignable<is_assignable<_Tp, _Arg>::value, _Tp, _Arg>
3556{
3557};
3558
3559#endif // _LIBCPP_HAS_NO_NOEXCEPT
3560
3561#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3562template <class _Tp, class _Arg>
3563_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_nothrow_assignable_v
3564 = is_nothrow_assignable<_Tp, _Arg>::value;
3565#endif
3566
3567// is_nothrow_copy_assignable
3568
3569template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_nothrow_copy_assignable
3570 : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
3571 typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
3572
3573#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3574template <class _Tp>
3575_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_nothrow_copy_assignable_v
3576 = is_nothrow_copy_assignable<_Tp>::value;
3577#endif
3578
3579// is_nothrow_move_assignable
3580
3581template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_nothrow_move_assignable
3582 : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
3583 typename add_rvalue_reference<_Tp>::type>
3584 {};
3585
3586#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3587template <class _Tp>
3588_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_nothrow_move_assignable_v
3589 = is_nothrow_move_assignable<_Tp>::value;
3590#endif
3591
3592// is_nothrow_destructible
3593
3594#if !defined(_LIBCPP_CXX03_LANG)
3595
3596template <bool, class _Tp> struct __libcpp_is_nothrow_destructible;
3597
3598template <class _Tp>
3599struct __libcpp_is_nothrow_destructible<false, _Tp>
3600 : public false_type
3601{
3602};
3603
3604template <class _Tp>
3605struct __libcpp_is_nothrow_destructible<true, _Tp>
3606 : public integral_constant<bool, noexcept(declval<_Tp>().~_Tp()) >
3607{
3608};
3609
3610template <class _Tp>
3611struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_nothrow_destructible
3612 : public __libcpp_is_nothrow_destructible<is_destructible<_Tp>::value, _Tp>
3613{
3614};
3615
3616template <class _Tp, size_t _Ns>
3617struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_nothrow_destructible<_Tp[_Ns]>
3618 : public is_nothrow_destructible<_Tp>
3619{
3620};
3621
3622template <class _Tp>
3623struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_nothrow_destructible<_Tp&>
3624 : public true_type
3625{
3626};
3627
3628template <class _Tp>
3629struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_nothrow_destructible<_Tp&&>
3630 : public true_type
3631{
3632};
3633
3634#else
3635
3636template <class _Tp> struct __libcpp_nothrow_destructor
3637 : public integral_constant<bool, is_scalar<_Tp>::value ||
3638 is_reference<_Tp>::value> {};
3639
3640template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_nothrow_destructible
3641 : public __libcpp_nothrow_destructor<typename remove_all_extents<_Tp>::type> {};
3642
3643template <class _Tp>
3644struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_nothrow_destructible<_Tp[]>
3645 : public false_type {};
3646
3647#endif
3648
3649#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3650template <class _Tp>
3651_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_nothrow_destructible_v
3652 = is_nothrow_destructible<_Tp>::value;
3653#endif
3654
3655// is_pod
3656
3657#if __has_feature(is_pod)1 || defined(_LIBCPP_COMPILER_GCC)
3658
3659template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_pod
3660 : public integral_constant<bool, __is_pod(_Tp)> {};
3661
3662#else
3663
3664template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_pod
3665 : public integral_constant<bool, is_trivially_default_constructible<_Tp>::value &&
3666 is_trivially_copy_constructible<_Tp>::value &&
3667 is_trivially_copy_assignable<_Tp>::value &&
3668 is_trivially_destructible<_Tp>::value> {};
3669
3670#endif
3671
3672#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3673template <class _Tp>
3674_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_pod_v
3675 = is_pod<_Tp>::value;
3676#endif
3677
3678// is_literal_type;
3679
3680#if _LIBCPP_STD_VER14 <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS)
3681template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) _LIBCPP_DEPRECATED_IN_CXX17 is_literal_type
3682 : public integral_constant<bool, __is_literal_type(_Tp)>
3683 {};
3684
3685#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3686template <class _Tp>
3687_LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_literal_type_v
3688 = is_literal_type<_Tp>::value;
3689#endif // _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3690#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS)
3691
3692// is_standard_layout;
3693
3694template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_standard_layout
3695#if __has_feature(is_standard_layout)1 || defined(_LIBCPP_COMPILER_GCC)
3696 : public integral_constant<bool, __is_standard_layout(_Tp)>
3697#else
3698 : integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value>
3699#endif
3700 {};
3701
3702#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3703template <class _Tp>
3704_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_standard_layout_v
3705 = is_standard_layout<_Tp>::value;
3706#endif
3707
3708// is_trivially_copyable;
3709
3710template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_trivially_copyable
3711#if __has_feature(is_trivially_copyable)1
3712 : public integral_constant<bool, __is_trivially_copyable(_Tp)>
3713#elif _GNUC_VER(4 * 100 + 2) >= 501
3714 : public integral_constant<bool, !is_volatile<_Tp>::value && __is_trivially_copyable(_Tp)>
3715#else
3716 : integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value>
3717#endif
3718 {};
3719
3720#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3721template <class _Tp>
3722_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_trivially_copyable_v
3723 = is_trivially_copyable<_Tp>::value;
3724#endif
3725
3726// is_trivial;
3727
3728template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_trivial
3729#if __has_feature(is_trivial)1 || defined(_LIBCPP_COMPILER_GCC)
3730 : public integral_constant<bool, __is_trivial(_Tp)>
3731#else
3732 : integral_constant<bool, is_trivially_copyable<_Tp>::value &&
3733 is_trivially_default_constructible<_Tp>::value>
3734#endif
3735 {};
3736
3737#if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
3738template <class _Tp>
3739_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_trivial_v
3740 = is_trivial<_Tp>::value;
3741#endif
3742
3743template <class _Tp> struct __is_reference_wrapper_impl : public false_type {};
3744template <class _Tp> struct __is_reference_wrapper_impl<reference_wrapper<_Tp> > : public true_type {};
3745template <class _Tp> struct __is_reference_wrapper
3746 : public __is_reference_wrapper_impl<typename remove_cv<_Tp>::type> {};
3747
3748#ifndef _LIBCPP_CXX03_LANG
3749
3750template <class _Fp, class _A0,
3751 class _DecayFp = typename decay<_Fp>::type,
3752 class _DecayA0 = typename decay<_A0>::type,
3753 class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
3754using __enable_if_bullet1 = typename enable_if
3755 <
3756 is_member_function_pointer<_DecayFp>::value
3757 && is_base_of<_ClassT, _DecayA0>::value
3758 >::type;
3759
3760template <class _Fp, class _A0,
3761 class _DecayFp = typename decay<_Fp>::type,
3762 class _DecayA0 = typename decay<_A0>::type>
3763using __enable_if_bullet2 = typename enable_if
3764 <
3765 is_member_function_pointer<_DecayFp>::value
3766 && __is_reference_wrapper<_DecayA0>::value
3767 >::type;
3768
3769template <class _Fp, class _A0,
3770 class _DecayFp = typename decay<_Fp>::type,
3771 class _DecayA0 = typename decay<_A0>::type,
3772 class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
3773using __enable_if_bullet3 = typename enable_if
3774 <
3775 is_member_function_pointer<_DecayFp>::value
3776 && !is_base_of<_ClassT, _DecayA0>::value
3777 && !__is_reference_wrapper<_DecayA0>::value
3778 >::type;
3779
3780template <class _Fp, class _A0,
3781 class _DecayFp = typename decay<_Fp>::type,
3782 class _DecayA0 = typename decay<_A0>::type,
3783 class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
3784using __enable_if_bullet4 = typename enable_if
3785 <
3786 is_member_object_pointer<_DecayFp>::value
3787 && is_base_of<_ClassT, _DecayA0>::value
3788 >::type;
3789
3790template <class _Fp, class _A0,
3791 class _DecayFp = typename decay<_Fp>::type,
3792 class _DecayA0 = typename decay<_A0>::type>
3793using __enable_if_bullet5 = typename enable_if
3794 <
3795 is_member_object_pointer<_DecayFp>::value
3796 && __is_reference_wrapper<_DecayA0>::value
3797 >::type;
3798
3799template <class _Fp, class _A0,
3800 class _DecayFp = typename decay<_Fp>::type,
3801 class _DecayA0 = typename decay<_A0>::type,
3802 class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
3803using __enable_if_bullet6 = typename enable_if
3804 <
3805 is_member_object_pointer<_DecayFp>::value
3806 && !is_base_of<_ClassT, _DecayA0>::value
3807 && !__is_reference_wrapper<_DecayA0>::value
3808 >::type;
3809
3810// __invoke forward declarations
3811
3812// fall back - none of the bullets
3813
3814#define _LIBCPP_INVOKE_RETURN(...) \
3815 noexcept(noexcept(__VA_ARGS__)) -> decltype(__VA_ARGS__) \
3816 { return __VA_ARGS__; }
3817
3818template <class ..._Args>
3819auto __invoke(__any, _Args&& ...__args) -> __nat;
3820
3821template <class ..._Args>
3822auto __invoke_constexpr(__any, _Args&& ...__args) -> __nat;
3823
3824// bullets 1, 2 and 3
3825
3826template <class _Fp, class _A0, class ..._Args,
3827 class = __enable_if_bullet1<_Fp, _A0>>
3828inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
3829_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
3830__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
3831_LIBCPP_INVOKE_RETURN((static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...))
3832
3833template <class _Fp, class _A0, class ..._Args,
3834 class = __enable_if_bullet1<_Fp, _A0>>
3835inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
3836_LIBCPP_CONSTEXPRconstexpr auto
3837__invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
3838_LIBCPP_INVOKE_RETURN((static_cast<_A0&&>(__a0).*__f)(static_cast<_Args&&>(__args)...))
3839
3840template <class _Fp, class _A0, class ..._Args,
3841 class = __enable_if_bullet2<_Fp, _A0>>
3842inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
3843_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
3844__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
3845_LIBCPP_INVOKE_RETURN((__a0.get().*__f)(static_cast<_Args&&>(__args)...))
3846
3847template <class _Fp, class _A0, class ..._Args,
3848 class = __enable_if_bullet2<_Fp, _A0>>
3849inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
3850_LIBCPP_CONSTEXPRconstexpr auto
3851__invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
3852_LIBCPP_INVOKE_RETURN((__a0.get().*__f)(static_cast<_Args&&>(__args)...))
3853
3854template <class _Fp, class _A0, class ..._Args,
3855 class = __enable_if_bullet3<_Fp, _A0>>
3856inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
3857_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
3858__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
3859_LIBCPP_INVOKE_RETURN(((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...))
3860
3861template <class _Fp, class _A0, class ..._Args,
3862 class = __enable_if_bullet3<_Fp, _A0>>
3863inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
3864_LIBCPP_CONSTEXPRconstexpr auto
3865__invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
3866_LIBCPP_INVOKE_RETURN(((*static_cast<_A0&&>(__a0)).*__f)(static_cast<_Args&&>(__args)...))
3867
3868// bullets 4, 5 and 6
3869
3870template <class _Fp, class _A0,
3871 class = __enable_if_bullet4<_Fp, _A0>>
3872inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
3873_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
3874__invoke(_Fp&& __f, _A0&& __a0)
3875_LIBCPP_INVOKE_RETURN(static_cast<_A0&&>(__a0).*__f)
3876
3877template <class _Fp, class _A0,
3878 class = __enable_if_bullet4<_Fp, _A0>>
3879inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
3880_LIBCPP_CONSTEXPRconstexpr auto
3881__invoke_constexpr(_Fp&& __f, _A0&& __a0)
3882_LIBCPP_INVOKE_RETURN(static_cast<_A0&&>(__a0).*__f)
3883
3884template <class _Fp, class _A0,
3885 class = __enable_if_bullet5<_Fp, _A0>>
3886inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
3887_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
3888__invoke(_Fp&& __f, _A0&& __a0)
3889_LIBCPP_INVOKE_RETURN(__a0.get().*__f)
3890
3891template <class _Fp, class _A0,
3892 class = __enable_if_bullet5<_Fp, _A0>>
3893inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
3894_LIBCPP_CONSTEXPRconstexpr auto
3895__invoke_constexpr(_Fp&& __f, _A0&& __a0)
3896_LIBCPP_INVOKE_RETURN(__a0.get().*__f)
3897
3898template <class _Fp, class _A0,
3899 class = __enable_if_bullet6<_Fp, _A0>>
3900inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
3901_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
3902__invoke(_Fp&& __f, _A0&& __a0)
3903_LIBCPP_INVOKE_RETURN((*static_cast<_A0&&>(__a0)).*__f)
3904
3905template <class _Fp, class _A0,
3906 class = __enable_if_bullet6<_Fp, _A0>>
3907inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
3908_LIBCPP_CONSTEXPRconstexpr auto
3909__invoke_constexpr(_Fp&& __f, _A0&& __a0)
3910_LIBCPP_INVOKE_RETURN((*static_cast<_A0&&>(__a0)).*__f)
3911
3912// bullet 7
3913
3914template <class _Fp, class ..._Args>
3915inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
3916_LIBCPP_CONSTEXPR_AFTER_CXX17 auto
3917__invoke(_Fp&& __f, _Args&& ...__args)
3918_LIBCPP_INVOKE_RETURN(static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...))
10
Calling 'operator()'
3919
3920template <class _Fp, class ..._Args>
3921inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
3922_LIBCPP_CONSTEXPRconstexpr auto
3923__invoke_constexpr(_Fp&& __f, _Args&& ...__args)
3924_LIBCPP_INVOKE_RETURN(static_cast<_Fp&&>(__f)(static_cast<_Args&&>(__args)...))
3925
3926#undef _LIBCPP_INVOKE_RETURN
3927
3928// __invokable
3929template <class _Ret, class _Fp, class ..._Args>
3930struct __invokable_r
3931{
3932 template <class _XFp, class ..._XArgs>
3933 static auto __try_call(int) -> decltype(
3934 _VSTDstd::__1::__invoke(declval<_XFp>(), declval<_XArgs>()...));
3935 template <class _XFp, class ..._XArgs>
3936 static __nat __try_call(...);
3937
3938 // FIXME: Check that _Ret, _Fp, and _Args... are all complete types, cv void,
3939 // or incomplete array types as required by the standard.
3940 using _Result = decltype(__try_call<_Fp, _Args...>(0));
3941
3942 using type =
3943 typename conditional<
3944 _IsNotSame<_Result, __nat>::value,
3945 typename conditional<
3946 is_void<_Ret>::value,
3947 true_type,
3948 is_convertible<_Result, _Ret>
3949 >::type,
3950 false_type
3951 >::type;
3952 static const bool value = type::value;
3953};
3954template <class _Fp, class ..._Args>
3955using __invokable = __invokable_r<void, _Fp, _Args...>;
3956
3957template <bool _IsInvokable, bool _IsCVVoid, class _Ret, class _Fp, class ..._Args>
3958struct __nothrow_invokable_r_imp {
3959 static const bool value = false;
3960};
3961
3962template <class _Ret, class _Fp, class ..._Args>
3963struct __nothrow_invokable_r_imp<true, false, _Ret, _Fp, _Args...>
3964{
3965 typedef __nothrow_invokable_r_imp _ThisT;
3966
3967 template <class _Tp>
3968 static void __test_noexcept(_Tp) noexcept;
3969
3970 static const bool value = noexcept(_ThisT::__test_noexcept<_Ret>(
3971 _VSTDstd::__1::__invoke(declval<_Fp>(), declval<_Args>()...)));
3972};
3973
3974template <class _Ret, class _Fp, class ..._Args>
3975struct __nothrow_invokable_r_imp<true, true, _Ret, _Fp, _Args...>
3976{
3977 static const bool value = noexcept(
3978 _VSTDstd::__1::__invoke(declval<_Fp>(), declval<_Args>()...));
3979};
3980
3981template <class _Ret, class _Fp, class ..._Args>
3982using __nothrow_invokable_r =
3983 __nothrow_invokable_r_imp<
3984 __invokable_r<_Ret, _Fp, _Args...>::value,
3985 is_void<_Ret>::value,
3986 _Ret, _Fp, _Args...
3987 >;
3988
3989template <class _Fp, class ..._Args>
3990using __nothrow_invokable =
3991 __nothrow_invokable_r_imp<
3992 __invokable<_Fp, _Args...>::value,
3993 true, void, _Fp, _Args...
3994 >;
3995
3996template <class _Fp, class ..._Args>
3997struct __invoke_of
3998 : public enable_if<
3999 __invokable<_Fp, _Args...>::value,
4000 typename __invokable_r<void, _Fp, _Args...>::_Result>
4001{
4002};
4003
4004#endif // _LIBCPP_CXX03_LANG
4005
4006// result_of
4007
4008#if _LIBCPP_STD_VER14 <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS)
4009template <class _Callable> class _LIBCPP_DEPRECATED_IN_CXX17 result_of;
4010
4011#ifndef _LIBCPP_CXX03_LANG
4012
4013template <class _Fp, class ..._Args>
4014class _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) result_of<_Fp(_Args...)>
4015 : public __invoke_of<_Fp, _Args...>
4016{
4017};
4018
4019#else // C++03
4020
4021template <class _Fn, bool, bool>
4022class __result_of
4023{
4024};
4025
4026template <class _Fn, class ..._Args>
4027class __result_of<_Fn(_Args...), true, false>
4028{
4029public:
4030 typedef decltype(declval<_Fn>()(declval<_Args>()...)) type;
4031};
4032
4033template <class _MP, class _Tp, bool _IsMemberFunctionPtr>
4034struct __result_of_mp;
4035
4036// member function pointer
4037
4038template <class _MP, class _Tp>
4039struct __result_of_mp<_MP, _Tp, true>
4040{
4041 using type = typename __member_pointer_traits<_MP>::_ReturnType;
4042};
4043
4044// member data pointer
4045
4046template <class _MP, class _Tp, bool>
4047struct __result_of_mdp;
4048
4049template <class _Rp, class _Class, class _Tp>
4050struct __result_of_mdp<_Rp _Class::*, _Tp, false>
4051{
4052 using type = typename __apply_cv<decltype(*declval<_Tp>()), _Rp>::type&;
4053};
4054
4055template <class _Rp, class _Class, class _Tp>
4056struct __result_of_mdp<_Rp _Class::*, _Tp, true>
4057{
4058 using type = typename __apply_cv<_Tp, _Rp>::type&;
4059};
4060
4061template <class _Rp, class _Class, class _Tp>
4062struct __result_of_mp<_Rp _Class::*, _Tp, false>
4063 : public __result_of_mdp<_Rp _Class::*, _Tp,
4064 is_base_of<_Class, typename remove_reference<_Tp>::type>::value>
4065{
4066};
4067
4068template <class _Fn, class _Tp>
4069class __result_of<_Fn(_Tp), false, true> // _Fn must be member pointer
4070 : public __result_of_mp<typename remove_reference<_Fn>::type,
4071 _Tp,
4072 is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
4073{
4074};
4075
4076template <class _Fn, class _Tp, class ..._Args>
4077class __result_of<_Fn(_Tp, _Args...), false, true> // _Fn must be member pointer
4078 : public __result_of_mp<typename remove_reference<_Fn>::type,
4079 _Tp,
4080 is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
4081{
4082};
4083
4084template <class _Fn, class ..._Args>
4085class _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) result_of<_Fn(_Args...)>
4086 : public __result_of<_Fn(_Args...),
4087 is_class<typename remove_reference<_Fn>::type>::value ||
4088 is_function<typename remove_pointer<typename remove_reference<_Fn>::type>::type>::value,
4089 is_member_pointer<typename remove_reference<_Fn>::type>::value
4090 >
4091{
4092};
4093
4094#endif // C++03
4095
4096#if _LIBCPP_STD_VER14 > 11
4097template <class _Tp> using result_of_t _LIBCPP_DEPRECATED_IN_CXX17 = typename result_of<_Tp>::type;
4098#endif // _LIBCPP_STD_VER > 11
4099#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS)
4100
4101#if _LIBCPP_STD_VER14 > 14
4102
4103// invoke_result
4104
4105template <class _Fn, class... _Args>
4106struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) invoke_result
4107 : __invoke_of<_Fn, _Args...>
4108{
4109};
4110
4111template <class _Fn, class... _Args>
4112using invoke_result_t = typename invoke_result<_Fn, _Args...>::type;
4113
4114// is_invocable
4115
4116template <class _Fn, class ..._Args>
4117struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_invocable
4118 : integral_constant<bool, __invokable<_Fn, _Args...>::value> {};
4119
4120template <class _Ret, class _Fn, class ..._Args>
4121struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_invocable_r
4122 : integral_constant<bool, __invokable_r<_Ret, _Fn, _Args...>::value> {};
4123
4124template <class _Fn, class ..._Args>
4125_LIBCPP_INLINE_VAR constexpr bool is_invocable_v
4126 = is_invocable<_Fn, _Args...>::value;
4127
4128template <class _Ret, class _Fn, class ..._Args>
4129_LIBCPP_INLINE_VAR constexpr bool is_invocable_r_v
4130 = is_invocable_r<_Ret, _Fn, _Args...>::value;
4131
4132// is_nothrow_invocable
4133
4134template <class _Fn, class ..._Args>
4135struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_nothrow_invocable
4136 : integral_constant<bool, __nothrow_invokable<_Fn, _Args...>::value> {};
4137
4138template <class _Ret, class _Fn, class ..._Args>
4139struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_nothrow_invocable_r
4140 : integral_constant<bool, __nothrow_invokable_r<_Ret, _Fn, _Args...>::value> {};
4141
4142template <class _Fn, class ..._Args>
4143_LIBCPP_INLINE_VAR constexpr bool is_nothrow_invocable_v
4144 = is_nothrow_invocable<_Fn, _Args...>::value;
4145
4146template <class _Ret, class _Fn, class ..._Args>
4147_LIBCPP_INLINE_VAR constexpr bool is_nothrow_invocable_r_v
4148 = is_nothrow_invocable_r<_Ret, _Fn, _Args...>::value;
4149
4150#endif // _LIBCPP_STD_VER > 14
4151
4152// __swappable
4153
4154template <class _Tp> struct __is_swappable;
4155template <class _Tp> struct __is_nothrow_swappable;
4156
4157
4158#ifndef _LIBCPP_CXX03_LANG
4159template <class _Tp>
4160using __swap_result_t = typename enable_if<is_move_constructible<_Tp>::value && is_move_assignable<_Tp>::value>::type;
4161#else
4162template <class>
4163using __swap_result_t = void;
4164#endif
4165
4166template <class _Tp>
4167inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4168_LIBCPP_CONSTEXPR_AFTER_CXX17 __swap_result_t<_Tp>
4169swap(_Tp& __x, _Tp& __y) _NOEXCEPT_(is_nothrow_move_constructible<_Tp>::value &&noexcept(is_nothrow_move_constructible<_Tp>::value &&
is_nothrow_move_assignable<_Tp>::value)
4170 is_nothrow_move_assignable<_Tp>::value)noexcept(is_nothrow_move_constructible<_Tp>::value &&
is_nothrow_move_assignable<_Tp>::value)
;
4171
4172template<class _Tp, size_t _Np>
4173inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
_LIBCPP_CONSTEXPR_AFTER_CXX17
4174typename enable_if<
4175 __is_swappable<_Tp>::value
4176>::type
4177swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value)noexcept(__is_nothrow_swappable<_Tp>::value);
4178
4179namespace __detail
4180{
4181// ALL generic swap overloads MUST already have a declaration available at this point.
4182
4183template <class _Tp, class _Up = _Tp,
4184 bool _NotVoid = !is_void<_Tp>::value && !is_void<_Up>::value>
4185struct __swappable_with
4186{
4187 template <class _LHS, class _RHS>
4188 static decltype(swap(declval<_LHS>(), declval<_RHS>()))
4189 __test_swap(int);
4190 template <class, class>
4191 static __nat __test_swap(long);
4192
4193 // Extra parens are needed for the C++03 definition of decltype.
4194 typedef decltype((__test_swap<_Tp, _Up>(0))) __swap1;
4195 typedef decltype((__test_swap<_Up, _Tp>(0))) __swap2;
4196
4197 static const bool value = _IsNotSame<__swap1, __nat>::value
4198 && _IsNotSame<__swap2, __nat>::value;
4199};
4200
4201template <class _Tp, class _Up>
4202struct __swappable_with<_Tp, _Up, false> : false_type {};
4203
4204template <class _Tp, class _Up = _Tp, bool _Swappable = __swappable_with<_Tp, _Up>::value>
4205struct __nothrow_swappable_with {
4206 static const bool value =
4207#ifndef _LIBCPP_HAS_NO_NOEXCEPT
4208 noexcept(swap(declval<_Tp>(), declval<_Up>()))
4209 && noexcept(swap(declval<_Up>(), declval<_Tp>()));
4210#else
4211 false;
4212#endif
4213};
4214
4215template <class _Tp, class _Up>
4216struct __nothrow_swappable_with<_Tp, _Up, false> : false_type {};
4217
4218} // __detail
4219
4220template <class _Tp>
4221struct __is_swappable
4222 : public integral_constant<bool, __detail::__swappable_with<_Tp&>::value>
4223{
4224};
4225
4226template <class _Tp>
4227struct __is_nothrow_swappable
4228 : public integral_constant<bool, __detail::__nothrow_swappable_with<_Tp&>::value>
4229{
4230};
4231
4232#if _LIBCPP_STD_VER14 > 14
4233
4234template <class _Tp, class _Up>
4235struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_swappable_with
4236 : public integral_constant<bool, __detail::__swappable_with<_Tp, _Up>::value>
4237{
4238};
4239
4240template <class _Tp>
4241struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_swappable
4242 : public conditional<
4243 __is_referenceable<_Tp>::value,
4244 is_swappable_with<
4245 typename add_lvalue_reference<_Tp>::type,
4246 typename add_lvalue_reference<_Tp>::type>,
4247 false_type
4248 >::type
4249{
4250};
4251
4252template <class _Tp, class _Up>
4253struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_nothrow_swappable_with
4254 : public integral_constant<bool, __detail::__nothrow_swappable_with<_Tp, _Up>::value>
4255{
4256};
4257
4258template <class _Tp>
4259struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_nothrow_swappable
4260 : public conditional<
4261 __is_referenceable<_Tp>::value,
4262 is_nothrow_swappable_with<
4263 typename add_lvalue_reference<_Tp>::type,
4264 typename add_lvalue_reference<_Tp>::type>,
4265 false_type
4266 >::type
4267{
4268};
4269
4270template <class _Tp, class _Up>
4271_LIBCPP_INLINE_VAR constexpr bool is_swappable_with_v
4272 = is_swappable_with<_Tp, _Up>::value;
4273
4274template <class _Tp>
4275_LIBCPP_INLINE_VAR constexpr bool is_swappable_v
4276 = is_swappable<_Tp>::value;
4277
4278template <class _Tp, class _Up>
4279_LIBCPP_INLINE_VAR constexpr bool is_nothrow_swappable_with_v
4280 = is_nothrow_swappable_with<_Tp, _Up>::value;
4281
4282template <class _Tp>
4283_LIBCPP_INLINE_VAR constexpr bool is_nothrow_swappable_v
4284 = is_nothrow_swappable<_Tp>::value;
4285
4286#endif // _LIBCPP_STD_VER > 14
4287
4288template <class _Tp, bool = is_enum<_Tp>::value> struct __underlying_type_impl;
4289
4290template <class _Tp>
4291struct __underlying_type_impl<_Tp, false> {};
4292
4293template <class _Tp>
4294struct __underlying_type_impl<_Tp, true>
4295{
4296 typedef __underlying_type(_Tp) type;
4297};
4298
4299template <class _Tp>
4300struct underlying_type : __underlying_type_impl<_Tp, is_enum<_Tp>::value> {};
4301
4302#if _LIBCPP_STD_VER14 > 11
4303template <class _Tp> using underlying_type_t = typename underlying_type<_Tp>::type;
4304#endif
4305
4306template <class _Tp, bool = is_enum<_Tp>::value>
4307struct __sfinae_underlying_type
4308{
4309 typedef typename underlying_type<_Tp>::type type;
4310 typedef decltype(((type)1) + 0) __promoted_type;
4311};
4312
4313template <class _Tp>
4314struct __sfinae_underlying_type<_Tp, false> {};
4315
4316inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
_LIBCPP_CONSTEXPRconstexpr
4317int __convert_to_integral(int __val) { return __val; }
4318
4319inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
_LIBCPP_CONSTEXPRconstexpr
4320unsigned __convert_to_integral(unsigned __val) { return __val; }
4321
4322inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
_LIBCPP_CONSTEXPRconstexpr
4323long __convert_to_integral(long __val) { return __val; }
4324
4325inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
_LIBCPP_CONSTEXPRconstexpr
4326unsigned long __convert_to_integral(unsigned long __val) { return __val; }
4327
4328inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
_LIBCPP_CONSTEXPRconstexpr
4329long long __convert_to_integral(long long __val) { return __val; }
4330
4331inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
_LIBCPP_CONSTEXPRconstexpr
4332unsigned long long __convert_to_integral(unsigned long long __val) {return __val; }
4333
4334template<typename _Fp>
4335inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
_LIBCPP_CONSTEXPRconstexpr
4336typename enable_if<is_floating_point<_Fp>::value, long long>::type
4337 __convert_to_integral(_Fp __val) { return __val; }
4338
4339#ifndef _LIBCPP_HAS_NO_INT128
4340inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
_LIBCPP_CONSTEXPRconstexpr
4341__int128_t __convert_to_integral(__int128_t __val) { return __val; }
4342
4343inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
_LIBCPP_CONSTEXPRconstexpr
4344__uint128_t __convert_to_integral(__uint128_t __val) { return __val; }
4345#endif
4346
4347template <class _Tp>
4348inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
_LIBCPP_CONSTEXPRconstexpr
4349typename __sfinae_underlying_type<_Tp>::__promoted_type
4350__convert_to_integral(_Tp __val) { return __val; }
4351
4352#ifndef _LIBCPP_CXX03_LANG
4353
4354template <class _Tp>
4355struct __has_operator_addressof_member_imp
4356{
4357 template <class _Up>
4358 static auto __test(int)
4359 -> typename __select_2nd<decltype(declval<_Up>().operator&()), true_type>::type;
4360 template <class>
4361 static auto __test(long) -> false_type;
4362
4363 static const bool value = decltype(__test<_Tp>(0))::value;
4364};
4365
4366template <class _Tp>
4367struct __has_operator_addressof_free_imp
4368{
4369 template <class _Up>
4370 static auto __test(int)
4371 -> typename __select_2nd<decltype(operator&(declval<_Up>())), true_type>::type;
4372 template <class>
4373 static auto __test(long) -> false_type;
4374
4375 static const bool value = decltype(__test<_Tp>(0))::value;
4376};
4377
4378template <class _Tp>
4379struct __has_operator_addressof
4380 : public integral_constant<bool, __has_operator_addressof_member_imp<_Tp>::value
4381 || __has_operator_addressof_free_imp<_Tp>::value>
4382{};
4383
4384#endif // _LIBCPP_CXX03_LANG
4385
4386// is_scoped_enum [meta.unary.prop]
4387
4388#if _LIBCPP_STD_VER14 > 20
4389template <class _Tp, bool = is_enum_v<_Tp> >
4390struct __is_scoped_enum_helper : false_type {};
4391
4392template <class _Tp>
4393struct __is_scoped_enum_helper<_Tp, true>
4394 : public bool_constant<!is_convertible_v<_Tp, underlying_type_t<_Tp> > > {};
4395
4396template <class _Tp>
4397struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_scoped_enum
4398 : public __is_scoped_enum_helper<_Tp> {};
4399
4400template <class _Tp>
4401_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_scoped_enum_v =
4402 is_scoped_enum<_Tp>::value;
4403#endif
4404
4405#if _LIBCPP_STD_VER14 > 14
4406
4407template <class... _Args>
4408struct conjunction : _And<_Args...> {};
4409template<class... _Args>
4410_LIBCPP_INLINE_VAR constexpr bool conjunction_v
4411 = conjunction<_Args...>::value;
4412
4413template <class... _Args>
4414struct disjunction : _Or<_Args...> {};
4415template<class... _Args>
4416_LIBCPP_INLINE_VAR constexpr bool disjunction_v
4417 = disjunction<_Args...>::value;
4418
4419template <class _Tp>
4420struct negation : _Not<_Tp> {};
4421template<class _Tp>
4422_LIBCPP_INLINE_VAR constexpr bool negation_v
4423 = negation<_Tp>::value;
4424#endif // _LIBCPP_STD_VER > 14
4425
4426// These traits are used in __tree and __hash_table
4427struct __extract_key_fail_tag {};
4428struct __extract_key_self_tag {};
4429struct __extract_key_first_tag {};
4430
4431template <class _ValTy, class _Key,
4432 class _RawValTy = typename __unconstref<_ValTy>::type>
4433struct __can_extract_key
4434 : conditional<_IsSame<_RawValTy, _Key>::value, __extract_key_self_tag,
4435 __extract_key_fail_tag>::type {};
4436
4437template <class _Pair, class _Key, class _First, class _Second>
4438struct __can_extract_key<_Pair, _Key, pair<_First, _Second> >
4439 : conditional<_IsSame<typename remove_const<_First>::type, _Key>::value,
4440 __extract_key_first_tag, __extract_key_fail_tag>::type {};
4441
4442// __can_extract_map_key uses true_type/false_type instead of the tags.
4443// It returns true if _Key != _ContainerValueTy (the container is a map not a set)
4444// and _ValTy == _Key.
4445template <class _ValTy, class _Key, class _ContainerValueTy,
4446 class _RawValTy = typename __unconstref<_ValTy>::type>
4447struct __can_extract_map_key
4448 : integral_constant<bool, _IsSame<_RawValTy, _Key>::value> {};
4449
4450// This specialization returns __extract_key_fail_tag for non-map containers
4451// because _Key == _ContainerValueTy
4452template <class _ValTy, class _Key, class _RawValTy>
4453struct __can_extract_map_key<_ValTy, _Key, _Key, _RawValTy>
4454 : false_type {};
4455
4456#ifndef _LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED
4457#if _LIBCPP_STD_VER14 > 17
4458_LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4459inline constexpr bool is_constant_evaluated() noexcept {
4460 return __builtin_is_constant_evaluated();
4461}
4462#endif
4463
4464inline _LIBCPP_CONSTEXPRconstexpr
4465bool __libcpp_is_constant_evaluated() _NOEXCEPTnoexcept { return __builtin_is_constant_evaluated(); }
4466#else
4467inline _LIBCPP_CONSTEXPRconstexpr
4468bool __libcpp_is_constant_evaluated() _NOEXCEPTnoexcept { return false; }
4469#endif
4470
4471template <class _CharT>
4472using _IsCharLikeType = _And<is_standard_layout<_CharT>, is_trivial<_CharT> >;
4473
4474template<class _Tp>
4475using __make_const_lvalue_ref = const typename remove_reference<_Tp>::type&;
4476
4477#if _LIBCPP_STD_VER14 > 17
4478template<bool _Const, class _Tp>
4479using __maybe_const = conditional_t<_Const, const _Tp, _Tp>;
4480#endif // _LIBCPP_STD_VER > 17
4481
4482_LIBCPP_END_NAMESPACE_STD} }
4483
4484#if _LIBCPP_STD_VER14 > 14
4485// std::byte
4486namespace std // purposefully not versioned
4487{
4488
4489
4490}
4491#endif
4492
4493#endif // _LIBCPP_TYPE_TRAITS

/usr/include/c++/v1/string

1// -*- C++ -*-
2//===--------------------------- string -----------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_STRING
11#define _LIBCPP_STRING
12
13/*
14 string synopsis
15
16namespace std
17{
18
19template <class stateT>
20class fpos
21{
22private:
23 stateT st;
24public:
25 fpos(streamoff = streamoff());
26
27 operator streamoff() const;
28
29 stateT state() const;
30 void state(stateT);
31
32 fpos& operator+=(streamoff);
33 fpos operator+ (streamoff) const;
34 fpos& operator-=(streamoff);
35 fpos operator- (streamoff) const;
36};
37
38template <class stateT> streamoff operator-(const fpos<stateT>& x, const fpos<stateT>& y);
39
40template <class stateT> bool operator==(const fpos<stateT>& x, const fpos<stateT>& y);
41template <class stateT> bool operator!=(const fpos<stateT>& x, const fpos<stateT>& y);
42
43template <class charT>
44struct char_traits
45{
46 typedef charT char_type;
47 typedef ... int_type;
48 typedef streamoff off_type;
49 typedef streampos pos_type;
50 typedef mbstate_t state_type;
51
52 static void assign(char_type& c1, const char_type& c2) noexcept;
53 static constexpr bool eq(char_type c1, char_type c2) noexcept;
54 static constexpr bool lt(char_type c1, char_type c2) noexcept;
55
56 static int compare(const char_type* s1, const char_type* s2, size_t n);
57 static size_t length(const char_type* s);
58 static const char_type* find(const char_type* s, size_t n, const char_type& a);
59 static char_type* move(char_type* s1, const char_type* s2, size_t n);
60 static char_type* copy(char_type* s1, const char_type* s2, size_t n);
61 static char_type* assign(char_type* s, size_t n, char_type a);
62
63 static constexpr int_type not_eof(int_type c) noexcept;
64 static constexpr char_type to_char_type(int_type c) noexcept;
65 static constexpr int_type to_int_type(char_type c) noexcept;
66 static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept;
67 static constexpr int_type eof() noexcept;
68};
69
70template <> struct char_traits<char>;
71template <> struct char_traits<wchar_t>;
72template <> struct char_traits<char8_t>; // C++20
73template <> struct char_traits<char16_t>;
74template <> struct char_traits<char32_t>;
75
76template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
77class basic_string
78{
79public:
80// types:
81 typedef traits traits_type;
82 typedef typename traits_type::char_type value_type;
83 typedef Allocator allocator_type;
84 typedef typename allocator_type::size_type size_type;
85 typedef typename allocator_type::difference_type difference_type;
86 typedef typename allocator_type::reference reference;
87 typedef typename allocator_type::const_reference const_reference;
88 typedef typename allocator_type::pointer pointer;
89 typedef typename allocator_type::const_pointer const_pointer;
90 typedef implementation-defined iterator;
91 typedef implementation-defined const_iterator;
92 typedef std::reverse_iterator<iterator> reverse_iterator;
93 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
94
95 static const size_type npos = -1;
96
97 basic_string()
98 noexcept(is_nothrow_default_constructible<allocator_type>::value);
99 explicit basic_string(const allocator_type& a);
100 basic_string(const basic_string& str);
101 basic_string(basic_string&& str)
102 noexcept(is_nothrow_move_constructible<allocator_type>::value);
103 basic_string(const basic_string& str, size_type pos,
104 const allocator_type& a = allocator_type());
105 basic_string(const basic_string& str, size_type pos, size_type n,
106 const Allocator& a = Allocator());
107 template<class T>
108 basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator()); // C++17
109 template <class T>
110 explicit basic_string(const T& t, const Allocator& a = Allocator()); // C++17
111 basic_string(const value_type* s, const allocator_type& a = allocator_type());
112 basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type());
113 basic_string(nullptr_t) = delete; // C++2b
114 basic_string(size_type n, value_type c, const allocator_type& a = allocator_type());
115 template<class InputIterator>
116 basic_string(InputIterator begin, InputIterator end,
117 const allocator_type& a = allocator_type());
118 basic_string(initializer_list<value_type>, const Allocator& = Allocator());
119 basic_string(const basic_string&, const Allocator&);
120 basic_string(basic_string&&, const Allocator&);
121
122 ~basic_string();
123
124 operator basic_string_view<charT, traits>() const noexcept;
125
126 basic_string& operator=(const basic_string& str);
127 template <class T>
128 basic_string& operator=(const T& t); // C++17
129 basic_string& operator=(basic_string&& str)
130 noexcept(
131 allocator_type::propagate_on_container_move_assignment::value ||
132 allocator_type::is_always_equal::value ); // C++17
133 basic_string& operator=(const value_type* s);
134 basic_string& operator=(nullptr_t) = delete; // C++2b
135 basic_string& operator=(value_type c);
136 basic_string& operator=(initializer_list<value_type>);
137
138 iterator begin() noexcept;
139 const_iterator begin() const noexcept;
140 iterator end() noexcept;
141 const_iterator end() const noexcept;
142
143 reverse_iterator rbegin() noexcept;
144 const_reverse_iterator rbegin() const noexcept;
145 reverse_iterator rend() noexcept;
146 const_reverse_iterator rend() const noexcept;
147
148 const_iterator cbegin() const noexcept;
149 const_iterator cend() const noexcept;
150 const_reverse_iterator crbegin() const noexcept;
151 const_reverse_iterator crend() const noexcept;
152
153 size_type size() const noexcept;
154 size_type length() const noexcept;
155 size_type max_size() const noexcept;
156 size_type capacity() const noexcept;
157
158 void resize(size_type n, value_type c);
159 void resize(size_type n);
160
161 void reserve(size_type res_arg);
162 void reserve(); // deprecated in C++20
163 void shrink_to_fit();
164 void clear() noexcept;
165 bool empty() const noexcept;
166
167 const_reference operator[](size_type pos) const;
168 reference operator[](size_type pos);
169
170 const_reference at(size_type n) const;
171 reference at(size_type n);
172
173 basic_string& operator+=(const basic_string& str);
174 template <class T>
175 basic_string& operator+=(const T& t); // C++17
176 basic_string& operator+=(const value_type* s);
177 basic_string& operator+=(value_type c);
178 basic_string& operator+=(initializer_list<value_type>);
179
180 basic_string& append(const basic_string& str);
181 template <class T>
182 basic_string& append(const T& t); // C++17
183 basic_string& append(const basic_string& str, size_type pos, size_type n=npos); //C++14
184 template <class T>
185 basic_string& append(const T& t, size_type pos, size_type n=npos); // C++17
186 basic_string& append(const value_type* s, size_type n);
187 basic_string& append(const value_type* s);
188 basic_string& append(size_type n, value_type c);
189 template<class InputIterator>
190 basic_string& append(InputIterator first, InputIterator last);
191 basic_string& append(initializer_list<value_type>);
192
193 void push_back(value_type c);
194 void pop_back();
195 reference front();
196 const_reference front() const;
197 reference back();
198 const_reference back() const;
199
200 basic_string& assign(const basic_string& str);
201 template <class T>
202 basic_string& assign(const T& t); // C++17
203 basic_string& assign(basic_string&& str);
204 basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14
205 template <class T>
206 basic_string& assign(const T& t, size_type pos, size_type n=npos); // C++17
207 basic_string& assign(const value_type* s, size_type n);
208 basic_string& assign(const value_type* s);
209 basic_string& assign(size_type n, value_type c);
210 template<class InputIterator>
211 basic_string& assign(InputIterator first, InputIterator last);
212 basic_string& assign(initializer_list<value_type>);
213
214 basic_string& insert(size_type pos1, const basic_string& str);
215 template <class T>
216 basic_string& insert(size_type pos1, const T& t);
217 basic_string& insert(size_type pos1, const basic_string& str,
218 size_type pos2, size_type n);
219 template <class T>
220 basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n); // C++17
221 basic_string& insert(size_type pos, const value_type* s, size_type n=npos); //C++14
222 basic_string& insert(size_type pos, const value_type* s);
223 basic_string& insert(size_type pos, size_type n, value_type c);
224 iterator insert(const_iterator p, value_type c);
225 iterator insert(const_iterator p, size_type n, value_type c);
226 template<class InputIterator>
227 iterator insert(const_iterator p, InputIterator first, InputIterator last);
228 iterator insert(const_iterator p, initializer_list<value_type>);
229
230 basic_string& erase(size_type pos = 0, size_type n = npos);
231 iterator erase(const_iterator position);
232 iterator erase(const_iterator first, const_iterator last);
233
234 basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
235 template <class T>
236 basic_string& replace(size_type pos1, size_type n1, const T& t); // C++17
237 basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
238 size_type pos2, size_type n2=npos); // C++14
239 template <class T>
240 basic_string& replace(size_type pos1, size_type n1, const T& t,
241 size_type pos2, size_type n); // C++17
242 basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2);
243 basic_string& replace(size_type pos, size_type n1, const value_type* s);
244 basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c);
245 basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
246 template <class T>
247 basic_string& replace(const_iterator i1, const_iterator i2, const T& t); // C++17
248 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n);
249 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s);
250 basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c);
251 template<class InputIterator>
252 basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2);
253 basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>);
254
255 size_type copy(value_type* s, size_type n, size_type pos = 0) const;
256 basic_string substr(size_type pos = 0, size_type n = npos) const;
257
258 void swap(basic_string& str)
259 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
260 allocator_traits<allocator_type>::is_always_equal::value); // C++17
261
262 const value_type* c_str() const noexcept;
263 const value_type* data() const noexcept;
264 value_type* data() noexcept; // C++17
265
266 allocator_type get_allocator() const noexcept;
267
268 size_type find(const basic_string& str, size_type pos = 0) const noexcept;
269 template <class T>
270 size_type find(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension
271 size_type find(const value_type* s, size_type pos, size_type n) const noexcept;
272 size_type find(const value_type* s, size_type pos = 0) const noexcept;
273 size_type find(value_type c, size_type pos = 0) const noexcept;
274
275 size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
276 template <class T>
277 size_type rfind(const T& t, size_type pos = npos) const noexcept; // C++17, noexcept as an extension
278 size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept;
279 size_type rfind(const value_type* s, size_type pos = npos) const noexcept;
280 size_type rfind(value_type c, size_type pos = npos) const noexcept;
281
282 size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
283 template <class T>
284 size_type find_first_of(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension
285 size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept;
286 size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept;
287 size_type find_first_of(value_type c, size_type pos = 0) const noexcept;
288
289 size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
290 template <class T>
291 size_type find_last_of(const T& t, size_type pos = npos) const noexcept noexcept; // C++17, noexcept as an extension
292 size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept;
293 size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept;
294 size_type find_last_of(value_type c, size_type pos = npos) const noexcept;
295
296 size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
297 template <class T>
298 size_type find_first_not_of(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension
299 size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
300 size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept;
301 size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept;
302
303 size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
304 template <class T>
305 size_type find_last_not_of(const T& t, size_type pos = npos) const noexcept; // C++17, noexcept as an extension
306 size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
307 size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept;
308 size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept;
309
310 int compare(const basic_string& str) const noexcept;
311 template <class T>
312 int compare(const T& t) const noexcept; // C++17, noexcept as an extension
313 int compare(size_type pos1, size_type n1, const basic_string& str) const;
314 template <class T>
315 int compare(size_type pos1, size_type n1, const T& t) const; // C++17
316 int compare(size_type pos1, size_type n1, const basic_string& str,
317 size_type pos2, size_type n2=npos) const; // C++14
318 template <class T>
319 int compare(size_type pos1, size_type n1, const T& t,
320 size_type pos2, size_type n2=npos) const; // C++17
321 int compare(const value_type* s) const noexcept;
322 int compare(size_type pos1, size_type n1, const value_type* s) const;
323 int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const;
324
325 bool starts_with(basic_string_view<charT, traits> sv) const noexcept; // C++20
326 bool starts_with(charT c) const noexcept; // C++20
327 bool starts_with(const charT* s) const; // C++20
328 bool ends_with(basic_string_view<charT, traits> sv) const noexcept; // C++20
329 bool ends_with(charT c) const noexcept; // C++20
330 bool ends_with(const charT* s) const; // C++20
331
332 constexpr bool contains(basic_string_view<charT, traits> sv) const noexcept; // C++2b
333 constexpr bool contains(charT c) const noexcept; // C++2b
334 constexpr bool contains(const charT* s) const; // C++2b
335
336 bool __invariants() const;
337};
338
339template<class InputIterator,
340 class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
341basic_string(InputIterator, InputIterator, Allocator = Allocator())
342 -> basic_string<typename iterator_traits<InputIterator>::value_type,
343 char_traits<typename iterator_traits<InputIterator>::value_type>,
344 Allocator>; // C++17
345
346template<class charT, class traits, class Allocator>
347basic_string<charT, traits, Allocator>
348operator+(const basic_string<charT, traits, Allocator>& lhs,
349 const basic_string<charT, traits, Allocator>& rhs);
350
351template<class charT, class traits, class Allocator>
352basic_string<charT, traits, Allocator>
353operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs);
354
355template<class charT, class traits, class Allocator>
356basic_string<charT, traits, Allocator>
357operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
358
359template<class charT, class traits, class Allocator>
360basic_string<charT, traits, Allocator>
361operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
362
363template<class charT, class traits, class Allocator>
364basic_string<charT, traits, Allocator>
365operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
366
367template<class charT, class traits, class Allocator>
368bool operator==(const basic_string<charT, traits, Allocator>& lhs,
369 const basic_string<charT, traits, Allocator>& rhs) noexcept;
370
371template<class charT, class traits, class Allocator>
372bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
373
374template<class charT, class traits, class Allocator>
375bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept;
376
377template<class charT, class traits, class Allocator>
378bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
379 const basic_string<charT, traits, Allocator>& rhs) noexcept;
380
381template<class charT, class traits, class Allocator>
382bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
383
384template<class charT, class traits, class Allocator>
385bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
386
387template<class charT, class traits, class Allocator>
388bool operator< (const basic_string<charT, traits, Allocator>& lhs,
389 const basic_string<charT, traits, Allocator>& rhs) noexcept;
390
391template<class charT, class traits, class Allocator>
392bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
393
394template<class charT, class traits, class Allocator>
395bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
396
397template<class charT, class traits, class Allocator>
398bool operator> (const basic_string<charT, traits, Allocator>& lhs,
399 const basic_string<charT, traits, Allocator>& rhs) noexcept;
400
401template<class charT, class traits, class Allocator>
402bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
403
404template<class charT, class traits, class Allocator>
405bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
406
407template<class charT, class traits, class Allocator>
408bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
409 const basic_string<charT, traits, Allocator>& rhs) noexcept;
410
411template<class charT, class traits, class Allocator>
412bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
413
414template<class charT, class traits, class Allocator>
415bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
416
417template<class charT, class traits, class Allocator>
418bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
419 const basic_string<charT, traits, Allocator>& rhs) noexcept;
420
421template<class charT, class traits, class Allocator>
422bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
423
424template<class charT, class traits, class Allocator>
425bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
426
427template<class charT, class traits, class Allocator>
428void swap(basic_string<charT, traits, Allocator>& lhs,
429 basic_string<charT, traits, Allocator>& rhs)
430 noexcept(noexcept(lhs.swap(rhs)));
431
432template<class charT, class traits, class Allocator>
433basic_istream<charT, traits>&
434operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
435
436template<class charT, class traits, class Allocator>
437basic_ostream<charT, traits>&
438operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
439
440template<class charT, class traits, class Allocator>
441basic_istream<charT, traits>&
442getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str,
443 charT delim);
444
445template<class charT, class traits, class Allocator>
446basic_istream<charT, traits>&
447getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
448
449template<class charT, class traits, class Allocator, class U>
450typename basic_string<charT, traits, Allocator>::size_type
451erase(basic_string<charT, traits, Allocator>& c, const U& value); // C++20
452template<class charT, class traits, class Allocator, class Predicate>
453typename basic_string<charT, traits, Allocator>::size_type
454erase_if(basic_string<charT, traits, Allocator>& c, Predicate pred); // C++20
455
456typedef basic_string<char> string;
457typedef basic_string<wchar_t> wstring;
458typedef basic_string<char8_t> u8string; // C++20
459typedef basic_string<char16_t> u16string;
460typedef basic_string<char32_t> u32string;
461
462int stoi (const string& str, size_t* idx = nullptr, int base = 10);
463long stol (const string& str, size_t* idx = nullptr, int base = 10);
464unsigned long stoul (const string& str, size_t* idx = nullptr, int base = 10);
465long long stoll (const string& str, size_t* idx = nullptr, int base = 10);
466unsigned long long stoull(const string& str, size_t* idx = nullptr, int base = 10);
467
468float stof (const string& str, size_t* idx = nullptr);
469double stod (const string& str, size_t* idx = nullptr);
470long double stold(const string& str, size_t* idx = nullptr);
471
472string to_string(int val);
473string to_string(unsigned val);
474string to_string(long val);
475string to_string(unsigned long val);
476string to_string(long long val);
477string to_string(unsigned long long val);
478string to_string(float val);
479string to_string(double val);
480string to_string(long double val);
481
482int stoi (const wstring& str, size_t* idx = nullptr, int base = 10);
483long stol (const wstring& str, size_t* idx = nullptr, int base = 10);
484unsigned long stoul (const wstring& str, size_t* idx = nullptr, int base = 10);
485long long stoll (const wstring& str, size_t* idx = nullptr, int base = 10);
486unsigned long long stoull(const wstring& str, size_t* idx = nullptr, int base = 10);
487
488float stof (const wstring& str, size_t* idx = nullptr);
489double stod (const wstring& str, size_t* idx = nullptr);
490long double stold(const wstring& str, size_t* idx = nullptr);
491
492wstring to_wstring(int val);
493wstring to_wstring(unsigned val);
494wstring to_wstring(long val);
495wstring to_wstring(unsigned long val);
496wstring to_wstring(long long val);
497wstring to_wstring(unsigned long long val);
498wstring to_wstring(float val);
499wstring to_wstring(double val);
500wstring to_wstring(long double val);
501
502template <> struct hash<string>;
503template <> struct hash<u8string>; // C++20
504template <> struct hash<u16string>;
505template <> struct hash<u32string>;
506template <> struct hash<wstring>;
507
508basic_string<char> operator "" s( const char *str, size_t len ); // C++14
509basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14
510basic_string<char8_t> operator "" s( const char8_t *str, size_t len ); // C++20
511basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14
512basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14
513
514} // std
515
516*/
517
518#include <__config>
519#include <__debug>
520#include <__functional_base>
521#include <__iterator/wrap_iter.h>
522#include <algorithm>
523#include <compare>
524#include <cstdio> // EOF
525#include <cstdlib>
526#include <cstring>
527#include <cwchar>
528#include <initializer_list>
529#include <iosfwd>
530#include <iterator>
531#include <memory>
532#include <stdexcept>
533#include <string_view>
534#include <type_traits>
535#include <utility>
536#include <version>
537
538#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
539# include <cstdint>
540#endif
541
542#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
543#pragma GCC system_header
544#endif
545
546_LIBCPP_PUSH_MACROSpush_macro("min") push_macro("max")
547#include <__undef_macros>
548
549
550_LIBCPP_BEGIN_NAMESPACE_STDnamespace std { inline namespace __1 {
551
552// fpos
553
554template <class _StateT>
555class _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) fpos
556{
557private:
558 _StateT __st_;
559 streamoff __off_;
560public:
561 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
562
563 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
operator streamoff() const {return __off_;}
564
565 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
_StateT state() const {return __st_;}
566 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
void state(_StateT __st) {__st_ = __st;}
567
568 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
569 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
570 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
571 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
572};
573
574template <class _StateT>
575inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
576streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
577 {return streamoff(__x) - streamoff(__y);}
578
579template <class _StateT>
580inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
581bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
582 {return streamoff(__x) == streamoff(__y);}
583
584template <class _StateT>
585inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
586bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
587 {return streamoff(__x) != streamoff(__y);}
588
589// basic_string
590
591template<class _CharT, class _Traits, class _Allocator>
592basic_string<_CharT, _Traits, _Allocator>
593operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
594 const basic_string<_CharT, _Traits, _Allocator>& __y);
595
596template<class _CharT, class _Traits, class _Allocator>
597basic_string<_CharT, _Traits, _Allocator>
598operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
599
600template<class _CharT, class _Traits, class _Allocator>
601basic_string<_CharT, _Traits, _Allocator>
602operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
603
604template<class _CharT, class _Traits, class _Allocator>
605inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
606basic_string<_CharT, _Traits, _Allocator>
607operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
608
609template<class _CharT, class _Traits, class _Allocator>
610basic_string<_CharT, _Traits, _Allocator>
611operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
612
613_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))extern template __attribute__ ((__visibility__("default"))) string
operator+<char, char_traits<char>, allocator<char
> >(char const*, string const&);
614
615template <bool>
616class _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) __basic_string_common
617{
618protected:
619 _LIBCPP_NORETURN[[noreturn]] void __throw_length_error() const;
620 _LIBCPP_NORETURN[[noreturn]] void __throw_out_of_range() const;
621};
622
623template <bool __b>
624void
625__basic_string_common<__b>::__throw_length_error() const
626{
627 _VSTDstd::__1::__throw_length_error("basic_string");
628}
629
630template <bool __b>
631void
632__basic_string_common<__b>::__throw_out_of_range() const
633{
634 _VSTDstd::__1::__throw_out_of_range("basic_string");
635}
636
637_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __basic_string_common<true>)extern template class __attribute__ ((__visibility__("default"
))) __basic_string_common<true>;
638
639template <class _Iter>
640struct __string_is_trivial_iterator : public false_type {};
641
642template <class _Tp>
643struct __string_is_trivial_iterator<_Tp*>
644 : public is_arithmetic<_Tp> {};
645
646template <class _Iter>
647struct __string_is_trivial_iterator<__wrap_iter<_Iter> >
648 : public __string_is_trivial_iterator<_Iter> {};
649
650template <class _CharT, class _Traits, class _Tp>
651struct __can_be_converted_to_string_view : public _BoolConstant<
652 is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value &&
653 !is_convertible<const _Tp&, const _CharT*>::value
654 > {};
655
656#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
657
658template <class _CharT, size_t = sizeof(_CharT)>
659struct __padding
660{
661 unsigned char __xx[sizeof(_CharT)-1];
662};
663
664template <class _CharT>
665struct __padding<_CharT, 1>
666{
667};
668
669#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
670
671#ifndef _LIBCPP_HAS_NO_CHAR8_T
672typedef basic_string<char8_t> u8string;
673#endif
674
675#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
676typedef basic_string<char16_t> u16string;
677typedef basic_string<char32_t> u32string;
678#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
679
680template<class _CharT, class _Traits, class _Allocator>
681class
682 _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default")))
683#ifndef _LIBCPP_HAS_NO_CHAR8_T
684 _LIBCPP_PREFERRED_NAME(u8string)__attribute__((__preferred_name__(u8string)))
685#endif
686#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
687 _LIBCPP_PREFERRED_NAME(u16string)__attribute__((__preferred_name__(u16string)))
688 _LIBCPP_PREFERRED_NAME(u32string)__attribute__((__preferred_name__(u32string)))
689#endif
690 basic_string
691 : private __basic_string_common<true>
692{
693public:
694 typedef basic_string __self;
695 typedef basic_string_view<_CharT, _Traits> __self_view;
696 typedef _Traits traits_type;
697 typedef _CharT value_type;
698 typedef _Allocator allocator_type;
699 typedef allocator_traits<allocator_type> __alloc_traits;
700 typedef typename __alloc_traits::size_type size_type;
701 typedef typename __alloc_traits::difference_type difference_type;
702 typedef value_type& reference;
703 typedef const value_type& const_reference;
704 typedef typename __alloc_traits::pointer pointer;
705 typedef typename __alloc_traits::const_pointer const_pointer;
706
707 static_assert((!is_array<value_type>::value), "Character type of basic_string must not be an array");
708 static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string must be standard-layout");
709 static_assert(( is_trivial<value_type>::value), "Character type of basic_string must be trivial");
710 static_assert(( is_same<_CharT, typename traits_type::char_type>::value),
711 "traits_type::char_type must be the same type as CharT");
712 static_assert(( is_same<typename allocator_type::value_type, value_type>::value),
713 "Allocator::value_type must be same type as value_type");
714
715 typedef __wrap_iter<pointer> iterator;
716 typedef __wrap_iter<const_pointer> const_iterator;
717 typedef _VSTDstd::__1::reverse_iterator<iterator> reverse_iterator;
718 typedef _VSTDstd::__1::reverse_iterator<const_iterator> const_reverse_iterator;
719
720private:
721
722#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
723
724 struct __long
725 {
726 pointer __data_;
727 size_type __size_;
728 size_type __cap_;
729 };
730
731#ifdef _LIBCPP_BIG_ENDIAN
732 static const size_type __short_mask = 0x01;
733 static const size_type __long_mask = 0x1ul;
734#else // _LIBCPP_BIG_ENDIAN
735 static const size_type __short_mask = 0x80;
736 static const size_type __long_mask = ~(size_type(~0) >> 1);
737#endif // _LIBCPP_BIG_ENDIAN
738
739 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
740 (sizeof(__long) - 1)/sizeof(value_type) : 2};
741
742 struct __short
743 {
744 value_type __data_[__min_cap];
745 struct
746 : __padding<value_type>
747 {
748 unsigned char __size_;
749 };
750 };
751
752#else
753
754 struct __long
755 {
756 size_type __cap_;
757 size_type __size_;
758 pointer __data_;
759 };
760
761#ifdef _LIBCPP_BIG_ENDIAN
762 static const size_type __short_mask = 0x80;
763 static const size_type __long_mask = ~(size_type(~0) >> 1);
764#else // _LIBCPP_BIG_ENDIAN
765 static const size_type __short_mask = 0x01;
766 static const size_type __long_mask = 0x1ul;
767#endif // _LIBCPP_BIG_ENDIAN
768
769 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
770 (sizeof(__long) - 1)/sizeof(value_type) : 2};
771
772 struct __short
773 {
774 union
775 {
776 unsigned char __size_;
777 value_type __lx;
778 };
779 value_type __data_[__min_cap];
780 };
781
782#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
783
784 union __ulx{__long __lx; __short __lxx;};
785
786 enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
787
788 struct __raw
789 {
790 size_type __words[__n_words];
791 };
792
793 struct __rep
794 {
795 union
796 {
797 __long __l;
798 __short __s;
799 __raw __r;
800 };
801 };
802
803 __compressed_pair<__rep, allocator_type> __r_;
804
805public:
806 _LIBCPP_TEMPLATE_DATA_VIS__attribute__ ((__visibility__("default")))
807 static const size_type npos = -1;
808
809 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
basic_string()
810 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)noexcept(is_nothrow_default_constructible<allocator_type>
::value)
;
811
812 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
explicit basic_string(const allocator_type& __a)
813#if _LIBCPP_STD_VER14 <= 14
814 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)noexcept(is_nothrow_copy_constructible<allocator_type>::
value)
;
815#else
816 _NOEXCEPTnoexcept;
817#endif
818
819 basic_string(const basic_string& __str);
820 basic_string(const basic_string& __str, const allocator_type& __a);
821
822#ifndef _LIBCPP_CXX03_LANG
823 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
824 basic_string(basic_string&& __str)
825#if _LIBCPP_STD_VER14 <= 14
826 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)noexcept(is_nothrow_move_constructible<allocator_type>::
value)
;
827#else
828 _NOEXCEPTnoexcept;
829#endif
830
831 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
832 basic_string(basic_string&& __str, const allocator_type& __a);
833#endif // _LIBCPP_CXX03_LANG
834
835 template <class = _EnableIf<__is_allocator<_Allocator>::value, nullptr_t> >
836 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
837 basic_string(const _CharT* __s) : __r_(__default_init_tag(), __default_init_tag()) {
838 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr")((void)0);
839 __init(__s, traits_type::length(__s));
840# if _LIBCPP_DEBUG_LEVEL0 == 2
841 __get_db()->__insert_c(this);
842# endif
843 }
844
845 template <class = _EnableIf<__is_allocator<_Allocator>::value, nullptr_t> >
846 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
847 basic_string(const _CharT* __s, const _Allocator& __a);
848
849#if _LIBCPP_STD_VER14 > 20
850 basic_string(nullptr_t) = delete;
851#endif
852
853 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
854 basic_string(const _CharT* __s, size_type __n);
855 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
856 basic_string(const _CharT* __s, size_type __n, const _Allocator& __a);
857 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
858 basic_string(size_type __n, _CharT __c);
859
860 template <class = _EnableIf<__is_allocator<_Allocator>::value, nullptr_t> >
861 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
862 basic_string(size_type __n, _CharT __c, const _Allocator& __a);
863
864 basic_string(const basic_string& __str, size_type __pos, size_type __n,
865 const _Allocator& __a = _Allocator());
866 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
867 basic_string(const basic_string& __str, size_type __pos,
868 const _Allocator& __a = _Allocator());
869
870 template<class _Tp, class = _EnableIf<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
871 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VISinline __attribute__ ((__visibility__("hidden")))
872 basic_string(const _Tp& __t, size_type __pos, size_type __n,
873 const allocator_type& __a = allocator_type());
874
875 template<class _Tp, class = _EnableIf<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
876 !__is_same_uncvref<_Tp, basic_string>::value> >
877 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VISinline __attribute__ ((__visibility__("hidden")))
878 explicit basic_string(const _Tp& __t);
879
880 template<class _Tp, class = _EnableIf<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
881 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VISinline __attribute__ ((__visibility__("hidden")))
882 explicit basic_string(const _Tp& __t, const allocator_type& __a);
883
884 template<class _InputIterator, class = _EnableIf<__is_cpp17_input_iterator<_InputIterator>::value> >
885 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
886 basic_string(_InputIterator __first, _InputIterator __last);
887 template<class _InputIterator, class = _EnableIf<__is_cpp17_input_iterator<_InputIterator>::value> >
888 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
889 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
890#ifndef _LIBCPP_CXX03_LANG
891 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
892 basic_string(initializer_list<_CharT> __il);
893 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
894 basic_string(initializer_list<_CharT> __il, const _Allocator& __a);
895#endif // _LIBCPP_CXX03_LANG
896
897 inline ~basic_string();
898
899 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
900 operator __self_view() const _NOEXCEPTnoexcept { return __self_view(data(), size()); }
901
902 basic_string& operator=(const basic_string& __str);
903
904 template <class _Tp, class = _EnableIf<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
905 basic_string& operator=(const _Tp& __t)
906 {__self_view __sv = __t; return assign(__sv);}
907
908#ifndef _LIBCPP_CXX03_LANG
909 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
910 basic_string& operator=(basic_string&& __str)
911 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))noexcept((__noexcept_move_assign_container<_Allocator, __alloc_traits
>::value))
;
912 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
913 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
914#endif
915 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
basic_string& operator=(const value_type* __s) {return assign(__s);}
916#if _LIBCPP_STD_VER14 > 20
917 basic_string& operator=(nullptr_t) = delete;
918#endif
919 basic_string& operator=(value_type __c);
920
921#if _LIBCPP_DEBUG_LEVEL0 == 2
922 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
923 iterator begin() _NOEXCEPTnoexcept
924 {return iterator(this, __get_pointer());}
925 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
926 const_iterator begin() const _NOEXCEPTnoexcept
927 {return const_iterator(this, __get_pointer());}
928 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
929 iterator end() _NOEXCEPTnoexcept
930 {return iterator(this, __get_pointer() + size());}
931 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
932 const_iterator end() const _NOEXCEPTnoexcept
933 {return const_iterator(this, __get_pointer() + size());}
934#else
935 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
936 iterator begin() _NOEXCEPTnoexcept
937 {return iterator(__get_pointer());}
938 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
939 const_iterator begin() const _NOEXCEPTnoexcept
940 {return const_iterator(__get_pointer());}
941 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
942 iterator end() _NOEXCEPTnoexcept
943 {return iterator(__get_pointer() + size());}
944 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
945 const_iterator end() const _NOEXCEPTnoexcept
946 {return const_iterator(__get_pointer() + size());}
947#endif // _LIBCPP_DEBUG_LEVEL == 2
948 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
949 reverse_iterator rbegin() _NOEXCEPTnoexcept
950 {return reverse_iterator(end());}
951 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
952 const_reverse_iterator rbegin() const _NOEXCEPTnoexcept
953 {return const_reverse_iterator(end());}
954 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
955 reverse_iterator rend() _NOEXCEPTnoexcept
956 {return reverse_iterator(begin());}
957 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
958 const_reverse_iterator rend() const _NOEXCEPTnoexcept
959 {return const_reverse_iterator(begin());}
960
961 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
962 const_iterator cbegin() const _NOEXCEPTnoexcept
963 {return begin();}
964 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
965 const_iterator cend() const _NOEXCEPTnoexcept
966 {return end();}
967 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
968 const_reverse_iterator crbegin() const _NOEXCEPTnoexcept
969 {return rbegin();}
970 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
971 const_reverse_iterator crend() const _NOEXCEPTnoexcept
972 {return rend();}
973
974 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
size_type size() const _NOEXCEPTnoexcept
975 {return __is_long() ? __get_long_size() : __get_short_size();}
976 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
size_type length() const _NOEXCEPTnoexcept {return size();}
977 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
size_type max_size() const _NOEXCEPTnoexcept;
978 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
size_type capacity() const _NOEXCEPTnoexcept
979 {return (__is_long() ? __get_long_cap()
980 : static_cast<size_type>(__min_cap)) - 1;}
981
982 void resize(size_type __n, value_type __c);
983 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
void resize(size_type __n) {resize(__n, value_type());}
984
985 void reserve(size_type __requested_capacity);
986 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
void __resize_default_init(size_type __n);
987
988 _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
989 void reserve() _NOEXCEPTnoexcept {shrink_to_fit();}
990 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
991 void shrink_to_fit() _NOEXCEPTnoexcept;
992 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
993 void clear() _NOEXCEPTnoexcept;
994 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
995 bool empty() const _NOEXCEPTnoexcept {return size() == 0;}
996
997 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
const_reference operator[](size_type __pos) const _NOEXCEPTnoexcept;
998 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
reference operator[](size_type __pos) _NOEXCEPTnoexcept;
999
1000 const_reference at(size_type __n) const;
1001 reference at(size_type __n);
1002
1003 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
basic_string& operator+=(const basic_string& __str) {return append(__str);}
1004
1005 template <class _Tp>
1006 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VISinline __attribute__ ((__visibility__("hidden")))
1007 _EnableIf
1008 <
1009 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
1010 && !__is_same_uncvref<_Tp, basic_string >::value,
1011 basic_string&
1012 >
1013 operator+=(const _Tp& __t) {__self_view __sv = __t; return append(__sv);}
1014 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
basic_string& operator+=(const value_type* __s) {return append(__s);}
1015 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
1016#ifndef _LIBCPP_CXX03_LANG
1017 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
1018#endif // _LIBCPP_CXX03_LANG
1019
1020 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1021 basic_string& append(const basic_string& __str);
1022
1023 template <class _Tp>
1024 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VISinline __attribute__ ((__visibility__("hidden")))
1025 _EnableIf<
1026 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
1027 && !__is_same_uncvref<_Tp, basic_string>::value,
1028 basic_string&
1029 >
1030 append(const _Tp& __t) { __self_view __sv = __t; return append(__sv.data(), __sv.size()); }
1031 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
1032
1033 template <class _Tp>
1034 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VISinline __attribute__ ((__visibility__("hidden")))
1035 _EnableIf
1036 <
1037 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
1038 && !__is_same_uncvref<_Tp, basic_string>::value,
1039 basic_string&
1040 >
1041 append(const _Tp& __t, size_type __pos, size_type __n=npos);
1042 basic_string& append(const value_type* __s, size_type __n);
1043 basic_string& append(const value_type* __s);
1044 basic_string& append(size_type __n, value_type __c);
1045
1046 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1047 void __append_default_init(size_type __n);
1048
1049 template<class _InputIterator>
1050 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VISinline __attribute__ ((__visibility__("hidden")))
1051 _EnableIf
1052 <
1053 __is_exactly_cpp17_input_iterator<_InputIterator>::value,
1054 basic_string&
1055 >
1056 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1057 append(_InputIterator __first, _InputIterator __last) {
1058 const basic_string __temp(__first, __last, __alloc());
1059 append(__temp.data(), __temp.size());
1060 return *this;
1061 }
1062 template<class _ForwardIterator>
1063 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VISinline __attribute__ ((__visibility__("hidden")))
1064 _EnableIf
1065 <
1066 __is_cpp17_forward_iterator<_ForwardIterator>::value,
1067 basic_string&
1068 >
1069 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1070 append(_ForwardIterator __first, _ForwardIterator __last);
1071
1072#ifndef _LIBCPP_CXX03_LANG
1073 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1074 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
1075#endif // _LIBCPP_CXX03_LANG
1076
1077 void push_back(value_type __c);
1078 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1079 void pop_back();
1080 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
reference front() _NOEXCEPTnoexcept;
1081 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
const_reference front() const _NOEXCEPTnoexcept;
1082 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
reference back() _NOEXCEPTnoexcept;
1083 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
const_reference back() const _NOEXCEPTnoexcept;
1084
1085 template <class _Tp>
1086 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VISinline __attribute__ ((__visibility__("hidden")))
1087 _EnableIf
1088 <
1089 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1090 basic_string&
1091 >
1092 assign(const _Tp & __t) { __self_view __sv = __t; return assign(__sv.data(), __sv.size()); }
1093 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1094 basic_string& assign(const basic_string& __str) { return *this = __str; }
1095#ifndef _LIBCPP_CXX03_LANG
1096 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1097 basic_string& assign(basic_string&& __str)
1098 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))noexcept((__noexcept_move_assign_container<_Allocator, __alloc_traits
>::value))
1099 {*this = _VSTDstd::__1::move(__str); return *this;}
1100#endif
1101 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
1102 template <class _Tp>
1103 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VISinline __attribute__ ((__visibility__("hidden")))
1104 _EnableIf
1105 <
1106 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
1107 && !__is_same_uncvref<_Tp, basic_string>::value,
1108 basic_string&
1109 >
1110 assign(const _Tp & __t, size_type __pos, size_type __n=npos);
1111 basic_string& assign(const value_type* __s, size_type __n);
1112 basic_string& assign(const value_type* __s);
1113 basic_string& assign(size_type __n, value_type __c);
1114 template<class _InputIterator>
1115 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VISinline __attribute__ ((__visibility__("hidden")))
1116 _EnableIf
1117 <
1118 __is_exactly_cpp17_input_iterator<_InputIterator>::value,
1119 basic_string&
1120 >
1121 assign(_InputIterator __first, _InputIterator __last);
1122 template<class _ForwardIterator>
1123 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VISinline __attribute__ ((__visibility__("hidden")))
1124 _EnableIf
1125 <
1126 __is_cpp17_forward_iterator<_ForwardIterator>::value,
1127 basic_string&
1128 >
1129 assign(_ForwardIterator __first, _ForwardIterator __last);
1130#ifndef _LIBCPP_CXX03_LANG
1131 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1132 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
1133#endif // _LIBCPP_CXX03_LANG
1134
1135 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1136 basic_string& insert(size_type __pos1, const basic_string& __str);
1137
1138 template <class _Tp>
1139 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VISinline __attribute__ ((__visibility__("hidden")))
1140 _EnableIf
1141 <
1142 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1143 basic_string&
1144 >
1145 insert(size_type __pos1, const _Tp& __t)
1146 { __self_view __sv = __t; return insert(__pos1, __sv.data(), __sv.size()); }
1147
1148 template <class _Tp>
1149 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VISinline __attribute__ ((__visibility__("hidden")))
1150 _EnableIf
1151 <
1152 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value,
1153 basic_string&
1154 >
1155 insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n=npos);
1156 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
1157 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1158 basic_string& insert(size_type __pos, const value_type* __s);
1159 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1160 iterator insert(const_iterator __pos, value_type __c);
1161 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1162 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1163 template<class _InputIterator>
1164 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VISinline __attribute__ ((__visibility__("hidden")))
1165 _EnableIf
1166 <
1167 __is_exactly_cpp17_input_iterator<_InputIterator>::value,
1168 iterator
1169 >
1170 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1171 template<class _ForwardIterator>
1172 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VISinline __attribute__ ((__visibility__("hidden")))
1173 _EnableIf
1174 <
1175 __is_cpp17_forward_iterator<_ForwardIterator>::value,
1176 iterator
1177 >
1178 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
1179#ifndef _LIBCPP_CXX03_LANG
1180 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1181 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1182 {return insert(__pos, __il.begin(), __il.end());}
1183#endif // _LIBCPP_CXX03_LANG
1184
1185 basic_string& erase(size_type __pos = 0, size_type __n = npos);
1186 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1187 iterator erase(const_iterator __pos);
1188 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1189 iterator erase(const_iterator __first, const_iterator __last);
1190
1191 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1192 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
1193
1194 template <class _Tp>
1195 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VISinline __attribute__ ((__visibility__("hidden")))
1196 _EnableIf
1197 <
1198 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1199 basic_string&
1200 >
1201 replace(size_type __pos1, size_type __n1, const _Tp& __t) { __self_view __sv = __t; return replace(__pos1, __n1, __sv.data(), __sv.size()); }
1202 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos);
1203 template <class _Tp>
1204 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VISinline __attribute__ ((__visibility__("hidden")))
1205 _EnableIf
1206 <
1207 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value,
1208 basic_string&
1209 >
1210 replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos);
1211 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1212 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
1213 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
1214 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1215 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
1216
1217 template <class _Tp>
1218 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VISinline __attribute__ ((__visibility__("hidden")))
1219 _EnableIf
1220 <
1221 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1222 basic_string&
1223 >
1224 replace(const_iterator __i1, const_iterator __i2, const _Tp& __t) { __self_view __sv = __t; return replace(__i1 - begin(), __i2 - __i1, __sv); }
1225
1226 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1227 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
1228 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1229 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
1230 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1231 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
1232 template<class _InputIterator>
1233 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VISinline __attribute__ ((__visibility__("hidden")))
1234 _EnableIf
1235 <
1236 __is_cpp17_input_iterator<_InputIterator>::value,
1237 basic_string&
1238 >
1239 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
1240#ifndef _LIBCPP_CXX03_LANG
1241 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1242 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
1243 {return replace(__i1, __i2, __il.begin(), __il.end());}
1244#endif // _LIBCPP_CXX03_LANG
1245
1246 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
1247 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1248 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1249
1250 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1251 void swap(basic_string& __str)
1252#if _LIBCPP_STD_VER14 >= 14
1253 _NOEXCEPTnoexcept;
1254#else
1255 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||noexcept(!__alloc_traits::propagate_on_container_swap::value ||
__is_nothrow_swappable<allocator_type>::value)
1256 __is_nothrow_swappable<allocator_type>::value)noexcept(!__alloc_traits::propagate_on_container_swap::value ||
__is_nothrow_swappable<allocator_type>::value)
;
1257#endif
1258
1259 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1260 const value_type* c_str() const _NOEXCEPTnoexcept {return data();}
1261 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1262 const value_type* data() const _NOEXCEPTnoexcept {return _VSTDstd::__1::__to_address(__get_pointer());}
1263#if _LIBCPP_STD_VER14 > 14 || defined(_LIBCPP_BUILDING_LIBRARY)
1264 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1265 value_type* data() _NOEXCEPTnoexcept {return _VSTDstd::__1::__to_address(__get_pointer());}
1266#endif
1267
1268 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1269 allocator_type get_allocator() const _NOEXCEPTnoexcept {return __alloc();}
1270
1271 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1272 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPTnoexcept;
1273
1274 template <class _Tp>
1275 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VISinline __attribute__ ((__visibility__("hidden")))
1276 _EnableIf
1277 <
1278 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1279 size_type
1280 >
1281 find(const _Tp& __t, size_type __pos = 0) const _NOEXCEPTnoexcept;
1282 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPTnoexcept;
1283 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1284 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPTnoexcept;
1285 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPTnoexcept;
1286
1287 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1288 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPTnoexcept;
1289
1290 template <class _Tp>
1291 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VISinline __attribute__ ((__visibility__("hidden")))
1292 _EnableIf
1293 <
1294 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1295 size_type
1296 >
1297 rfind(const _Tp& __t, size_type __pos = npos) const _NOEXCEPTnoexcept;
1298 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPTnoexcept;
1299 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1300 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPTnoexcept;
1301 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPTnoexcept;
1302
1303 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1304 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPTnoexcept;
1305
1306 template <class _Tp>
1307 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VISinline __attribute__ ((__visibility__("hidden")))
1308 _EnableIf
1309 <
1310 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1311 size_type
1312 >
1313 find_first_of(const _Tp& __t, size_type __pos = 0) const _NOEXCEPTnoexcept;
1314 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPTnoexcept;
1315 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1316 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPTnoexcept;
1317 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1318 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPTnoexcept;
1319
1320 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1321 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPTnoexcept;
1322
1323 template <class _Tp>
1324 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VISinline __attribute__ ((__visibility__("hidden")))
1325 _EnableIf
1326 <
1327 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1328 size_type
1329 >
1330 find_last_of(const _Tp& __t, size_type __pos = npos) const _NOEXCEPTnoexcept;
1331 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPTnoexcept;
1332 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1333 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPTnoexcept;
1334 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1335 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPTnoexcept;
1336
1337 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1338 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPTnoexcept;
1339
1340 template <class _Tp>
1341 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VISinline __attribute__ ((__visibility__("hidden")))
1342 _EnableIf
1343 <
1344 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1345 size_type
1346 >
1347 find_first_not_of(const _Tp &__t, size_type __pos = 0) const _NOEXCEPTnoexcept;
1348 size_type find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPTnoexcept;
1349 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1350 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPTnoexcept;
1351 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1352 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPTnoexcept;
1353
1354 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1355 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPTnoexcept;
1356
1357 template <class _Tp>
1358 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VISinline __attribute__ ((__visibility__("hidden")))
1359 _EnableIf
1360 <
1361 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1362 size_type
1363 >
1364 find_last_not_of(const _Tp& __t, size_type __pos = npos) const _NOEXCEPTnoexcept;
1365 size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPTnoexcept;
1366 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1367 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPTnoexcept;
1368 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1369 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPTnoexcept;
1370
1371 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1372 int compare(const basic_string& __str) const _NOEXCEPTnoexcept;
1373
1374 template <class _Tp>
1375 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VISinline __attribute__ ((__visibility__("hidden")))
1376 _EnableIf
1377 <
1378 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1379 int
1380 >
1381 compare(const _Tp &__t) const _NOEXCEPTnoexcept;
1382
1383 template <class _Tp>
1384 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VISinline __attribute__ ((__visibility__("hidden")))
1385 _EnableIf
1386 <
1387 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1388 int
1389 >
1390 compare(size_type __pos1, size_type __n1, const _Tp& __t) const;
1391
1392 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1393 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
1394 int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos) const;
1395
1396 template <class _Tp>
1397 inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1398 _EnableIf
1399 <
1400 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value,
1401 int
1402 >
1403 compare(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos) const;
1404 int compare(const value_type* __s) const _NOEXCEPTnoexcept;
1405 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1406 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
1407
1408#if _LIBCPP_STD_VER14 > 17
1409 _LIBCPP_CONSTEXPR_AFTER_CXX11constexpr _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1410 bool starts_with(__self_view __sv) const _NOEXCEPTnoexcept
1411 { return __self_view(data(), size()).starts_with(__sv); }
1412
1413 _LIBCPP_CONSTEXPR_AFTER_CXX11constexpr _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1414 bool starts_with(value_type __c) const _NOEXCEPTnoexcept
1415 { return !empty() && _Traits::eq(front(), __c); }
1416
1417 _LIBCPP_CONSTEXPR_AFTER_CXX11constexpr _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1418 bool starts_with(const value_type* __s) const _NOEXCEPTnoexcept
1419 { return starts_with(__self_view(__s)); }
1420
1421 _LIBCPP_CONSTEXPR_AFTER_CXX11constexpr _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1422 bool ends_with(__self_view __sv) const _NOEXCEPTnoexcept
1423 { return __self_view(data(), size()).ends_with( __sv); }
1424
1425 _LIBCPP_CONSTEXPR_AFTER_CXX11constexpr _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1426 bool ends_with(value_type __c) const _NOEXCEPTnoexcept
1427 { return !empty() && _Traits::eq(back(), __c); }
1428
1429 _LIBCPP_CONSTEXPR_AFTER_CXX11constexpr _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1430 bool ends_with(const value_type* __s) const _NOEXCEPTnoexcept
1431 { return ends_with(__self_view(__s)); }
1432#endif
1433
1434#if _LIBCPP_STD_VER14 > 20
1435 constexpr _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1436 bool contains(__self_view __sv) const noexcept
1437 { return __self_view(data(), size()).contains(__sv); }
1438
1439 constexpr _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1440 bool contains(value_type __c) const noexcept
1441 { return __self_view(data(), size()).contains(__c); }
1442
1443 constexpr _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1444 bool contains(const value_type* __s) const
1445 { return __self_view(data(), size()).contains(__s); }
1446#endif
1447
1448 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
bool __invariants() const;
1449
1450 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
void __clear_and_shrink() _NOEXCEPTnoexcept;
1451
1452 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
void __shrink_or_extend(size_type __target_capacity);
1453
1454 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1455 bool __is_long() const _NOEXCEPTnoexcept
1456 {return bool(__r_.first().__s.__size_ & __short_mask);}
1457
1458#if _LIBCPP_DEBUG_LEVEL0 == 2
1459
1460 bool __dereferenceable(const const_iterator* __i) const;
1461 bool __decrementable(const const_iterator* __i) const;
1462 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1463 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1464
1465#endif // _LIBCPP_DEBUG_LEVEL == 2
1466
1467private:
1468 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1469 allocator_type& __alloc() _NOEXCEPTnoexcept
1470 {return __r_.second();}
1471 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1472 const allocator_type& __alloc() const _NOEXCEPTnoexcept
1473 {return __r_.second();}
1474
1475#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
1476
1477 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1478 void __set_short_size(size_type __s) _NOEXCEPTnoexcept
1479# ifdef _LIBCPP_BIG_ENDIAN
1480 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1481# else
1482 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1483# endif
1484
1485 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1486 size_type __get_short_size() const _NOEXCEPTnoexcept
1487# ifdef _LIBCPP_BIG_ENDIAN
1488 {return __r_.first().__s.__size_ >> 1;}
1489# else
1490 {return __r_.first().__s.__size_;}
1491# endif
1492
1493#else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
1494
1495 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1496 void __set_short_size(size_type __s) _NOEXCEPTnoexcept
1497# ifdef _LIBCPP_BIG_ENDIAN
1498 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1499# else
1500 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1501# endif
1502
1503 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1504 size_type __get_short_size() const _NOEXCEPTnoexcept
1505# ifdef _LIBCPP_BIG_ENDIAN
1506 {return __r_.first().__s.__size_;}
1507# else
1508 {return __r_.first().__s.__size_ >> 1;}
1509# endif
1510
1511#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
1512
1513 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1514 void __set_long_size(size_type __s) _NOEXCEPTnoexcept
1515 {__r_.first().__l.__size_ = __s;}
1516 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1517 size_type __get_long_size() const _NOEXCEPTnoexcept
1518 {return __r_.first().__l.__size_;}
1519 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1520 void __set_size(size_type __s) _NOEXCEPTnoexcept
1521 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1522
1523 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1524 void __set_long_cap(size_type __s) _NOEXCEPTnoexcept
1525 {__r_.first().__l.__cap_ = __long_mask | __s;}
1526 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1527 size_type __get_long_cap() const _NOEXCEPTnoexcept
1528 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
1529
1530 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1531 void __set_long_pointer(pointer __p) _NOEXCEPTnoexcept
1532 {__r_.first().__l.__data_ = __p;}
1533 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1534 pointer __get_long_pointer() _NOEXCEPTnoexcept
1535 {return __r_.first().__l.__data_;}
1536 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1537 const_pointer __get_long_pointer() const _NOEXCEPTnoexcept
1538 {return __r_.first().__l.__data_;}
1539 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1540 pointer __get_short_pointer() _NOEXCEPTnoexcept
1541 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
1542 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1543 const_pointer __get_short_pointer() const _NOEXCEPTnoexcept
1544 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
1545 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1546 pointer __get_pointer() _NOEXCEPTnoexcept
1547 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1548 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1549 const_pointer __get_pointer() const _NOEXCEPTnoexcept
1550 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1551
1552 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1553 void __zero() _NOEXCEPTnoexcept
1554 {
1555 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1556 for (unsigned __i = 0; __i < __n_words; ++__i)
1557 __a[__i] = 0;
1558 }
1559
1560 template <size_type __a> static
1561 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1562 size_type __align_it(size_type __s) _NOEXCEPTnoexcept
1563 {return (__s + (__a-1)) & ~(__a-1);}
1564 enum {__alignment = 16};
1565 static _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1566 size_type __recommend(size_type __s) _NOEXCEPTnoexcept
1567 {
1568 if (__s < __min_cap) return static_cast<size_type>(__min_cap) - 1;
1569 size_type __guess = __align_it<sizeof(value_type) < __alignment ?
1570 __alignment/sizeof(value_type) : 1 > (__s+1) - 1;
1571 if (__guess == __min_cap) ++__guess;
1572 return __guess;
1573 }
1574
1575 inline
1576 void __init(const value_type* __s, size_type __sz, size_type __reserve);
1577 inline
1578 void __init(const value_type* __s, size_type __sz);
1579 inline
1580 void __init(size_type __n, value_type __c);
1581
1582 // Slow path for the (inlined) copy constructor for 'long' strings.
1583 // Always externally instantiated and not inlined.
1584 // Requires that __s is zero terminated.
1585 // The main reason for this function to exist is because for unstable, we
1586 // want to allow inlining of the copy constructor. However, we don't want
1587 // to call the __init() functions as those are marked as inline which may
1588 // result in over-aggressive inlining by the compiler, where our aim is
1589 // to only inline the fast path code directly in the ctor.
1590 void __init_copy_ctor_external(const value_type* __s, size_type __sz);
1591
1592 template <class _InputIterator>
1593 inline
1594 _EnableIf
1595 <
1596 __is_exactly_cpp17_input_iterator<_InputIterator>::value
1597 >
1598 __init(_InputIterator __first, _InputIterator __last);
1599
1600 template <class _ForwardIterator>
1601 inline
1602 _EnableIf
1603 <
1604 __is_cpp17_forward_iterator<_ForwardIterator>::value
1605 >
1606 __init(_ForwardIterator __first, _ForwardIterator __last);
1607
1608 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1609 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
1610 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1611 size_type __n_copy, size_type __n_del,
1612 size_type __n_add, const value_type* __p_new_stuff);
1613
1614 // __assign_no_alias is invoked for assignment operations where we
1615 // have proof that the input does not alias the current instance.
1616 // For example, operator=(basic_string) performs a 'self' check.
1617 template <bool __is_short>
1618 basic_string& __assign_no_alias(const value_type* __s, size_type __n);
1619
1620 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1621 void __erase_to_end(size_type __pos);
1622
1623 // __erase_external_with_move is invoked for erase() invocations where
1624 // `n ~= npos`, likely requiring memory moves on the string data.
1625 void __erase_external_with_move(size_type __pos, size_type __n);
1626
1627 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1628 void __copy_assign_alloc(const basic_string& __str)
1629 {__copy_assign_alloc(__str, integral_constant<bool,
1630 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1631
1632 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1633 void __copy_assign_alloc(const basic_string& __str, true_type)
1634 {
1635 if (__alloc() == __str.__alloc())
1636 __alloc() = __str.__alloc();
1637 else
1638 {
1639 if (!__str.__is_long())
1640 {
1641 __clear_and_shrink();
1642 __alloc() = __str.__alloc();
1643 }
1644 else
1645 {
1646 allocator_type __a = __str.__alloc();
1647 pointer __p = __alloc_traits::allocate(__a, __str.__get_long_cap());
1648 __clear_and_shrink();
1649 __alloc() = _VSTDstd::__1::move(__a);
1650 __set_long_pointer(__p);
1651 __set_long_cap(__str.__get_long_cap());
1652 __set_long_size(__str.size());
1653 }
1654 }
1655 }
1656
1657 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1658 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPTnoexcept
1659 {}
1660
1661#ifndef _LIBCPP_CXX03_LANG
1662 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1663 void __move_assign(basic_string& __str, false_type)
1664 _NOEXCEPT_(__alloc_traits::is_always_equal::value)noexcept(__alloc_traits::is_always_equal::value);
1665 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1666 void __move_assign(basic_string& __str, true_type)
1667#if _LIBCPP_STD_VER14 > 14
1668 _NOEXCEPTnoexcept;
1669#else
1670 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)noexcept(is_nothrow_move_assignable<allocator_type>::value
)
;
1671#endif
1672#endif
1673
1674 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1675 void
1676 __move_assign_alloc(basic_string& __str)
1677 _NOEXCEPT_(noexcept(!__alloc_traits::propagate_on_container_move_assignment
::value || is_nothrow_move_assignable<allocator_type>::
value)
1678 !__alloc_traits::propagate_on_container_move_assignment::value ||noexcept(!__alloc_traits::propagate_on_container_move_assignment
::value || is_nothrow_move_assignable<allocator_type>::
value)
1679 is_nothrow_move_assignable<allocator_type>::value)noexcept(!__alloc_traits::propagate_on_container_move_assignment
::value || is_nothrow_move_assignable<allocator_type>::
value)
1680 {__move_assign_alloc(__str, integral_constant<bool,
1681 __alloc_traits::propagate_on_container_move_assignment::value>());}
1682
1683 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1684 void __move_assign_alloc(basic_string& __c, true_type)
1685 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)noexcept(is_nothrow_move_assignable<allocator_type>::value
)
1686 {
1687 __alloc() = _VSTDstd::__1::move(__c.__alloc());
1688 }
1689
1690 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1691 void __move_assign_alloc(basic_string&, false_type)
1692 _NOEXCEPTnoexcept
1693 {}
1694
1695 basic_string& __assign_external(const value_type* __s);
1696 basic_string& __assign_external(const value_type* __s, size_type __n);
1697
1698 // Assigns the value in __s, guaranteed to be __n < __min_cap in length.
1699 inline basic_string& __assign_short(const value_type* __s, size_type __n) {
1700 pointer __p = __is_long()
1701 ? (__set_long_size(__n), __get_long_pointer())
1702 : (__set_short_size(__n), __get_short_pointer());
1703 traits_type::move(_VSTDstd::__1::__to_address(__p), __s, __n);
1704 traits_type::assign(__p[__n], value_type());
1705 return *this;
1706 }
1707
1708 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
void __invalidate_all_iterators();
1709 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
void __invalidate_iterators_past(size_type);
1710
1711 template<class _Tp>
1712 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1713 bool __addr_in_range(_Tp&& __t) const {
1714 const volatile void *__p = _VSTDstd::__1::addressof(__t);
1715 return data() <= __p && __p <= data() + size();
1716 }
1717
1718 _LIBCPP_NORETURN[[noreturn]] _LIBCPP_HIDE_FROM_ABI__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1719 void __throw_length_error() const {
1720#ifndef _LIBCPP_NO_EXCEPTIONS
1721 __basic_string_common<true>::__throw_length_error();
1722#else
1723 _VSTDstd::__1::abort();
1724#endif
1725 }
1726
1727 _LIBCPP_NORETURN[[noreturn]] _LIBCPP_HIDE_FROM_ABI__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
1728 void __throw_out_of_range() const {
1729#ifndef _LIBCPP_NO_EXCEPTIONS
1730 __basic_string_common<true>::__throw_out_of_range();
1731#else
1732 _VSTDstd::__1::abort();
1733#endif
1734 }
1735
1736 friend basic_string operator+<>(const basic_string&, const basic_string&);
1737 friend basic_string operator+<>(const value_type*, const basic_string&);
1738 friend basic_string operator+<>(value_type, const basic_string&);
1739 friend basic_string operator+<>(const basic_string&, const value_type*);
1740 friend basic_string operator+<>(const basic_string&, value_type);
1741};
1742
1743// These declarations must appear before any functions are implicitly used
1744// so that they have the correct visibility specifier.
1745#ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
1746_LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char)extern template __attribute__ ((__visibility__("default"))) basic_string
<char>& basic_string<char>::replace(size_type
, size_type, value_type const*, size_type); extern template __attribute__
((__visibility__("default"))) basic_string<char>::size_type
basic_string<char>::rfind(value_type const*, size_type
, size_type) const; extern template __attribute__ ((__visibility__
("default"))) void basic_string<char>::__init(value_type
const*, size_type, size_type); extern template __attribute__
((__visibility__("default"))) basic_string<char>& basic_string
<char>::replace(size_type, size_type, value_type const*
); extern template __attribute__ ((__visibility__("default"))
) basic_string<char>::size_type basic_string<char>
::find_last_not_of(value_type const*, size_type, size_type) const
; extern template __attribute__ ((__visibility__("default")))
basic_string<char>::~basic_string(); extern template __attribute__
((__visibility__("default"))) basic_string<char>::size_type
basic_string<char>::find_first_not_of(value_type const
*, size_type, size_type) const; extern template __attribute__
((__visibility__("default"))) basic_string<char>& basic_string
<char>::insert(size_type, size_type, value_type); extern
template __attribute__ ((__visibility__("default"))) basic_string
<char>& basic_string<char>::operator=(value_type
); extern template __attribute__ ((__visibility__("default"))
) void basic_string<char>::__init(value_type const*, size_type
); extern template __attribute__ ((__visibility__("default"))
) void basic_string<char>::__init_copy_ctor_external(value_type
const*, size_type); extern template __attribute__ ((__visibility__
("default"))) const char& basic_string<char>::at(size_type
) const; extern template __attribute__ ((__visibility__("default"
))) basic_string<char>& basic_string<char>::insert
(size_type, value_type const*, size_type); extern template __attribute__
((__visibility__("default"))) basic_string<char>::size_type
basic_string<char>::find_first_of(value_type const*, size_type
, size_type) const; extern template __attribute__ ((__visibility__
("default"))) basic_string<char>& basic_string<char
>::replace(size_type, size_type, size_type, value_type); extern
template __attribute__ ((__visibility__("default"))) basic_string
<char>& basic_string<char>::__assign_external
(value_type const*, size_type); extern template __attribute__
((__visibility__("default"))) basic_string<char>& basic_string
<char>::__assign_external(value_type const*); extern template
__attribute__ ((__visibility__("default"))) void basic_string
<char>::reserve(size_type); extern template __attribute__
((__visibility__("default"))) basic_string<char>& basic_string
<char>::append(value_type const*, size_type); extern template
__attribute__ ((__visibility__("default"))) basic_string<
char>& basic_string<char>::assign(basic_string const
&, size_type, size_type); extern template __attribute__ (
(__visibility__("default"))) basic_string<char>::size_type
basic_string<char>::copy(value_type*, size_type, size_type
) const; extern template __attribute__ ((__visibility__("default"
))) basic_string<char>::basic_string(basic_string const
&, size_type, size_type, allocator<char> const&
); extern template __attribute__ ((__visibility__("default"))
) basic_string<char>::size_type basic_string<char>
::find(value_type, size_type) const; extern template __attribute__
((__visibility__("default"))) void basic_string<char>::
__init(size_type, value_type); extern template __attribute__ (
(__visibility__("default"))) basic_string<char>& basic_string
<char>::insert(size_type, value_type const*); extern template
__attribute__ ((__visibility__("default"))) basic_string<
char>::size_type basic_string<char>::find_last_of(value_type
const*, size_type, size_type) const; extern template __attribute__
((__visibility__("default"))) void basic_string<char>::
__grow_by(size_type, size_type, size_type, size_type, size_type
, size_type); extern template __attribute__ ((__visibility__(
"default"))) void basic_string<char>::__grow_by_and_replace
(size_type, size_type, size_type, size_type, size_type, size_type
, value_type const*); extern template __attribute__ ((__visibility__
("default"))) basic_string<char>& basic_string<char
>::__assign_no_alias<false>(value_type const*, size_type
); extern template __attribute__ ((__visibility__("default"))
) basic_string<char>& basic_string<char>::__assign_no_alias
<true>(value_type const*, size_type); extern template __attribute__
((__visibility__("default"))) void basic_string<char>::
push_back(value_type); extern template __attribute__ ((__visibility__
("default"))) basic_string<char>& basic_string<char
>::append(size_type, value_type); extern template __attribute__
((__visibility__("default"))) basic_string<char>::size_type
basic_string<char>::rfind(value_type, size_type) const
; extern template __attribute__ ((__visibility__("default")))
const basic_string<char>::size_type basic_string<char
>::npos; extern template __attribute__ ((__visibility__("default"
))) basic_string<char>& basic_string<char>::assign
(size_type, value_type); extern template __attribute__ ((__visibility__
("default"))) void basic_string<char>::__erase_external_with_move
(size_type, size_type); extern template __attribute__ ((__visibility__
("default"))) basic_string<char>& basic_string<char
>::append(basic_string const&, size_type, size_type); extern
template __attribute__ ((__visibility__("default"))) int basic_string
<char>::compare(value_type const*) const; extern template
__attribute__ ((__visibility__("default"))) int basic_string
<char>::compare(size_type, size_type, value_type const*
) const; extern template __attribute__ ((__visibility__("default"
))) char& basic_string<char>::at(size_type); extern
template __attribute__ ((__visibility__("default"))) basic_string
<char>::size_type basic_string<char>::find(value_type
const*, size_type, size_type) const; extern template __attribute__
((__visibility__("default"))) int basic_string<char>::
compare(size_type, size_type, basic_string const&, size_type
, size_type) const; extern template __attribute__ ((__visibility__
("default"))) int basic_string<char>::compare(size_type
, size_type, value_type const*, size_type) const; extern template
__attribute__ ((__visibility__("default"))) basic_string<
char>& basic_string<char>::append(value_type const
*); extern template __attribute__ ((__visibility__("default")
)) basic_string<char>& basic_string<char>::replace
(size_type, size_type, basic_string const&, size_type, size_type
); extern template __attribute__ ((__visibility__("default"))
) basic_string<char>::iterator basic_string<char>
::insert(basic_string::const_iterator, value_type); extern template
__attribute__ ((__visibility__("default"))) void basic_string
<char>::resize(size_type, value_type); extern template __attribute__
((__visibility__("default"))) basic_string<char>& basic_string
<char>::insert(size_type, basic_string const&, size_type
, size_type);
1747_LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t)extern template __attribute__ ((__visibility__("default"))) basic_string
<wchar_t>& basic_string<wchar_t>::replace(size_type
, size_type, value_type const*, size_type); extern template __attribute__
((__visibility__("default"))) basic_string<wchar_t>::size_type
basic_string<wchar_t>::rfind(value_type const*, size_type
, size_type) const; extern template __attribute__ ((__visibility__
("default"))) void basic_string<wchar_t>::__init(value_type
const*, size_type, size_type); extern template __attribute__
((__visibility__("default"))) basic_string<wchar_t>&
basic_string<wchar_t>::replace(size_type, size_type, value_type
const*); extern template __attribute__ ((__visibility__("default"
))) basic_string<wchar_t>::size_type basic_string<wchar_t
>::find_last_not_of(value_type const*, size_type, size_type
) const; extern template __attribute__ ((__visibility__("default"
))) basic_string<wchar_t>::~basic_string(); extern template
__attribute__ ((__visibility__("default"))) basic_string<
wchar_t>::size_type basic_string<wchar_t>::find_first_not_of
(value_type const*, size_type, size_type) const; extern template
__attribute__ ((__visibility__("default"))) basic_string<
wchar_t>& basic_string<wchar_t>::insert(size_type
, size_type, value_type); extern template __attribute__ ((__visibility__
("default"))) basic_string<wchar_t>& basic_string<
wchar_t>::operator=(value_type); extern template __attribute__
((__visibility__("default"))) void basic_string<wchar_t>
::__init(value_type const*, size_type); extern template __attribute__
((__visibility__("default"))) void basic_string<wchar_t>
::__init_copy_ctor_external(value_type const*, size_type); extern
template __attribute__ ((__visibility__("default"))) const wchar_t
& basic_string<wchar_t>::at(size_type) const; extern
template __attribute__ ((__visibility__("default"))) basic_string
<wchar_t>& basic_string<wchar_t>::insert(size_type
, value_type const*, size_type); extern template __attribute__
((__visibility__("default"))) basic_string<wchar_t>::size_type
basic_string<wchar_t>::find_first_of(value_type const*
, size_type, size_type) const; extern template __attribute__ (
(__visibility__("default"))) basic_string<wchar_t>&
basic_string<wchar_t>::replace(size_type, size_type, size_type
, value_type); extern template __attribute__ ((__visibility__
("default"))) basic_string<wchar_t>& basic_string<
wchar_t>::__assign_external(value_type const*, size_type);
extern template __attribute__ ((__visibility__("default"))) basic_string
<wchar_t>& basic_string<wchar_t>::__assign_external
(value_type const*); extern template __attribute__ ((__visibility__
("default"))) void basic_string<wchar_t>::reserve(size_type
); extern template __attribute__ ((__visibility__("default"))
) basic_string<wchar_t>& basic_string<wchar_t>
::append(value_type const*, size_type); extern template __attribute__
((__visibility__("default"))) basic_string<wchar_t>&
basic_string<wchar_t>::assign(basic_string const&,
size_type, size_type); extern template __attribute__ ((__visibility__
("default"))) basic_string<wchar_t>::size_type basic_string
<wchar_t>::copy(value_type*, size_type, size_type) const
; extern template __attribute__ ((__visibility__("default")))
basic_string<wchar_t>::basic_string(basic_string const
&, size_type, size_type, allocator<wchar_t> const&
); extern template __attribute__ ((__visibility__("default"))
) basic_string<wchar_t>::size_type basic_string<wchar_t
>::find(value_type, size_type) const; extern template __attribute__
((__visibility__("default"))) void basic_string<wchar_t>
::__init(size_type, value_type); extern template __attribute__
((__visibility__("default"))) basic_string<wchar_t>&
basic_string<wchar_t>::insert(size_type, value_type const
*); extern template __attribute__ ((__visibility__("default")
)) basic_string<wchar_t>::size_type basic_string<wchar_t
>::find_last_of(value_type const*, size_type, size_type) const
; extern template __attribute__ ((__visibility__("default")))
void basic_string<wchar_t>::__grow_by(size_type, size_type
, size_type, size_type, size_type, size_type); extern template
__attribute__ ((__visibility__("default"))) void basic_string
<wchar_t>::__grow_by_and_replace(size_type, size_type, size_type
, size_type, size_type, size_type, value_type const*); extern
template __attribute__ ((__visibility__("default"))) basic_string
<wchar_t>& basic_string<wchar_t>::__assign_no_alias
<false>(value_type const*, size_type); extern template __attribute__
((__visibility__("default"))) basic_string<wchar_t>&
basic_string<wchar_t>::__assign_no_alias<true>(value_type
const*, size_type); extern template __attribute__ ((__visibility__
("default"))) void basic_string<wchar_t>::push_back(value_type
); extern template __attribute__ ((__visibility__("default"))
) basic_string<wchar_t>& basic_string<wchar_t>
::append(size_type, value_type); extern template __attribute__
((__visibility__("default"))) basic_string<wchar_t>::size_type
basic_string<wchar_t>::rfind(value_type, size_type) const
; extern template __attribute__ ((__visibility__("default")))
const basic_string<wchar_t>::size_type basic_string<
wchar_t>::npos; extern template __attribute__ ((__visibility__
("default"))) basic_string<wchar_t>& basic_string<
wchar_t>::assign(size_type, value_type); extern template __attribute__
((__visibility__("default"))) void basic_string<wchar_t>
::__erase_external_with_move(size_type, size_type); extern template
__attribute__ ((__visibility__("default"))) basic_string<
wchar_t>& basic_string<wchar_t>::append(basic_string
const&, size_type, size_type); extern template __attribute__
((__visibility__("default"))) int basic_string<wchar_t>
::compare(value_type const*) const; extern template __attribute__
((__visibility__("default"))) int basic_string<wchar_t>
::compare(size_type, size_type, value_type const*) const; extern
template __attribute__ ((__visibility__("default"))) wchar_t
& basic_string<wchar_t>::at(size_type); extern template
__attribute__ ((__visibility__("default"))) basic_string<
wchar_t>::size_type basic_string<wchar_t>::find(value_type
const*, size_type, size_type) const; extern template __attribute__
((__visibility__("default"))) int basic_string<wchar_t>
::compare(size_type, size_type, basic_string const&, size_type
, size_type) const; extern template __attribute__ ((__visibility__
("default"))) int basic_string<wchar_t>::compare(size_type
, size_type, value_type const*, size_type) const; extern template
__attribute__ ((__visibility__("default"))) basic_string<
wchar_t>& basic_string<wchar_t>::append(value_type
const*); extern template __attribute__ ((__visibility__("default"
))) basic_string<wchar_t>& basic_string<wchar_t>
::replace(size_type, size_type, basic_string const&, size_type
, size_type); extern template __attribute__ ((__visibility__(
"default"))) basic_string<wchar_t>::iterator basic_string
<wchar_t>::insert(basic_string::const_iterator, value_type
); extern template __attribute__ ((__visibility__("default"))
) void basic_string<wchar_t>::resize(size_type, value_type
); extern template __attribute__ ((__visibility__("default"))
) basic_string<wchar_t>& basic_string<wchar_t>
::insert(size_type, basic_string const&, size_type, size_type
);
1748#else
1749_LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char)extern template __attribute__ ((__visibility__("default"))) basic_string
<char>& basic_string<char>::replace(size_type
, size_type, value_type const*, size_type); extern template __attribute__
((__visibility__("default"))) basic_string<char>::size_type
basic_string<char>::rfind(value_type const*, size_type
, size_type) const; extern template __attribute__ ((__visibility__
("default"))) void basic_string<char>::__init(value_type
const*, size_type, size_type); extern template __attribute__
((__visibility__("default"))) basic_string<char>::basic_string
(basic_string const&); extern template __attribute__ ((__visibility__
("default"))) basic_string<char>& basic_string<char
>::replace(size_type, size_type, value_type const*); extern
template __attribute__ ((__visibility__("default"))) basic_string
<char>::basic_string(basic_string const&, allocator
<char> const&); extern template __attribute__ ((__visibility__
("default"))) basic_string<char>::size_type basic_string
<char>::find_last_not_of(value_type const*, size_type, size_type
) const; extern template __attribute__ ((__visibility__("default"
))) basic_string<char>::~basic_string(); extern template
__attribute__ ((__visibility__("default"))) basic_string<
char>::size_type basic_string<char>::find_first_not_of
(value_type const*, size_type, size_type) const; extern template
__attribute__ ((__visibility__("default"))) basic_string<
char>& basic_string<char>::insert(size_type, size_type
, value_type); extern template __attribute__ ((__visibility__
("default"))) basic_string<char>& basic_string<char
>::operator=(value_type); extern template __attribute__ ((
__visibility__("default"))) void basic_string<char>::__init
(value_type const*, size_type); extern template __attribute__
((__visibility__("default"))) const char& basic_string<
char>::at(size_type) const; extern template __attribute__ (
(__visibility__("default"))) basic_string<char>& basic_string
<char>::insert(size_type, value_type const*, size_type)
; extern template __attribute__ ((__visibility__("default")))
basic_string<char>::size_type basic_string<char>
::find_first_of(value_type const*, size_type, size_type) const
; extern template __attribute__ ((__visibility__("default")))
basic_string<char>& basic_string<char>::replace
(size_type, size_type, size_type, value_type); extern template
__attribute__ ((__visibility__("default"))) basic_string<
char>& basic_string<char>::assign(value_type const
*, size_type); extern template __attribute__ ((__visibility__
("default"))) void basic_string<char>::reserve(size_type
); extern template __attribute__ ((__visibility__("default"))
) basic_string<char>& basic_string<char>::append
(value_type const*, size_type); extern template __attribute__
((__visibility__("default"))) basic_string<char>& basic_string
<char>::assign(basic_string const&, size_type, size_type
); extern template __attribute__ ((__visibility__("default"))
) basic_string<char>::size_type basic_string<char>
::copy(value_type*, size_type, size_type) const; extern template
__attribute__ ((__visibility__("default"))) basic_string<
char>::basic_string(basic_string const&, size_type, size_type
, allocator<char> const&); extern template __attribute__
((__visibility__("default"))) basic_string<char>::size_type
basic_string<char>::find(value_type, size_type) const;
extern template __attribute__ ((__visibility__("default"))) void
basic_string<char>::__init(size_type, value_type); extern
template __attribute__ ((__visibility__("default"))) basic_string
<char>& basic_string<char>::insert(size_type,
value_type const*); extern template __attribute__ ((__visibility__
("default"))) basic_string<char>::size_type basic_string
<char>::find_last_of(value_type const*, size_type, size_type
) const; extern template __attribute__ ((__visibility__("default"
))) void basic_string<char>::__grow_by(size_type, size_type
, size_type, size_type, size_type, size_type); extern template
__attribute__ ((__visibility__("default"))) void basic_string
<char>::__grow_by_and_replace(size_type, size_type, size_type
, size_type, size_type, size_type, value_type const*); extern
template __attribute__ ((__visibility__("default"))) void basic_string
<char>::push_back(value_type); extern template __attribute__
((__visibility__("default"))) basic_string<char>& basic_string
<char>::append(size_type, value_type); extern template __attribute__
((__visibility__("default"))) basic_string<char>::size_type
basic_string<char>::rfind(value_type, size_type) const
; extern template __attribute__ ((__visibility__("default")))
const basic_string<char>::size_type basic_string<char
>::npos; extern template __attribute__ ((__visibility__("default"
))) basic_string<char>& basic_string<char>::assign
(size_type, value_type); extern template __attribute__ ((__visibility__
("default"))) basic_string<char>& basic_string<char
>::erase(size_type, size_type); extern template __attribute__
((__visibility__("default"))) basic_string<char>& basic_string
<char>::append(basic_string const&, size_type, size_type
); extern template __attribute__ ((__visibility__("default"))
) int basic_string<char>::compare(value_type const*) const
; extern template __attribute__ ((__visibility__("default")))
int basic_string<char>::compare(size_type, size_type, value_type
const*) const; extern template __attribute__ ((__visibility__
("default"))) char& basic_string<char>::at(size_type
); extern template __attribute__ ((__visibility__("default"))
) basic_string<char>& basic_string<char>::assign
(value_type const*); extern template __attribute__ ((__visibility__
("default"))) basic_string<char>::size_type basic_string
<char>::find(value_type const*, size_type, size_type) const
; extern template __attribute__ ((__visibility__("default")))
int basic_string<char>::compare(size_type, size_type, basic_string
const&, size_type, size_type) const; extern template __attribute__
((__visibility__("default"))) int basic_string<char>::
compare(size_type, size_type, value_type const*, size_type) const
; extern template __attribute__ ((__visibility__("default")))
basic_string<char>& basic_string<char>::operator
=(basic_string const&); extern template __attribute__ ((__visibility__
("default"))) basic_string<char>& basic_string<char
>::append(value_type const*); extern template __attribute__
((__visibility__("default"))) basic_string<char>& basic_string
<char>::replace(size_type, size_type, basic_string const
&, size_type, size_type); extern template __attribute__ (
(__visibility__("default"))) basic_string<char>::iterator
basic_string<char>::insert(basic_string::const_iterator
, value_type); extern template __attribute__ ((__visibility__
("default"))) void basic_string<char>::resize(size_type
, value_type); extern template __attribute__ ((__visibility__
("default"))) basic_string<char>& basic_string<char
>::insert(size_type, basic_string const&, size_type, size_type
);
1750_LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t)extern template __attribute__ ((__visibility__("default"))) basic_string
<wchar_t>& basic_string<wchar_t>::replace(size_type
, size_type, value_type const*, size_type); extern template __attribute__
((__visibility__("default"))) basic_string<wchar_t>::size_type
basic_string<wchar_t>::rfind(value_type const*, size_type
, size_type) const; extern template __attribute__ ((__visibility__
("default"))) void basic_string<wchar_t>::__init(value_type
const*, size_type, size_type); extern template __attribute__
((__visibility__("default"))) basic_string<wchar_t>::basic_string
(basic_string const&); extern template __attribute__ ((__visibility__
("default"))) basic_string<wchar_t>& basic_string<
wchar_t>::replace(size_type, size_type, value_type const*)
; extern template __attribute__ ((__visibility__("default")))
basic_string<wchar_t>::basic_string(basic_string const
&, allocator<wchar_t> const&); extern template __attribute__
((__visibility__("default"))) basic_string<wchar_t>::size_type
basic_string<wchar_t>::find_last_not_of(value_type const
*, size_type, size_type) const; extern template __attribute__
((__visibility__("default"))) basic_string<wchar_t>::~
basic_string(); extern template __attribute__ ((__visibility__
("default"))) basic_string<wchar_t>::size_type basic_string
<wchar_t>::find_first_not_of(value_type const*, size_type
, size_type) const; extern template __attribute__ ((__visibility__
("default"))) basic_string<wchar_t>& basic_string<
wchar_t>::insert(size_type, size_type, value_type); extern
template __attribute__ ((__visibility__("default"))) basic_string
<wchar_t>& basic_string<wchar_t>::operator=(value_type
); extern template __attribute__ ((__visibility__("default"))
) void basic_string<wchar_t>::__init(value_type const*,
size_type); extern template __attribute__ ((__visibility__("default"
))) const wchar_t& basic_string<wchar_t>::at(size_type
) const; extern template __attribute__ ((__visibility__("default"
))) basic_string<wchar_t>& basic_string<wchar_t>
::insert(size_type, value_type const*, size_type); extern template
__attribute__ ((__visibility__("default"))) basic_string<
wchar_t>::size_type basic_string<wchar_t>::find_first_of
(value_type const*, size_type, size_type) const; extern template
__attribute__ ((__visibility__("default"))) basic_string<
wchar_t>& basic_string<wchar_t>::replace(size_type
, size_type, size_type, value_type); extern template __attribute__
((__visibility__("default"))) basic_string<wchar_t>&
basic_string<wchar_t>::assign(value_type const*, size_type
); extern template __attribute__ ((__visibility__("default"))
) void basic_string<wchar_t>::reserve(size_type); extern
template __attribute__ ((__visibility__("default"))) basic_string
<wchar_t>& basic_string<wchar_t>::append(value_type
const*, size_type); extern template __attribute__ ((__visibility__
("default"))) basic_string<wchar_t>& basic_string<
wchar_t>::assign(basic_string const&, size_type, size_type
); extern template __attribute__ ((__visibility__("default"))
) basic_string<wchar_t>::size_type basic_string<wchar_t
>::copy(value_type*, size_type, size_type) const; extern template
__attribute__ ((__visibility__("default"))) basic_string<
wchar_t>::basic_string(basic_string const&, size_type,
size_type, allocator<wchar_t> const&); extern template
__attribute__ ((__visibility__("default"))) basic_string<
wchar_t>::size_type basic_string<wchar_t>::find(value_type
, size_type) const; extern template __attribute__ ((__visibility__
("default"))) void basic_string<wchar_t>::__init(size_type
, value_type); extern template __attribute__ ((__visibility__
("default"))) basic_string<wchar_t>& basic_string<
wchar_t>::insert(size_type, value_type const*); extern template
__attribute__ ((__visibility__("default"))) basic_string<
wchar_t>::size_type basic_string<wchar_t>::find_last_of
(value_type const*, size_type, size_type) const; extern template
__attribute__ ((__visibility__("default"))) void basic_string
<wchar_t>::__grow_by(size_type, size_type, size_type, size_type
, size_type, size_type); extern template __attribute__ ((__visibility__
("default"))) void basic_string<wchar_t>::__grow_by_and_replace
(size_type, size_type, size_type, size_type, size_type, size_type
, value_type const*); extern template __attribute__ ((__visibility__
("default"))) void basic_string<wchar_t>::push_back(value_type
); extern template __attribute__ ((__visibility__("default"))
) basic_string<wchar_t>& basic_string<wchar_t>
::append(size_type, value_type); extern template __attribute__
((__visibility__("default"))) basic_string<wchar_t>::size_type
basic_string<wchar_t>::rfind(value_type, size_type) const
; extern template __attribute__ ((__visibility__("default")))
const basic_string<wchar_t>::size_type basic_string<
wchar_t>::npos; extern template __attribute__ ((__visibility__
("default"))) basic_string<wchar_t>& basic_string<
wchar_t>::assign(size_type, value_type); extern template __attribute__
((__visibility__("default"))) basic_string<wchar_t>&
basic_string<wchar_t>::erase(size_type, size_type); extern
template __attribute__ ((__visibility__("default"))) basic_string
<wchar_t>& basic_string<wchar_t>::append(basic_string
const&, size_type, size_type); extern template __attribute__
((__visibility__("default"))) int basic_string<wchar_t>
::compare(value_type const*) const; extern template __attribute__
((__visibility__("default"))) int basic_string<wchar_t>
::compare(size_type, size_type, value_type const*) const; extern
template __attribute__ ((__visibility__("default"))) wchar_t
& basic_string<wchar_t>::at(size_type); extern template
__attribute__ ((__visibility__("default"))) basic_string<
wchar_t>& basic_string<wchar_t>::assign(value_type
const*); extern template __attribute__ ((__visibility__("default"
))) basic_string<wchar_t>::size_type basic_string<wchar_t
>::find(value_type const*, size_type, size_type) const; extern
template __attribute__ ((__visibility__("default"))) int basic_string
<wchar_t>::compare(size_type, size_type, basic_string const
&, size_type, size_type) const; extern template __attribute__
((__visibility__("default"))) int basic_string<wchar_t>
::compare(size_type, size_type, value_type const*, size_type)
const; extern template __attribute__ ((__visibility__("default"
))) basic_string<wchar_t>& basic_string<wchar_t>
::operator=(basic_string const&); extern template __attribute__
((__visibility__("default"))) basic_string<wchar_t>&
basic_string<wchar_t>::append(value_type const*); extern
template __attribute__ ((__visibility__("default"))) basic_string
<wchar_t>& basic_string<wchar_t>::replace(size_type
, size_type, basic_string const&, size_type, size_type); extern
template __attribute__ ((__visibility__("default"))) basic_string
<wchar_t>::iterator basic_string<wchar_t>::insert
(basic_string::const_iterator, value_type); extern template __attribute__
((__visibility__("default"))) void basic_string<wchar_t>
::resize(size_type, value_type); extern template __attribute__
((__visibility__("default"))) basic_string<wchar_t>&
basic_string<wchar_t>::insert(size_type, basic_string const
&, size_type, size_type);
1751#endif
1752
1753
1754#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1755template<class _InputIterator,
1756 class _CharT = __iter_value_type<_InputIterator>,
1757 class _Allocator = allocator<_CharT>,
1758 class = _EnableIf<__is_cpp17_input_iterator<_InputIterator>::value>,
1759 class = _EnableIf<__is_allocator<_Allocator>::value>
1760 >
1761basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
1762 -> basic_string<_CharT, char_traits<_CharT>, _Allocator>;
1763
1764template<class _CharT,
1765 class _Traits,
1766 class _Allocator = allocator<_CharT>,
1767 class = _EnableIf<__is_allocator<_Allocator>::value>
1768 >
1769explicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator())
1770 -> basic_string<_CharT, _Traits, _Allocator>;
1771
1772template<class _CharT,
1773 class _Traits,
1774 class _Allocator = allocator<_CharT>,
1775 class = _EnableIf<__is_allocator<_Allocator>::value>,
1776 class _Sz = typename allocator_traits<_Allocator>::size_type
1777 >
1778basic_string(basic_string_view<_CharT, _Traits>, _Sz, _Sz, const _Allocator& = _Allocator())
1779 -> basic_string<_CharT, _Traits, _Allocator>;
1780#endif
1781
1782template <class _CharT, class _Traits, class _Allocator>
1783inline
1784void
1785basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1786{
1787#if _LIBCPP_DEBUG_LEVEL0 == 2
1788 __get_db()->__invalidate_all(this);
1789#endif
1790}
1791
1792template <class _CharT, class _Traits, class _Allocator>
1793inline
1794void
1795basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type __pos)
1796{
1797#if _LIBCPP_DEBUG_LEVEL0 == 2
1798 __c_node* __c = __get_db()->__find_c_and_lock(this);
1799 if (__c)
1800 {
1801 const_pointer __new_last = __get_pointer() + __pos;
1802 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1803 {
1804 --__p;
1805 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1806 if (__i->base() > __new_last)
1807 {
1808 (*__p)->__c_ = nullptr;
1809 if (--__c->end_ != __p)
1810 _VSTDstd::__1::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1811 }
1812 }
1813 __get_db()->unlock();
1814 }
1815#else
1816 (void)__pos;
1817#endif // _LIBCPP_DEBUG_LEVEL == 2
1818}
1819
1820template <class _CharT, class _Traits, class _Allocator>
1821inline
1822basic_string<_CharT, _Traits, _Allocator>::basic_string()
1823 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)noexcept(is_nothrow_default_constructible<allocator_type>
::value)
1824 : __r_(__default_init_tag(), __default_init_tag())
1825{
1826#if _LIBCPP_DEBUG_LEVEL0 == 2
1827 __get_db()->__insert_c(this);
1828#endif
1829 __zero();
1830}
1831
1832template <class _CharT, class _Traits, class _Allocator>
1833inline
1834basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
1835#if _LIBCPP_STD_VER14 <= 14
1836 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)noexcept(is_nothrow_copy_constructible<allocator_type>::
value)
1837#else
1838 _NOEXCEPTnoexcept
1839#endif
1840: __r_(__default_init_tag(), __a)
1841{
1842#if _LIBCPP_DEBUG_LEVEL0 == 2
1843 __get_db()->__insert_c(this);
1844#endif
1845 __zero();
1846}
1847
1848template <class _CharT, class _Traits, class _Allocator>
1849void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
1850 size_type __sz,
1851 size_type __reserve)
1852{
1853 if (__reserve > max_size())
1854 this->__throw_length_error();
1855 pointer __p;
1856 if (__reserve < __min_cap)
1857 {
1858 __set_short_size(__sz);
1859 __p = __get_short_pointer();
1860 }
1861 else
1862 {
1863 size_type __cap = __recommend(__reserve);
1864 __p = __alloc_traits::allocate(__alloc(), __cap+1);
1865 __set_long_pointer(__p);
1866 __set_long_cap(__cap+1);
1867 __set_long_size(__sz);
1868 }
1869 traits_type::copy(_VSTDstd::__1::__to_address(__p), __s, __sz);
1870 traits_type::assign(__p[__sz], value_type());
1871}
1872
1873template <class _CharT, class _Traits, class _Allocator>
1874void
1875basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
1876{
1877 if (__sz > max_size())
1878 this->__throw_length_error();
1879 pointer __p;
1880 if (__sz < __min_cap)
1881 {
1882 __set_short_size(__sz);
1883 __p = __get_short_pointer();
1884 }
1885 else
1886 {
1887 size_type __cap = __recommend(__sz);
1888 __p = __alloc_traits::allocate(__alloc(), __cap+1);
1889 __set_long_pointer(__p);
1890 __set_long_cap(__cap+1);
1891 __set_long_size(__sz);
1892 }
1893 traits_type::copy(_VSTDstd::__1::__to_address(__p), __s, __sz);
1894 traits_type::assign(__p[__sz], value_type());
1895}
1896
1897template <class _CharT, class _Traits, class _Allocator>
1898template <class>
1899basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a)
1900 : __r_(__default_init_tag(), __a)
1901{
1902 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr")((void)0);
1903 __init(__s, traits_type::length(__s));
1904#if _LIBCPP_DEBUG_LEVEL0 == 2
1905 __get_db()->__insert_c(this);
1906#endif
1907}
1908
1909template <class _CharT, class _Traits, class _Allocator>
1910inline
1911basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n)
1912 : __r_(__default_init_tag(), __default_init_tag())
1913{
1914 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr")((void)0);
1915 __init(__s, __n);
1916#if _LIBCPP_DEBUG_LEVEL0 == 2
1917 __get_db()->__insert_c(this);
1918#endif
1919}
1920
1921template <class _CharT, class _Traits, class _Allocator>
1922inline
1923basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n, const _Allocator& __a)
1924 : __r_(__default_init_tag(), __a)
1925{
1926 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr")((void)0);
1927 __init(__s, __n);
1928#if _LIBCPP_DEBUG_LEVEL0 == 2
1929 __get_db()->__insert_c(this);
1930#endif
1931}
1932
1933template <class _CharT, class _Traits, class _Allocator>
1934basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
1935 : __r_(__default_init_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc()))
1936{
1937 if (!__str.__is_long())
1938 __r_.first().__r = __str.__r_.first().__r;
1939 else
1940 __init_copy_ctor_external(_VSTDstd::__1::__to_address(__str.__get_long_pointer()),
1941 __str.__get_long_size());
1942
1943#if _LIBCPP_DEBUG_LEVEL0 == 2
1944 __get_db()->__insert_c(this);
1945#endif
1946}
1947
1948template <class _CharT, class _Traits, class _Allocator>
1949basic_string<_CharT, _Traits, _Allocator>::basic_string(
1950 const basic_string& __str, const allocator_type& __a)
1951 : __r_(__default_init_tag(), __a)
1952{
1953 if (!__str.__is_long())
1954 __r_.first().__r = __str.__r_.first().__r;
1955 else
1956 __init_copy_ctor_external(_VSTDstd::__1::__to_address(__str.__get_long_pointer()),
1957 __str.__get_long_size());
1958#if _LIBCPP_DEBUG_LEVEL0 == 2
1959 __get_db()->__insert_c(this);
1960#endif
1961}
1962
1963template <class _CharT, class _Traits, class _Allocator>
1964void basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external(
1965 const value_type* __s, size_type __sz) {
1966 pointer __p;
1967 if (__sz < __min_cap) {
1968 __p = __get_short_pointer();
1969 __set_short_size(__sz);
1970 } else {
1971 if (__sz > max_size())
1972 this->__throw_length_error();
1973 size_t __cap = __recommend(__sz);
1974 __p = __alloc_traits::allocate(__alloc(), __cap + 1);
1975 __set_long_pointer(__p);
1976 __set_long_cap(__cap + 1);
1977 __set_long_size(__sz);
1978 }
1979 traits_type::copy(_VSTDstd::__1::__to_address(__p), __s, __sz + 1);
1980}
1981
1982#ifndef _LIBCPP_CXX03_LANG
1983
1984template <class _CharT, class _Traits, class _Allocator>
1985inline
1986basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
1987#if _LIBCPP_STD_VER14 <= 14
1988 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)noexcept(is_nothrow_move_constructible<allocator_type>::
value)
1989#else
1990 _NOEXCEPTnoexcept
1991#endif
1992 : __r_(_VSTDstd::__1::move(__str.__r_))
1993{
1994 __str.__zero();
1995#if _LIBCPP_DEBUG_LEVEL0 == 2
1996 __get_db()->__insert_c(this);
1997 if (__is_long())
1998 __get_db()->swap(this, &__str);
1999#endif
2000}
2001
2002template <class _CharT, class _Traits, class _Allocator>
2003inline
2004basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
2005 : __r_(__default_init_tag(), __a)
2006{
2007 if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
2008 __init(_VSTDstd::__1::__to_address(__str.__get_long_pointer()), __str.__get_long_size());
2009 else
2010 {
2011 __r_.first().__r = __str.__r_.first().__r;
2012 __str.__zero();
2013 }
2014#if _LIBCPP_DEBUG_LEVEL0 == 2
2015 __get_db()->__insert_c(this);
2016 if (__is_long())
2017 __get_db()->swap(this, &__str);
2018#endif
2019}
2020
2021#endif // _LIBCPP_CXX03_LANG
2022
2023template <class _CharT, class _Traits, class _Allocator>
2024void
2025basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
2026{
2027 if (__n > max_size())
2028 this->__throw_length_error();
2029 pointer __p;
2030 if (__n < __min_cap)
2031 {
2032 __set_short_size(__n);
2033 __p = __get_short_pointer();
2034 }
2035 else
2036 {
2037 size_type __cap = __recommend(__n);
2038 __p = __alloc_traits::allocate(__alloc(), __cap+1);
2039 __set_long_pointer(__p);
2040 __set_long_cap(__cap+1);
2041 __set_long_size(__n);
2042 }
2043 traits_type::assign(_VSTDstd::__1::__to_address(__p), __n, __c);
2044 traits_type::assign(__p[__n], value_type());
2045}
2046
2047template <class _CharT, class _Traits, class _Allocator>
2048inline
2049basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c)
2050 : __r_(__default_init_tag(), __default_init_tag())
2051{
2052 __init(__n, __c);
2053#if _LIBCPP_DEBUG_LEVEL0 == 2
2054 __get_db()->__insert_c(this);
2055#endif
2056}
2057
2058template <class _CharT, class _Traits, class _Allocator>
2059template <class>
2060basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c, const _Allocator& __a)
2061 : __r_(__default_init_tag(), __a)
2062{
2063 __init(__n, __c);
2064#if _LIBCPP_DEBUG_LEVEL0 == 2
2065 __get_db()->__insert_c(this);
2066#endif
2067}
2068
2069template <class _CharT, class _Traits, class _Allocator>
2070basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str,
2071 size_type __pos, size_type __n,
2072 const _Allocator& __a)
2073 : __r_(__default_init_tag(), __a)
2074{
2075 size_type __str_sz = __str.size();
2076 if (__pos > __str_sz)
2077 this->__throw_out_of_range();
2078 __init(__str.data() + __pos, _VSTDstd::__1::min(__n, __str_sz - __pos));
2079#if _LIBCPP_DEBUG_LEVEL0 == 2
2080 __get_db()->__insert_c(this);
2081#endif
2082}
2083
2084template <class _CharT, class _Traits, class _Allocator>
2085inline
2086basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos,
2087 const _Allocator& __a)
2088 : __r_(__default_init_tag(), __a)
2089{
2090 size_type __str_sz = __str.size();
2091 if (__pos > __str_sz)
2092 this->__throw_out_of_range();
2093 __init(__str.data() + __pos, __str_sz - __pos);
2094#if _LIBCPP_DEBUG_LEVEL0 == 2
2095 __get_db()->__insert_c(this);
2096#endif
2097}
2098
2099template <class _CharT, class _Traits, class _Allocator>
2100template <class _Tp, class>
2101basic_string<_CharT, _Traits, _Allocator>::basic_string(
2102 const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a)
2103 : __r_(__default_init_tag(), __a)
2104{
2105 __self_view __sv0 = __t;
2106 __self_view __sv = __sv0.substr(__pos, __n);
2107 __init(__sv.data(), __sv.size());
2108#if _LIBCPP_DEBUG_LEVEL0 == 2
2109 __get_db()->__insert_c(this);
2110#endif
2111}
2112
2113template <class _CharT, class _Traits, class _Allocator>
2114template <class _Tp, class>
2115basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t)
2116 : __r_(__default_init_tag(), __default_init_tag())
2117{
2118 __self_view __sv = __t;
2119 __init(__sv.data(), __sv.size());
2120#if _LIBCPP_DEBUG_LEVEL0 == 2
2121 __get_db()->__insert_c(this);
2122#endif
2123}
2124
2125template <class _CharT, class _Traits, class _Allocator>
2126template <class _Tp, class>
2127basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t, const _Allocator& __a)
2128 : __r_(__default_init_tag(), __a)
2129{
2130 __self_view __sv = __t;
2131 __init(__sv.data(), __sv.size());
2132#if _LIBCPP_DEBUG_LEVEL0 == 2
2133 __get_db()->__insert_c(this);
2134#endif
2135}
2136
2137template <class _CharT, class _Traits, class _Allocator>
2138template <class _InputIterator>
2139_EnableIf
2140<
2141 __is_exactly_cpp17_input_iterator<_InputIterator>::value
2142>
2143basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
2144{
2145 __zero();
2146#ifndef _LIBCPP_NO_EXCEPTIONS
2147 try
2148 {
2149#endif // _LIBCPP_NO_EXCEPTIONS
2150 for (; __first != __last; ++__first)
2151 push_back(*__first);
2152#ifndef _LIBCPP_NO_EXCEPTIONS
2153 }
2154 catch (...)
2155 {
2156 if (__is_long())
2157 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
2158 throw;
2159 }
2160#endif // _LIBCPP_NO_EXCEPTIONS
2161}
2162
2163template <class _CharT, class _Traits, class _Allocator>
2164template <class _ForwardIterator>
2165_EnableIf
2166<
2167 __is_cpp17_forward_iterator<_ForwardIterator>::value
2168>
2169basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
2170{
2171 size_type __sz = static_cast<size_type>(_VSTDstd::__1::distance(__first, __last));
2172 if (__sz > max_size())
2173 this->__throw_length_error();
2174 pointer __p;
2175 if (__sz < __min_cap)
2176 {
2177 __set_short_size(__sz);
2178 __p = __get_short_pointer();
2179 }
2180 else
2181 {
2182 size_type __cap = __recommend(__sz);
2183 __p = __alloc_traits::allocate(__alloc(), __cap+1);
2184 __set_long_pointer(__p);
2185 __set_long_cap(__cap+1);
2186 __set_long_size(__sz);
2187 }
2188
2189#ifndef _LIBCPP_NO_EXCEPTIONS
2190 try
2191 {
2192#endif // _LIBCPP_NO_EXCEPTIONS
2193 for (; __first != __last; ++__first, (void) ++__p)
2194 traits_type::assign(*__p, *__first);
2195 traits_type::assign(*__p, value_type());
2196#ifndef _LIBCPP_NO_EXCEPTIONS
2197 }
2198 catch (...)
2199 {
2200 if (__is_long())
2201 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
2202 throw;
2203 }
2204#endif // _LIBCPP_NO_EXCEPTIONS
2205}
2206
2207template <class _CharT, class _Traits, class _Allocator>
2208template<class _InputIterator, class>
2209inline
2210basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
2211 : __r_(__default_init_tag(), __default_init_tag())
2212{
2213 __init(__first, __last);
2214#if _LIBCPP_DEBUG_LEVEL0 == 2
2215 __get_db()->__insert_c(this);
2216#endif
2217}
2218
2219template <class _CharT, class _Traits, class _Allocator>
2220template<class _InputIterator, class>
2221inline
2222basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
2223 const allocator_type& __a)
2224 : __r_(__default_init_tag(), __a)
2225{
2226 __init(__first, __last);
2227#if _LIBCPP_DEBUG_LEVEL0 == 2
2228 __get_db()->__insert_c(this);
2229#endif
2230}
2231
2232#ifndef _LIBCPP_CXX03_LANG
2233
2234template <class _CharT, class _Traits, class _Allocator>
2235inline
2236basic_string<_CharT, _Traits, _Allocator>::basic_string(
2237 initializer_list<_CharT> __il)
2238 : __r_(__default_init_tag(), __default_init_tag())
2239{
2240 __init(__il.begin(), __il.end());
2241#if _LIBCPP_DEBUG_LEVEL0 == 2
2242 __get_db()->__insert_c(this);
2243#endif
2244}
2245
2246template <class _CharT, class _Traits, class _Allocator>
2247inline
2248
2249basic_string<_CharT, _Traits, _Allocator>::basic_string(
2250 initializer_list<_CharT> __il, const _Allocator& __a)
2251 : __r_(__default_init_tag(), __a)
2252{
2253 __init(__il.begin(), __il.end());
2254#if _LIBCPP_DEBUG_LEVEL0 == 2
2255 __get_db()->__insert_c(this);
2256#endif
2257}
2258
2259#endif // _LIBCPP_CXX03_LANG
2260
2261template <class _CharT, class _Traits, class _Allocator>
2262basic_string<_CharT, _Traits, _Allocator>::~basic_string()
2263{
2264#if _LIBCPP_DEBUG_LEVEL0 == 2
2265 __get_db()->__erase_c(this);
2266#endif
2267 if (__is_long())
2268 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
2269}
2270
2271template <class _CharT, class _Traits, class _Allocator>
2272void
2273basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
2274 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2275 size_type __n_copy, size_type __n_del, size_type __n_add, const value_type* __p_new_stuff)
2276{
2277 size_type __ms = max_size();
2278 if (__delta_cap > __ms - __old_cap - 1)
2279 this->__throw_length_error();
2280 pointer __old_p = __get_pointer();
2281 size_type __cap = __old_cap < __ms / 2 - __alignment ?
2282 __recommend(_VSTDstd::__1::max(__old_cap + __delta_cap, 2 * __old_cap)) :
2283 __ms - 1;
2284 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
2285 __invalidate_all_iterators();
2286 if (__n_copy != 0)
2287 traits_type::copy(_VSTDstd::__1::__to_address(__p),
2288 _VSTDstd::__1::__to_address(__old_p), __n_copy);
2289 if (__n_add != 0)
2290 traits_type::copy(_VSTDstd::__1::__to_address(__p) + __n_copy, __p_new_stuff, __n_add);
2291 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2292 if (__sec_cp_sz != 0)
2293 traits_type::copy(_VSTDstd::__1::__to_address(__p) + __n_copy + __n_add,
2294 _VSTDstd::__1::__to_address(__old_p) + __n_copy + __n_del, __sec_cp_sz);
2295 if (__old_cap+1 != __min_cap)
2296 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
2297 __set_long_pointer(__p);
2298 __set_long_cap(__cap+1);
2299 __old_sz = __n_copy + __n_add + __sec_cp_sz;
2300 __set_long_size(__old_sz);
2301 traits_type::assign(__p[__old_sz], value_type());
2302}
2303
2304template <class _CharT, class _Traits, class _Allocator>
2305void
2306basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2307 size_type __n_copy, size_type __n_del, size_type __n_add)
2308{
2309 size_type __ms = max_size();
2310 if (__delta_cap > __ms - __old_cap)
2311 this->__throw_length_error();
2312 pointer __old_p = __get_pointer();
2313 size_type __cap = __old_cap < __ms / 2 - __alignment ?
2314 __recommend(_VSTDstd::__1::max(__old_cap + __delta_cap, 2 * __old_cap)) :
2315 __ms - 1;
2316 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
2317 __invalidate_all_iterators();
2318 if (__n_copy != 0)
2319 traits_type::copy(_VSTDstd::__1::__to_address(__p),
2320 _VSTDstd::__1::__to_address(__old_p), __n_copy);
2321 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2322 if (__sec_cp_sz != 0)
2323 traits_type::copy(_VSTDstd::__1::__to_address(__p) + __n_copy + __n_add,
2324 _VSTDstd::__1::__to_address(__old_p) + __n_copy + __n_del,
2325 __sec_cp_sz);
2326 if (__old_cap+1 != __min_cap)
2327 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
2328 __set_long_pointer(__p);
2329 __set_long_cap(__cap+1);
2330}
2331
2332// assign
2333
2334template <class _CharT, class _Traits, class _Allocator>
2335template <bool __is_short>
2336basic_string<_CharT, _Traits, _Allocator>&
2337basic_string<_CharT, _Traits, _Allocator>::__assign_no_alias(
2338 const value_type* __s, size_type __n) {
2339 size_type __cap = __is_short ? __min_cap : __get_long_cap();
2340 if (__n < __cap) {
2341 pointer __p = __is_short ? __get_short_pointer() : __get_long_pointer();
2342 __is_short ? __set_short_size(__n) : __set_long_size(__n);
2343 traits_type::copy(_VSTDstd::__1::__to_address(__p), __s, __n);
2344 traits_type::assign(__p[__n], value_type());
2345 __invalidate_iterators_past(__n);
2346 } else {
2347 size_type __sz = __is_short ? __get_short_size() : __get_long_size();
2348 __grow_by_and_replace(__cap - 1, __n - __cap + 1, __sz, 0, __sz, __n, __s);
2349 }
2350 return *this;
2351}
2352
2353template <class _CharT, class _Traits, class _Allocator>
2354basic_string<_CharT, _Traits, _Allocator>&
2355basic_string<_CharT, _Traits, _Allocator>::__assign_external(
2356 const value_type* __s, size_type __n) {
2357 size_type __cap = capacity();
2358 if (__cap >= __n) {
2359 value_type* __p = _VSTDstd::__1::__to_address(__get_pointer());
2360 traits_type::move(__p, __s, __n);
2361 traits_type::assign(__p[__n], value_type());
2362 __set_size(__n);
2363 __invalidate_iterators_past(__n);
2364 } else {
2365 size_type __sz = size();
2366 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2367 }
2368 return *this;
2369}
2370
2371template <class _CharT, class _Traits, class _Allocator>
2372basic_string<_CharT, _Traits, _Allocator>&
2373basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
2374{
2375 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr")((void)0);
2376 return (_LIBCPP_BUILTIN_CONSTANT_P(__n)__builtin_constant_p(__n) && __n < __min_cap)
2377 ? __assign_short(__s, __n)
2378 : __assign_external(__s, __n);
2379}
2380
2381template <class _CharT, class _Traits, class _Allocator>
2382basic_string<_CharT, _Traits, _Allocator>&
2383basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2384{
2385 size_type __cap = capacity();
2386 if (__cap < __n)
2387 {
2388 size_type __sz = size();
2389 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2390 }
2391 value_type* __p = _VSTDstd::__1::__to_address(__get_pointer());
2392 traits_type::assign(__p, __n, __c);
2393 traits_type::assign(__p[__n], value_type());
2394 __set_size(__n);
2395 __invalidate_iterators_past(__n);
2396 return *this;
2397}
2398
2399template <class _CharT, class _Traits, class _Allocator>
2400basic_string<_CharT, _Traits, _Allocator>&
2401basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2402{
2403 pointer __p;
2404 if (__is_long())
2405 {
2406 __p = __get_long_pointer();
2407 __set_long_size(1);
2408 }
2409 else
2410 {
2411 __p = __get_short_pointer();
2412 __set_short_size(1);
2413 }
2414 traits_type::assign(*__p, __c);
2415 traits_type::assign(*++__p, value_type());
2416 __invalidate_iterators_past(1);
2417 return *this;
2418}
2419
2420template <class _CharT, class _Traits, class _Allocator>
2421basic_string<_CharT, _Traits, _Allocator>&
2422basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2423{
2424 if (this != &__str) {
2425 __copy_assign_alloc(__str);
2426 if (!__is_long()) {
2427 if (!__str.__is_long()) {
2428 __r_.first().__r = __str.__r_.first().__r;
2429 } else {
2430 return __assign_no_alias<true>(__str.data(), __str.size());
2431 }
2432 } else {
2433 return __assign_no_alias<false>(__str.data(), __str.size());
2434 }
2435 }
2436 return *this;
2437}
2438
2439#ifndef _LIBCPP_CXX03_LANG
2440
2441template <class _CharT, class _Traits, class _Allocator>
2442inline
2443void
2444basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
2445 _NOEXCEPT_(__alloc_traits::is_always_equal::value)noexcept(__alloc_traits::is_always_equal::value)
2446{
2447 if (__alloc() != __str.__alloc())
2448 assign(__str);
2449 else
2450 __move_assign(__str, true_type());
2451}
2452
2453template <class _CharT, class _Traits, class _Allocator>
2454inline
2455void
2456basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
2457#if _LIBCPP_STD_VER14 > 14
2458 _NOEXCEPTnoexcept
2459#else
2460 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)noexcept(is_nothrow_move_assignable<allocator_type>::value
)
2461#endif
2462{
2463 if (__is_long()) {
2464 __alloc_traits::deallocate(__alloc(), __get_long_pointer(),
2465 __get_long_cap());
2466#if _LIBCPP_STD_VER14 <= 14
2467 if (!is_nothrow_move_assignable<allocator_type>::value) {
2468 __set_short_size(0);
2469 traits_type::assign(__get_short_pointer()[0], value_type());
2470 }
2471#endif
2472 }
2473 __move_assign_alloc(__str);
2474 __r_.first() = __str.__r_.first();
2475 __str.__set_short_size(0);
2476 traits_type::assign(__str.__get_short_pointer()[0], value_type());
2477}
2478
2479template <class _CharT, class _Traits, class _Allocator>
2480inline
2481basic_string<_CharT, _Traits, _Allocator>&
2482basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
2483 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))noexcept((__noexcept_move_assign_container<_Allocator, __alloc_traits
>::value))
2484{
2485 __move_assign(__str, integral_constant<bool,
2486 __alloc_traits::propagate_on_container_move_assignment::value>());
2487 return *this;
2488}
2489
2490#endif
2491
2492template <class _CharT, class _Traits, class _Allocator>
2493template<class _InputIterator>
2494_EnableIf
2495<
2496 __is_exactly_cpp17_input_iterator<_InputIterator>::value,
2497 basic_string<_CharT, _Traits, _Allocator>&
2498>
2499basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2500{
2501 const basic_string __temp(__first, __last, __alloc());
2502 assign(__temp.data(), __temp.size());
2503 return *this;
2504}
2505
2506template <class _CharT, class _Traits, class _Allocator>
2507template<class _ForwardIterator>
2508_EnableIf
2509<
2510 __is_cpp17_forward_iterator<_ForwardIterator>::value,
2511 basic_string<_CharT, _Traits, _Allocator>&
2512>
2513basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2514{
2515 size_type __cap = capacity();
2516 size_type __n = __string_is_trivial_iterator<_ForwardIterator>::value ?
2517 static_cast<size_type>(_VSTDstd::__1::distance(__first, __last)) : 0;
2518
2519 if (__string_is_trivial_iterator<_ForwardIterator>::value &&
2520 (__cap >= __n || !__addr_in_range(*__first)))
2521 {
2522 if (__cap < __n)
2523 {
2524 size_type __sz = size();
2525 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2526 }
2527 pointer __p = __get_pointer();
2528 for (; __first != __last; ++__first, ++__p)
2529 traits_type::assign(*__p, *__first);
2530 traits_type::assign(*__p, value_type());
2531 __set_size(__n);
2532 __invalidate_iterators_past(__n);
2533 }
2534 else
2535 {
2536 const basic_string __temp(__first, __last, __alloc());
2537 assign(__temp.data(), __temp.size());
2538 }
2539 return *this;
2540}
2541
2542template <class _CharT, class _Traits, class _Allocator>
2543basic_string<_CharT, _Traits, _Allocator>&
2544basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2545{
2546 size_type __sz = __str.size();
2547 if (__pos > __sz)
2548 this->__throw_out_of_range();
2549 return assign(__str.data() + __pos, _VSTDstd::__1::min(__n, __sz - __pos));
2550}
2551
2552template <class _CharT, class _Traits, class _Allocator>
2553template <class _Tp>
2554_EnableIf
2555<
2556 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
2557 && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
2558 basic_string<_CharT, _Traits, _Allocator>&
2559>
2560basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __pos, size_type __n)
2561{
2562 __self_view __sv = __t;
2563 size_type __sz = __sv.size();
2564 if (__pos > __sz)
2565 this->__throw_out_of_range();
2566 return assign(__sv.data() + __pos, _VSTDstd::__1::min(__n, __sz - __pos));
2567}
2568
2569
2570template <class _CharT, class _Traits, class _Allocator>
2571basic_string<_CharT, _Traits, _Allocator>&
2572basic_string<_CharT, _Traits, _Allocator>::__assign_external(const value_type* __s) {
2573 return __assign_external(__s, traits_type::length(__s));
2574}
2575
2576template <class _CharT, class _Traits, class _Allocator>
2577basic_string<_CharT, _Traits, _Allocator>&
2578basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
2579{
2580 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr")((void)0);
2581 return _LIBCPP_BUILTIN_CONSTANT_P(*__s)__builtin_constant_p(*__s)
2582 ? (traits_type::length(__s) < __min_cap
2583 ? __assign_short(__s, traits_type::length(__s))
2584 : __assign_external(__s, traits_type::length(__s)))
2585 : __assign_external(__s);
2586}
2587// append
2588
2589template <class _CharT, class _Traits, class _Allocator>
2590basic_string<_CharT, _Traits, _Allocator>&
2591basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
2592{
2593 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr")((void)0);
2594 size_type __cap = capacity();
2595 size_type __sz = size();
2596 if (__cap - __sz >= __n)
2597 {
2598 if (__n)
2599 {
2600 value_type* __p = _VSTDstd::__1::__to_address(__get_pointer());
2601 traits_type::copy(__p + __sz, __s, __n);
2602 __sz += __n;
2603 __set_size(__sz);
2604 traits_type::assign(__p[__sz], value_type());
2605 }
2606 }
2607 else
2608 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2609 return *this;
2610}
2611
2612template <class _CharT, class _Traits, class _Allocator>
2613basic_string<_CharT, _Traits, _Allocator>&
2614basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2615{
2616 if (__n)
2617 {
2618 size_type __cap = capacity();
2619 size_type __sz = size();
2620 if (__cap - __sz < __n)
2621 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2622 pointer __p = __get_pointer();
2623 traits_type::assign(_VSTDstd::__1::__to_address(__p) + __sz, __n, __c);
2624 __sz += __n;
2625 __set_size(__sz);
2626 traits_type::assign(__p[__sz], value_type());
2627 }
2628 return *this;
2629}
2630
2631template <class _CharT, class _Traits, class _Allocator>
2632inline void
2633basic_string<_CharT, _Traits, _Allocator>::__append_default_init(size_type __n)
2634{
2635 if (__n)
2636 {
2637 size_type __cap = capacity();
2638 size_type __sz = size();
2639 if (__cap - __sz < __n)
2640 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2641 pointer __p = __get_pointer();
2642 __sz += __n;
2643 __set_size(__sz);
2644 traits_type::assign(__p[__sz], value_type());
2645 }
2646}
2647
2648template <class _CharT, class _Traits, class _Allocator>
2649void
2650basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2651{
2652 bool __is_short = !__is_long();
2653 size_type __cap;
2654 size_type __sz;
2655 if (__is_short)
2656 {
2657 __cap = __min_cap - 1;
2658 __sz = __get_short_size();
2659 }
2660 else
2661 {
2662 __cap = __get_long_cap() - 1;
2663 __sz = __get_long_size();
2664 }
2665 if (__sz == __cap)
2666 {
2667 __grow_by(__cap, 1, __sz, __sz, 0);
2668 __is_short = !__is_long();
2669 }
2670 pointer __p;
2671 if (__is_short)
2672 {
2673 __p = __get_short_pointer() + __sz;
2674 __set_short_size(__sz+1);
2675 }
2676 else
2677 {
2678 __p = __get_long_pointer() + __sz;
2679 __set_long_size(__sz+1);
2680 }
2681 traits_type::assign(*__p, __c);
2682 traits_type::assign(*++__p, value_type());
2683}
2684
2685template <class _CharT, class _Traits, class _Allocator>
2686template<class _ForwardIterator>
2687_EnableIf
2688<
2689 __is_cpp17_forward_iterator<_ForwardIterator>::value,
2690 basic_string<_CharT, _Traits, _Allocator>&
2691>
2692basic_string<_CharT, _Traits, _Allocator>::append(
2693 _ForwardIterator __first, _ForwardIterator __last)
2694{
2695 size_type __sz = size();
2696 size_type __cap = capacity();
2697 size_type __n = static_cast<size_type>(_VSTDstd::__1::distance(__first, __last));
2698 if (__n)
2699 {
2700 if (__string_is_trivial_iterator<_ForwardIterator>::value &&
2701 !__addr_in_range(*__first))
2702 {
2703 if (__cap - __sz < __n)
2704 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2705 pointer __p = __get_pointer() + __sz;
2706 for (; __first != __last; ++__p, ++__first)
2707 traits_type::assign(*__p, *__first);
2708 traits_type::assign(*__p, value_type());
2709 __set_size(__sz + __n);
2710 }
2711 else
2712 {
2713 const basic_string __temp(__first, __last, __alloc());
2714 append(__temp.data(), __temp.size());
2715 }
2716 }
2717 return *this;
2718}
2719
2720template <class _CharT, class _Traits, class _Allocator>
2721inline
2722basic_string<_CharT, _Traits, _Allocator>&
2723basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2724{
2725 return append(__str.data(), __str.size());
2726}
2727
2728template <class _CharT, class _Traits, class _Allocator>
2729basic_string<_CharT, _Traits, _Allocator>&
2730basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2731{
2732 size_type __sz = __str.size();
2733 if (__pos > __sz)
2734 this->__throw_out_of_range();
2735 return append(__str.data() + __pos, _VSTDstd::__1::min(__n, __sz - __pos));
2736}
2737
2738template <class _CharT, class _Traits, class _Allocator>
2739template <class _Tp>
2740 _EnableIf
2741 <
2742 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
2743 basic_string<_CharT, _Traits, _Allocator>&
2744 >
2745basic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __pos, size_type __n)
2746{
2747 __self_view __sv = __t;
2748 size_type __sz = __sv.size();
2749 if (__pos > __sz)
2750 this->__throw_out_of_range();
2751 return append(__sv.data() + __pos, _VSTDstd::__1::min(__n, __sz - __pos));
2752}
2753
2754template <class _CharT, class _Traits, class _Allocator>
2755basic_string<_CharT, _Traits, _Allocator>&
2756basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
2757{
2758 _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr")((void)0);
2759 return append(__s, traits_type::length(__s));
2760}
2761
2762// insert
2763
2764template <class _CharT, class _Traits, class _Allocator>
2765basic_string<_CharT, _Traits, _Allocator>&
2766basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
2767{
2768 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr")((void)0);
2769 size_type __sz = size();
2770 if (__pos > __sz)
2771 this->__throw_out_of_range();
2772 size_type __cap = capacity();
2773 if (__cap - __sz >= __n)
2774 {
2775 if (__n)
2776 {
2777 value_type* __p = _VSTDstd::__1::__to_address(__get_pointer());
2778 size_type __n_move = __sz - __pos;
2779 if (__n_move != 0)
2780 {
2781 if (__p + __pos <= __s && __s < __p + __sz)
2782 __s += __n;
2783 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2784 }
2785 traits_type::move(__p + __pos, __s, __n);
2786 __sz += __n;
2787 __set_size(__sz);
2788 traits_type::assign(__p[__sz], value_type());
2789 }
2790 }
2791 else
2792 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2793 return *this;
2794}
2795
2796template <class _CharT, class _Traits, class _Allocator>
2797basic_string<_CharT, _Traits, _Allocator>&
2798basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2799{
2800 size_type __sz = size();
2801 if (__pos > __sz)
2802 this->__throw_out_of_range();
2803 if (__n)
2804 {
2805 size_type __cap = capacity();
2806 value_type* __p;
2807 if (__cap - __sz >= __n)
2808 {
2809 __p = _VSTDstd::__1::__to_address(__get_pointer());
2810 size_type __n_move = __sz - __pos;
2811 if (__n_move != 0)
2812 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2813 }
2814 else
2815 {
2816 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
2817 __p = _VSTDstd::__1::__to_address(__get_long_pointer());
2818 }
2819 traits_type::assign(__p + __pos, __n, __c);
2820 __sz += __n;
2821 __set_size(__sz);
2822 traits_type::assign(__p[__sz], value_type());
2823 }
2824 return *this;
2825}
2826
2827template <class _CharT, class _Traits, class _Allocator>
2828template<class _InputIterator>
2829_EnableIf
2830<
2831 __is_exactly_cpp17_input_iterator<_InputIterator>::value,
2832 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2833>
2834basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2835{
2836#if _LIBCPP_DEBUG_LEVEL0 == 2
2837 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,((void)0)
2838 "string::insert(iterator, range) called with an iterator not"((void)0)
2839 " referring to this string")((void)0);
2840#endif
2841 const basic_string __temp(__first, __last, __alloc());
2842 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
2843}
2844
2845template <class _CharT, class _Traits, class _Allocator>
2846template<class _ForwardIterator>
2847_EnableIf
2848<
2849 __is_cpp17_forward_iterator<_ForwardIterator>::value,
2850 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2851>
2852basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2853{
2854#if _LIBCPP_DEBUG_LEVEL0 == 2
2855 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,((void)0)
2856 "string::insert(iterator, range) called with an iterator not"((void)0)
2857 " referring to this string")((void)0);
2858#endif
2859 size_type __ip = static_cast<size_type>(__pos - begin());
2860 size_type __n = static_cast<size_type>(_VSTDstd::__1::distance(__first, __last));
2861 if (__n)
2862 {
2863 if (__string_is_trivial_iterator<_ForwardIterator>::value &&
2864 !__addr_in_range(*__first))
2865 {
2866 size_type __sz = size();
2867 size_type __cap = capacity();
2868 value_type* __p;
2869 if (__cap - __sz >= __n)
2870 {
2871 __p = _VSTDstd::__1::__to_address(__get_pointer());
2872 size_type __n_move = __sz - __ip;
2873 if (__n_move != 0)
2874 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2875 }
2876 else
2877 {
2878 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
2879 __p = _VSTDstd::__1::__to_address(__get_long_pointer());
2880 }
2881 __sz += __n;
2882 __set_size(__sz);
2883 traits_type::assign(__p[__sz], value_type());
2884 for (__p += __ip; __first != __last; ++__p, ++__first)
2885 traits_type::assign(*__p, *__first);
2886 }
2887 else
2888 {
2889 const basic_string __temp(__first, __last, __alloc());
2890 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
2891 }
2892 }
2893 return begin() + __ip;
2894}
2895
2896template <class _CharT, class _Traits, class _Allocator>
2897inline
2898basic_string<_CharT, _Traits, _Allocator>&
2899basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2900{
2901 return insert(__pos1, __str.data(), __str.size());
2902}
2903
2904template <class _CharT, class _Traits, class _Allocator>
2905basic_string<_CharT, _Traits, _Allocator>&
2906basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2907 size_type __pos2, size_type __n)
2908{
2909 size_type __str_sz = __str.size();
2910 if (__pos2 > __str_sz)
2911 this->__throw_out_of_range();
2912 return insert(__pos1, __str.data() + __pos2, _VSTDstd::__1::min(__n, __str_sz - __pos2));
2913}
2914
2915template <class _CharT, class _Traits, class _Allocator>
2916template <class _Tp>
2917_EnableIf
2918<
2919 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
2920 basic_string<_CharT, _Traits, _Allocator>&
2921>
2922basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t,
2923 size_type __pos2, size_type __n)
2924{
2925 __self_view __sv = __t;
2926 size_type __str_sz = __sv.size();
2927 if (__pos2 > __str_sz)
2928 this->__throw_out_of_range();
2929 return insert(__pos1, __sv.data() + __pos2, _VSTDstd::__1::min(__n, __str_sz - __pos2));
2930}
2931
2932template <class _CharT, class _Traits, class _Allocator>
2933basic_string<_CharT, _Traits, _Allocator>&
2934basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
2935{
2936 _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr")((void)0);
2937 return insert(__pos, __s, traits_type::length(__s));
2938}
2939
2940template <class _CharT, class _Traits, class _Allocator>
2941typename basic_string<_CharT, _Traits, _Allocator>::iterator
2942basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2943{
2944 size_type __ip = static_cast<size_type>(__pos - begin());
2945 size_type __sz = size();
2946 size_type __cap = capacity();
2947 value_type* __p;
2948 if (__cap == __sz)
2949 {
2950 __grow_by(__cap, 1, __sz, __ip, 0, 1);
2951 __p = _VSTDstd::__1::__to_address(__get_long_pointer());
2952 }
2953 else
2954 {
2955 __p = _VSTDstd::__1::__to_address(__get_pointer());
2956 size_type __n_move = __sz - __ip;
2957 if (__n_move != 0)
2958 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2959 }
2960 traits_type::assign(__p[__ip], __c);
2961 traits_type::assign(__p[++__sz], value_type());
2962 __set_size(__sz);
2963 return begin() + static_cast<difference_type>(__ip);
2964}
2965
2966template <class _CharT, class _Traits, class _Allocator>
2967inline
2968typename basic_string<_CharT, _Traits, _Allocator>::iterator
2969basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2970{
2971#if _LIBCPP_DEBUG_LEVEL0 == 2
2972 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,((void)0)
2973 "string::insert(iterator, n, value) called with an iterator not"((void)0)
2974 " referring to this string")((void)0);
2975#endif
2976 difference_type __p = __pos - begin();
2977 insert(static_cast<size_type>(__p), __n, __c);
2978 return begin() + __p;
2979}
2980
2981// replace
2982
2983template <class _CharT, class _Traits, class _Allocator>
2984basic_string<_CharT, _Traits, _Allocator>&
2985basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2)
2986 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK__attribute__((__no_sanitize__("unsigned-integer-overflow")))
2987{
2988 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr")((void)0);
2989 size_type __sz = size();
2990 if (__pos > __sz)
2991 this->__throw_out_of_range();
2992 __n1 = _VSTDstd::__1::min(__n1, __sz - __pos);
2993 size_type __cap = capacity();
2994 if (__cap - __sz + __n1 >= __n2)
2995 {
2996 value_type* __p = _VSTDstd::__1::__to_address(__get_pointer());
2997 if (__n1 != __n2)
2998 {
2999 size_type __n_move = __sz - __pos - __n1;
3000 if (__n_move != 0)
3001 {
3002 if (__n1 > __n2)
3003 {
3004 traits_type::move(__p + __pos, __s, __n2);
3005 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
3006 goto __finish;
3007 }
3008 if (__p + __pos < __s && __s < __p + __sz)
3009 {
3010 if (__p + __pos + __n1 <= __s)
3011 __s += __n2 - __n1;
3012 else // __p + __pos < __s < __p + __pos + __n1
3013 {
3014 traits_type::move(__p + __pos, __s, __n1);
3015 __pos += __n1;
3016 __s += __n2;
3017 __n2 -= __n1;
3018 __n1 = 0;
3019 }
3020 }
3021 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
3022 }
3023 }
3024 traits_type::move(__p + __pos, __s, __n2);
3025__finish:
3026// __sz += __n2 - __n1; in this and the below function below can cause unsigned
3027// integer overflow, but this is a safe operation, so we disable the check.
3028 __sz += __n2 - __n1;
3029 __set_size(__sz);
3030 __invalidate_iterators_past(__sz);
3031 traits_type::assign(__p[__sz], value_type());
3032 }
3033 else
3034 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
3035 return *this;
3036}
3037
3038template <class _CharT, class _Traits, class _Allocator>
3039basic_string<_CharT, _Traits, _Allocator>&
3040basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
3041 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK__attribute__((__no_sanitize__("unsigned-integer-overflow")))
3042{
3043 size_type __sz = size();
3044 if (__pos > __sz)
3045 this->__throw_out_of_range();
3046 __n1 = _VSTDstd::__1::min(__n1, __sz - __pos);
3047 size_type __cap = capacity();
3048 value_type* __p;
3049 if (__cap - __sz + __n1 >= __n2)
3050 {
3051 __p = _VSTDstd::__1::__to_address(__get_pointer());
3052 if (__n1 != __n2)
3053 {
3054 size_type __n_move = __sz - __pos - __n1;
3055 if (__n_move != 0)
3056 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
3057 }
3058 }
3059 else
3060 {
3061 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
3062 __p = _VSTDstd::__1::__to_address(__get_long_pointer());
3063 }
3064 traits_type::assign(__p + __pos, __n2, __c);
3065 __sz += __n2 - __n1;
3066 __set_size(__sz);
3067 __invalidate_iterators_past(__sz);
3068 traits_type::assign(__p[__sz], value_type());
3069 return *this;
3070}
3071
3072template <class _CharT, class _Traits, class _Allocator>
3073template<class _InputIterator>
3074_EnableIf
3075<
3076 __is_cpp17_input_iterator<_InputIterator>::value,
3077 basic_string<_CharT, _Traits, _Allocator>&
3078>
3079basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
3080 _InputIterator __j1, _InputIterator __j2)
3081{
3082 const basic_string __temp(__j1, __j2, __alloc());
3083 return this->replace(__i1, __i2, __temp);
3084}
3085
3086template <class _CharT, class _Traits, class _Allocator>
3087inline
3088basic_string<_CharT, _Traits, _Allocator>&
3089basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
3090{
3091 return replace(__pos1, __n1, __str.data(), __str.size());
3092}
3093
3094template <class _CharT, class _Traits, class _Allocator>
3095basic_string<_CharT, _Traits, _Allocator>&
3096basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
3097 size_type __pos2, size_type __n2)
3098{
3099 size_type __str_sz = __str.size();
3100 if (__pos2 > __str_sz)
3101 this->__throw_out_of_range();
3102 return replace(__pos1, __n1, __str.data() + __pos2, _VSTDstd::__1::min(__n2, __str_sz - __pos2));
3103}
3104
3105template <class _CharT, class _Traits, class _Allocator>
3106template <class _Tp>
3107_EnableIf
3108<
3109 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
3110 basic_string<_CharT, _Traits, _Allocator>&
3111>
3112basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const _Tp& __t,
3113 size_type __pos2, size_type __n2)
3114{
3115 __self_view __sv = __t;
3116 size_type __str_sz = __sv.size();
3117 if (__pos2 > __str_sz)
3118 this->__throw_out_of_range();
3119 return replace(__pos1, __n1, __sv.data() + __pos2, _VSTDstd::__1::min(__n2, __str_sz - __pos2));
3120}
3121
3122template <class _CharT, class _Traits, class _Allocator>
3123basic_string<_CharT, _Traits, _Allocator>&
3124basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
3125{
3126 _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr")((void)0);
3127 return replace(__pos, __n1, __s, traits_type::length(__s));
3128}
3129
3130template <class _CharT, class _Traits, class _Allocator>
3131inline
3132basic_string<_CharT, _Traits, _Allocator>&
3133basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
3134{
3135 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
3136 __str.data(), __str.size());
3137}
3138
3139template <class _CharT, class _Traits, class _Allocator>
3140inline
3141basic_string<_CharT, _Traits, _Allocator>&
3142basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n)
3143{
3144 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
3145}
3146
3147template <class _CharT, class _Traits, class _Allocator>
3148inline
3149basic_string<_CharT, _Traits, _Allocator>&
3150basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
3151{
3152 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
3153}
3154
3155template <class _CharT, class _Traits, class _Allocator>
3156inline
3157basic_string<_CharT, _Traits, _Allocator>&
3158basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
3159{
3160 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
3161}
3162
3163// erase
3164
3165// 'externally instantiated' erase() implementation, called when __n != npos.
3166// Does not check __pos against size()
3167template <class _CharT, class _Traits, class _Allocator>
3168void
3169basic_string<_CharT, _Traits, _Allocator>::__erase_external_with_move(
3170 size_type __pos, size_type __n)
3171{
3172 if (__n)
3173 {
3174 size_type __sz = size();
3175 value_type* __p = _VSTDstd::__1::__to_address(__get_pointer());
3176 __n = _VSTDstd::__1::min(__n, __sz - __pos);
3177 size_type __n_move = __sz - __pos - __n;
3178 if (__n_move != 0)
3179 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
3180 __sz -= __n;
3181 __set_size(__sz);
3182 __invalidate_iterators_past(__sz);
3183 traits_type::assign(__p[__sz], value_type());
3184 }
3185}
3186
3187template <class _CharT, class _Traits, class _Allocator>
3188basic_string<_CharT, _Traits, _Allocator>&
3189basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos,
3190 size_type __n) {
3191 if (__pos > size()) this->__throw_out_of_range();
3192 if (__n == npos) {
3193 __erase_to_end(__pos);
3194 } else {
3195 __erase_external_with_move(__pos, __n);
3196 }
3197 return *this;
3198}
3199
3200template <class _CharT, class _Traits, class _Allocator>
3201inline
3202typename basic_string<_CharT, _Traits, _Allocator>::iterator
3203basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
3204{
3205#if _LIBCPP_DEBUG_LEVEL0 == 2
3206 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,((void)0)
3207 "string::erase(iterator) called with an iterator not"((void)0)
3208 " referring to this string")((void)0);
3209#endif
3210 _LIBCPP_ASSERT(__pos != end(),((void)0)
3211 "string::erase(iterator) called with a non-dereferenceable iterator")((void)0);
3212 iterator __b = begin();
3213 size_type __r = static_cast<size_type>(__pos - __b);
3214 erase(__r, 1);
3215 return __b + static_cast<difference_type>(__r);
3216}
3217
3218template <class _CharT, class _Traits, class _Allocator>
3219inline
3220typename basic_string<_CharT, _Traits, _Allocator>::iterator
3221basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
3222{
3223#if _LIBCPP_DEBUG_LEVEL0 == 2
3224 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,((void)0)
3225 "string::erase(iterator, iterator) called with an iterator not"((void)0)
3226 " referring to this string")((void)0);
3227#endif
3228 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range")((void)0);
3229 iterator __b = begin();
3230 size_type __r = static_cast<size_type>(__first - __b);
3231 erase(__r, static_cast<size_type>(__last - __first));
3232 return __b + static_cast<difference_type>(__r);
3233}
3234
3235template <class _CharT, class _Traits, class _Allocator>
3236inline
3237void
3238basic_string<_CharT, _Traits, _Allocator>::pop_back()
3239{
3240 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty")((void)0);
3241 size_type __sz;
3242 if (__is_long())
3243 {
3244 __sz = __get_long_size() - 1;
3245 __set_long_size(__sz);
3246 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
3247 }
3248 else
3249 {
3250 __sz = __get_short_size() - 1;
3251 __set_short_size(__sz);
3252 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
3253 }
3254 __invalidate_iterators_past(__sz);
3255}
3256
3257template <class _CharT, class _Traits, class _Allocator>
3258inline
3259void
3260basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPTnoexcept
3261{
3262 __invalidate_all_iterators();
3263 if (__is_long())
3264 {
3265 traits_type::assign(*__get_long_pointer(), value_type());
3266 __set_long_size(0);
3267 }
3268 else
3269 {
3270 traits_type::assign(*__get_short_pointer(), value_type());
3271 __set_short_size(0);
3272 }
3273}
3274
3275template <class _CharT, class _Traits, class _Allocator>
3276inline
3277void
3278basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
3279{
3280 if (__is_long())
3281 {
3282 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
3283 __set_long_size(__pos);
3284 }
3285 else
3286 {
3287 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
3288 __set_short_size(__pos);
3289 }
3290 __invalidate_iterators_past(__pos);
3291}
3292
3293template <class _CharT, class _Traits, class _Allocator>
3294void
3295basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
3296{
3297 size_type __sz = size();
3298 if (__n > __sz)
3299 append(__n - __sz, __c);
3300 else
3301 __erase_to_end(__n);
3302}
3303
3304template <class _CharT, class _Traits, class _Allocator>
3305inline void
3306basic_string<_CharT, _Traits, _Allocator>::__resize_default_init(size_type __n)
3307{
3308 size_type __sz = size();
3309 if (__n > __sz) {
3310 __append_default_init(__n - __sz);
3311 } else
3312 __erase_to_end(__n);
3313}
3314
3315template <class _CharT, class _Traits, class _Allocator>
3316inline
3317typename basic_string<_CharT, _Traits, _Allocator>::size_type
3318basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPTnoexcept
3319{
3320 size_type __m = __alloc_traits::max_size(__alloc());
3321#ifdef _LIBCPP_BIG_ENDIAN
3322 return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
3323#else
3324 return __m - __alignment;
3325#endif
3326}
3327
3328template <class _CharT, class _Traits, class _Allocator>
3329void
3330basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __requested_capacity)
3331{
3332 if (__requested_capacity > max_size())
3333 this->__throw_length_error();
3334
3335#if _LIBCPP_STD_VER14 > 17
3336 // Reserve never shrinks as of C++20.
3337 if (__requested_capacity <= capacity()) return;
3338#endif
3339
3340 size_type __target_capacity = _VSTDstd::__1::max(__requested_capacity, size());
3341 __target_capacity = __recommend(__target_capacity);
3342 if (__target_capacity == capacity()) return;
3343
3344 __shrink_or_extend(__target_capacity);
3345}
3346
3347template <class _CharT, class _Traits, class _Allocator>
3348void
3349basic_string<_CharT, _Traits, _Allocator>::shrink_to_fit() _NOEXCEPTnoexcept
3350{
3351 size_type __target_capacity = __recommend(size());
3352 if (__target_capacity == capacity()) return;
3353
3354 __shrink_or_extend(__target_capacity);
3355}
3356
3357template <class _CharT, class _Traits, class _Allocator>
3358void
3359basic_string<_CharT, _Traits, _Allocator>::__shrink_or_extend(size_type __target_capacity)
3360{
3361 size_type __cap = capacity();
3362 size_type __sz = size();
3363
3364 pointer __new_data, __p;
3365 bool __was_long, __now_long;
3366 if (__target_capacity == __min_cap - 1)
3367 {
3368 __was_long = true;
3369 __now_long = false;
3370 __new_data = __get_short_pointer();
3371 __p = __get_long_pointer();
3372 }
3373 else
3374 {
3375 if (__target_capacity > __cap)
3376 __new_data = __alloc_traits::allocate(__alloc(), __target_capacity+1);
3377 else
3378 {
3379 #ifndef _LIBCPP_NO_EXCEPTIONS
3380 try
3381 {
3382 #endif // _LIBCPP_NO_EXCEPTIONS
3383 __new_data = __alloc_traits::allocate(__alloc(), __target_capacity+1);
3384 #ifndef _LIBCPP_NO_EXCEPTIONS
3385 }
3386 catch (...)
3387 {
3388 return;
3389 }
3390 #else // _LIBCPP_NO_EXCEPTIONS
3391 if (__new_data == nullptr)
3392 return;
3393 #endif // _LIBCPP_NO_EXCEPTIONS
3394 }
3395 __now_long = true;
3396 __was_long = __is_long();
3397 __p = __get_pointer();
3398 }
3399 traits_type::copy(_VSTDstd::__1::__to_address(__new_data),
3400 _VSTDstd::__1::__to_address(__p), size()+1);
3401 if (__was_long)
3402 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
3403 if (__now_long)
3404 {
3405 __set_long_cap(__target_capacity+1);
3406 __set_long_size(__sz);
3407 __set_long_pointer(__new_data);
3408 }
3409 else
3410 __set_short_size(__sz);
3411 __invalidate_all_iterators();
3412}
3413
3414template <class _CharT, class _Traits, class _Allocator>
3415inline
3416typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3417basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPTnoexcept
3418{
3419 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds")((void)0);
3420 return *(data() + __pos);
3421}
3422
3423template <class _CharT, class _Traits, class _Allocator>
3424inline
3425typename basic_string<_CharT, _Traits, _Allocator>::reference
3426basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPTnoexcept
3427{
3428 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds")((void)0);
3429 return *(__get_pointer() + __pos);
3430}
3431
3432template <class _CharT, class _Traits, class _Allocator>
3433typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3434basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
3435{
3436 if (__n >= size())
3437 this->__throw_out_of_range();
3438 return (*this)[__n];
3439}
3440
3441template <class _CharT, class _Traits, class _Allocator>
3442typename basic_string<_CharT, _Traits, _Allocator>::reference
3443basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
3444{
3445 if (__n >= size())
3446 this->__throw_out_of_range();
3447 return (*this)[__n];
3448}
3449
3450template <class _CharT, class _Traits, class _Allocator>
3451inline
3452typename basic_string<_CharT, _Traits, _Allocator>::reference
3453basic_string<_CharT, _Traits, _Allocator>::front() _NOEXCEPTnoexcept
3454{
3455 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty")((void)0);
3456 return *__get_pointer();
3457}
3458
3459template <class _CharT, class _Traits, class _Allocator>
3460inline
3461typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3462basic_string<_CharT, _Traits, _Allocator>::front() const _NOEXCEPTnoexcept
3463{
3464 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty")((void)0);
3465 return *data();
3466}
3467
3468template <class _CharT, class _Traits, class _Allocator>
3469inline
3470typename basic_string<_CharT, _Traits, _Allocator>::reference
3471basic_string<_CharT, _Traits, _Allocator>::back() _NOEXCEPTnoexcept
3472{
3473 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty")((void)0);
3474 return *(__get_pointer() + size() - 1);
3475}
3476
3477template <class _CharT, class _Traits, class _Allocator>
3478inline
3479typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3480basic_string<_CharT, _Traits, _Allocator>::back() const _NOEXCEPTnoexcept
3481{
3482 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty")((void)0);
3483 return *(data() + size() - 1);
3484}
3485
3486template <class _CharT, class _Traits, class _Allocator>
3487typename basic_string<_CharT, _Traits, _Allocator>::size_type
3488basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
3489{
3490 size_type __sz = size();
3491 if (__pos > __sz)
3492 this->__throw_out_of_range();
3493 size_type __rlen = _VSTDstd::__1::min(__n, __sz - __pos);
3494 traits_type::copy(__s, data() + __pos, __rlen);
3495 return __rlen;
3496}
3497
3498template <class _CharT, class _Traits, class _Allocator>
3499inline
3500basic_string<_CharT, _Traits, _Allocator>
3501basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3502{
3503 return basic_string(*this, __pos, __n, __alloc());
3504}
3505
3506template <class _CharT, class _Traits, class _Allocator>
3507inline
3508void
3509basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
3510#if _LIBCPP_STD_VER14 >= 14
3511 _NOEXCEPTnoexcept
3512#else
3513 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||noexcept(!__alloc_traits::propagate_on_container_swap::value ||
__is_nothrow_swappable<allocator_type>::value)
3514 __is_nothrow_swappable<allocator_type>::value)noexcept(!__alloc_traits::propagate_on_container_swap::value ||
__is_nothrow_swappable<allocator_type>::value)
3515#endif
3516{
3517#if _LIBCPP_DEBUG_LEVEL0 == 2
3518 if (!__is_long())
3519 __get_db()->__invalidate_all(this);
3520 if (!__str.__is_long())
3521 __get_db()->__invalidate_all(&__str);
3522 __get_db()->swap(this, &__str);
3523#endif
3524 _LIBCPP_ASSERT(((void)0)
3525 __alloc_traits::propagate_on_container_swap::value ||((void)0)
3526 __alloc_traits::is_always_equal::value ||((void)0)
3527 __alloc() == __str.__alloc(), "swapping non-equal allocators")((void)0);
3528 _VSTDstd::__1::swap(__r_.first(), __str.__r_.first());
3529 _VSTDstd::__1::__swap_allocator(__alloc(), __str.__alloc());
3530}
3531
3532// find
3533
3534template <class _Traits>
3535struct _LIBCPP_HIDDEN__attribute__ ((__visibility__("hidden"))) __traits_eq
3536{
3537 typedef typename _Traits::char_type char_type;
3538 _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
3539 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPTnoexcept
3540 {return _Traits::eq(__x, __y);}
3541};
3542
3543template<class _CharT, class _Traits, class _Allocator>
3544typename basic_string<_CharT, _Traits, _Allocator>::size_type
3545basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
3546 size_type __pos,
3547 size_type __n) const _NOEXCEPTnoexcept
3548{
3549 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr")((void)0);
3550 return __str_find<value_type, size_type, traits_type, npos>
3551 (data(), size(), __s, __pos, __n);
3552}
3553
3554template<class _CharT, class _Traits, class _Allocator>
3555inline
3556typename basic_string<_CharT, _Traits, _Allocator>::size_type
3557basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3558 size_type __pos) const _NOEXCEPTnoexcept
3559{
3560 return __str_find<value_type, size_type, traits_type, npos>
3561 (data(), size(), __str.data(), __pos, __str.size());
3562}
3563
3564template<class _CharT, class _Traits, class _Allocator>
3565template <class _Tp>
3566_EnableIf
3567<
3568 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3569 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3570>
3571basic_string<_CharT, _Traits, _Allocator>::find(const _Tp &__t,
3572 size_type __pos) const _NOEXCEPTnoexcept
3573{
3574 __self_view __sv = __t;
3575 return __str_find<value_type, size_type, traits_type, npos>
3576 (data(), size(), __sv.data(), __pos, __sv.size());
3577}
3578
3579template<class _CharT, class _Traits, class _Allocator>
3580inline
3581typename basic_string<_CharT, _Traits, _Allocator>::size_type
3582basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
3583 size_type __pos) const _NOEXCEPTnoexcept
3584{
3585 _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr")((void)0);
3586 return __str_find<value_type, size_type, traits_type, npos>
3587 (data(), size(), __s, __pos, traits_type::length(__s));
3588}
3589
3590template<class _CharT, class _Traits, class _Allocator>
3591typename basic_string<_CharT, _Traits, _Allocator>::size_type
3592basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3593 size_type __pos) const _NOEXCEPTnoexcept
3594{
3595 return __str_find<value_type, size_type, traits_type, npos>
3596 (data(), size(), __c, __pos);
3597}
3598
3599// rfind
3600
3601template<class _CharT, class _Traits, class _Allocator>
3602typename basic_string<_CharT, _Traits, _Allocator>::size_type
3603basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
3604 size_type __pos,
3605 size_type __n) const _NOEXCEPTnoexcept
3606{
3607 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr")((void)0);
3608 return __str_rfind<value_type, size_type, traits_type, npos>
3609 (data(), size(), __s, __pos, __n);
3610}
3611
3612template<class _CharT, class _Traits, class _Allocator>
3613inline
3614typename basic_string<_CharT, _Traits, _Allocator>::size_type
3615basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3616 size_type __pos) const _NOEXCEPTnoexcept
3617{
3618 return __str_rfind<value_type, size_type, traits_type, npos>
3619 (data(), size(), __str.data(), __pos, __str.size());
3620}
3621
3622template<class _CharT, class _Traits, class _Allocator>
3623template <class _Tp>
3624_EnableIf
3625<
3626 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3627 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3628>
3629basic_string<_CharT, _Traits, _Allocator>::rfind(const _Tp& __t,
3630 size_type __pos) const _NOEXCEPTnoexcept
3631{
3632 __self_view __sv = __t;
3633 return __str_rfind<value_type, size_type, traits_type, npos>
3634 (data(), size(), __sv.data(), __pos, __sv.size());
3635}
3636
3637template<class _CharT, class _Traits, class _Allocator>
3638inline
3639typename basic_string<_CharT, _Traits, _Allocator>::size_type
3640basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
3641 size_type __pos) const _NOEXCEPTnoexcept
3642{
3643 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr")((void)0);
3644 return __str_rfind<value_type, size_type, traits_type, npos>
3645 (data(), size(), __s, __pos, traits_type::length(__s));
3646}
3647
3648template<class _CharT, class _Traits, class _Allocator>
3649typename basic_string<_CharT, _Traits, _Allocator>::size_type
3650basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3651 size_type __pos) const _NOEXCEPTnoexcept
3652{
3653 return __str_rfind<value_type, size_type, traits_type, npos>
3654 (data(), size(), __c, __pos);
3655}
3656
3657// find_first_of
3658
3659template<class _CharT, class _Traits, class _Allocator>
3660typename basic_string<_CharT, _Traits, _Allocator>::size_type
3661basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
3662 size_type __pos,
3663 size_type __n) const _NOEXCEPTnoexcept
3664{
3665 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr")((void)0);
3666 return __str_find_first_of<value_type, size_type, traits_type, npos>
3667 (data(), size(), __s, __pos, __n);
3668}
3669
3670template<class _CharT, class _Traits, class _Allocator>
3671inline
3672typename basic_string<_CharT, _Traits, _Allocator>::size_type
3673basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3674 size_type __pos) const _NOEXCEPTnoexcept
3675{
3676 return __str_find_first_of<value_type, size_type, traits_type, npos>
3677 (data(), size(), __str.data(), __pos, __str.size());
3678}
3679
3680template<class _CharT, class _Traits, class _Allocator>
3681template <class _Tp>
3682_EnableIf
3683<
3684 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3685 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3686>
3687basic_string<_CharT, _Traits, _Allocator>::find_first_of(const _Tp& __t,
3688 size_type __pos) const _NOEXCEPTnoexcept
3689{
3690 __self_view __sv = __t;
3691 return __str_find_first_of<value_type, size_type, traits_type, npos>
3692 (data(), size(), __sv.data(), __pos, __sv.size());
3693}
3694
3695template<class _CharT, class _Traits, class _Allocator>
3696inline
3697typename basic_string<_CharT, _Traits, _Allocator>::size_type
3698basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
3699 size_type __pos) const _NOEXCEPTnoexcept
3700{
3701 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr")((void)0);
3702 return __str_find_first_of<value_type, size_type, traits_type, npos>
3703 (data(), size(), __s, __pos, traits_type::length(__s));
3704}
3705
3706template<class _CharT, class _Traits, class _Allocator>
3707inline
3708typename basic_string<_CharT, _Traits, _Allocator>::size_type
3709basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3710 size_type __pos) const _NOEXCEPTnoexcept
3711{
3712 return find(__c, __pos);
3713}
3714
3715// find_last_of
3716
3717template<class _CharT, class _Traits, class _Allocator>
3718typename basic_string<_CharT, _Traits, _Allocator>::size_type
3719basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
3720 size_type __pos,
3721 size_type __n) const _NOEXCEPTnoexcept
3722{
3723 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr")((void)0);
3724 return __str_find_last_of<value_type, size_type, traits_type, npos>
3725 (data(), size(), __s, __pos, __n);
3726}
3727
3728template<class _CharT, class _Traits, class _Allocator>
3729inline
3730typename basic_string<_CharT, _Traits, _Allocator>::size_type
3731basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3732 size_type __pos) const _NOEXCEPTnoexcept
3733{
3734 return __str_find_last_of<value_type, size_type, traits_type, npos>
3735 (data(), size(), __str.data(), __pos, __str.size());
3736}
3737
3738template<class _CharT, class _Traits, class _Allocator>
3739template <class _Tp>
3740_EnableIf
3741<
3742 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3743 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3744>
3745basic_string<_CharT, _Traits, _Allocator>::find_last_of(const _Tp& __t,
3746 size_type __pos) const _NOEXCEPTnoexcept
3747{
3748 __self_view __sv = __t;
3749 return __str_find_last_of<value_type, size_type, traits_type, npos>
3750 (data(), size(), __sv.data(), __pos, __sv.size());
3751}
3752
3753template<class _CharT, class _Traits, class _Allocator>
3754inline
3755typename basic_string<_CharT, _Traits, _Allocator>::size_type
3756basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
3757 size_type __pos) const _NOEXCEPTnoexcept
3758{
3759 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr")((void)0);
3760 return __str_find_last_of<value_type, size_type, traits_type, npos>
3761 (data(), size(), __s, __pos, traits_type::length(__s));
3762}
3763
3764template<class _CharT, class _Traits, class _Allocator>
3765inline
3766typename basic_string<_CharT, _Traits, _Allocator>::size_type
3767basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3768 size_type __pos) const _NOEXCEPTnoexcept
3769{
3770 return rfind(__c, __pos);
3771}
3772
3773// find_first_not_of
3774
3775template<class _CharT, class _Traits, class _Allocator>
3776typename basic_string<_CharT, _Traits, _Allocator>::size_type
3777basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
3778 size_type __pos,
3779 size_type __n) const _NOEXCEPTnoexcept
3780{
3781 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr")((void)0);
3782 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3783 (data(), size(), __s, __pos, __n);
3784}
3785
3786template<class _CharT, class _Traits, class _Allocator>
3787inline
3788typename basic_string<_CharT, _Traits, _Allocator>::size_type
3789basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3790 size_type __pos) const _NOEXCEPTnoexcept
3791{
3792 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3793 (data(), size(), __str.data(), __pos, __str.size());
3794}
3795
3796template<class _CharT, class _Traits, class _Allocator>
3797template <class _Tp>
3798_EnableIf
3799<
3800 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3801 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3802>
3803basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const _Tp& __t,
3804 size_type __pos) const _NOEXCEPTnoexcept
3805{
3806 __self_view __sv = __t;
3807 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3808 (data(), size(), __sv.data(), __pos, __sv.size());
3809}
3810
3811template<class _CharT, class _Traits, class _Allocator>
3812inline
3813typename basic_string<_CharT, _Traits, _Allocator>::size_type
3814basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
3815 size_type __pos) const _NOEXCEPTnoexcept
3816{
3817 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr")((void)0);
3818 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3819 (data(), size(), __s, __pos, traits_type::length(__s));
3820}
3821
3822template<class _CharT, class _Traits, class _Allocator>
3823inline
3824typename basic_string<_CharT, _Traits, _Allocator>::size_type
3825basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3826 size_type __pos) const _NOEXCEPTnoexcept
3827{
3828 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3829 (data(), size(), __c, __pos);
3830}
3831
3832// find_last_not_of
3833
3834template<class _CharT, class _Traits, class _Allocator>
3835typename basic_string<_CharT, _Traits, _Allocator>::size_type
3836basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
3837 size_type __pos,
3838 size_type __n) const _NOEXCEPTnoexcept
3839{
3840 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr")((void)0);
3841 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3842 (data(), size(), __s, __pos, __n);
3843}
3844
3845template<class _CharT, class _Traits, class _Allocator>
3846inline
3847typename basic_string<_CharT, _Traits, _Allocator>::size_type
3848basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3849 size_type __pos) const _NOEXCEPTnoexcept
3850{
3851 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3852 (data(), size(), __str.data(), __pos, __str.size());
3853}
3854
3855template<class _CharT, class _Traits, class _Allocator>
3856template <class _Tp>
3857_EnableIf
3858<
3859 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3860 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3861>
3862basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const _Tp& __t,
3863 size_type __pos) const _NOEXCEPTnoexcept
3864{
3865 __self_view __sv = __t;
3866 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3867 (data(), size(), __sv.data(), __pos, __sv.size());
3868}
3869
3870template<class _CharT, class _Traits, class _Allocator>
3871inline
3872typename basic_string<_CharT, _Traits, _Allocator>::size_type
3873basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
3874 size_type __pos) const _NOEXCEPTnoexcept
3875{
3876 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr")((void)0);
3877 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3878 (data(), size(), __s, __pos, traits_type::length(__s));
3879}
3880
3881template<class _CharT, class _Traits, class _Allocator>
3882inline
3883typename basic_string<_CharT, _Traits, _Allocator>::size_type
3884basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3885 size_type __pos) const _NOEXCEPTnoexcept
3886{
3887 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3888 (data(), size(), __c, __pos);
3889}
3890
3891// compare
3892
3893template <class _CharT, class _Traits, class _Allocator>
3894template <class _Tp>
3895_EnableIf
3896<
3897 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3898 int
3899>
3900basic_string<_CharT, _Traits, _Allocator>::compare(const _Tp& __t) const _NOEXCEPTnoexcept
3901{
3902 __self_view __sv = __t;
3903 size_t __lhs_sz = size();
3904 size_t __rhs_sz = __sv.size();
3905 int __result = traits_type::compare(data(), __sv.data(),
3906 _VSTDstd::__1::min(__lhs_sz, __rhs_sz));
3907 if (__result != 0)
3908 return __result;
3909 if (__lhs_sz < __rhs_sz)
3910 return -1;
3911 if (__lhs_sz > __rhs_sz)
3912 return 1;
3913 return 0;
3914}
3915
3916template <class _CharT, class _Traits, class _Allocator>
3917inline
3918int
3919basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPTnoexcept
3920{
3921 return compare(__self_view(__str));
3922}
3923
3924template <class _CharT, class _Traits, class _Allocator>
3925int
3926basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3927 size_type __n1,
3928 const value_type* __s,
3929 size_type __n2) const
3930{
3931 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr")((void)0);
3932 size_type __sz = size();
3933 if (__pos1 > __sz || __n2 == npos)
3934 this->__throw_out_of_range();
3935 size_type __rlen = _VSTDstd::__1::min(__n1, __sz - __pos1);
3936 int __r = traits_type::compare(data() + __pos1, __s, _VSTDstd::__1::min(__rlen, __n2));
3937 if (__r == 0)
3938 {
3939 if (__rlen < __n2)
3940 __r = -1;
3941 else if (__rlen > __n2)
3942 __r = 1;
3943 }
3944 return __r;
3945}
3946
3947template <class _CharT, class _Traits, class _Allocator>
3948template <class _Tp>
3949_EnableIf
3950<
3951 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3952 int
3953>
3954basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3955 size_type __n1,
3956 const _Tp& __t) const
3957{
3958 __self_view __sv = __t;
3959 return compare(__pos1, __n1, __sv.data(), __sv.size());
3960}
3961
3962template <class _CharT, class _Traits, class _Allocator>
3963inline
3964int
3965basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3966 size_type __n1,
3967 const basic_string& __str) const
3968{
3969 return compare(__pos1, __n1, __str.data(), __str.size());
3970}
3971
3972template <class _CharT, class _Traits, class _Allocator>
3973template <class _Tp>
3974_EnableIf
3975<
3976 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
3977 && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
3978 int
3979>
3980basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3981 size_type __n1,
3982 const _Tp& __t,
3983 size_type __pos2,
3984 size_type __n2) const
3985{
3986 __self_view __sv = __t;
3987 return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
3988}
3989
3990template <class _CharT, class _Traits, class _Allocator>
3991int
3992basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3993 size_type __n1,
3994 const basic_string& __str,
3995 size_type __pos2,
3996 size_type __n2) const
3997{
3998 return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
3999}
4000
4001template <class _CharT, class _Traits, class _Allocator>
4002int
4003basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPTnoexcept
4004{
4005 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr")((void)0);
4006 return compare(0, npos, __s, traits_type::length(__s));
4007}
4008
4009template <class _CharT, class _Traits, class _Allocator>
4010int
4011basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
4012 size_type __n1,
4013 const value_type* __s) const
4014{
4015 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr")((void)0);
4016 return compare(__pos1, __n1, __s, traits_type::length(__s));
4017}
4018
4019// __invariants
4020
4021template<class _CharT, class _Traits, class _Allocator>
4022inline
4023bool
4024basic_string<_CharT, _Traits, _Allocator>::__invariants() const
4025{
4026 if (size() > capacity())
4027 return false;
4028 if (capacity() < __min_cap - 1)
4029 return false;
4030 if (data() == nullptr)
4031 return false;
4032 if (data()[size()] != value_type())
4033 return false;
4034 return true;
4035}
4036
4037// __clear_and_shrink
4038
4039template<class _CharT, class _Traits, class _Allocator>
4040inline
4041void
4042basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPTnoexcept
4043{
4044 clear();
4045 if(__is_long())
4046 {
4047 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1);
4048 __set_long_cap(0);
4049 __set_short_size(0);
4050 traits_type::assign(*__get_short_pointer(), value_type());
4051 }
4052}
4053
4054// operator==
4055
4056template<class _CharT, class _Traits, class _Allocator>
4057inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4058bool
4059operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4060 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPTnoexcept
4061{
4062 size_t __lhs_sz = __lhs.size();
4063 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
4064 __rhs.data(),
4065 __lhs_sz) == 0;
4066}
4067
4068template<class _Allocator>
4069inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4070bool
4071operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
4072 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPTnoexcept
4073{
4074 size_t __lhs_sz = __lhs.size();
4075 if (__lhs_sz != __rhs.size())
4076 return false;
4077 const char* __lp = __lhs.data();
4078 const char* __rp = __rhs.data();
4079 if (__lhs.__is_long())
4080 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
4081 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
4082 if (*__lp != *__rp)
4083 return false;
4084 return true;
4085}
4086
4087template<class _CharT, class _Traits, class _Allocator>
4088inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4089bool
4090operator==(const _CharT* __lhs,
4091 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPTnoexcept
4092{
4093 typedef basic_string<_CharT, _Traits, _Allocator> _String;
4094 _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr")((void)0);
4095 size_t __lhs_len = _Traits::length(__lhs);
4096 if (__lhs_len != __rhs.size()) return false;
4097 return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
4098}
4099
4100template<class _CharT, class _Traits, class _Allocator>
4101inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4102bool
4103operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
4104 const _CharT* __rhs) _NOEXCEPTnoexcept
4105{
4106 typedef basic_string<_CharT, _Traits, _Allocator> _String;
4107 _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr")((void)0);
4108 size_t __rhs_len = _Traits::length(__rhs);
4109 if (__rhs_len != __lhs.size()) return false;
26
Assuming the condition is false
27
Taking false branch
4110 return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
28
Assuming the condition is true
29
Returning the value 1, which participates in a condition later
4111}
4112
4113template<class _CharT, class _Traits, class _Allocator>
4114inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4115bool
4116operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
4117 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPTnoexcept
4118{
4119 return !(__lhs == __rhs);
4120}
4121
4122template<class _CharT, class _Traits, class _Allocator>
4123inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4124bool
4125operator!=(const _CharT* __lhs,
4126 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPTnoexcept
4127{
4128 return !(__lhs == __rhs);
4129}
4130
4131template<class _CharT, class _Traits, class _Allocator>
4132inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4133bool
4134operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4135 const _CharT* __rhs) _NOEXCEPTnoexcept
4136{
4137 return !(__lhs == __rhs);
4138}
4139
4140// operator<
4141
4142template<class _CharT, class _Traits, class _Allocator>
4143inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4144bool
4145operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4146 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPTnoexcept
4147{
4148 return __lhs.compare(__rhs) < 0;
4149}
4150
4151template<class _CharT, class _Traits, class _Allocator>
4152inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4153bool
4154operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4155 const _CharT* __rhs) _NOEXCEPTnoexcept
4156{
4157 return __lhs.compare(__rhs) < 0;
4158}
4159
4160template<class _CharT, class _Traits, class _Allocator>
4161inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4162bool
4163operator< (const _CharT* __lhs,
4164 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPTnoexcept
4165{
4166 return __rhs.compare(__lhs) > 0;
4167}
4168
4169// operator>
4170
4171template<class _CharT, class _Traits, class _Allocator>
4172inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4173bool
4174operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4175 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPTnoexcept
4176{
4177 return __rhs < __lhs;
4178}
4179
4180template<class _CharT, class _Traits, class _Allocator>
4181inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4182bool
4183operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4184 const _CharT* __rhs) _NOEXCEPTnoexcept
4185{
4186 return __rhs < __lhs;
4187}
4188
4189template<class _CharT, class _Traits, class _Allocator>
4190inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4191bool
4192operator> (const _CharT* __lhs,
4193 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPTnoexcept
4194{
4195 return __rhs < __lhs;
4196}
4197
4198// operator<=
4199
4200template<class _CharT, class _Traits, class _Allocator>
4201inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4202bool
4203operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4204 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPTnoexcept
4205{
4206 return !(__rhs < __lhs);
4207}
4208
4209template<class _CharT, class _Traits, class _Allocator>
4210inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4211bool
4212operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4213 const _CharT* __rhs) _NOEXCEPTnoexcept
4214{
4215 return !(__rhs < __lhs);
4216}
4217
4218template<class _CharT, class _Traits, class _Allocator>
4219inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4220bool
4221operator<=(const _CharT* __lhs,
4222 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPTnoexcept
4223{
4224 return !(__rhs < __lhs);
4225}
4226
4227// operator>=
4228
4229template<class _CharT, class _Traits, class _Allocator>
4230inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4231bool
4232operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4233 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPTnoexcept
4234{
4235 return !(__lhs < __rhs);
4236}
4237
4238template<class _CharT, class _Traits, class _Allocator>
4239inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4240bool
4241operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4242 const _CharT* __rhs) _NOEXCEPTnoexcept
4243{
4244 return !(__lhs < __rhs);
4245}
4246
4247template<class _CharT, class _Traits, class _Allocator>
4248inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4249bool
4250operator>=(const _CharT* __lhs,
4251 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPTnoexcept
4252{
4253 return !(__lhs < __rhs);
4254}
4255
4256// operator +
4257
4258template<class _CharT, class _Traits, class _Allocator>
4259basic_string<_CharT, _Traits, _Allocator>
4260operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4261 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4262{
4263 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4264 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4265 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4266 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4267 __r.append(__rhs.data(), __rhs_sz);
4268 return __r;
4269}
4270
4271template<class _CharT, class _Traits, class _Allocator>
4272basic_string<_CharT, _Traits, _Allocator>
4273operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4274{
4275 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4276 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
4277 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4278 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
4279 __r.append(__rhs.data(), __rhs_sz);
4280 return __r;
4281}
4282
4283template<class _CharT, class _Traits, class _Allocator>
4284basic_string<_CharT, _Traits, _Allocator>
4285operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4286{
4287 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4288 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4289 __r.__init(&__lhs, 1, 1 + __rhs_sz);
4290 __r.append(__rhs.data(), __rhs_sz);
4291 return __r;
4292}
4293
4294template<class _CharT, class _Traits, class _Allocator>
4295inline
4296basic_string<_CharT, _Traits, _Allocator>
4297operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
4298{
4299 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4300 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4301 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
4302 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4303 __r.append(__rhs, __rhs_sz);
4304 return __r;
4305}
4306
4307template<class _CharT, class _Traits, class _Allocator>
4308basic_string<_CharT, _Traits, _Allocator>
4309operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
4310{
4311 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4312 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4313 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
4314 __r.push_back(__rhs);
4315 return __r;
4316}
4317
4318#ifndef _LIBCPP_CXX03_LANG
4319
4320template<class _CharT, class _Traits, class _Allocator>
4321inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4322basic_string<_CharT, _Traits, _Allocator>
4323operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4324{
4325 return _VSTDstd::__1::move(__lhs.append(__rhs));
4326}
4327
4328template<class _CharT, class _Traits, class _Allocator>
4329inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4330basic_string<_CharT, _Traits, _Allocator>
4331operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4332{
4333 return _VSTDstd::__1::move(__rhs.insert(0, __lhs));
4334}
4335
4336template<class _CharT, class _Traits, class _Allocator>
4337inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4338basic_string<_CharT, _Traits, _Allocator>
4339operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4340{
4341 return _VSTDstd::__1::move(__lhs.append(__rhs));
4342}
4343
4344template<class _CharT, class _Traits, class _Allocator>
4345inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4346basic_string<_CharT, _Traits, _Allocator>
4347operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4348{
4349 return _VSTDstd::__1::move(__rhs.insert(0, __lhs));
4350}
4351
4352template<class _CharT, class _Traits, class _Allocator>
4353inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4354basic_string<_CharT, _Traits, _Allocator>
4355operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4356{
4357 __rhs.insert(__rhs.begin(), __lhs);
4358 return _VSTDstd::__1::move(__rhs);
4359}
4360
4361template<class _CharT, class _Traits, class _Allocator>
4362inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4363basic_string<_CharT, _Traits, _Allocator>
4364operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
4365{
4366 return _VSTDstd::__1::move(__lhs.append(__rhs));
4367}
4368
4369template<class _CharT, class _Traits, class _Allocator>
4370inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4371basic_string<_CharT, _Traits, _Allocator>
4372operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
4373{
4374 __lhs.push_back(__rhs);
4375 return _VSTDstd::__1::move(__lhs);
4376}
4377
4378#endif // _LIBCPP_CXX03_LANG
4379
4380// swap
4381
4382template<class _CharT, class _Traits, class _Allocator>
4383inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4384void
4385swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
4386 basic_string<_CharT, _Traits, _Allocator>& __rhs)
4387 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))noexcept(noexcept(__lhs.swap(__rhs)))
4388{
4389 __lhs.swap(__rhs);
4390}
4391
4392_LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) int stoi (const string& __str, size_t* __idx = nullptr, int __base = 10);
4393_LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) long stol (const string& __str, size_t* __idx = nullptr, int __base = 10);
4394_LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) unsigned long stoul (const string& __str, size_t* __idx = nullptr, int __base = 10);
4395_LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) long long stoll (const string& __str, size_t* __idx = nullptr, int __base = 10);
4396_LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) unsigned long long stoull(const string& __str, size_t* __idx = nullptr, int __base = 10);
4397
4398_LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) float stof (const string& __str, size_t* __idx = nullptr);
4399_LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) double stod (const string& __str, size_t* __idx = nullptr);
4400_LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) long double stold(const string& __str, size_t* __idx = nullptr);
4401
4402_LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) string to_string(int __val);
4403_LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) string to_string(unsigned __val);
4404_LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) string to_string(long __val);
4405_LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) string to_string(unsigned long __val);
4406_LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) string to_string(long long __val);
4407_LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) string to_string(unsigned long long __val);
4408_LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) string to_string(float __val);
4409_LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) string to_string(double __val);
4410_LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) string to_string(long double __val);
4411
4412_LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) int stoi (const wstring& __str, size_t* __idx = nullptr, int __base = 10);
4413_LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) long stol (const wstring& __str, size_t* __idx = nullptr, int __base = 10);
4414_LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) unsigned long stoul (const wstring& __str, size_t* __idx = nullptr, int __base = 10);
4415_LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) long long stoll (const wstring& __str, size_t* __idx = nullptr, int __base = 10);
4416_LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) unsigned long long stoull(const wstring& __str, size_t* __idx = nullptr, int __base = 10);
4417
4418_LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) float stof (const wstring& __str, size_t* __idx = nullptr);
4419_LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) double stod (const wstring& __str, size_t* __idx = nullptr);
4420_LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) long double stold(const wstring& __str, size_t* __idx = nullptr);
4421
4422_LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) wstring to_wstring(int __val);
4423_LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) wstring to_wstring(unsigned __val);
4424_LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) wstring to_wstring(long __val);
4425_LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) wstring to_wstring(unsigned long __val);
4426_LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) wstring to_wstring(long long __val);
4427_LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) wstring to_wstring(unsigned long long __val);
4428_LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) wstring to_wstring(float __val);
4429_LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) wstring to_wstring(double __val);
4430_LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) wstring to_wstring(long double __val);
4431
4432template<class _CharT, class _Traits, class _Allocator>
4433_LIBCPP_TEMPLATE_DATA_VIS__attribute__ ((__visibility__("default")))
4434const typename basic_string<_CharT, _Traits, _Allocator>::size_type
4435 basic_string<_CharT, _Traits, _Allocator>::npos;
4436
4437template <class _CharT, class _Allocator>
4438struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default")))
4439 hash<basic_string<_CharT, char_traits<_CharT>, _Allocator> >
4440 : public unary_function<
4441 basic_string<_CharT, char_traits<_CharT>, _Allocator>, size_t>
4442{
4443 size_t
4444 operator()(const basic_string<_CharT, char_traits<_CharT>, _Allocator>& __val) const _NOEXCEPTnoexcept
4445 { return __do_string_hash(__val.data(), __val.data() + __val.size()); }
4446};
4447
4448
4449template<class _CharT, class _Traits, class _Allocator>
4450basic_ostream<_CharT, _Traits>&
4451operator<<(basic_ostream<_CharT, _Traits>& __os,
4452 const basic_string<_CharT, _Traits, _Allocator>& __str);
4453
4454template<class _CharT, class _Traits, class _Allocator>
4455basic_istream<_CharT, _Traits>&
4456operator>>(basic_istream<_CharT, _Traits>& __is,
4457 basic_string<_CharT, _Traits, _Allocator>& __str);
4458
4459template<class _CharT, class _Traits, class _Allocator>
4460basic_istream<_CharT, _Traits>&
4461getline(basic_istream<_CharT, _Traits>& __is,
4462 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4463
4464template<class _CharT, class _Traits, class _Allocator>
4465inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4466basic_istream<_CharT, _Traits>&
4467getline(basic_istream<_CharT, _Traits>& __is,
4468 basic_string<_CharT, _Traits, _Allocator>& __str);
4469
4470template<class _CharT, class _Traits, class _Allocator>
4471inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4472basic_istream<_CharT, _Traits>&
4473getline(basic_istream<_CharT, _Traits>&& __is,
4474 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4475
4476template<class _CharT, class _Traits, class _Allocator>
4477inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4478basic_istream<_CharT, _Traits>&
4479getline(basic_istream<_CharT, _Traits>&& __is,
4480 basic_string<_CharT, _Traits, _Allocator>& __str);
4481
4482#if _LIBCPP_STD_VER14 > 17
4483template <class _CharT, class _Traits, class _Allocator, class _Up>
4484inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4485 typename basic_string<_CharT, _Traits, _Allocator>::size_type
4486 erase(basic_string<_CharT, _Traits, _Allocator>& __str, const _Up& __v) {
4487 auto __old_size = __str.size();
4488 __str.erase(_VSTDstd::__1::remove(__str.begin(), __str.end(), __v), __str.end());
4489 return __old_size - __str.size();
4490}
4491
4492template <class _CharT, class _Traits, class _Allocator, class _Predicate>
4493inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4494 typename basic_string<_CharT, _Traits, _Allocator>::size_type
4495 erase_if(basic_string<_CharT, _Traits, _Allocator>& __str,
4496 _Predicate __pred) {
4497 auto __old_size = __str.size();
4498 __str.erase(_VSTDstd::__1::remove_if(__str.begin(), __str.end(), __pred),
4499 __str.end());
4500 return __old_size - __str.size();
4501}
4502#endif
4503
4504#if _LIBCPP_DEBUG_LEVEL0 == 2
4505
4506template<class _CharT, class _Traits, class _Allocator>
4507bool
4508basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
4509{
4510 return this->data() <= _VSTDstd::__1::__to_address(__i->base()) &&
4511 _VSTDstd::__1::__to_address(__i->base()) < this->data() + this->size();
4512}
4513
4514template<class _CharT, class _Traits, class _Allocator>
4515bool
4516basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
4517{
4518 return this->data() < _VSTDstd::__1::__to_address(__i->base()) &&
4519 _VSTDstd::__1::__to_address(__i->base()) <= this->data() + this->size();
4520}
4521
4522template<class _CharT, class _Traits, class _Allocator>
4523bool
4524basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
4525{
4526 const value_type* __p = _VSTDstd::__1::__to_address(__i->base()) + __n;
4527 return this->data() <= __p && __p <= this->data() + this->size();
4528}
4529
4530template<class _CharT, class _Traits, class _Allocator>
4531bool
4532basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
4533{
4534 const value_type* __p = _VSTDstd::__1::__to_address(__i->base()) + __n;
4535 return this->data() <= __p && __p < this->data() + this->size();
4536}
4537
4538#endif // _LIBCPP_DEBUG_LEVEL == 2
4539
4540#if _LIBCPP_STD_VER14 > 11
4541// Literal suffixes for basic_string [basic.string.literals]
4542inline namespace literals
4543{
4544 inline namespace string_literals
4545 {
4546 inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4547 basic_string<char> operator "" s( const char *__str, size_t __len )
4548 {
4549 return basic_string<char> (__str, __len);
4550 }
4551
4552 inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4553 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
4554 {
4555 return basic_string<wchar_t> (__str, __len);
4556 }
4557
4558#ifndef _LIBCPP_HAS_NO_CHAR8_T
4559 inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4560 basic_string<char8_t> operator "" s(const char8_t *__str, size_t __len) _NOEXCEPTnoexcept
4561 {
4562 return basic_string<char8_t> (__str, __len);
4563 }
4564#endif
4565
4566 inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4567 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
4568 {
4569 return basic_string<char16_t> (__str, __len);
4570 }
4571
4572 inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__
))
4573 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
4574 {
4575 return basic_string<char32_t> (__str, __len);
4576 }
4577 }
4578}
4579#endif
4580
4581_LIBCPP_END_NAMESPACE_STD} }
4582
4583_LIBCPP_POP_MACROSpop_macro("min") pop_macro("max")
4584
4585#endif // _LIBCPP_STRING