| File: | src/gnu/usr.bin/clang/liblldbPluginPlatform/../../../llvm/lldb/source/Plugins/Platform/Android/AdbClient.cpp |
| Warning: | line 87, column 13 2nd function call argument is an uninitialized value |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 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 | |||||||||||
| 40 | using namespace lldb; | ||||||||||
| 41 | using namespace lldb_private; | ||||||||||
| 42 | using namespace lldb_private::platform_android; | ||||||||||
| 43 | using namespace std::chrono; | ||||||||||
| 44 | |||||||||||
| 45 | namespace { | ||||||||||
| 46 | |||||||||||
| 47 | const seconds kReadTimeout(20); | ||||||||||
| 48 | const char *kOKAY = "OKAY"; | ||||||||||
| 49 | const char *kFAIL = "FAIL"; | ||||||||||
| 50 | const char *kDATA = "DATA"; | ||||||||||
| 51 | const char *kDONE = "DONE"; | ||||||||||
| 52 | |||||||||||
| 53 | const char *kSEND = "SEND"; | ||||||||||
| 54 | const char *kRECV = "RECV"; | ||||||||||
| 55 | const char *kSTAT = "STAT"; | ||||||||||
| 56 | |||||||||||
| 57 | const size_t kSyncPacketLen = 8; | ||||||||||
| 58 | // Maximum size of a filesync DATA packet. | ||||||||||
| 59 | const size_t kMaxPushData = 2 * 1024; | ||||||||||
| 60 | // Default mode for pushed files. | ||||||||||
| 61 | const uint32_t kDefaultMode = 0100770; // S_IFREG | S_IRWXU | S_IRWXG | ||||||||||
| 62 | |||||||||||
| 63 | const char *kSocketNamespaceAbstract = "localabstract"; | ||||||||||
| 64 | const char *kSocketNamespaceFileSystem = "localfilesystem"; | ||||||||||
| 65 | |||||||||||
| 66 | Status 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
| ||||||||||
| 87 | error = Status( | ||||||||||
| |||||||||||
| 88 | "Unable to read requested number of bytes. Connection status: %d.", | ||||||||||
| 89 | status); | ||||||||||
| 90 | return error; | ||||||||||
| 91 | } | ||||||||||
| 92 | |||||||||||
| 93 | } // namespace | ||||||||||
| 94 | |||||||||||
| 95 | Status 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 | |||||||||||
| 121 | AdbClient::AdbClient() = default; | ||||||||||
| 122 | |||||||||||
| 123 | AdbClient::AdbClient(const std::string &device_id) : m_device_id(device_id) {} | ||||||||||
| 124 | |||||||||||
| 125 | AdbClient::~AdbClient() = default; | ||||||||||
| 126 | |||||||||||
| 127 | void AdbClient::SetDeviceID(const std::string &device_id) { | ||||||||||
| 128 | m_device_id = device_id; | ||||||||||
| 129 | } | ||||||||||
| 130 | |||||||||||
| 131 | const std::string &AdbClient::GetDeviceID() const { return m_device_id; } | ||||||||||
| 132 | |||||||||||
| 133 | Status 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 | |||||||||||
| 146 | Status 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 | |||||||||||
| 173 | Status 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 | |||||||||||
| 186 | Status | ||||||||||
| 187 | AdbClient::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 | |||||||||||
| 205 | Status 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 | |||||||||||
| 216 | Status 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 | |||||||||||
| 238 | Status 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 | |||||||||||
| 244 | Status 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 | |||||||||||
| 265 | Status 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 | |||||||||||
| 288 | Status 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 | |||||||||||
| 304 | Status 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 | |||||||||||
| 317 | Status 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 | |||||||||||
| 328 | Status 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 | |||||||||||
| 341 | Status AdbClient::Sync() { | ||||||||||
| 342 | auto error = SendMessage("sync:", false); | ||||||||||
| 343 | if (error.Fail()) | ||||||||||
| 344 | return error; | ||||||||||
| 345 | |||||||||||
| 346 | return ReadResponseStatus(); | ||||||||||
| 347 | } | ||||||||||
| 348 | |||||||||||
| 349 | Status AdbClient::ReadAllBytes(void *buffer, size_t size) { | ||||||||||
| 350 | return ::ReadAllBytes(*m_conn, buffer, size); | ||||||||||
| 351 | } | ||||||||||
| 352 | |||||||||||
| 353 | Status 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 | |||||||||||
| 388 | Status 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 | |||||||||||
| 400 | Status 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 | |||||||||||
| 420 | std::unique_ptr<AdbClient::SyncService> | ||||||||||
| 421 | AdbClient::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 | |||||||||||
| 430 | Status 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) | ||||||||||
| 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()) | ||||||||||
| 444 | return error; | ||||||||||
| 445 | |||||||||||
| 446 | std::vector<char> chunk; | ||||||||||
| 447 | bool eof = false; | ||||||||||
| 448 | while (!eof) { | ||||||||||
| 449 | error = PullFileChunk(chunk, eof); | ||||||||||
| 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 | |||||||||||
| 463 | Status 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 | |||||||||||
| 512 | Status 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 | |||||||||||
| 546 | Status AdbClient::SyncService::PullFile(const FileSpec &remote_file, | ||||||||||
| 547 | const FileSpec &local_file) { | ||||||||||
| 548 | return executeCommand([this, &remote_file, &local_file]() { | ||||||||||
| 549 | return internalPullFile(remote_file, local_file); | ||||||||||
| 550 | }); | ||||||||||
| 551 | } | ||||||||||
| 552 | |||||||||||
| 553 | Status 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 | |||||||||||
| 560 | Status 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 | |||||||||||
| 567 | bool AdbClient::SyncService::IsConnected() const { | ||||||||||
| 568 | return m_conn && m_conn->IsConnected(); | ||||||||||
| 569 | } | ||||||||||
| 570 | |||||||||||
| 571 | AdbClient::SyncService::SyncService(std::unique_ptr<Connection> &&conn) | ||||||||||
| 572 | : m_conn(std::move(conn)) {} | ||||||||||
| 573 | |||||||||||
| 574 | Status | ||||||||||
| 575 | AdbClient::SyncService::executeCommand(const std::function<Status()> &cmd) { | ||||||||||
| 576 | if (!m_conn) | ||||||||||
| 577 | return Status("SyncService is disconnected"); | ||||||||||
| 578 | |||||||||||
| 579 | const auto error = cmd(); | ||||||||||
| 580 | if (error.Fail()) | ||||||||||
| 581 | m_conn.reset(); | ||||||||||
| 582 | |||||||||||
| 583 | return error; | ||||||||||
| 584 | } | ||||||||||
| 585 | |||||||||||
| 586 | AdbClient::SyncService::~SyncService() = default; | ||||||||||
| 587 | |||||||||||
| 588 | Status 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 | |||||||||||
| 607 | Status 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()) { | ||||||||||
| 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; | ||||||||||
| 620 | } | ||||||||||
| 621 | |||||||||||
| 622 | Status AdbClient::SyncService::PullFileChunk(std::vector<char> &buffer, | ||||||||||
| 623 | bool &eof) { | ||||||||||
| 624 | buffer.clear(); | ||||||||||
| 625 | |||||||||||
| 626 | std::string response_id; | ||||||||||
| 627 | uint32_t data_len; | ||||||||||
| 628 | auto error = ReadSyncHeader(response_id, data_len); | ||||||||||
| 629 | if (error.Fail()) | ||||||||||
| 630 | return error; | ||||||||||
| 631 | |||||||||||
| 632 | if (response_id == kDATA) { | ||||||||||
| 633 | buffer.resize(data_len, 0); | ||||||||||
| 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 | |||||||||||
| 651 | Status AdbClient::SyncService::ReadAllBytes(void *buffer, size_t size) { | ||||||||||
| 652 | return ::ReadAllBytes(*m_conn, buffer, size); | ||||||||||
| 653 | } |
| 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 | |
| 34 | class _LIBCPP_EXCEPTION_ABI__attribute__ ((__visibility__("default"))) bad_function_call |
| 35 | : public exception |
| 36 | { |
| 37 | #ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION |
| 38 | public: |
| 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__ )) |
| 46 | void __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 | |
| 62 | template<class _Fp> class _LIBCPP_DEPRECATED_CXX03_FUNCTION _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) function; // undefined |
| 63 | |
| 64 | namespace __function |
| 65 | { |
| 66 | |
| 67 | template<class _Rp> |
| 68 | struct __maybe_derive_from_unary_function |
| 69 | { |
| 70 | }; |
| 71 | |
| 72 | template<class _Rp, class _A1> |
| 73 | struct __maybe_derive_from_unary_function<_Rp(_A1)> |
| 74 | : public unary_function<_A1, _Rp> |
| 75 | { |
| 76 | }; |
| 77 | |
| 78 | template<class _Rp> |
| 79 | struct __maybe_derive_from_binary_function |
| 80 | { |
| 81 | }; |
| 82 | |
| 83 | template<class _Rp, class _A1, class _A2> |
| 84 | struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)> |
| 85 | : public binary_function<_A1, _A2, _Rp> |
| 86 | { |
| 87 | }; |
| 88 | |
| 89 | template <class _Fp> |
| 90 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 91 | bool __not_null(_Fp const&) { return true; } |
| 92 | |
| 93 | template <class _Fp> |
| 94 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 95 | bool __not_null(_Fp* __ptr) { return __ptr; } |
| 96 | |
| 97 | template <class _Ret, class _Class> |
| 98 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 99 | bool __not_null(_Ret _Class::*__ptr) { return __ptr; } |
| 100 | |
| 101 | template <class _Fp> |
| 102 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 103 | bool __not_null(function<_Fp> const& __f) { return !!__f; } |
| 104 | |
| 105 | #ifdef _LIBCPP_HAS_EXTENSION_BLOCKS |
| 106 | template <class _Rp, class ..._Args> |
| 107 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 108 | bool __not_null(_Rp (^__p)(_Args...)) { return __p; } |
| 109 | #endif |
| 110 | |
| 111 | } // namespace __function |
| 112 | |
| 113 | #ifndef _LIBCPP_CXX03_LANG |
| 114 | |
| 115 | namespace __function { |
| 116 | |
| 117 | // __alloc_func holds a functor and an allocator. |
| 118 | |
| 119 | template <class _Fp, class _Ap, class _FB> class __alloc_func; |
| 120 | template <class _Fp, class _FB> |
| 121 | class __default_alloc_func; |
| 122 | |
| 123 | template <class _Fp, class _Ap, class _Rp, class... _ArgTypes> |
| 124 | class __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(), |
| 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 | |
| 202 | template <class _Fp, class _Rp, class... _ArgTypes> |
| 203 | class __default_alloc_func<_Fp, _Rp(_ArgTypes...)> { |
| 204 | _Fp __f_; |
| 205 | |
| 206 | public: |
| 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 | |
| 245 | template<class _Fp> class _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) __base; |
| 246 | |
| 247 | template<class _Rp, class ..._ArgTypes> |
| 248 | class __base<_Rp(_ArgTypes...)> |
| 249 | { |
| 250 | __base(const __base&); |
| 251 | __base& operator=(const __base&); |
| 252 | public: |
| 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 | |
| 268 | template<class _FD, class _Alloc, class _FB> class __func; |
| 269 | |
| 270 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
| 271 | class __func<_Fp, _Alloc, _Rp(_ArgTypes...)> |
| 272 | : public __base<_Rp(_ArgTypes...)> |
| 273 | { |
| 274 | __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> __f_; |
| 275 | public: |
| 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 | |
| 303 | template<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 | |
| 316 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
| 317 | void |
| 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 | |
| 323 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
| 324 | void |
| 325 | __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPTnoexcept |
| 326 | { |
| 327 | __f_.destroy(); |
| 328 | } |
| 329 | |
| 330 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
| 331 | void |
| 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 | |
| 341 | template<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)...); |
| 346 | } |
| 347 | |
| 348 | #ifndef _LIBCPP_NO_RTTI |
| 349 | |
| 350 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
| 351 | const 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 | |
| 359 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
| 360 | const 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 | |
| 370 | template <class _Fp> class __value_func; |
| 371 | |
| 372 | template <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) |
| 497 | __throw_bad_function_call(); |
| 498 | return (*__f_)(_VSTDstd::__1::forward<_ArgTypes>(__args)...); |
| 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. |
| 563 | union __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. |
| 570 | template <typename _Fun> |
| 571 | struct __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. |
| 580 | struct __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. |
| 658 | template <typename _Tp> |
| 659 | using __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 | |
| 664 | template <class _Fp> struct __policy_invoker; |
| 665 | |
| 666 | template <class _Rp, class... _ArgTypes> |
| 667 | struct __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 | |
| 709 | template <class _Fp> class __policy_func; |
| 710 | |
| 711 | template <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 | |
| 874 | extern "C" void *_Block_copy(const void *); |
| 875 | extern "C" void _Block_release(const void *); |
| 876 | |
| 877 | template<class _Rp1, class ..._ArgTypes1, class _Alloc, class _Rp, class ..._ArgTypes> |
| 878 | class __func<_Rp1(^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)> |
| 879 | : public __base<_Rp(_ArgTypes...)> |
| 880 | { |
| 881 | typedef _Rp1(^__block_type)(_ArgTypes1...); |
| 882 | __block_type __f_; |
| 883 | |
| 884 | public: |
| 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 | |
| 943 | template<class _Rp, class ..._ArgTypes> |
| 944 | class _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; |
| 978 | public: |
| 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; |
| 1035 | public: |
| 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 |
| 1048 | template<class _Rp, class ..._Ap> |
| 1049 | function(_Rp(*)(_Ap...)) -> function<_Rp(_Ap...)>; |
| 1050 | |
| 1051 | template<class _Fp> |
| 1052 | struct __strip_signature; |
| 1053 | |
| 1054 | template<class _Rp, class _Gp, class ..._Ap> |
| 1055 | struct __strip_signature<_Rp (_Gp::*) (_Ap...)> { using type = _Rp(_Ap...); }; |
| 1056 | template<class _Rp, class _Gp, class ..._Ap> |
| 1057 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) const> { using type = _Rp(_Ap...); }; |
| 1058 | template<class _Rp, class _Gp, class ..._Ap> |
| 1059 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile> { using type = _Rp(_Ap...); }; |
| 1060 | template<class _Rp, class _Gp, class ..._Ap> |
| 1061 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile> { using type = _Rp(_Ap...); }; |
| 1062 | |
| 1063 | template<class _Rp, class _Gp, class ..._Ap> |
| 1064 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) &> { using type = _Rp(_Ap...); }; |
| 1065 | template<class _Rp, class _Gp, class ..._Ap> |
| 1066 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) const &> { using type = _Rp(_Ap...); }; |
| 1067 | template<class _Rp, class _Gp, class ..._Ap> |
| 1068 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile &> { using type = _Rp(_Ap...); }; |
| 1069 | template<class _Rp, class _Gp, class ..._Ap> |
| 1070 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile &> { using type = _Rp(_Ap...); }; |
| 1071 | |
| 1072 | template<class _Rp, class _Gp, class ..._Ap> |
| 1073 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) noexcept> { using type = _Rp(_Ap...); }; |
| 1074 | template<class _Rp, class _Gp, class ..._Ap> |
| 1075 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) const noexcept> { using type = _Rp(_Ap...); }; |
| 1076 | template<class _Rp, class _Gp, class ..._Ap> |
| 1077 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile noexcept> { using type = _Rp(_Ap...); }; |
| 1078 | template<class _Rp, class _Gp, class ..._Ap> |
| 1079 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile noexcept> { using type = _Rp(_Ap...); }; |
| 1080 | |
| 1081 | template<class _Rp, class _Gp, class ..._Ap> |
| 1082 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) & noexcept> { using type = _Rp(_Ap...); }; |
| 1083 | template<class _Rp, class _Gp, class ..._Ap> |
| 1084 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) const & noexcept> { using type = _Rp(_Ap...); }; |
| 1085 | template<class _Rp, class _Gp, class ..._Ap> |
| 1086 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile & noexcept> { using type = _Rp(_Ap...); }; |
| 1087 | template<class _Rp, class _Gp, class ..._Ap> |
| 1088 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile & noexcept> { using type = _Rp(_Ap...); }; |
| 1089 | |
| 1090 | template<class _Fp, class _Stripped = typename __strip_signature<decltype(&_Fp::operator())>::type> |
| 1091 | function(_Fp) -> function<_Stripped>; |
| 1092 | #endif // !_LIBCPP_HAS_NO_DEDUCTION_GUIDES |
| 1093 | |
| 1094 | template<class _Rp, class ..._ArgTypes> |
| 1095 | function<_Rp(_ArgTypes...)>::function(const function& __f) : __f_(__f.__f_) {} |
| 1096 | |
| 1097 | #if _LIBCPP_STD_VER14 <= 14 |
| 1098 | template<class _Rp, class ..._ArgTypes> |
| 1099 | template <class _Alloc> |
| 1100 | function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, |
| 1101 | const function& __f) : __f_(__f.__f_) {} |
| 1102 | #endif |
| 1103 | |
| 1104 | template <class _Rp, class... _ArgTypes> |
| 1105 | function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPTnoexcept |
| 1106 | : __f_(_VSTDstd::__1::move(__f.__f_)) {} |
| 1107 | |
| 1108 | #if _LIBCPP_STD_VER14 <= 14 |
| 1109 | template<class _Rp, class ..._ArgTypes> |
| 1110 | template <class _Alloc> |
| 1111 | function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, |
| 1112 | function&& __f) |
| 1113 | : __f_(_VSTDstd::__1::move(__f.__f_)) {} |
| 1114 | #endif |
| 1115 | |
| 1116 | template <class _Rp, class... _ArgTypes> |
| 1117 | template <class _Fp, class> |
| 1118 | function<_Rp(_ArgTypes...)>::function(_Fp __f) : __f_(_VSTDstd::__1::move(__f)) {} |
| 1119 | |
| 1120 | #if _LIBCPP_STD_VER14 <= 14 |
| 1121 | template <class _Rp, class... _ArgTypes> |
| 1122 | template <class _Fp, class _Alloc, class> |
| 1123 | function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a, |
| 1124 | _Fp __f) |
| 1125 | : __f_(_VSTDstd::__1::move(__f), __a) {} |
| 1126 | #endif |
| 1127 | |
| 1128 | template<class _Rp, class ..._ArgTypes> |
| 1129 | function<_Rp(_ArgTypes...)>& |
| 1130 | function<_Rp(_ArgTypes...)>::operator=(const function& __f) |
| 1131 | { |
| 1132 | function(__f).swap(*this); |
| 1133 | return *this; |
| 1134 | } |
| 1135 | |
| 1136 | template<class _Rp, class ..._ArgTypes> |
| 1137 | function<_Rp(_ArgTypes...)>& |
| 1138 | function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPTnoexcept |
| 1139 | { |
| 1140 | __f_ = _VSTDstd::__1::move(__f.__f_); |
| 1141 | return *this; |
| 1142 | } |
| 1143 | |
| 1144 | template<class _Rp, class ..._ArgTypes> |
| 1145 | function<_Rp(_ArgTypes...)>& |
| 1146 | function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPTnoexcept |
| 1147 | { |
| 1148 | __f_ = nullptr; |
| 1149 | return *this; |
| 1150 | } |
| 1151 | |
| 1152 | template<class _Rp, class ..._ArgTypes> |
| 1153 | template <class _Fp, class> |
| 1154 | function<_Rp(_ArgTypes...)>& |
| 1155 | function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f) |
| 1156 | { |
| 1157 | function(_VSTDstd::__1::forward<_Fp>(__f)).swap(*this); |
| 1158 | return *this; |
| 1159 | } |
| 1160 | |
| 1161 | template<class _Rp, class ..._ArgTypes> |
| 1162 | function<_Rp(_ArgTypes...)>::~function() {} |
| 1163 | |
| 1164 | template<class _Rp, class ..._ArgTypes> |
| 1165 | void |
| 1166 | function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPTnoexcept |
| 1167 | { |
| 1168 | __f_.swap(__f.__f_); |
| 1169 | } |
| 1170 | |
| 1171 | template<class _Rp, class ..._ArgTypes> |
| 1172 | _Rp |
| 1173 | function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const |
| 1174 | { |
| 1175 | return __f_(_VSTDstd::__1::forward<_ArgTypes>(__arg)...); |
| 1176 | } |
| 1177 | |
| 1178 | #ifndef _LIBCPP_NO_RTTI |
| 1179 | |
| 1180 | template<class _Rp, class ..._ArgTypes> |
| 1181 | const std::type_info& |
| 1182 | function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPTnoexcept |
| 1183 | { |
| 1184 | return __f_.target_type(); |
| 1185 | } |
| 1186 | |
| 1187 | template<class _Rp, class ..._ArgTypes> |
| 1188 | template <typename _Tp> |
| 1189 | _Tp* |
| 1190 | function<_Rp(_ArgTypes...)>::target() _NOEXCEPTnoexcept |
| 1191 | { |
| 1192 | return (_Tp*)(__f_.template target<_Tp>()); |
| 1193 | } |
| 1194 | |
| 1195 | template<class _Rp, class ..._ArgTypes> |
| 1196 | template <typename _Tp> |
| 1197 | const _Tp* |
| 1198 | function<_Rp(_ArgTypes...)>::target() const _NOEXCEPTnoexcept |
| 1199 | { |
| 1200 | return __f_.template target<_Tp>(); |
| 1201 | } |
| 1202 | |
| 1203 | #endif // _LIBCPP_NO_RTTI |
| 1204 | |
| 1205 | template <class _Rp, class... _ArgTypes> |
| 1206 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 1207 | bool |
| 1208 | operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPTnoexcept {return !__f;} |
| 1209 | |
| 1210 | template <class _Rp, class... _ArgTypes> |
| 1211 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 1212 | bool |
| 1213 | operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPTnoexcept {return !__f;} |
| 1214 | |
| 1215 | template <class _Rp, class... _ArgTypes> |
| 1216 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 1217 | bool |
| 1218 | operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPTnoexcept {return (bool)__f;} |
| 1219 | |
| 1220 | template <class _Rp, class... _ArgTypes> |
| 1221 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 1222 | bool |
| 1223 | operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPTnoexcept {return (bool)__f;} |
| 1224 | |
| 1225 | template <class _Rp, class... _ArgTypes> |
| 1226 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 1227 | void |
| 1228 | swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPTnoexcept |
| 1229 | {return __x.swap(__y);} |
| 1230 | |
| 1231 | #else // _LIBCPP_CXX03_LANG |
| 1232 | |
| 1233 | namespace __function { |
| 1234 | |
| 1235 | template<class _Fp> class __base; |
| 1236 | |
| 1237 | template<class _Rp> |
| 1238 | class __base<_Rp()> |
| 1239 | { |
| 1240 | __base(const __base&); |
| 1241 | __base& operator=(const __base&); |
| 1242 | public: |
| 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 | |
| 1256 | template<class _Rp, class _A0> |
| 1257 | class __base<_Rp(_A0)> |
| 1258 | { |
| 1259 | __base(const __base&); |
| 1260 | __base& operator=(const __base&); |
| 1261 | public: |
| 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 | |
| 1275 | template<class _Rp, class _A0, class _A1> |
| 1276 | class __base<_Rp(_A0, _A1)> |
| 1277 | { |
| 1278 | __base(const __base&); |
| 1279 | __base& operator=(const __base&); |
| 1280 | public: |
| 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 | |
| 1294 | template<class _Rp, class _A0, class _A1, class _A2> |
| 1295 | class __base<_Rp(_A0, _A1, _A2)> |
| 1296 | { |
| 1297 | __base(const __base&); |
| 1298 | __base& operator=(const __base&); |
| 1299 | public: |
| 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 | |
| 1313 | template<class _FD, class _Alloc, class _FB> class __func; |
| 1314 | |
| 1315 | template<class _Fp, class _Alloc, class _Rp> |
| 1316 | class __func<_Fp, _Alloc, _Rp()> |
| 1317 | : public __base<_Rp()> |
| 1318 | { |
| 1319 | __compressed_pair<_Fp, _Alloc> __f_; |
| 1320 | public: |
| 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 | |
| 1334 | template<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 | |
| 1347 | template<class _Fp, class _Alloc, class _Rp> |
| 1348 | void |
| 1349 | __func<_Fp, _Alloc, _Rp()>::__clone(__base<_Rp()>* __p) const |
| 1350 | { |
| 1351 | ::new ((void*)__p) __func(__f_.first(), __f_.second()); |
| 1352 | } |
| 1353 | |
| 1354 | template<class _Fp, class _Alloc, class _Rp> |
| 1355 | void |
| 1356 | __func<_Fp, _Alloc, _Rp()>::destroy() |
| 1357 | { |
| 1358 | __f_.~__compressed_pair<_Fp, _Alloc>(); |
| 1359 | } |
| 1360 | |
| 1361 | template<class _Fp, class _Alloc, class _Rp> |
| 1362 | void |
| 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 | |
| 1372 | template<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 | |
| 1382 | template<class _Fp, class _Alloc, class _Rp> |
| 1383 | const 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 | |
| 1391 | template<class _Fp, class _Alloc, class _Rp> |
| 1392 | const std::type_info& |
| 1393 | __func<_Fp, _Alloc, _Rp()>::target_type() const |
| 1394 | { |
| 1395 | return typeid(_Fp); |
| 1396 | } |
| 1397 | |
| 1398 | #endif // _LIBCPP_NO_RTTI |
| 1399 | |
| 1400 | template<class _Fp, class _Alloc, class _Rp, class _A0> |
| 1401 | class __func<_Fp, _Alloc, _Rp(_A0)> |
| 1402 | : public __base<_Rp(_A0)> |
| 1403 | { |
| 1404 | __compressed_pair<_Fp, _Alloc> __f_; |
| 1405 | public: |
| 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 | |
| 1420 | template<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 | |
| 1433 | template<class _Fp, class _Alloc, class _Rp, class _A0> |
| 1434 | void |
| 1435 | __func<_Fp, _Alloc, _Rp(_A0)>::__clone(__base<_Rp(_A0)>* __p) const |
| 1436 | { |
| 1437 | ::new ((void*)__p) __func(__f_.first(), __f_.second()); |
| 1438 | } |
| 1439 | |
| 1440 | template<class _Fp, class _Alloc, class _Rp, class _A0> |
| 1441 | void |
| 1442 | __func<_Fp, _Alloc, _Rp(_A0)>::destroy() |
| 1443 | { |
| 1444 | __f_.~__compressed_pair<_Fp, _Alloc>(); |
| 1445 | } |
| 1446 | |
| 1447 | template<class _Fp, class _Alloc, class _Rp, class _A0> |
| 1448 | void |
| 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 | |
| 1458 | template<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 | |
| 1468 | template<class _Fp, class _Alloc, class _Rp, class _A0> |
| 1469 | const 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 | |
| 1477 | template<class _Fp, class _Alloc, class _Rp, class _A0> |
| 1478 | const 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 | |
| 1486 | template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> |
| 1487 | class __func<_Fp, _Alloc, _Rp(_A0, _A1)> |
| 1488 | : public __base<_Rp(_A0, _A1)> |
| 1489 | { |
| 1490 | __compressed_pair<_Fp, _Alloc> __f_; |
| 1491 | public: |
| 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 | |
| 1506 | template<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 | |
| 1519 | template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> |
| 1520 | void |
| 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 | |
| 1526 | template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> |
| 1527 | void |
| 1528 | __func<_Fp, _Alloc, _Rp(_A0, _A1)>::destroy() |
| 1529 | { |
| 1530 | __f_.~__compressed_pair<_Fp, _Alloc>(); |
| 1531 | } |
| 1532 | |
| 1533 | template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> |
| 1534 | void |
| 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 | |
| 1544 | template<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 | |
| 1554 | template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> |
| 1555 | const 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 | |
| 1563 | template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1> |
| 1564 | const 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 | |
| 1572 | template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2> |
| 1573 | class __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)> |
| 1574 | : public __base<_Rp(_A0, _A1, _A2)> |
| 1575 | { |
| 1576 | __compressed_pair<_Fp, _Alloc> __f_; |
| 1577 | public: |
| 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 | |
| 1592 | template<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 | |
| 1605 | template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2> |
| 1606 | void |
| 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 | |
| 1612 | template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2> |
| 1613 | void |
| 1614 | __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::destroy() |
| 1615 | { |
| 1616 | __f_.~__compressed_pair<_Fp, _Alloc>(); |
| 1617 | } |
| 1618 | |
| 1619 | template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2> |
| 1620 | void |
| 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 | |
| 1630 | template<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 | |
| 1640 | template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2> |
| 1641 | const 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 | |
| 1649 | template<class _Fp, class _Alloc, class _Rp, class _A0, class _A1, class _A2> |
| 1650 | const 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 | |
| 1660 | template<class _Rp> |
| 1661 | class _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 | |
| 1667 | public: |
| 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 | |
| 1712 | private: |
| 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; |
| 1718 | public: |
| 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 | |
| 1730 | template<class _Rp> |
| 1731 | function<_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 | |
| 1744 | template<class _Rp> |
| 1745 | template<class _Alloc> |
| 1746 | function<_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 | |
| 1759 | template<class _Rp> |
| 1760 | template <class _Fp> |
| 1761 | function<_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 | |
| 1785 | template<class _Rp> |
| 1786 | template <class _Fp, class _Alloc> |
| 1787 | function<_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 | |
| 1812 | template<class _Rp> |
| 1813 | function<_Rp()>& |
| 1814 | function<_Rp()>::operator=(const function& __f) |
| 1815 | { |
| 1816 | if (__f) |
| 1817 | function(__f).swap(*this); |
| 1818 | else |
| 1819 | *this = nullptr; |
| 1820 | return *this; |
| 1821 | } |
| 1822 | |
| 1823 | template<class _Rp> |
| 1824 | function<_Rp()>& |
| 1825 | function<_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 | |
| 1836 | template<class _Rp> |
| 1837 | template <class _Fp> |
| 1838 | typename enable_if |
| 1839 | < |
| 1840 | !is_integral<_Fp>::value, |
| 1841 | function<_Rp()>& |
| 1842 | >::type |
| 1843 | function<_Rp()>::operator=(_Fp __f) |
| 1844 | { |
| 1845 | function(_VSTDstd::__1::move(__f)).swap(*this); |
| 1846 | return *this; |
| 1847 | } |
| 1848 | |
| 1849 | template<class _Rp> |
| 1850 | function<_Rp()>::~function() |
| 1851 | { |
| 1852 | if (__f_ == (__base*)&__buf_) |
| 1853 | __f_->destroy(); |
| 1854 | else if (__f_) |
| 1855 | __f_->destroy_deallocate(); |
| 1856 | } |
| 1857 | |
| 1858 | template<class _Rp> |
| 1859 | void |
| 1860 | function<_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 | |
| 1897 | template<class _Rp> |
| 1898 | _Rp |
| 1899 | function<_Rp()>::operator()() const |
| 1900 | { |
| 1901 | if (__f_ == 0) |
| 1902 | __throw_bad_function_call(); |
| 1903 | return (*__f_)(); |
| 1904 | } |
| 1905 | |
| 1906 | #ifndef _LIBCPP_NO_RTTI |
| 1907 | |
| 1908 | template<class _Rp> |
| 1909 | const std::type_info& |
| 1910 | function<_Rp()>::target_type() const |
| 1911 | { |
| 1912 | if (__f_ == 0) |
| 1913 | return typeid(void); |
| 1914 | return __f_->target_type(); |
| 1915 | } |
| 1916 | |
| 1917 | template<class _Rp> |
| 1918 | template <typename _Tp> |
| 1919 | _Tp* |
| 1920 | function<_Rp()>::target() |
| 1921 | { |
| 1922 | if (__f_ == 0) |
| 1923 | return (_Tp*)0; |
| 1924 | return (_Tp*) const_cast<void *>(__f_->target(typeid(_Tp))); |
| 1925 | } |
| 1926 | |
| 1927 | template<class _Rp> |
| 1928 | template <typename _Tp> |
| 1929 | const _Tp* |
| 1930 | function<_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 | |
| 1939 | template<class _Rp, class _A0> |
| 1940 | class _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 | |
| 1947 | public: |
| 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 | |
| 1992 | private: |
| 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; |
| 1998 | public: |
| 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 | |
| 2010 | template<class _Rp, class _A0> |
| 2011 | function<_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 | |
| 2024 | template<class _Rp, class _A0> |
| 2025 | template<class _Alloc> |
| 2026 | function<_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 | |
| 2039 | template<class _Rp, class _A0> |
| 2040 | template <class _Fp> |
| 2041 | function<_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 | |
| 2065 | template<class _Rp, class _A0> |
| 2066 | template <class _Fp, class _Alloc> |
| 2067 | function<_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 | |
| 2092 | template<class _Rp, class _A0> |
| 2093 | function<_Rp(_A0)>& |
| 2094 | function<_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 | |
| 2103 | template<class _Rp, class _A0> |
| 2104 | function<_Rp(_A0)>& |
| 2105 | function<_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 | |
| 2116 | template<class _Rp, class _A0> |
| 2117 | template <class _Fp> |
| 2118 | typename enable_if |
| 2119 | < |
| 2120 | !is_integral<_Fp>::value, |
| 2121 | function<_Rp(_A0)>& |
| 2122 | >::type |
| 2123 | function<_Rp(_A0)>::operator=(_Fp __f) |
| 2124 | { |
| 2125 | function(_VSTDstd::__1::move(__f)).swap(*this); |
| 2126 | return *this; |
| 2127 | } |
| 2128 | |
| 2129 | template<class _Rp, class _A0> |
| 2130 | function<_Rp(_A0)>::~function() |
| 2131 | { |
| 2132 | if (__f_ == (__base*)&__buf_) |
| 2133 | __f_->destroy(); |
| 2134 | else if (__f_) |
| 2135 | __f_->destroy_deallocate(); |
| 2136 | } |
| 2137 | |
| 2138 | template<class _Rp, class _A0> |
| 2139 | void |
| 2140 | function<_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 | |
| 2177 | template<class _Rp, class _A0> |
| 2178 | _Rp |
| 2179 | function<_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 | |
| 2188 | template<class _Rp, class _A0> |
| 2189 | const std::type_info& |
| 2190 | function<_Rp(_A0)>::target_type() const |
| 2191 | { |
| 2192 | if (__f_ == 0) |
| 2193 | return typeid(void); |
| 2194 | return __f_->target_type(); |
| 2195 | } |
| 2196 | |
| 2197 | template<class _Rp, class _A0> |
| 2198 | template <typename _Tp> |
| 2199 | _Tp* |
| 2200 | function<_Rp(_A0)>::target() |
| 2201 | { |
| 2202 | if (__f_ == 0) |
| 2203 | return (_Tp*)0; |
| 2204 | return (_Tp*) const_cast<void *>(__f_->target(typeid(_Tp))); |
| 2205 | } |
| 2206 | |
| 2207 | template<class _Rp, class _A0> |
| 2208 | template <typename _Tp> |
| 2209 | const _Tp* |
| 2210 | function<_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 | |
| 2219 | template<class _Rp, class _A0, class _A1> |
| 2220 | class _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 | |
| 2227 | public: |
| 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 | |
| 2272 | private: |
| 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; |
| 2278 | public: |
| 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 | |
| 2290 | template<class _Rp, class _A0, class _A1> |
| 2291 | function<_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 | |
| 2304 | template<class _Rp, class _A0, class _A1> |
| 2305 | template<class _Alloc> |
| 2306 | function<_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 | |
| 2319 | template<class _Rp, class _A0, class _A1> |
| 2320 | template <class _Fp> |
| 2321 | function<_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 | |
| 2345 | template<class _Rp, class _A0, class _A1> |
| 2346 | template <class _Fp, class _Alloc> |
| 2347 | function<_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 | |
| 2372 | template<class _Rp, class _A0, class _A1> |
| 2373 | function<_Rp(_A0, _A1)>& |
| 2374 | function<_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 | |
| 2383 | template<class _Rp, class _A0, class _A1> |
| 2384 | function<_Rp(_A0, _A1)>& |
| 2385 | function<_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 | |
| 2396 | template<class _Rp, class _A0, class _A1> |
| 2397 | template <class _Fp> |
| 2398 | typename enable_if |
| 2399 | < |
| 2400 | !is_integral<_Fp>::value, |
| 2401 | function<_Rp(_A0, _A1)>& |
| 2402 | >::type |
| 2403 | function<_Rp(_A0, _A1)>::operator=(_Fp __f) |
| 2404 | { |
| 2405 | function(_VSTDstd::__1::move(__f)).swap(*this); |
| 2406 | return *this; |
| 2407 | } |
| 2408 | |
| 2409 | template<class _Rp, class _A0, class _A1> |
| 2410 | function<_Rp(_A0, _A1)>::~function() |
| 2411 | { |
| 2412 | if (__f_ == (__base*)&__buf_) |
| 2413 | __f_->destroy(); |
| 2414 | else if (__f_) |
| 2415 | __f_->destroy_deallocate(); |
| 2416 | } |
| 2417 | |
| 2418 | template<class _Rp, class _A0, class _A1> |
| 2419 | void |
| 2420 | function<_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 | |
| 2457 | template<class _Rp, class _A0, class _A1> |
| 2458 | _Rp |
| 2459 | function<_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 | |
| 2468 | template<class _Rp, class _A0, class _A1> |
| 2469 | const std::type_info& |
| 2470 | function<_Rp(_A0, _A1)>::target_type() const |
| 2471 | { |
| 2472 | if (__f_ == 0) |
| 2473 | return typeid(void); |
| 2474 | return __f_->target_type(); |
| 2475 | } |
| 2476 | |
| 2477 | template<class _Rp, class _A0, class _A1> |
| 2478 | template <typename _Tp> |
| 2479 | _Tp* |
| 2480 | function<_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 | |
| 2487 | template<class _Rp, class _A0, class _A1> |
| 2488 | template <typename _Tp> |
| 2489 | const _Tp* |
| 2490 | function<_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 | |
| 2499 | template<class _Rp, class _A0, class _A1, class _A2> |
| 2500 | class _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 | |
| 2506 | public: |
| 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 | |
| 2551 | private: |
| 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; |
| 2557 | public: |
| 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 | |
| 2569 | template<class _Rp, class _A0, class _A1, class _A2> |
| 2570 | function<_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 | |
| 2583 | template<class _Rp, class _A0, class _A1, class _A2> |
| 2584 | template<class _Alloc> |
| 2585 | function<_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 | |
| 2599 | template<class _Rp, class _A0, class _A1, class _A2> |
| 2600 | template <class _Fp> |
| 2601 | function<_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 | |
| 2625 | template<class _Rp, class _A0, class _A1, class _A2> |
| 2626 | template <class _Fp, class _Alloc> |
| 2627 | function<_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 | |
| 2652 | template<class _Rp, class _A0, class _A1, class _A2> |
| 2653 | function<_Rp(_A0, _A1, _A2)>& |
| 2654 | function<_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 | |
| 2663 | template<class _Rp, class _A0, class _A1, class _A2> |
| 2664 | function<_Rp(_A0, _A1, _A2)>& |
| 2665 | function<_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 | |
| 2676 | template<class _Rp, class _A0, class _A1, class _A2> |
| 2677 | template <class _Fp> |
| 2678 | typename enable_if |
| 2679 | < |
| 2680 | !is_integral<_Fp>::value, |
| 2681 | function<_Rp(_A0, _A1, _A2)>& |
| 2682 | >::type |
| 2683 | function<_Rp(_A0, _A1, _A2)>::operator=(_Fp __f) |
| 2684 | { |
| 2685 | function(_VSTDstd::__1::move(__f)).swap(*this); |
| 2686 | return *this; |
| 2687 | } |
| 2688 | |
| 2689 | template<class _Rp, class _A0, class _A1, class _A2> |
| 2690 | function<_Rp(_A0, _A1, _A2)>::~function() |
| 2691 | { |
| 2692 | if (__f_ == (__base*)&__buf_) |
| 2693 | __f_->destroy(); |
| 2694 | else if (__f_) |
| 2695 | __f_->destroy_deallocate(); |
| 2696 | } |
| 2697 | |
| 2698 | template<class _Rp, class _A0, class _A1, class _A2> |
| 2699 | void |
| 2700 | function<_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 | |
| 2737 | template<class _Rp, class _A0, class _A1, class _A2> |
| 2738 | _Rp |
| 2739 | function<_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 | |
| 2748 | template<class _Rp, class _A0, class _A1, class _A2> |
| 2749 | const std::type_info& |
| 2750 | function<_Rp(_A0, _A1, _A2)>::target_type() const |
| 2751 | { |
| 2752 | if (__f_ == 0) |
| 2753 | return typeid(void); |
| 2754 | return __f_->target_type(); |
| 2755 | } |
| 2756 | |
| 2757 | template<class _Rp, class _A0, class _A1, class _A2> |
| 2758 | template <typename _Tp> |
| 2759 | _Tp* |
| 2760 | function<_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 | |
| 2767 | template<class _Rp, class _A0, class _A1, class _A2> |
| 2768 | template <typename _Tp> |
| 2769 | const _Tp* |
| 2770 | function<_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 | |
| 2779 | template <class _Fp> |
| 2780 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 2781 | bool |
| 2782 | operator==(const function<_Fp>& __f, nullptr_t) {return !__f;} |
| 2783 | |
| 2784 | template <class _Fp> |
| 2785 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 2786 | bool |
| 2787 | operator==(nullptr_t, const function<_Fp>& __f) {return !__f;} |
| 2788 | |
| 2789 | template <class _Fp> |
| 2790 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 2791 | bool |
| 2792 | operator!=(const function<_Fp>& __f, nullptr_t) {return (bool)__f;} |
| 2793 | |
| 2794 | template <class _Fp> |
| 2795 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 2796 | bool |
| 2797 | operator!=(nullptr_t, const function<_Fp>& __f) {return (bool)__f;} |
| 2798 | |
| 2799 | template <class _Fp> |
| 2800 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 2801 | void |
| 2802 | swap(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 |
| 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 | |
| 24 | template <class _Ret, bool = is_void<_Ret>::value> |
| 25 | struct __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)...); |
| 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 | |
| 55 | template <class _Ret> |
| 56 | struct __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 | |
| 88 | template <class _Fn, class ..._Args> |
| 89 | _LIBCPP_CONSTEXPR_AFTER_CXX17 invoke_result_t<_Fn, _Args...> |
| 90 | invoke(_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 |
| 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 | |
| 16 | namespace 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 | |
| 429 | template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) pair; |
| 430 | template <class _Tp> class _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) reference_wrapper; |
| 431 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) hash; |
| 432 | |
| 433 | template <class _Tp, _Tp __v> |
| 434 | struct _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 | |
| 447 | template <class _Tp, _Tp __v> |
| 448 | _LIBCPP_CONSTEXPRconstexpr const _Tp integral_constant<_Tp, __v>::value; |
| 449 | |
| 450 | #if _LIBCPP_STD_VER14 > 14 |
| 451 | template <bool __b> |
| 452 | using 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 | |
| 458 | typedef _LIBCPP_BOOL_CONSTANT(true)integral_constant<bool,(true)> true_type; |
| 459 | typedef _LIBCPP_BOOL_CONSTANT(false)integral_constant<bool,(false)> false_type; |
| 460 | |
| 461 | template <bool _Val> |
| 462 | using _BoolConstant _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = integral_constant<bool, _Val>; |
| 463 | |
| 464 | template <bool> struct _MetaBase; |
| 465 | template <> |
| 466 | struct _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 | |
| 481 | template <> |
| 482 | struct _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 | }; |
| 490 | template <bool _Cond, class _Ret = void> |
| 491 | using _EnableIf _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = typename _MetaBase<_Cond>::template _EnableIfImpl<_Ret>; |
| 492 | template <bool _Cond, class _IfRes, class _ElseRes> |
| 493 | using _If _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = typename _MetaBase<_Cond>::template _SelectImpl<_IfRes, _ElseRes>; |
| 494 | template <class ..._Rest> |
| 495 | using _Or _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = typename _MetaBase< sizeof...(_Rest) != 0 >::template _OrImpl<false_type, _Rest...>; |
| 496 | template <class _Pred> |
| 497 | struct _Not : _BoolConstant<!_Pred::value> {}; |
| 498 | template <class ..._Args> |
| 499 | using _FirstType _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = typename _MetaBase<(sizeof...(_Args) >= 1)>::template _FirstImpl<_Args...>; |
| 500 | template <class ..._Args> |
| 501 | using _SecondType _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = typename _MetaBase<(sizeof...(_Args) >= 2)>::template _SecondImpl<_Args...>; |
| 502 | |
| 503 | template <class ...> using __expand_to_true = true_type; |
| 504 | template <class ..._Pred> |
| 505 | __expand_to_true<_EnableIf<_Pred::value>...> __and_helper(int); |
| 506 | template <class ...> |
| 507 | false_type __and_helper(...); |
| 508 | template <class ..._Pred> |
| 509 | using _And _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = decltype(__and_helper<_Pred...>(0)); |
| 510 | |
| 511 | template <template <class...> class _Func, class ..._Args> |
| 512 | struct _Lazy : _Func<_Args...> {}; |
| 513 | |
| 514 | // Member detector base |
| 515 | |
| 516 | template <template <class...> class _Templ, class ..._Args, class = _Templ<_Args...> > |
| 517 | true_type __sfinae_test_impl(int); |
| 518 | template <template <class...> class, class ...> |
| 519 | false_type __sfinae_test_impl(...); |
| 520 | |
| 521 | template <template <class ...> class _Templ, class ..._Args> |
| 522 | using _IsValidExpansion _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = decltype(__sfinae_test_impl<_Templ, _Args...>(0)); |
| 523 | |
| 524 | template <class> |
| 525 | struct __void_t { typedef void type; }; |
| 526 | |
| 527 | template <class _Tp> |
| 528 | struct __identity { typedef _Tp type; }; |
| 529 | |
| 530 | template <class _Tp> |
| 531 | using __identity_t _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = typename __identity<_Tp>::type; |
| 532 | |
| 533 | template <class _Tp, bool> |
| 534 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) __dependent_type : public _Tp {}; |
| 535 | |
| 536 | |
| 537 | template <bool _Bp, class _If, class _Then> |
| 538 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) conditional {typedef _If type;}; |
| 539 | template <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 |
| 543 | template <bool _Bp, class _If, class _Then> using conditional_t = typename conditional<_Bp, _If, _Then>::type; |
| 544 | #endif |
| 545 | |
| 546 | template <bool, class _Tp = void> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) enable_if {}; |
| 547 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) enable_if<true, _Tp> {typedef _Tp type;}; |
| 548 | |
| 549 | #if _LIBCPP_STD_VER14 > 11 |
| 550 | template <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 | |
| 557 | template <class _Tp, class _Up> |
| 558 | struct _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) |
| 561 | template <class _Tp, class _Up> |
| 562 | _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_same_v = __is_same(_Tp, _Up); |
| 563 | #endif |
| 564 | |
| 565 | #else |
| 566 | |
| 567 | template <class _Tp, class _Up> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_same : public false_type {}; |
| 568 | template <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) |
| 571 | template <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 | |
| 578 | template <class _Tp, class _Up> |
| 579 | using _IsSame = _BoolConstant< |
| 580 | #ifdef __clang__1 |
| 581 | __is_same(_Tp, _Up) |
| 582 | #else |
| 583 | is_same<_Tp, _Up>::value |
| 584 | #endif |
| 585 | >; |
| 586 | |
| 587 | template <class _Tp, class _Up> |
| 588 | using _IsNotSame = _BoolConstant< |
| 589 | #ifdef __clang__1 |
| 590 | !__is_same(_Tp, _Up) |
| 591 | #else |
| 592 | !is_same<_Tp, _Up>::value |
| 593 | #endif |
| 594 | >; |
| 595 | |
| 596 | |
| 597 | template <class _Tp> |
| 598 | using __test_for_primary_template = _EnableIf< |
| 599 | _IsSame<_Tp, typename _Tp::__primary_template>::value |
| 600 | >; |
| 601 | template <class _Tp> |
| 602 | using __is_primary_template = _IsValidExpansion< |
| 603 | __test_for_primary_template, _Tp |
| 604 | >; |
| 605 | |
| 606 | struct __two {char __lx[2];}; |
| 607 | |
| 608 | // helper class: |
| 609 | |
| 610 | // is_const |
| 611 | |
| 612 | #if __has_keyword(__is_const)!(0) |
| 613 | |
| 614 | template <class _Tp> |
| 615 | struct _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) |
| 618 | template <class _Tp> |
| 619 | _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_const_v = __is_const(_Tp); |
| 620 | #endif |
| 621 | |
| 622 | #else |
| 623 | |
| 624 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_const : public false_type {}; |
| 625 | template <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) |
| 628 | template <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 | |
| 639 | template <class _Tp> |
| 640 | struct _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) |
| 643 | template <class _Tp> |
| 644 | _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_volatile_v = __is_volatile(_Tp); |
| 645 | #endif |
| 646 | |
| 647 | #else |
| 648 | |
| 649 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_volatile : public false_type {}; |
| 650 | template <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) |
| 653 | template <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 | |
| 664 | template <class _Tp> |
| 665 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_const {typedef __remove_const(_Tp) type;}; |
| 666 | |
| 667 | #if _LIBCPP_STD_VER14 > 11 |
| 668 | template <class _Tp> using remove_const_t = __remove_const(_Tp); |
| 669 | #endif |
| 670 | |
| 671 | #else |
| 672 | |
| 673 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_const {typedef _Tp type;}; |
| 674 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_const<const _Tp> {typedef _Tp type;}; |
| 675 | #if _LIBCPP_STD_VER14 > 11 |
| 676 | template <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 | |
| 685 | template <class _Tp> |
| 686 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_volatile {typedef __remove_volatile(_Tp) type;}; |
| 687 | |
| 688 | #if _LIBCPP_STD_VER14 > 11 |
| 689 | template <class _Tp> using remove_volatile_t = __remove_volatile(_Tp); |
| 690 | #endif |
| 691 | |
| 692 | #else |
| 693 | |
| 694 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_volatile {typedef _Tp type;}; |
| 695 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_volatile<volatile _Tp> {typedef _Tp type;}; |
| 696 | #if _LIBCPP_STD_VER14 > 11 |
| 697 | template <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 | |
| 706 | template <class _Tp> |
| 707 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_cv {typedef __remove_cv(_Tp) type;}; |
| 708 | |
| 709 | #if _LIBCPP_STD_VER14 > 11 |
| 710 | template <class _Tp> using remove_cv_t = __remove_cv(_Tp); |
| 711 | #endif |
| 712 | |
| 713 | #else |
| 714 | |
| 715 | template <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 |
| 718 | template <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 | |
| 727 | template <class _Tp> |
| 728 | struct _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) |
| 731 | template <class _Tp> |
| 732 | _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_void_v = __is_void(_Tp); |
| 733 | #endif |
| 734 | |
| 735 | #else |
| 736 | |
| 737 | template <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) |
| 741 | template <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 | |
| 750 | template <class _Tp> struct __is_nullptr_t_impl : public false_type {}; |
| 751 | template <> struct __is_nullptr_t_impl<nullptr_t> : public true_type {}; |
| 752 | |
| 753 | template <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 |
| 757 | template <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) |
| 761 | template <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 | |
| 771 | template <class _Tp> |
| 772 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_integral : _BoolConstant<__is_integral(_Tp)> { }; |
| 773 | |
| 774 | #if _LIBCPP_STD_VER14 > 14 |
| 775 | template <class _Tp> |
| 776 | _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_integral_v = __is_integral(_Tp); |
| 777 | #endif |
| 778 | |
| 779 | #else |
| 780 | |
| 781 | template <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) |
| 785 | template <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 | |
| 799 | template <class _Tp> struct __libcpp_is_signed_integer : public false_type {}; |
| 800 | template <> struct __libcpp_is_signed_integer<signed char> : public true_type {}; |
| 801 | template <> struct __libcpp_is_signed_integer<signed short> : public true_type {}; |
| 802 | template <> struct __libcpp_is_signed_integer<signed int> : public true_type {}; |
| 803 | template <> struct __libcpp_is_signed_integer<signed long> : public true_type {}; |
| 804 | template <> struct __libcpp_is_signed_integer<signed long long> : public true_type {}; |
| 805 | #ifndef _LIBCPP_HAS_NO_INT128 |
| 806 | template <> struct __libcpp_is_signed_integer<__int128_t> : public true_type {}; |
| 807 | #endif |
| 808 | |
| 809 | template <class _Tp> struct __libcpp_is_unsigned_integer : public false_type {}; |
| 810 | template <> struct __libcpp_is_unsigned_integer<unsigned char> : public true_type {}; |
| 811 | template <> struct __libcpp_is_unsigned_integer<unsigned short> : public true_type {}; |
| 812 | template <> struct __libcpp_is_unsigned_integer<unsigned int> : public true_type {}; |
| 813 | template <> struct __libcpp_is_unsigned_integer<unsigned long> : public true_type {}; |
| 814 | template <> struct __libcpp_is_unsigned_integer<unsigned long long> : public true_type {}; |
| 815 | #ifndef _LIBCPP_HAS_NO_INT128 |
| 816 | template <> struct __libcpp_is_unsigned_integer<__uint128_t> : public true_type {}; |
| 817 | #endif |
| 818 | |
| 819 | // is_floating_point |
| 820 | |
| 821 | template <class _Tp> struct __libcpp_is_floating_point : public false_type {}; |
| 822 | template <> struct __libcpp_is_floating_point<float> : public true_type {}; |
| 823 | template <> struct __libcpp_is_floating_point<double> : public true_type {}; |
| 824 | template <> struct __libcpp_is_floating_point<long double> : public true_type {}; |
| 825 | |
| 826 | template <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) |
| 830 | template <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 | |
| 839 | template <class _Tp> |
| 840 | struct _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) |
| 843 | template <class _Tp> |
| 844 | _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_array_v = __is_array(_Tp); |
| 845 | #endif |
| 846 | |
| 847 | #else |
| 848 | |
| 849 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_array |
| 850 | : public false_type {}; |
| 851 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_array<_Tp[]> |
| 852 | : public true_type {}; |
| 853 | template <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) |
| 857 | template <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 | |
| 871 | template<class _Tp> |
| 872 | struct _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) |
| 875 | template <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 | |
| 881 | template <class _Tp> struct __libcpp_is_pointer : public false_type {}; |
| 882 | template <class _Tp> struct __libcpp_is_pointer<_Tp*> : public true_type {}; |
| 883 | |
| 884 | template <class _Tp> struct __libcpp_remove_objc_qualifiers { typedef _Tp type; }; |
| 885 | #if defined(_LIBCPP_HAS_OBJC_ARC) |
| 886 | template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __strong> { typedef _Tp type; }; |
| 887 | template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __weak> { typedef _Tp type; }; |
| 888 | template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __autoreleasing> { typedef _Tp type; }; |
| 889 | template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __unsafe_unretained> { typedef _Tp type; }; |
| 890 | #endif |
| 891 | |
| 892 | template <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) |
| 896 | template <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 | |
| 909 | template<class _Tp> |
| 910 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_lvalue_reference : _BoolConstant<__is_lvalue_reference(_Tp)> { }; |
| 911 | |
| 912 | template<class _Tp> |
| 913 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_rvalue_reference : _BoolConstant<__is_rvalue_reference(_Tp)> { }; |
| 914 | |
| 915 | template<class _Tp> |
| 916 | struct _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) |
| 919 | template <class _Tp> |
| 920 | _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_reference_v = __is_reference(_Tp); |
| 921 | |
| 922 | template <class _Tp> |
| 923 | _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_lvalue_reference_v = __is_lvalue_reference(_Tp); |
| 924 | |
| 925 | template <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 | |
| 931 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_lvalue_reference : public false_type {}; |
| 932 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_lvalue_reference<_Tp&> : public true_type {}; |
| 933 | |
| 934 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_rvalue_reference : public false_type {}; |
| 935 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_rvalue_reference<_Tp&&> : public true_type {}; |
| 936 | |
| 937 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_reference : public false_type {}; |
| 938 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_reference<_Tp&> : public true_type {}; |
| 939 | template <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) |
| 942 | template <class _Tp> |
| 943 | _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_reference_v |
| 944 | = is_reference<_Tp>::value; |
| 945 | |
| 946 | template <class _Tp> |
| 947 | _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_lvalue_reference_v |
| 948 | = is_lvalue_reference<_Tp>::value; |
| 949 | |
| 950 | template <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 | |
| 961 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_union |
| 962 | : public integral_constant<bool, __is_union(_Tp)> {}; |
| 963 | |
| 964 | #else |
| 965 | |
| 966 | template <class _Tp> struct __libcpp_union : public false_type {}; |
| 967 | template <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) |
| 973 | template <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 | |
| 982 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_class |
| 983 | : public integral_constant<bool, __is_class(_Tp)> {}; |
| 984 | |
| 985 | #else |
| 986 | |
| 987 | namespace __is_class_imp |
| 988 | { |
| 989 | template <class _Tp> char __test(int _Tp::*); |
| 990 | template <class _Tp> __two __test(...); |
| 991 | } |
| 992 | |
| 993 | template <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) |
| 999 | template <class _Tp> |
| 1000 | _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_class_v |
| 1001 | = is_class<_Tp>::value; |
| 1002 | #endif |
| 1003 | |
| 1004 | // is_function |
| 1005 | |
| 1006 | template <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) |
| 1017 | template <class _Tp> |
| 1018 | _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_function_v |
| 1019 | = is_function<_Tp>::value; |
| 1020 | #endif |
| 1021 | |
| 1022 | template <class _Tp> struct __libcpp_is_member_pointer { |
| 1023 | enum { |
| 1024 | __is_member = false, |
| 1025 | __is_func = false, |
| 1026 | __is_obj = false |
| 1027 | }; |
| 1028 | }; |
| 1029 | template <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 | |
| 1039 | template<class _Tp> |
| 1040 | struct _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) |
| 1044 | template <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 | |
| 1051 | template <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) |
| 1055 | template <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 | |
| 1066 | template<class _Tp> |
| 1067 | struct _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) |
| 1070 | template <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 | |
| 1076 | template <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) |
| 1080 | template <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 | |
| 1091 | template<class _Tp> |
| 1092 | struct _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) |
| 1096 | template <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 | |
| 1103 | template <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) |
| 1107 | template <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 | |
| 1118 | template <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) |
| 1122 | template <class _Tp> |
| 1123 | _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_enum_v = __is_enum(_Tp); |
| 1124 | #endif |
| 1125 | |
| 1126 | #else |
| 1127 | |
| 1128 | template <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) |
| 1141 | template <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 | |
| 1151 | template <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) |
| 1156 | template <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 | |
| 1169 | template<class _Tp> |
| 1170 | struct _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) |
| 1173 | template <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 | |
| 1179 | template <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) |
| 1185 | template <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 | |
| 1197 | template<class _Tp> |
| 1198 | struct _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) |
| 1201 | template <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 | |
| 1207 | template <class _Tp> struct __is_block : false_type {}; |
| 1208 | #if defined(_LIBCPP_HAS_EXTENSION_BLOCKS) |
| 1209 | template <class _Rp, class ..._Args> struct __is_block<_Rp (^)(_Args...)> : true_type {}; |
| 1210 | #endif |
| 1211 | |
| 1212 | template <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 | |
| 1220 | template <> 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) |
| 1223 | template <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 | |
| 1234 | template<class _Tp> |
| 1235 | struct _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) |
| 1238 | template <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 | |
| 1244 | template <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) |
| 1251 | template <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 | |
| 1263 | template<class _Tp> |
| 1264 | struct _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) |
| 1267 | template <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 | |
| 1273 | template <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) |
| 1277 | template <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 | |
| 1286 | struct __is_referenceable_impl { |
| 1287 | template <class _Tp> static _Tp& __test(int); |
| 1288 | template <class _Tp> static __two __test(...); |
| 1289 | }; |
| 1290 | |
| 1291 | template <class _Tp> |
| 1292 | struct __is_referenceable : integral_constant<bool, |
| 1293 | _IsNotSame<decltype(__is_referenceable_impl::__test<_Tp>(0)), __two>::value> {}; |
| 1294 | |
| 1295 | |
| 1296 | // add_const |
| 1297 | |
| 1298 | template <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 |
| 1303 | template <class _Tp> using add_const_t = typename add_const<_Tp>::type; |
| 1304 | #endif |
| 1305 | |
| 1306 | // add_volatile |
| 1307 | |
| 1308 | template <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 |
| 1313 | template <class _Tp> using add_volatile_t = typename add_volatile<_Tp>::type; |
| 1314 | #endif |
| 1315 | |
| 1316 | // add_cv |
| 1317 | template <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 |
| 1322 | template <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 | |
| 1329 | template<class _Tp> |
| 1330 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_reference { typedef __remove_reference(_Tp) type; }; |
| 1331 | |
| 1332 | #else // __has_keyword(__remove_reference) |
| 1333 | |
| 1334 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_reference {typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) _Tp type;}; |
| 1335 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_reference<_Tp&> {typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) _Tp type;}; |
| 1336 | template <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 |
| 1339 | template <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 | |
| 1346 | template <class _Tp, bool = __is_referenceable<_Tp>::value> struct __add_lvalue_reference_impl { typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) _Tp type; }; |
| 1347 | template <class _Tp > struct __add_lvalue_reference_impl<_Tp, true> { typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) _Tp& type; }; |
| 1348 | |
| 1349 | template <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 |
| 1353 | template <class _Tp> using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type; |
| 1354 | #endif |
| 1355 | |
| 1356 | template <class _Tp, bool = __is_referenceable<_Tp>::value> struct __add_rvalue_reference_impl { typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) _Tp type; }; |
| 1357 | template <class _Tp > struct __add_rvalue_reference_impl<_Tp, true> { typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) _Tp&& type; }; |
| 1358 | |
| 1359 | template <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 |
| 1363 | template <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" |
| 1369 | template <class _Tp> _Tp&& __declval(int); |
| 1370 | template <class _Tp> _Tp __declval(long); |
| 1371 | _LIBCPP_SUPPRESS_DEPRECATED_POPGCC diagnostic pop |
| 1372 | |
| 1373 | template <class _Tp> |
| 1374 | decltype(__declval<_Tp>(0)) |
| 1375 | declval() _NOEXCEPTnoexcept; |
| 1376 | |
| 1377 | // __uncvref |
| 1378 | |
| 1379 | template <class _Tp> |
| 1380 | struct __uncvref { |
| 1381 | typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) typename remove_cv<typename remove_reference<_Tp>::type>::type type; |
| 1382 | }; |
| 1383 | |
| 1384 | template <class _Tp> |
| 1385 | struct __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 |
| 1390 | template <class _Tp> |
| 1391 | using __uncvref_t _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = typename __uncvref<_Tp>::type; |
| 1392 | #endif |
| 1393 | |
| 1394 | // __is_same_uncvref |
| 1395 | |
| 1396 | template <class _Tp, class _Up> |
| 1397 | struct __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 |
| 1402 | template <class _Tp> |
| 1403 | struct remove_cvref : public __uncvref<_Tp> {}; |
| 1404 | |
| 1405 | template <class _Tp> using remove_cvref_t = typename remove_cvref<_Tp>::type; |
| 1406 | #endif |
| 1407 | |
| 1408 | |
| 1409 | struct __any |
| 1410 | { |
| 1411 | __any(...); |
| 1412 | }; |
| 1413 | |
| 1414 | // remove_pointer |
| 1415 | |
| 1416 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_pointer {typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) _Tp type;}; |
| 1417 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_pointer<_Tp*> {typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) _Tp type;}; |
| 1418 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_pointer<_Tp* const> {typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) _Tp type;}; |
| 1419 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_pointer<_Tp* volatile> {typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) _Tp type;}; |
| 1420 | template <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 |
| 1423 | template <class _Tp> using remove_pointer_t = typename remove_pointer<_Tp>::type; |
| 1424 | #endif |
| 1425 | |
| 1426 | // add_pointer |
| 1427 | |
| 1428 | template <class _Tp, |
| 1429 | bool = __is_referenceable<_Tp>::value || |
| 1430 | _IsSame<typename remove_cv<_Tp>::type, void>::value> |
| 1431 | struct __add_pointer_impl |
| 1432 | {typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) typename remove_reference<_Tp>::type* type;}; |
| 1433 | template <class _Tp> struct __add_pointer_impl<_Tp, false> |
| 1434 | {typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) _Tp type;}; |
| 1435 | |
| 1436 | template <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 |
| 1440 | template <class _Tp> using add_pointer_t = typename add_pointer<_Tp>::type; |
| 1441 | #endif |
| 1442 | |
| 1443 | // type_identity |
| 1444 | #if _LIBCPP_STD_VER14 > 17 |
| 1445 | template<class _Tp> struct type_identity { typedef _Tp type; }; |
| 1446 | template<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 | |
| 1455 | template<class _Tp> |
| 1456 | struct _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) |
| 1459 | template <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 | |
| 1465 | template <class _Tp, bool = is_integral<_Tp>::value> |
| 1466 | struct __libcpp_is_signed_impl : public _LIBCPP_BOOL_CONSTANT(_Tp(-1) < _Tp(0))integral_constant<bool,(_Tp(-1) < _Tp(0))> {}; |
| 1467 | |
| 1468 | template <class _Tp> |
| 1469 | struct __libcpp_is_signed_impl<_Tp, false> : public true_type {}; // floating point |
| 1470 | |
| 1471 | template <class _Tp, bool = is_arithmetic<_Tp>::value> |
| 1472 | struct __libcpp_is_signed : public __libcpp_is_signed_impl<_Tp> {}; |
| 1473 | |
| 1474 | template <class _Tp> struct __libcpp_is_signed<_Tp, false> : public false_type {}; |
| 1475 | |
| 1476 | template <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) |
| 1479 | template <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 | |
| 1494 | template<class _Tp> |
| 1495 | struct _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) |
| 1498 | template <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 | |
| 1504 | template <class _Tp, bool = is_integral<_Tp>::value> |
| 1505 | struct __libcpp_is_unsigned_impl : public _LIBCPP_BOOL_CONSTANT(_Tp(0) < _Tp(-1))integral_constant<bool,(_Tp(0) < _Tp(-1))> {}; |
| 1506 | |
| 1507 | template <class _Tp> |
| 1508 | struct __libcpp_is_unsigned_impl<_Tp, false> : public false_type {}; // floating point |
| 1509 | |
| 1510 | template <class _Tp, bool = is_arithmetic<_Tp>::value> |
| 1511 | struct __libcpp_is_unsigned : public __libcpp_is_unsigned_impl<_Tp> {}; |
| 1512 | |
| 1513 | template <class _Tp> struct __libcpp_is_unsigned<_Tp, false> : public false_type {}; |
| 1514 | |
| 1515 | template <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) |
| 1518 | template <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 | |
| 1527 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) rank |
| 1528 | : public integral_constant<size_t, 0> {}; |
| 1529 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) rank<_Tp[]> |
| 1530 | : public integral_constant<size_t, rank<_Tp>::value + 1> {}; |
| 1531 | template <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) |
| 1535 | template <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 | |
| 1544 | template<class _Tp, size_t _Dim = 0> |
| 1545 | struct _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) |
| 1549 | template <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 | |
| 1555 | template <class _Tp, unsigned _Ip = 0> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) extent |
| 1556 | : public integral_constant<size_t, 0> {}; |
| 1557 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) extent<_Tp[], 0> |
| 1558 | : public integral_constant<size_t, 0> {}; |
| 1559 | template <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> {}; |
| 1561 | template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) extent<_Tp[_Np], 0> |
| 1562 | : public integral_constant<size_t, _Np> {}; |
| 1563 | template <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) |
| 1567 | template <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 | |
| 1576 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_extent |
| 1577 | {typedef _Tp type;}; |
| 1578 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_extent<_Tp[]> |
| 1579 | {typedef _Tp type;}; |
| 1580 | template <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 |
| 1584 | template <class _Tp> using remove_extent_t = typename remove_extent<_Tp>::type; |
| 1585 | #endif |
| 1586 | |
| 1587 | // remove_all_extents |
| 1588 | |
| 1589 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_all_extents |
| 1590 | {typedef _Tp type;}; |
| 1591 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) remove_all_extents<_Tp[]> |
| 1592 | {typedef typename remove_all_extents<_Tp>::type type;}; |
| 1593 | template <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 |
| 1597 | template <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 | |
| 1603 | template <class> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_bounded_array : false_type {}; |
| 1604 | template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_bounded_array<_Tp[_Np]> : true_type {}; |
| 1605 | |
| 1606 | template <class _Tp> |
| 1607 | _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr |
| 1608 | bool is_bounded_array_v = is_bounded_array<_Tp>::value; |
| 1609 | |
| 1610 | // is_unbounded_array |
| 1611 | |
| 1612 | template <class> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_unbounded_array : false_type {}; |
| 1613 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_unbounded_array<_Tp[]> : true_type {}; |
| 1614 | |
| 1615 | template <class _Tp> |
| 1616 | _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr |
| 1617 | bool is_unbounded_array_v = is_unbounded_array<_Tp>::value; |
| 1618 | #endif |
| 1619 | |
| 1620 | // decay |
| 1621 | |
| 1622 | template <class _Up, bool> |
| 1623 | struct __decay { |
| 1624 | typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) typename remove_cv<_Up>::type type; |
| 1625 | }; |
| 1626 | |
| 1627 | template <class _Up> |
| 1628 | struct __decay<_Up, true> { |
| 1629 | public: |
| 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 | |
| 1643 | template <class _Tp> |
| 1644 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) decay |
| 1645 | { |
| 1646 | private: |
| 1647 | typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) typename remove_reference<_Tp>::type _Up; |
| 1648 | public: |
| 1649 | typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) typename __decay<_Up, __is_referenceable<_Up>::value>::type type; |
| 1650 | }; |
| 1651 | |
| 1652 | #if _LIBCPP_STD_VER14 > 11 |
| 1653 | template <class _Tp> using decay_t = typename decay<_Tp>::type; |
| 1654 | #endif |
| 1655 | |
| 1656 | // is_abstract |
| 1657 | |
| 1658 | template <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) |
| 1662 | template <class _Tp> |
| 1663 | _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_abstract_v |
| 1664 | = is_abstract<_Tp>::value; |
| 1665 | #endif |
| 1666 | |
| 1667 | // is_final |
| 1668 | |
| 1669 | template <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 |
| 1673 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) |
| 1674 | is_final : public integral_constant<bool, __is_final(_Tp)> {}; |
| 1675 | #endif |
| 1676 | |
| 1677 | #if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) |
| 1678 | template <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 | |
| 1686 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) |
| 1687 | is_aggregate : public integral_constant<bool, __is_aggregate(_Tp)> {}; |
| 1688 | |
| 1689 | #if !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) |
| 1690 | template <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 | |
| 1699 | template <class _Bp, class _Dp> |
| 1700 | struct _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) |
| 1704 | template <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 | |
| 1716 | template <class _Tp, class _Up, class = void> |
| 1717 | struct __is_core_convertible : public false_type {}; |
| 1718 | |
| 1719 | template <class _Tp, class _Up> |
| 1720 | struct __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 | |
| 1728 | template <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 | |
| 1733 | namespace __is_convertible_imp |
| 1734 | { |
| 1735 | template <class _Tp> void __test_convert(_Tp); |
| 1736 | |
| 1737 | template <class _From, class _To, class = void> |
| 1738 | struct __is_convertible_test : public false_type {}; |
| 1739 | |
| 1740 | template <class _From, class _To> |
| 1741 | struct __is_convertible_test<_From, _To, |
| 1742 | decltype(__is_convertible_imp::__test_convert<_To>(declval<_From>()))> : public true_type |
| 1743 | {}; |
| 1744 | |
| 1745 | template <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};}; |
| 1749 | template <class _Tp> struct __is_array_function_or_void<_Tp, true, false, false> {enum {value = 1};}; |
| 1750 | template <class _Tp> struct __is_array_function_or_void<_Tp, false, true, false> {enum {value = 2};}; |
| 1751 | template <class _Tp> struct __is_array_function_or_void<_Tp, false, false, true> {enum {value = 3};}; |
| 1752 | } |
| 1753 | |
| 1754 | template <class _Tp, |
| 1755 | unsigned = __is_convertible_imp::__is_array_function_or_void<typename remove_reference<_Tp>::type>::value> |
| 1756 | struct __is_convertible_check |
| 1757 | { |
| 1758 | static const size_t __v = 0; |
| 1759 | }; |
| 1760 | |
| 1761 | template <class _Tp> |
| 1762 | struct __is_convertible_check<_Tp, 0> |
| 1763 | { |
| 1764 | static const size_t __v = sizeof(_Tp); |
| 1765 | }; |
| 1766 | |
| 1767 | template <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> |
| 1770 | struct __is_convertible |
| 1771 | : public integral_constant<bool, |
| 1772 | __is_convertible_imp::__is_convertible_test<_T1, _T2>::value |
| 1773 | > |
| 1774 | {}; |
| 1775 | |
| 1776 | template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 1> : public false_type {}; |
| 1777 | template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 1> : public false_type {}; |
| 1778 | template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 1> : public false_type {}; |
| 1779 | template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 1> : public false_type {}; |
| 1780 | |
| 1781 | template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 2> : public false_type {}; |
| 1782 | template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 2> : public false_type {}; |
| 1783 | template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 2> : public false_type {}; |
| 1784 | template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 2> : public false_type {}; |
| 1785 | |
| 1786 | template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 3> : public false_type {}; |
| 1787 | template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 3> : public false_type {}; |
| 1788 | template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 3> : public false_type {}; |
| 1789 | template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 3> : public true_type {}; |
| 1790 | |
| 1791 | template <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) |
| 1801 | template <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 | |
| 1810 | template <typename _Tp> |
| 1811 | static void __test_noexcept(_Tp) noexcept; |
| 1812 | |
| 1813 | template<typename _Fm, typename _To> |
| 1814 | static bool_constant<noexcept(_VSTDstd::__1::__test_noexcept<_To>(declval<_Fm>()))> |
| 1815 | __is_nothrow_convertible_test(); |
| 1816 | |
| 1817 | template <typename _Fm, typename _To> |
| 1818 | struct __is_nothrow_convertible_helper: decltype(__is_nothrow_convertible_test<_Fm, _To>()) |
| 1819 | { }; |
| 1820 | |
| 1821 | template <typename _Fm, typename _To> |
| 1822 | struct 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 | |
| 1827 | template <typename _Fm, typename _To> |
| 1828 | inline 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 | |
| 1836 | template <class _Tp> |
| 1837 | struct _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 | |
| 1842 | template <class _Tp> |
| 1843 | struct __is_empty1 |
| 1844 | : public _Tp |
| 1845 | { |
| 1846 | double __lx; |
| 1847 | }; |
| 1848 | |
| 1849 | struct __is_empty2 |
| 1850 | { |
| 1851 | double __lx; |
| 1852 | }; |
| 1853 | |
| 1854 | template <class _Tp, bool = is_class<_Tp>::value> |
| 1855 | struct __libcpp_empty : public integral_constant<bool, sizeof(__is_empty1<_Tp>) == sizeof(__is_empty2)> {}; |
| 1856 | |
| 1857 | template <class _Tp> struct __libcpp_empty<_Tp, false> : public false_type {}; |
| 1858 | |
| 1859 | template <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) |
| 1864 | template <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 | |
| 1873 | template <class _Tp> |
| 1874 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_polymorphic |
| 1875 | : public integral_constant<bool, __is_polymorphic(_Tp)> {}; |
| 1876 | |
| 1877 | #else |
| 1878 | |
| 1879 | template<typename _Tp> char &__is_polymorphic_impl( |
| 1880 | typename enable_if<sizeof((_Tp*)dynamic_cast<const volatile void*>(declval<_Tp*>())) != 0, |
| 1881 | int>::type); |
| 1882 | template<typename _Tp> __two &__is_polymorphic_impl(...); |
| 1883 | |
| 1884 | template <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) |
| 1890 | template <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 | |
| 1899 | template <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 | |
| 1904 | template <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) |
| 1910 | template <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 | |
| 1919 | template <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) |
| 1924 | template <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 | |
| 1933 | template <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) |
| 1937 | template <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 | |
| 1944 | template <class _Hp, class _Tp> |
| 1945 | struct __type_list |
| 1946 | { |
| 1947 | typedef _Hp _Head; |
| 1948 | typedef _Tp _Tail; |
| 1949 | }; |
| 1950 | |
| 1951 | struct __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 | |
| 1961 | template <class _Tp> |
| 1962 | struct __align_type |
| 1963 | { |
| 1964 | static const size_t value = _LIBCPP_PREFERRED_ALIGNOF(_Tp)__alignof(_Tp); |
| 1965 | typedef _Tp type; |
| 1966 | }; |
| 1967 | |
| 1968 | struct __struct_double {long double __lx;}; |
| 1969 | struct __struct_double4 {double __lx[4];}; |
| 1970 | |
| 1971 | typedef |
| 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 | |
| 1985 | template <size_t _Align> |
| 1986 | struct _ALIGNAS(_Align)alignas(_Align) __fallback_overaligned {}; |
| 1987 | |
| 1988 | template <class _TL, size_t _Align> struct __find_pod; |
| 1989 | |
| 1990 | template <class _Hp, size_t _Align> |
| 1991 | struct __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 | |
| 2000 | template <class _Hp, class _Tp, size_t _Align> |
| 2001 | struct __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 | |
| 2010 | template <class _TL, size_t _Len> struct __find_max_align; |
| 2011 | |
| 2012 | template <class _Hp, size_t _Len> |
| 2013 | struct __find_max_align<__type_list<_Hp, __nat>, _Len> : public integral_constant<size_t, _Hp::value> {}; |
| 2014 | |
| 2015 | template <size_t _Len, size_t _A1, size_t _A2> |
| 2016 | struct __select_align |
| 2017 | { |
| 2018 | private: |
| 2019 | static const size_t __min = _A2 < _A1 ? _A2 : _A1; |
| 2020 | static const size_t __max = _A1 < _A2 ? _A2 : _A1; |
| 2021 | public: |
| 2022 | static const size_t value = _Len < __max ? __min : __max; |
| 2023 | }; |
| 2024 | |
| 2025 | template <class _Hp, class _Tp, size_t _Len> |
| 2026 | struct __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 | |
| 2029 | template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value> |
| 2030 | struct _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 |
| 2041 | template <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) \ |
| 2046 | template <size_t _Len>\ |
| 2047 | struct _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 | |
| 2079 | template <size_t _I0, size_t ..._In> |
| 2080 | struct __static_max; |
| 2081 | |
| 2082 | template <size_t _I0> |
| 2083 | struct __static_max<_I0> |
| 2084 | { |
| 2085 | static const size_t value = _I0; |
| 2086 | }; |
| 2087 | |
| 2088 | template <size_t _I0, size_t _I1, size_t ..._In> |
| 2089 | struct __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 | |
| 2095 | template <size_t _Len, class _Type0, class ..._Types> |
| 2096 | struct 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 |
| 2106 | template <size_t _Len, class ..._Types> using aligned_union_t = typename aligned_union<_Len, _Types...>::type; |
| 2107 | #endif |
| 2108 | |
| 2109 | template <class _Tp> |
| 2110 | struct __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 | |
| 2128 | template <> |
| 2129 | struct __numeric_type<void> |
| 2130 | { |
| 2131 | static const bool value = true; |
| 2132 | }; |
| 2133 | |
| 2134 | // __promote |
| 2135 | |
| 2136 | template <class _A1, class _A2 = void, class _A3 = void, |
| 2137 | bool = __numeric_type<_A1>::value && |
| 2138 | __numeric_type<_A2>::value && |
| 2139 | __numeric_type<_A3>::value> |
| 2140 | class __promote_imp |
| 2141 | { |
| 2142 | public: |
| 2143 | static const bool value = false; |
| 2144 | }; |
| 2145 | |
| 2146 | template <class _A1, class _A2, class _A3> |
| 2147 | class __promote_imp<_A1, _A2, _A3, true> |
| 2148 | { |
| 2149 | private: |
| 2150 | typedef typename __promote_imp<_A1>::type __type1; |
| 2151 | typedef typename __promote_imp<_A2>::type __type2; |
| 2152 | typedef typename __promote_imp<_A3>::type __type3; |
| 2153 | public: |
| 2154 | typedef decltype(__type1() + __type2() + __type3()) type; |
| 2155 | static const bool value = true; |
| 2156 | }; |
| 2157 | |
| 2158 | template <class _A1, class _A2> |
| 2159 | class __promote_imp<_A1, _A2, void, true> |
| 2160 | { |
| 2161 | private: |
| 2162 | typedef typename __promote_imp<_A1>::type __type1; |
| 2163 | typedef typename __promote_imp<_A2>::type __type2; |
| 2164 | public: |
| 2165 | typedef decltype(__type1() + __type2()) type; |
| 2166 | static const bool value = true; |
| 2167 | }; |
| 2168 | |
| 2169 | template <class _A1> |
| 2170 | class __promote_imp<_A1, void, void, true> |
| 2171 | { |
| 2172 | public: |
| 2173 | typedef typename __numeric_type<_A1>::type type; |
| 2174 | static const bool value = true; |
| 2175 | }; |
| 2176 | |
| 2177 | template <class _A1, class _A2 = void, class _A3 = void> |
| 2178 | class __promote : public __promote_imp<_A1, _A2, _A3> {}; |
| 2179 | |
| 2180 | // make_signed / make_unsigned |
| 2181 | |
| 2182 | typedef |
| 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 | |
| 2197 | typedef |
| 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 | |
| 2212 | template <class _TypeList, size_t _Size, bool = _Size <= sizeof(typename _TypeList::_Head)> struct __find_first; |
| 2213 | |
| 2214 | template <class _Hp, class _Tp, size_t _Size> |
| 2215 | struct __find_first<__type_list<_Hp, _Tp>, _Size, true> |
| 2216 | { |
| 2217 | typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) _Hp type; |
| 2218 | }; |
| 2219 | |
| 2220 | template <class _Hp, class _Tp, size_t _Size> |
| 2221 | struct __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 | |
| 2226 | template <class _Tp, class _Up, bool = is_const<typename remove_reference<_Tp>::type>::value, |
| 2227 | bool = is_volatile<typename remove_reference<_Tp>::type>::value> |
| 2228 | struct __apply_cv |
| 2229 | { |
| 2230 | typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) _Up type; |
| 2231 | }; |
| 2232 | |
| 2233 | template <class _Tp, class _Up> |
| 2234 | struct __apply_cv<_Tp, _Up, true, false> |
| 2235 | { |
| 2236 | typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) const _Up type; |
| 2237 | }; |
| 2238 | |
| 2239 | template <class _Tp, class _Up> |
| 2240 | struct __apply_cv<_Tp, _Up, false, true> |
| 2241 | { |
| 2242 | typedef volatile _Up type; |
| 2243 | }; |
| 2244 | |
| 2245 | template <class _Tp, class _Up> |
| 2246 | struct __apply_cv<_Tp, _Up, true, true> |
| 2247 | { |
| 2248 | typedef const volatile _Up type; |
| 2249 | }; |
| 2250 | |
| 2251 | template <class _Tp, class _Up> |
| 2252 | struct __apply_cv<_Tp&, _Up, false, false> |
| 2253 | { |
| 2254 | typedef _Up& type; |
| 2255 | }; |
| 2256 | |
| 2257 | template <class _Tp, class _Up> |
| 2258 | struct __apply_cv<_Tp&, _Up, true, false> |
| 2259 | { |
| 2260 | typedef const _Up& type; |
| 2261 | }; |
| 2262 | |
| 2263 | template <class _Tp, class _Up> |
| 2264 | struct __apply_cv<_Tp&, _Up, false, true> |
| 2265 | { |
| 2266 | typedef volatile _Up& type; |
| 2267 | }; |
| 2268 | |
| 2269 | template <class _Tp, class _Up> |
| 2270 | struct __apply_cv<_Tp&, _Up, true, true> |
| 2271 | { |
| 2272 | typedef const volatile _Up& type; |
| 2273 | }; |
| 2274 | |
| 2275 | template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value> |
| 2276 | struct __make_signed {}; |
| 2277 | |
| 2278 | template <class _Tp> |
| 2279 | struct __make_signed<_Tp, true> |
| 2280 | { |
| 2281 | typedef typename __find_first<__signed_types, sizeof(_Tp)>::type type; |
| 2282 | }; |
| 2283 | |
| 2284 | template <> struct __make_signed<bool, true> {}; |
| 2285 | template <> struct __make_signed< signed short, true> {typedef short type;}; |
| 2286 | template <> struct __make_signed<unsigned short, true> {typedef short type;}; |
| 2287 | template <> struct __make_signed< signed int, true> {typedef int type;}; |
| 2288 | template <> struct __make_signed<unsigned int, true> {typedef int type;}; |
| 2289 | template <> struct __make_signed< signed long, true> {typedef long type;}; |
| 2290 | template <> struct __make_signed<unsigned long, true> {typedef long type;}; |
| 2291 | template <> struct __make_signed< signed long long, true> {typedef long long type;}; |
| 2292 | template <> struct __make_signed<unsigned long long, true> {typedef long long type;}; |
| 2293 | #ifndef _LIBCPP_HAS_NO_INT128 |
| 2294 | template <> struct __make_signed<__int128_t, true> {typedef __int128_t type;}; |
| 2295 | template <> struct __make_signed<__uint128_t, true> {typedef __int128_t type;}; |
| 2296 | #endif |
| 2297 | |
| 2298 | template <class _Tp> |
| 2299 | struct _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 |
| 2305 | template <class _Tp> using make_signed_t = typename make_signed<_Tp>::type; |
| 2306 | #endif |
| 2307 | |
| 2308 | template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value> |
| 2309 | struct __make_unsigned {}; |
| 2310 | |
| 2311 | template <class _Tp> |
| 2312 | struct __make_unsigned<_Tp, true> |
| 2313 | { |
| 2314 | typedef typename __find_first<__unsigned_types, sizeof(_Tp)>::type type; |
| 2315 | }; |
| 2316 | |
| 2317 | template <> struct __make_unsigned<bool, true> {}; |
| 2318 | template <> struct __make_unsigned< signed short, true> {typedef unsigned short type;}; |
| 2319 | template <> struct __make_unsigned<unsigned short, true> {typedef unsigned short type;}; |
| 2320 | template <> struct __make_unsigned< signed int, true> {typedef unsigned int type;}; |
| 2321 | template <> struct __make_unsigned<unsigned int, true> {typedef unsigned int type;}; |
| 2322 | template <> struct __make_unsigned< signed long, true> {typedef unsigned long type;}; |
| 2323 | template <> struct __make_unsigned<unsigned long, true> {typedef unsigned long type;}; |
| 2324 | template <> struct __make_unsigned< signed long long, true> {typedef unsigned long long type;}; |
| 2325 | template <> struct __make_unsigned<unsigned long long, true> {typedef unsigned long long type;}; |
| 2326 | #ifndef _LIBCPP_HAS_NO_INT128 |
| 2327 | template <> struct __make_unsigned<__int128_t, true> {typedef __uint128_t type;}; |
| 2328 | template <> struct __make_unsigned<__uint128_t, true> {typedef __uint128_t type;}; |
| 2329 | #endif |
| 2330 | |
| 2331 | template <class _Tp> |
| 2332 | struct _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 |
| 2338 | template <class _Tp> using make_unsigned_t = typename make_unsigned<_Tp>::type; |
| 2339 | #endif |
| 2340 | |
| 2341 | #ifndef _LIBCPP_CXX03_LANG |
| 2342 | template <class _Tp> |
| 2343 | _LIBCPP_NODISCARD_ATTRIBUTE[[nodiscard]] _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) constexpr |
| 2344 | typename 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 |
| 2350 | template <class...> using void_t = void; |
| 2351 | #endif |
| 2352 | |
| 2353 | #if _LIBCPP_STD_VER14 > 17 |
| 2354 | // Let COND_RES(X, Y) be: |
| 2355 | template <class _Tp, class _Up> |
| 2356 | using __cond_type = decltype(false ? declval<_Tp>() : declval<_Up>()); |
| 2357 | |
| 2358 | template <class _Tp, class _Up, class = void> |
| 2359 | struct __common_type3 {}; |
| 2360 | |
| 2361 | // sub-bullet 4 - "if COND_RES(CREF(D1), CREF(D2)) denotes a type..." |
| 2362 | template <class _Tp, class _Up> |
| 2363 | struct __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 | |
| 2368 | template <class _Tp, class _Up, class = void> |
| 2369 | struct __common_type2_imp : __common_type3<_Tp, _Up> {}; |
| 2370 | #else |
| 2371 | template <class _Tp, class _Up, class = void> |
| 2372 | struct __common_type2_imp {}; |
| 2373 | #endif |
| 2374 | |
| 2375 | // sub-bullet 3 - "if decay_t<decltype(false ? declval<D1>() : declval<D2>())> ..." |
| 2376 | template <class _Tp, class _Up> |
| 2377 | struct __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 | |
| 2387 | template <class, class = void> |
| 2388 | struct __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__ |
| 2393 | template <class... Tp> |
| 2394 | struct __common_types; |
| 2395 | template <class... _Tp> |
| 2396 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) common_type; |
| 2397 | #else |
| 2398 | # define _LIBCPP_OPTIONAL_PACK(...) |
| 2399 | struct __no_arg; |
| 2400 | template <class _Tp, class _Up, class = __no_arg> |
| 2401 | struct __common_types; |
| 2402 | template <class _Tp = __no_arg, class _Up = __no_arg, class _Vp = __no_arg, |
| 2403 | class _Unused = __no_arg> |
| 2404 | struct 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 | |
| 2410 | template <class _Tp, class _Up> |
| 2411 | struct __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 | |
| 2418 | template <class _Tp, class _Up, class _Vp _LIBCPP_OPTIONAL_PACK(class... _Rest)> |
| 2419 | struct __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 | |
| 2428 | template <> |
| 2429 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) common_type<> {}; |
| 2430 | |
| 2431 | // bullet 2 - sizeof...(Tp) == 1 |
| 2432 | |
| 2433 | template <class _Tp> |
| 2434 | struct _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 ..." |
| 2440 | template <class _Tp, class _Up> |
| 2441 | struct _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 | |
| 2451 | template <class _Tp, class _Up, class _Vp _LIBCPP_OPTIONAL_PACK(class... _Rest)> |
| 2452 | struct _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 |
| 2460 | template <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. |
| 2466 | template <class _From, class _To> |
| 2467 | struct __copy_cv |
| 2468 | { |
| 2469 | using type = _To; |
| 2470 | }; |
| 2471 | |
| 2472 | template <class _From, class _To> |
| 2473 | struct __copy_cv<const _From, _To> |
| 2474 | { |
| 2475 | using type = add_const_t<_To>; |
| 2476 | }; |
| 2477 | |
| 2478 | template <class _From, class _To> |
| 2479 | struct __copy_cv<volatile _From, _To> |
| 2480 | { |
| 2481 | using type = add_volatile_t<_To>; |
| 2482 | }; |
| 2483 | |
| 2484 | template <class _From, class _To> |
| 2485 | struct __copy_cv<const volatile _From, _To> |
| 2486 | { |
| 2487 | using type = add_cv_t<_To>; |
| 2488 | }; |
| 2489 | |
| 2490 | template <class _From, class _To> |
| 2491 | using __copy_cv_t = typename __copy_cv<_From, _To>::type; |
| 2492 | |
| 2493 | template <class _From, class _To> |
| 2494 | struct __copy_cvref |
| 2495 | { |
| 2496 | using type = __copy_cv_t<_From, _To>; |
| 2497 | }; |
| 2498 | |
| 2499 | template <class _From, class _To> |
| 2500 | struct __copy_cvref<_From&, _To> |
| 2501 | { |
| 2502 | using type = add_lvalue_reference_t<__copy_cv_t<_From, _To>>; |
| 2503 | }; |
| 2504 | |
| 2505 | template <class _From, class _To> |
| 2506 | struct __copy_cvref<_From&&, _To> |
| 2507 | { |
| 2508 | using type = add_rvalue_reference_t<__copy_cv_t<_From, _To>>; |
| 2509 | }; |
| 2510 | |
| 2511 | template <class _From, class _To> |
| 2512 | using __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: |
| 2519 | template <class _Xp, class _Yp> |
| 2520 | using __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`] |
| 2527 | template <class _Tp> |
| 2528 | struct __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: |
| 2535 | template<class _Ap, class _Bp, class _Xp = remove_reference_t<_Ap>, class _Yp = remove_reference_t<_Bp>> |
| 2536 | struct __common_ref; |
| 2537 | |
| 2538 | template<class _Xp, class _Yp> |
| 2539 | using __common_ref_t = typename __common_ref<_Xp, _Yp>::__type; |
| 2540 | |
| 2541 | template<class _Xp, class _Yp> |
| 2542 | using __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. |
| 2547 | template<class _Ap, class _Bp, class _Xp, class _Yp> |
| 2548 | requires requires { typename __cv_cond_res<_Xp, _Yp>; } && is_reference_v<__cv_cond_res<_Xp, _Yp>> |
| 2549 | struct __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&)>&&. ... |
| 2555 | template <class _Xp, class _Yp> |
| 2556 | using __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. |
| 2561 | template<class _Ap, class _Bp, class _Xp, class _Yp> |
| 2562 | requires |
| 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>> |
| 2566 | struct __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&). ... |
| 2572 | template <class _Tp, class _Up> |
| 2573 | using __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. |
| 2577 | template<class _Ap, class _Bp, class _Xp, class _Yp> |
| 2578 | requires requires { typename __common_ref_D<_Xp, _Yp>; } && |
| 2579 | is_convertible_v<_Ap&&, __common_ref_D<_Xp, _Yp>> |
| 2580 | struct __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). |
| 2587 | template<class _Ap, class _Bp, class _Xp, class _Yp> |
| 2588 | struct __common_ref<_Ap&, _Bp&&, _Xp, _Yp> : __common_ref<_Bp&&, _Ap&> {}; |
| 2589 | |
| 2590 | // Otherwise, COMMON-REF(A, B) is ill-formed. |
| 2591 | template<class _Ap, class _Bp, class _Xp, class _Yp> |
| 2592 | struct __common_ref {}; |
| 2593 | |
| 2594 | // Note C: For the common_reference trait applied to a parameter pack [...] |
| 2595 | |
| 2596 | template <class...> |
| 2597 | struct common_reference; |
| 2598 | |
| 2599 | template <class... _Types> |
| 2600 | using common_reference_t = typename common_reference<_Types...>::type; |
| 2601 | |
| 2602 | // bullet 1 - sizeof...(T) == 0 |
| 2603 | template<> |
| 2604 | struct common_reference<> {}; |
| 2605 | |
| 2606 | // bullet 2 - sizeof...(T) == 1 |
| 2607 | template <class _Tp> |
| 2608 | struct common_reference<_Tp> |
| 2609 | { |
| 2610 | using type = _Tp; |
| 2611 | }; |
| 2612 | |
| 2613 | // bullet 3 - sizeof...(T) == 2 |
| 2614 | template <class _Tp, class _Up> struct __common_reference_sub_bullet3; |
| 2615 | template <class _Tp, class _Up> struct __common_reference_sub_bullet2 : __common_reference_sub_bullet3<_Tp, _Up> {}; |
| 2616 | template <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. |
| 2620 | template <class _Tp, class _Up> struct common_reference<_Tp, _Up> : __common_reference_sub_bullet1<_Tp, _Up> {}; |
| 2621 | |
| 2622 | template <class _Tp, class _Up> |
| 2623 | requires is_reference_v<_Tp> && is_reference_v<_Up> && requires { typename __common_ref_t<_Tp, _Up>; } |
| 2624 | struct __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. |
| 2631 | template <class, class, template <class> class, template <class> class> struct basic_common_reference {}; |
| 2632 | |
| 2633 | template <class _Tp, class _Up> |
| 2634 | using __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 | |
| 2638 | template <class _Tp, class _Up> |
| 2639 | requires requires { typename __basic_common_reference_t<_Tp, _Up>; } |
| 2640 | struct __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. |
| 2647 | template <class _Tp, class _Up> |
| 2648 | requires requires { typename __cond_res<_Tp, _Up>; } |
| 2649 | struct __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`. |
| 2658 | template <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...>`. |
| 2662 | template <class _Tp, class _Up, class _Vp, class... _Rest> |
| 2663 | requires requires { typename common_reference_t<_Tp, _Up>; } |
| 2664 | struct 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`. |
| 2669 | template <class...> struct common_reference {}; |
| 2670 | |
| 2671 | #endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS) |
| 2672 | |
| 2673 | // is_assignable |
| 2674 | |
| 2675 | template<typename, typename _Tp> struct __select_2nd { typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) _Tp type; }; |
| 2676 | |
| 2677 | #if __has_keyword(__is_assignable)!(0) |
| 2678 | |
| 2679 | template<class _Tp, class _Up> |
| 2680 | struct _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) |
| 2683 | template <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 | |
| 2689 | template <class _Tp, class _Arg> |
| 2690 | typename __select_2nd<decltype((declval<_Tp>() = declval<_Arg>())), true_type>::type |
| 2691 | __is_assignable_test(int); |
| 2692 | |
| 2693 | template <class, class> |
| 2694 | false_type __is_assignable_test(...); |
| 2695 | |
| 2696 | |
| 2697 | template <class _Tp, class _Arg, bool = is_void<_Tp>::value || is_void<_Arg>::value> |
| 2698 | struct __is_assignable_imp |
| 2699 | : public decltype((_VSTDstd::__1::__is_assignable_test<_Tp, _Arg>(0))) {}; |
| 2700 | |
| 2701 | template <class _Tp, class _Arg> |
| 2702 | struct __is_assignable_imp<_Tp, _Arg, true> |
| 2703 | : public false_type |
| 2704 | { |
| 2705 | }; |
| 2706 | |
| 2707 | template <class _Tp, class _Arg> |
| 2708 | struct is_assignable |
| 2709 | : public __is_assignable_imp<_Tp, _Arg> {}; |
| 2710 | |
| 2711 | #if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) |
| 2712 | template <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 | |
| 2721 | template <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) |
| 2726 | template <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 | |
| 2733 | template <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) |
| 2738 | template <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 | |
| 2747 | template<class _Tp> |
| 2748 | struct _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) |
| 2751 | template <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 | |
| 2764 | template <class> |
| 2765 | struct __is_destructible_apply { typedef int type; }; |
| 2766 | |
| 2767 | template <typename _Tp> |
| 2768 | struct __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 | |
| 2780 | template <class _Tp, bool> |
| 2781 | struct __destructible_imp; |
| 2782 | |
| 2783 | template <class _Tp> |
| 2784 | struct __destructible_imp<_Tp, false> |
| 2785 | : public integral_constant<bool, |
| 2786 | __is_destructor_wellformed<typename remove_all_extents<_Tp>::type>::value> {}; |
| 2787 | |
| 2788 | template <class _Tp> |
| 2789 | struct __destructible_imp<_Tp, true> |
| 2790 | : public true_type {}; |
| 2791 | |
| 2792 | template <class _Tp, bool> |
| 2793 | struct __destructible_false; |
| 2794 | |
| 2795 | template <class _Tp> |
| 2796 | struct __destructible_false<_Tp, false> : public __destructible_imp<_Tp, is_reference<_Tp>::value> {}; |
| 2797 | |
| 2798 | template <class _Tp> |
| 2799 | struct __destructible_false<_Tp, true> : public false_type {}; |
| 2800 | |
| 2801 | template <class _Tp> |
| 2802 | struct is_destructible |
| 2803 | : public __destructible_false<_Tp, is_function<_Tp>::value> {}; |
| 2804 | |
| 2805 | template <class _Tp> |
| 2806 | struct is_destructible<_Tp[]> |
| 2807 | : public false_type {}; |
| 2808 | |
| 2809 | template <> |
| 2810 | struct is_destructible<void> |
| 2811 | : public false_type {}; |
| 2812 | |
| 2813 | #if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) |
| 2814 | template <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 | |
| 2821 | template <class _MP, bool _IsMemberFunctionPtr, bool _IsMemberObjectPtr> |
| 2822 | struct __member_pointer_traits_imp |
| 2823 | { |
| 2824 | }; |
| 2825 | |
| 2826 | template <class _Rp, class _Class, class ..._Param> |
| 2827 | struct __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 | |
| 2834 | template <class _Rp, class _Class, class ..._Param> |
| 2835 | struct __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 | |
| 2842 | template <class _Rp, class _Class, class ..._Param> |
| 2843 | struct __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 | |
| 2850 | template <class _Rp, class _Class, class ..._Param> |
| 2851 | struct __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 | |
| 2858 | template <class _Rp, class _Class, class ..._Param> |
| 2859 | struct __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 | |
| 2866 | template <class _Rp, class _Class, class ..._Param> |
| 2867 | struct __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 | |
| 2874 | template <class _Rp, class _Class, class ..._Param> |
| 2875 | struct __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 | |
| 2882 | template <class _Rp, class _Class, class ..._Param> |
| 2883 | struct __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 | |
| 2892 | template <class _Rp, class _Class, class ..._Param> |
| 2893 | struct __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 | |
| 2900 | template <class _Rp, class _Class, class ..._Param> |
| 2901 | struct __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 | |
| 2908 | template <class _Rp, class _Class, class ..._Param> |
| 2909 | struct __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 | |
| 2916 | template <class _Rp, class _Class, class ..._Param> |
| 2917 | struct __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 | |
| 2924 | template <class _Rp, class _Class, class ..._Param> |
| 2925 | struct __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 | |
| 2932 | template <class _Rp, class _Class, class ..._Param> |
| 2933 | struct __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 | |
| 2940 | template <class _Rp, class _Class, class ..._Param> |
| 2941 | struct __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 | |
| 2948 | template <class _Rp, class _Class, class ..._Param> |
| 2949 | struct __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 | |
| 2956 | template <class _Rp, class _Class, class ..._Param> |
| 2957 | struct __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 | |
| 2964 | template <class _Rp, class _Class, class ..._Param> |
| 2965 | struct __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 | |
| 2972 | template <class _Rp, class _Class, class ..._Param> |
| 2973 | struct __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 | |
| 2980 | template <class _Rp, class _Class, class ..._Param> |
| 2981 | struct __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 | |
| 2988 | template <class _Rp, class _Class, class ..._Param> |
| 2989 | struct __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 | |
| 2996 | template <class _Rp, class _Class, class ..._Param> |
| 2997 | struct __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 | |
| 3004 | template <class _Rp, class _Class, class ..._Param> |
| 3005 | struct __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 | |
| 3012 | template <class _Rp, class _Class, class ..._Param> |
| 3013 | struct __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 | |
| 3023 | template <class _Rp, class _Class> |
| 3024 | struct __member_pointer_traits_imp<_Rp _Class::*, false, true> |
| 3025 | { |
| 3026 | typedef _Class _ClassType; |
| 3027 | typedef _Rp _ReturnType; |
| 3028 | }; |
| 3029 | |
| 3030 | template <class _MP> |
| 3031 | struct __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 | |
| 3042 | template <class _DecayedFp> |
| 3043 | struct __member_pointer_class_type {}; |
| 3044 | |
| 3045 | template <class _Ret, class _ClassType> |
| 3046 | struct __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 | |
| 3058 | template <class _Tp, class... _Args> |
| 3059 | struct __libcpp_is_constructible; |
| 3060 | |
| 3061 | template <class _To, class _From> |
| 3062 | struct __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 | |
| 3073 | template <class _To, class _From> |
| 3074 | struct __is_invalid_lvalue_to_rvalue_cast : false_type { |
| 3075 | static_assert(is_reference<_To>::value, "Wrong specialization"); |
| 3076 | }; |
| 3077 | |
| 3078 | template <class _ToRef, class _FromRef> |
| 3079 | struct __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 | |
| 3090 | struct __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 | |
| 3126 | template <class _Tp, bool = is_void<_Tp>::value> |
| 3127 | struct __is_default_constructible |
| 3128 | : decltype(__is_constructible_helper::__test_nary<_Tp>(0)) |
| 3129 | {}; |
| 3130 | |
| 3131 | template <class _Tp> |
| 3132 | struct __is_default_constructible<_Tp, true> : false_type {}; |
| 3133 | |
| 3134 | template <class _Tp> |
| 3135 | struct __is_default_constructible<_Tp[], false> : false_type {}; |
| 3136 | |
| 3137 | template <class _Tp, size_t _Nx> |
| 3138 | struct __is_default_constructible<_Tp[_Nx], false> |
| 3139 | : __is_default_constructible<typename remove_all_extents<_Tp>::type> {}; |
| 3140 | |
| 3141 | template <class _Tp, class... _Args> |
| 3142 | struct __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 | |
| 3149 | template <class _Tp> |
| 3150 | struct __libcpp_is_constructible<_Tp> : __is_default_constructible<_Tp> {}; |
| 3151 | |
| 3152 | template <class _Tp, class _A0> |
| 3153 | struct __libcpp_is_constructible<_Tp, _A0> |
| 3154 | : public decltype(__is_constructible_helper::__test_unary<_Tp, _A0>(0)) |
| 3155 | {}; |
| 3156 | |
| 3157 | template <class _Tp, class _A0> |
| 3158 | struct __libcpp_is_constructible<_Tp&, _A0> |
| 3159 | : public decltype(__is_constructible_helper:: |
| 3160 | __test_cast<_Tp&, _A0>(0)) |
| 3161 | {}; |
| 3162 | |
| 3163 | template <class _Tp, class _A0> |
| 3164 | struct __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) |
| 3172 | template <class _Tp, class ..._Args> |
| 3173 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_constructible |
| 3174 | : public integral_constant<bool, __is_constructible(_Tp, _Args...)> |
| 3175 | {}; |
| 3176 | #else |
| 3177 | template <class _Tp, class... _Args> |
| 3178 | struct _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) |
| 3183 | template <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 | |
| 3190 | template <class _Tp> |
| 3191 | struct _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) |
| 3196 | template <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. |
| 3206 | template <class _Tp> |
| 3207 | void __test_implicit_default_constructible(_Tp); |
| 3208 | |
| 3209 | template <class _Tp, class = void, class = typename is_default_constructible<_Tp>::type> |
| 3210 | struct __is_implicitly_default_constructible |
| 3211 | : false_type |
| 3212 | { }; |
| 3213 | |
| 3214 | template <class _Tp> |
| 3215 | struct __is_implicitly_default_constructible<_Tp, decltype(__test_implicit_default_constructible<_Tp const&>({})), true_type> |
| 3216 | : true_type |
| 3217 | { }; |
| 3218 | |
| 3219 | template <class _Tp> |
| 3220 | struct __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 | |
| 3227 | template <class _Tp> |
| 3228 | struct _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) |
| 3233 | template <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 | |
| 3240 | template <class _Tp> |
| 3241 | struct _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) |
| 3246 | template <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 | |
| 3255 | template <class _Tp, class... _Args> |
| 3256 | struct _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 | |
| 3263 | template <class _Tp, class... _Args> |
| 3264 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_trivially_constructible |
| 3265 | : false_type |
| 3266 | { |
| 3267 | }; |
| 3268 | |
| 3269 | template <class _Tp> |
| 3270 | struct _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 | |
| 3279 | template <class _Tp> |
| 3280 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_trivially_constructible<_Tp, _Tp&&> |
| 3281 | : integral_constant<bool, is_scalar<_Tp>::value> |
| 3282 | { |
| 3283 | }; |
| 3284 | |
| 3285 | template <class _Tp> |
| 3286 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_trivially_constructible<_Tp, const _Tp&> |
| 3287 | : integral_constant<bool, is_scalar<_Tp>::value> |
| 3288 | { |
| 3289 | }; |
| 3290 | |
| 3291 | template <class _Tp> |
| 3292 | struct _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) |
| 3301 | template <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 | |
| 3308 | template <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) |
| 3313 | template <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 | |
| 3320 | template <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) |
| 3325 | template <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 | |
| 3332 | template <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) |
| 3337 | template <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 | |
| 3346 | template <class _Tp, class _Arg> |
| 3347 | struct is_trivially_assignable |
| 3348 | : integral_constant<bool, __is_trivially_assignable(_Tp, _Arg)> |
| 3349 | { |
| 3350 | }; |
| 3351 | |
| 3352 | #else // !__has_feature(is_trivially_assignable) |
| 3353 | |
| 3354 | template <class _Tp, class _Arg> |
| 3355 | struct is_trivially_assignable |
| 3356 | : public false_type {}; |
| 3357 | |
| 3358 | template <class _Tp> |
| 3359 | struct is_trivially_assignable<_Tp&, _Tp> |
| 3360 | : integral_constant<bool, is_scalar<_Tp>::value> {}; |
| 3361 | |
| 3362 | template <class _Tp> |
| 3363 | struct is_trivially_assignable<_Tp&, _Tp&> |
| 3364 | : integral_constant<bool, is_scalar<_Tp>::value> {}; |
| 3365 | |
| 3366 | template <class _Tp> |
| 3367 | struct is_trivially_assignable<_Tp&, const _Tp&> |
| 3368 | : integral_constant<bool, is_scalar<_Tp>::value> {}; |
| 3369 | |
| 3370 | template <class _Tp> |
| 3371 | struct 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) |
| 3377 | template <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 | |
| 3384 | template <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) |
| 3389 | template <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 | |
| 3396 | template <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) |
| 3402 | template <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 | |
| 3411 | template <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 | |
| 3416 | template <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 | |
| 3421 | template <class _Tp> struct __libcpp_trivial_destructor |
| 3422 | : public integral_constant<bool, is_scalar<_Tp>::value || |
| 3423 | is_reference<_Tp>::value> {}; |
| 3424 | |
| 3425 | template <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 | |
| 3428 | template <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) |
| 3434 | template <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 | |
| 3443 | template <class _Tp, class... _Args> |
| 3444 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_nothrow_constructible |
| 3445 | : public integral_constant<bool, __is_nothrow_constructible(_Tp, _Args...)> {}; |
| 3446 | |
| 3447 | #else |
| 3448 | |
| 3449 | template <bool, bool, class _Tp, class... _Args> struct __libcpp_is_nothrow_constructible; |
| 3450 | |
| 3451 | template <class _Tp, class... _Args> |
| 3452 | struct __libcpp_is_nothrow_constructible</*is constructible*/true, /*is reference*/false, _Tp, _Args...> |
| 3453 | : public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))> |
| 3454 | { |
| 3455 | }; |
| 3456 | |
| 3457 | template <class _Tp> |
| 3458 | void __implicit_conversion_to(_Tp) noexcept { } |
| 3459 | |
| 3460 | template <class _Tp, class _Arg> |
| 3461 | struct __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 | |
| 3466 | template <class _Tp, bool _IsReference, class... _Args> |
| 3467 | struct __libcpp_is_nothrow_constructible</*is constructible*/false, _IsReference, _Tp, _Args...> |
| 3468 | : public false_type |
| 3469 | { |
| 3470 | }; |
| 3471 | |
| 3472 | template <class _Tp, class... _Args> |
| 3473 | struct _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 | |
| 3478 | template <class _Tp, size_t _Ns> |
| 3479 | struct _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) |
| 3488 | template <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 | |
| 3495 | template <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) |
| 3500 | template <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 | |
| 3507 | template <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) |
| 3512 | template <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 | |
| 3519 | template <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) |
| 3524 | template <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 | |
| 3533 | template <class _Tp, class _Arg> |
| 3534 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_nothrow_assignable |
| 3535 | : public integral_constant<bool, __is_nothrow_assignable(_Tp, _Arg)> {}; |
| 3536 | |
| 3537 | #else |
| 3538 | |
| 3539 | template <bool, class _Tp, class _Arg> struct __libcpp_is_nothrow_assignable; |
| 3540 | |
| 3541 | template <class _Tp, class _Arg> |
| 3542 | struct __libcpp_is_nothrow_assignable<false, _Tp, _Arg> |
| 3543 | : public false_type |
| 3544 | { |
| 3545 | }; |
| 3546 | |
| 3547 | template <class _Tp, class _Arg> |
| 3548 | struct __libcpp_is_nothrow_assignable<true, _Tp, _Arg> |
| 3549 | : public integral_constant<bool, noexcept(declval<_Tp>() = declval<_Arg>()) > |
| 3550 | { |
| 3551 | }; |
| 3552 | |
| 3553 | template <class _Tp, class _Arg> |
| 3554 | struct _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) |
| 3562 | template <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 | |
| 3569 | template <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) |
| 3574 | template <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 | |
| 3581 | template <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) |
| 3587 | template <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 | |
| 3596 | template <bool, class _Tp> struct __libcpp_is_nothrow_destructible; |
| 3597 | |
| 3598 | template <class _Tp> |
| 3599 | struct __libcpp_is_nothrow_destructible<false, _Tp> |
| 3600 | : public false_type |
| 3601 | { |
| 3602 | }; |
| 3603 | |
| 3604 | template <class _Tp> |
| 3605 | struct __libcpp_is_nothrow_destructible<true, _Tp> |
| 3606 | : public integral_constant<bool, noexcept(declval<_Tp>().~_Tp()) > |
| 3607 | { |
| 3608 | }; |
| 3609 | |
| 3610 | template <class _Tp> |
| 3611 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_nothrow_destructible |
| 3612 | : public __libcpp_is_nothrow_destructible<is_destructible<_Tp>::value, _Tp> |
| 3613 | { |
| 3614 | }; |
| 3615 | |
| 3616 | template <class _Tp, size_t _Ns> |
| 3617 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_nothrow_destructible<_Tp[_Ns]> |
| 3618 | : public is_nothrow_destructible<_Tp> |
| 3619 | { |
| 3620 | }; |
| 3621 | |
| 3622 | template <class _Tp> |
| 3623 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_nothrow_destructible<_Tp&> |
| 3624 | : public true_type |
| 3625 | { |
| 3626 | }; |
| 3627 | |
| 3628 | template <class _Tp> |
| 3629 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_nothrow_destructible<_Tp&&> |
| 3630 | : public true_type |
| 3631 | { |
| 3632 | }; |
| 3633 | |
| 3634 | #else |
| 3635 | |
| 3636 | template <class _Tp> struct __libcpp_nothrow_destructor |
| 3637 | : public integral_constant<bool, is_scalar<_Tp>::value || |
| 3638 | is_reference<_Tp>::value> {}; |
| 3639 | |
| 3640 | template <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 | |
| 3643 | template <class _Tp> |
| 3644 | struct _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) |
| 3650 | template <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 | |
| 3659 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_pod |
| 3660 | : public integral_constant<bool, __is_pod(_Tp)> {}; |
| 3661 | |
| 3662 | #else |
| 3663 | |
| 3664 | template <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) |
| 3673 | template <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) |
| 3681 | template <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) |
| 3686 | template <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 | |
| 3694 | template <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) |
| 3703 | template <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 | |
| 3710 | template <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) |
| 3721 | template <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 | |
| 3728 | template <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) |
| 3738 | template <class _Tp> |
| 3739 | _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool is_trivial_v |
| 3740 | = is_trivial<_Tp>::value; |
| 3741 | #endif |
| 3742 | |
| 3743 | template <class _Tp> struct __is_reference_wrapper_impl : public false_type {}; |
| 3744 | template <class _Tp> struct __is_reference_wrapper_impl<reference_wrapper<_Tp> > : public true_type {}; |
| 3745 | template <class _Tp> struct __is_reference_wrapper |
| 3746 | : public __is_reference_wrapper_impl<typename remove_cv<_Tp>::type> {}; |
| 3747 | |
| 3748 | #ifndef _LIBCPP_CXX03_LANG |
| 3749 | |
| 3750 | template <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> |
| 3754 | using __enable_if_bullet1 = typename enable_if |
| 3755 | < |
| 3756 | is_member_function_pointer<_DecayFp>::value |
| 3757 | && is_base_of<_ClassT, _DecayA0>::value |
| 3758 | >::type; |
| 3759 | |
| 3760 | template <class _Fp, class _A0, |
| 3761 | class _DecayFp = typename decay<_Fp>::type, |
| 3762 | class _DecayA0 = typename decay<_A0>::type> |
| 3763 | using __enable_if_bullet2 = typename enable_if |
| 3764 | < |
| 3765 | is_member_function_pointer<_DecayFp>::value |
| 3766 | && __is_reference_wrapper<_DecayA0>::value |
| 3767 | >::type; |
| 3768 | |
| 3769 | template <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> |
| 3773 | using __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 | |
| 3780 | template <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> |
| 3784 | using __enable_if_bullet4 = typename enable_if |
| 3785 | < |
| 3786 | is_member_object_pointer<_DecayFp>::value |
| 3787 | && is_base_of<_ClassT, _DecayA0>::value |
| 3788 | >::type; |
| 3789 | |
| 3790 | template <class _Fp, class _A0, |
| 3791 | class _DecayFp = typename decay<_Fp>::type, |
| 3792 | class _DecayA0 = typename decay<_A0>::type> |
| 3793 | using __enable_if_bullet5 = typename enable_if |
| 3794 | < |
| 3795 | is_member_object_pointer<_DecayFp>::value |
| 3796 | && __is_reference_wrapper<_DecayA0>::value |
| 3797 | >::type; |
| 3798 | |
| 3799 | template <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> |
| 3803 | using __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 | |
| 3818 | template <class ..._Args> |
| 3819 | auto __invoke(__any, _Args&& ...__args) -> __nat; |
| 3820 | |
| 3821 | template <class ..._Args> |
| 3822 | auto __invoke_constexpr(__any, _Args&& ...__args) -> __nat; |
| 3823 | |
| 3824 | // bullets 1, 2 and 3 |
| 3825 | |
| 3826 | template <class _Fp, class _A0, class ..._Args, |
| 3827 | class = __enable_if_bullet1<_Fp, _A0>> |
| 3828 | inline _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 | |
| 3833 | template <class _Fp, class _A0, class ..._Args, |
| 3834 | class = __enable_if_bullet1<_Fp, _A0>> |
| 3835 | inline _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 | |
| 3840 | template <class _Fp, class _A0, class ..._Args, |
| 3841 | class = __enable_if_bullet2<_Fp, _A0>> |
| 3842 | inline _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 | |
| 3847 | template <class _Fp, class _A0, class ..._Args, |
| 3848 | class = __enable_if_bullet2<_Fp, _A0>> |
| 3849 | inline _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 | |
| 3854 | template <class _Fp, class _A0, class ..._Args, |
| 3855 | class = __enable_if_bullet3<_Fp, _A0>> |
| 3856 | inline _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 | |
| 3861 | template <class _Fp, class _A0, class ..._Args, |
| 3862 | class = __enable_if_bullet3<_Fp, _A0>> |
| 3863 | inline _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 | |
| 3870 | template <class _Fp, class _A0, |
| 3871 | class = __enable_if_bullet4<_Fp, _A0>> |
| 3872 | inline _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 | |
| 3877 | template <class _Fp, class _A0, |
| 3878 | class = __enable_if_bullet4<_Fp, _A0>> |
| 3879 | inline _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 | |
| 3884 | template <class _Fp, class _A0, |
| 3885 | class = __enable_if_bullet5<_Fp, _A0>> |
| 3886 | inline _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 | |
| 3891 | template <class _Fp, class _A0, |
| 3892 | class = __enable_if_bullet5<_Fp, _A0>> |
| 3893 | inline _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 | |
| 3898 | template <class _Fp, class _A0, |
| 3899 | class = __enable_if_bullet6<_Fp, _A0>> |
| 3900 | inline _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 | |
| 3905 | template <class _Fp, class _A0, |
| 3906 | class = __enable_if_bullet6<_Fp, _A0>> |
| 3907 | inline _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 | |
| 3914 | template <class _Fp, class ..._Args> |
| 3915 | inline _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)...)) |
| 3919 | |
| 3920 | template <class _Fp, class ..._Args> |
| 3921 | inline _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 |
| 3929 | template <class _Ret, class _Fp, class ..._Args> |
| 3930 | struct __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 | }; |
| 3954 | template <class _Fp, class ..._Args> |
| 3955 | using __invokable = __invokable_r<void, _Fp, _Args...>; |
| 3956 | |
| 3957 | template <bool _IsInvokable, bool _IsCVVoid, class _Ret, class _Fp, class ..._Args> |
| 3958 | struct __nothrow_invokable_r_imp { |
| 3959 | static const bool value = false; |
| 3960 | }; |
| 3961 | |
| 3962 | template <class _Ret, class _Fp, class ..._Args> |
| 3963 | struct __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 | |
| 3974 | template <class _Ret, class _Fp, class ..._Args> |
| 3975 | struct __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 | |
| 3981 | template <class _Ret, class _Fp, class ..._Args> |
| 3982 | using __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 | |
| 3989 | template <class _Fp, class ..._Args> |
| 3990 | using __nothrow_invokable = |
| 3991 | __nothrow_invokable_r_imp< |
| 3992 | __invokable<_Fp, _Args...>::value, |
| 3993 | true, void, _Fp, _Args... |
| 3994 | >; |
| 3995 | |
| 3996 | template <class _Fp, class ..._Args> |
| 3997 | struct __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) |
| 4009 | template <class _Callable> class _LIBCPP_DEPRECATED_IN_CXX17 result_of; |
| 4010 | |
| 4011 | #ifndef _LIBCPP_CXX03_LANG |
| 4012 | |
| 4013 | template <class _Fp, class ..._Args> |
| 4014 | class _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 | |
| 4021 | template <class _Fn, bool, bool> |
| 4022 | class __result_of |
| 4023 | { |
| 4024 | }; |
| 4025 | |
| 4026 | template <class _Fn, class ..._Args> |
| 4027 | class __result_of<_Fn(_Args...), true, false> |
| 4028 | { |
| 4029 | public: |
| 4030 | typedef decltype(declval<_Fn>()(declval<_Args>()...)) type; |
| 4031 | }; |
| 4032 | |
| 4033 | template <class _MP, class _Tp, bool _IsMemberFunctionPtr> |
| 4034 | struct __result_of_mp; |
| 4035 | |
| 4036 | // member function pointer |
| 4037 | |
| 4038 | template <class _MP, class _Tp> |
| 4039 | struct __result_of_mp<_MP, _Tp, true> |
| 4040 | { |
| 4041 | using type = typename __member_pointer_traits<_MP>::_ReturnType; |
| 4042 | }; |
| 4043 | |
| 4044 | // member data pointer |
| 4045 | |
| 4046 | template <class _MP, class _Tp, bool> |
| 4047 | struct __result_of_mdp; |
| 4048 | |
| 4049 | template <class _Rp, class _Class, class _Tp> |
| 4050 | struct __result_of_mdp<_Rp _Class::*, _Tp, false> |
| 4051 | { |
| 4052 | using type = typename __apply_cv<decltype(*declval<_Tp>()), _Rp>::type&; |
| 4053 | }; |
| 4054 | |
| 4055 | template <class _Rp, class _Class, class _Tp> |
| 4056 | struct __result_of_mdp<_Rp _Class::*, _Tp, true> |
| 4057 | { |
| 4058 | using type = typename __apply_cv<_Tp, _Rp>::type&; |
| 4059 | }; |
| 4060 | |
| 4061 | template <class _Rp, class _Class, class _Tp> |
| 4062 | struct __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 | |
| 4068 | template <class _Fn, class _Tp> |
| 4069 | class __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 | |
| 4076 | template <class _Fn, class _Tp, class ..._Args> |
| 4077 | class __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 | |
| 4084 | template <class _Fn, class ..._Args> |
| 4085 | class _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 |
| 4097 | template <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 | |
| 4105 | template <class _Fn, class... _Args> |
| 4106 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) invoke_result |
| 4107 | : __invoke_of<_Fn, _Args...> |
| 4108 | { |
| 4109 | }; |
| 4110 | |
| 4111 | template <class _Fn, class... _Args> |
| 4112 | using invoke_result_t = typename invoke_result<_Fn, _Args...>::type; |
| 4113 | |
| 4114 | // is_invocable |
| 4115 | |
| 4116 | template <class _Fn, class ..._Args> |
| 4117 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_invocable |
| 4118 | : integral_constant<bool, __invokable<_Fn, _Args...>::value> {}; |
| 4119 | |
| 4120 | template <class _Ret, class _Fn, class ..._Args> |
| 4121 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_invocable_r |
| 4122 | : integral_constant<bool, __invokable_r<_Ret, _Fn, _Args...>::value> {}; |
| 4123 | |
| 4124 | template <class _Fn, class ..._Args> |
| 4125 | _LIBCPP_INLINE_VAR constexpr bool is_invocable_v |
| 4126 | = is_invocable<_Fn, _Args...>::value; |
| 4127 | |
| 4128 | template <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 | |
| 4134 | template <class _Fn, class ..._Args> |
| 4135 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_nothrow_invocable |
| 4136 | : integral_constant<bool, __nothrow_invokable<_Fn, _Args...>::value> {}; |
| 4137 | |
| 4138 | template <class _Ret, class _Fn, class ..._Args> |
| 4139 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_nothrow_invocable_r |
| 4140 | : integral_constant<bool, __nothrow_invokable_r<_Ret, _Fn, _Args...>::value> {}; |
| 4141 | |
| 4142 | template <class _Fn, class ..._Args> |
| 4143 | _LIBCPP_INLINE_VAR constexpr bool is_nothrow_invocable_v |
| 4144 | = is_nothrow_invocable<_Fn, _Args...>::value; |
| 4145 | |
| 4146 | template <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 | |
| 4154 | template <class _Tp> struct __is_swappable; |
| 4155 | template <class _Tp> struct __is_nothrow_swappable; |
| 4156 | |
| 4157 | |
| 4158 | #ifndef _LIBCPP_CXX03_LANG |
| 4159 | template <class _Tp> |
| 4160 | using __swap_result_t = typename enable_if<is_move_constructible<_Tp>::value && is_move_assignable<_Tp>::value>::type; |
| 4161 | #else |
| 4162 | template <class> |
| 4163 | using __swap_result_t = void; |
| 4164 | #endif |
| 4165 | |
| 4166 | template <class _Tp> |
| 4167 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 4168 | _LIBCPP_CONSTEXPR_AFTER_CXX17 __swap_result_t<_Tp> |
| 4169 | swap(_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 | |
| 4172 | template<class _Tp, size_t _Np> |
| 4173 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPR_AFTER_CXX17 |
| 4174 | typename enable_if< |
| 4175 | __is_swappable<_Tp>::value |
| 4176 | >::type |
| 4177 | swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value)noexcept(__is_nothrow_swappable<_Tp>::value); |
| 4178 | |
| 4179 | namespace __detail |
| 4180 | { |
| 4181 | // ALL generic swap overloads MUST already have a declaration available at this point. |
| 4182 | |
| 4183 | template <class _Tp, class _Up = _Tp, |
| 4184 | bool _NotVoid = !is_void<_Tp>::value && !is_void<_Up>::value> |
| 4185 | struct __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 | |
| 4201 | template <class _Tp, class _Up> |
| 4202 | struct __swappable_with<_Tp, _Up, false> : false_type {}; |
| 4203 | |
| 4204 | template <class _Tp, class _Up = _Tp, bool _Swappable = __swappable_with<_Tp, _Up>::value> |
| 4205 | struct __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 | |
| 4215 | template <class _Tp, class _Up> |
| 4216 | struct __nothrow_swappable_with<_Tp, _Up, false> : false_type {}; |
| 4217 | |
| 4218 | } // __detail |
| 4219 | |
| 4220 | template <class _Tp> |
| 4221 | struct __is_swappable |
| 4222 | : public integral_constant<bool, __detail::__swappable_with<_Tp&>::value> |
| 4223 | { |
| 4224 | }; |
| 4225 | |
| 4226 | template <class _Tp> |
| 4227 | struct __is_nothrow_swappable |
| 4228 | : public integral_constant<bool, __detail::__nothrow_swappable_with<_Tp&>::value> |
| 4229 | { |
| 4230 | }; |
| 4231 | |
| 4232 | #if _LIBCPP_STD_VER14 > 14 |
| 4233 | |
| 4234 | template <class _Tp, class _Up> |
| 4235 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_swappable_with |
| 4236 | : public integral_constant<bool, __detail::__swappable_with<_Tp, _Up>::value> |
| 4237 | { |
| 4238 | }; |
| 4239 | |
| 4240 | template <class _Tp> |
| 4241 | struct _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 | |
| 4252 | template <class _Tp, class _Up> |
| 4253 | struct _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 | |
| 4258 | template <class _Tp> |
| 4259 | struct _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 | |
| 4270 | template <class _Tp, class _Up> |
| 4271 | _LIBCPP_INLINE_VAR constexpr bool is_swappable_with_v |
| 4272 | = is_swappable_with<_Tp, _Up>::value; |
| 4273 | |
| 4274 | template <class _Tp> |
| 4275 | _LIBCPP_INLINE_VAR constexpr bool is_swappable_v |
| 4276 | = is_swappable<_Tp>::value; |
| 4277 | |
| 4278 | template <class _Tp, class _Up> |
| 4279 | _LIBCPP_INLINE_VAR constexpr bool is_nothrow_swappable_with_v |
| 4280 | = is_nothrow_swappable_with<_Tp, _Up>::value; |
| 4281 | |
| 4282 | template <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 | |
| 4288 | template <class _Tp, bool = is_enum<_Tp>::value> struct __underlying_type_impl; |
| 4289 | |
| 4290 | template <class _Tp> |
| 4291 | struct __underlying_type_impl<_Tp, false> {}; |
| 4292 | |
| 4293 | template <class _Tp> |
| 4294 | struct __underlying_type_impl<_Tp, true> |
| 4295 | { |
| 4296 | typedef __underlying_type(_Tp) type; |
| 4297 | }; |
| 4298 | |
| 4299 | template <class _Tp> |
| 4300 | struct underlying_type : __underlying_type_impl<_Tp, is_enum<_Tp>::value> {}; |
| 4301 | |
| 4302 | #if _LIBCPP_STD_VER14 > 11 |
| 4303 | template <class _Tp> using underlying_type_t = typename underlying_type<_Tp>::type; |
| 4304 | #endif |
| 4305 | |
| 4306 | template <class _Tp, bool = is_enum<_Tp>::value> |
| 4307 | struct __sfinae_underlying_type |
| 4308 | { |
| 4309 | typedef typename underlying_type<_Tp>::type type; |
| 4310 | typedef decltype(((type)1) + 0) __promoted_type; |
| 4311 | }; |
| 4312 | |
| 4313 | template <class _Tp> |
| 4314 | struct __sfinae_underlying_type<_Tp, false> {}; |
| 4315 | |
| 4316 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPRconstexpr |
| 4317 | int __convert_to_integral(int __val) { return __val; } |
| 4318 | |
| 4319 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPRconstexpr |
| 4320 | unsigned __convert_to_integral(unsigned __val) { return __val; } |
| 4321 | |
| 4322 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPRconstexpr |
| 4323 | long __convert_to_integral(long __val) { return __val; } |
| 4324 | |
| 4325 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPRconstexpr |
| 4326 | unsigned long __convert_to_integral(unsigned long __val) { return __val; } |
| 4327 | |
| 4328 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPRconstexpr |
| 4329 | long long __convert_to_integral(long long __val) { return __val; } |
| 4330 | |
| 4331 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPRconstexpr |
| 4332 | unsigned long long __convert_to_integral(unsigned long long __val) {return __val; } |
| 4333 | |
| 4334 | template<typename _Fp> |
| 4335 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPRconstexpr |
| 4336 | typename 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 |
| 4340 | inline _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 | |
| 4343 | inline _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 | |
| 4347 | template <class _Tp> |
| 4348 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPRconstexpr |
| 4349 | typename __sfinae_underlying_type<_Tp>::__promoted_type |
| 4350 | __convert_to_integral(_Tp __val) { return __val; } |
| 4351 | |
| 4352 | #ifndef _LIBCPP_CXX03_LANG |
| 4353 | |
| 4354 | template <class _Tp> |
| 4355 | struct __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 | |
| 4366 | template <class _Tp> |
| 4367 | struct __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 | |
| 4378 | template <class _Tp> |
| 4379 | struct __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 |
| 4389 | template <class _Tp, bool = is_enum_v<_Tp> > |
| 4390 | struct __is_scoped_enum_helper : false_type {}; |
| 4391 | |
| 4392 | template <class _Tp> |
| 4393 | struct __is_scoped_enum_helper<_Tp, true> |
| 4394 | : public bool_constant<!is_convertible_v<_Tp, underlying_type_t<_Tp> > > {}; |
| 4395 | |
| 4396 | template <class _Tp> |
| 4397 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) is_scoped_enum |
| 4398 | : public __is_scoped_enum_helper<_Tp> {}; |
| 4399 | |
| 4400 | template <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 | |
| 4407 | template <class... _Args> |
| 4408 | struct conjunction : _And<_Args...> {}; |
| 4409 | template<class... _Args> |
| 4410 | _LIBCPP_INLINE_VAR constexpr bool conjunction_v |
| 4411 | = conjunction<_Args...>::value; |
| 4412 | |
| 4413 | template <class... _Args> |
| 4414 | struct disjunction : _Or<_Args...> {}; |
| 4415 | template<class... _Args> |
| 4416 | _LIBCPP_INLINE_VAR constexpr bool disjunction_v |
| 4417 | = disjunction<_Args...>::value; |
| 4418 | |
| 4419 | template <class _Tp> |
| 4420 | struct negation : _Not<_Tp> {}; |
| 4421 | template<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 |
| 4427 | struct __extract_key_fail_tag {}; |
| 4428 | struct __extract_key_self_tag {}; |
| 4429 | struct __extract_key_first_tag {}; |
| 4430 | |
| 4431 | template <class _ValTy, class _Key, |
| 4432 | class _RawValTy = typename __unconstref<_ValTy>::type> |
| 4433 | struct __can_extract_key |
| 4434 | : conditional<_IsSame<_RawValTy, _Key>::value, __extract_key_self_tag, |
| 4435 | __extract_key_fail_tag>::type {}; |
| 4436 | |
| 4437 | template <class _Pair, class _Key, class _First, class _Second> |
| 4438 | struct __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. |
| 4445 | template <class _ValTy, class _Key, class _ContainerValueTy, |
| 4446 | class _RawValTy = typename __unconstref<_ValTy>::type> |
| 4447 | struct __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 |
| 4452 | template <class _ValTy, class _Key, class _RawValTy> |
| 4453 | struct __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__ )) |
| 4459 | inline constexpr bool is_constant_evaluated() noexcept { |
| 4460 | return __builtin_is_constant_evaluated(); |
| 4461 | } |
| 4462 | #endif |
| 4463 | |
| 4464 | inline _LIBCPP_CONSTEXPRconstexpr |
| 4465 | bool __libcpp_is_constant_evaluated() _NOEXCEPTnoexcept { return __builtin_is_constant_evaluated(); } |
| 4466 | #else |
| 4467 | inline _LIBCPP_CONSTEXPRconstexpr |
| 4468 | bool __libcpp_is_constant_evaluated() _NOEXCEPTnoexcept { return false; } |
| 4469 | #endif |
| 4470 | |
| 4471 | template <class _CharT> |
| 4472 | using _IsCharLikeType = _And<is_standard_layout<_CharT>, is_trivial<_CharT> >; |
| 4473 | |
| 4474 | template<class _Tp> |
| 4475 | using __make_const_lvalue_ref = const typename remove_reference<_Tp>::type&; |
| 4476 | |
| 4477 | #if _LIBCPP_STD_VER14 > 17 |
| 4478 | template<bool _Const, class _Tp> |
| 4479 | using __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 |
| 4486 | namespace std // purposefully not versioned |
| 4487 | { |
| 4488 | |
| 4489 | |
| 4490 | } |
| 4491 | #endif |
| 4492 | |
| 4493 | #endif // _LIBCPP_TYPE_TRAITS |
| 1 | // -*- C++ -*- |
| 2 | //===---------------------------- chrono ----------------------------------===// |
| 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_CHRONO |
| 11 | #define _LIBCPP_CHRONO |
| 12 | |
| 13 | /* |
| 14 | chrono synopsis |
| 15 | |
| 16 | namespace std |
| 17 | { |
| 18 | namespace chrono |
| 19 | { |
| 20 | |
| 21 | template <class ToDuration, class Rep, class Period> |
| 22 | constexpr |
| 23 | ToDuration |
| 24 | duration_cast(const duration<Rep, Period>& fd); |
| 25 | |
| 26 | template <class Rep> struct treat_as_floating_point : is_floating_point<Rep> {}; |
| 27 | |
| 28 | template <class Rep> inline constexpr bool treat_as_floating_point_v |
| 29 | = treat_as_floating_point<Rep>::value; // C++17 |
| 30 | |
| 31 | template <class Rep> |
| 32 | struct duration_values |
| 33 | { |
| 34 | public: |
| 35 | static constexpr Rep zero(); // noexcept in C++20 |
| 36 | static constexpr Rep max(); // noexcept in C++20 |
| 37 | static constexpr Rep min(); // noexcept in C++20 |
| 38 | }; |
| 39 | |
| 40 | // duration |
| 41 | |
| 42 | template <class Rep, class Period = ratio<1>> |
| 43 | class duration |
| 44 | { |
| 45 | static_assert(!__is_duration<Rep>::value, "A duration representation can not be a duration"); |
| 46 | static_assert(__is_ratio<Period>::value, "Second template parameter of duration must be a std::ratio"); |
| 47 | static_assert(Period::num > 0, "duration period must be positive"); |
| 48 | public: |
| 49 | typedef Rep rep; |
| 50 | typedef typename _Period::type period; |
| 51 | |
| 52 | constexpr duration() = default; |
| 53 | template <class Rep2> |
| 54 | constexpr explicit duration(const Rep2& r, |
| 55 | typename enable_if |
| 56 | < |
| 57 | is_convertible<Rep2, rep>::value && |
| 58 | (treat_as_floating_point<rep>::value || |
| 59 | !treat_as_floating_point<rep>::value && !treat_as_floating_point<Rep2>::value) |
| 60 | >::type* = 0); |
| 61 | |
| 62 | // conversions |
| 63 | template <class Rep2, class Period2> |
| 64 | constexpr duration(const duration<Rep2, Period2>& d, |
| 65 | typename enable_if |
| 66 | < |
| 67 | treat_as_floating_point<rep>::value || |
| 68 | ratio_divide<Period2, period>::type::den == 1 |
| 69 | >::type* = 0); |
| 70 | |
| 71 | // observer |
| 72 | |
| 73 | constexpr rep count() const; |
| 74 | |
| 75 | // arithmetic |
| 76 | |
| 77 | constexpr common_type<duration>::type operator+() const; |
| 78 | constexpr common_type<duration>::type operator-() const; |
| 79 | constexpr duration& operator++(); // constexpr in C++17 |
| 80 | constexpr duration operator++(int); // constexpr in C++17 |
| 81 | constexpr duration& operator--(); // constexpr in C++17 |
| 82 | constexpr duration operator--(int); // constexpr in C++17 |
| 83 | |
| 84 | constexpr duration& operator+=(const duration& d); // constexpr in C++17 |
| 85 | constexpr duration& operator-=(const duration& d); // constexpr in C++17 |
| 86 | |
| 87 | duration& operator*=(const rep& rhs); // constexpr in C++17 |
| 88 | duration& operator/=(const rep& rhs); // constexpr in C++17 |
| 89 | duration& operator%=(const rep& rhs); // constexpr in C++17 |
| 90 | duration& operator%=(const duration& rhs); // constexpr in C++17 |
| 91 | |
| 92 | // special values |
| 93 | |
| 94 | static constexpr duration zero(); // noexcept in C++20 |
| 95 | static constexpr duration min(); // noexcept in C++20 |
| 96 | static constexpr duration max(); // noexcept in C++20 |
| 97 | }; |
| 98 | |
| 99 | typedef duration<long long, nano> nanoseconds; |
| 100 | typedef duration<long long, micro> microseconds; |
| 101 | typedef duration<long long, milli> milliseconds; |
| 102 | typedef duration<long long > seconds; |
| 103 | typedef duration< long, ratio< 60> > minutes; |
| 104 | typedef duration< long, ratio<3600> > hours; |
| 105 | |
| 106 | template <class Clock, class Duration = typename Clock::duration> |
| 107 | class time_point |
| 108 | { |
| 109 | public: |
| 110 | typedef Clock clock; |
| 111 | typedef Duration duration; |
| 112 | typedef typename duration::rep rep; |
| 113 | typedef typename duration::period period; |
| 114 | private: |
| 115 | duration d_; // exposition only |
| 116 | |
| 117 | public: |
| 118 | time_point(); // has value "epoch" // constexpr in C++14 |
| 119 | explicit time_point(const duration& d); // same as time_point() + d // constexpr in C++14 |
| 120 | |
| 121 | // conversions |
| 122 | template <class Duration2> |
| 123 | time_point(const time_point<clock, Duration2>& t); // constexpr in C++14 |
| 124 | |
| 125 | // observer |
| 126 | |
| 127 | duration time_since_epoch() const; // constexpr in C++14 |
| 128 | |
| 129 | // arithmetic |
| 130 | |
| 131 | time_point& operator+=(const duration& d); // constexpr in C++17 |
| 132 | time_point& operator-=(const duration& d); // constexpr in C++17 |
| 133 | |
| 134 | // special values |
| 135 | |
| 136 | static constexpr time_point min(); // noexcept in C++20 |
| 137 | static constexpr time_point max(); // noexcept in C++20 |
| 138 | }; |
| 139 | |
| 140 | } // chrono |
| 141 | |
| 142 | // common_type traits |
| 143 | template <class Rep1, class Period1, class Rep2, class Period2> |
| 144 | struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2>>; |
| 145 | |
| 146 | template <class Clock, class Duration1, class Duration2> |
| 147 | struct common_type<chrono::time_point<Clock, Duration1>, chrono::time_point<Clock, Duration2>>; |
| 148 | |
| 149 | namespace chrono { |
| 150 | |
| 151 | |
| 152 | template<class T> struct is_clock; // C++20 |
| 153 | template<class T> inline constexpr bool is_clock_v = is_clock<T>::value; // C++20 |
| 154 | |
| 155 | |
| 156 | // duration arithmetic |
| 157 | template <class Rep1, class Period1, class Rep2, class Period2> |
| 158 | constexpr |
| 159 | typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type |
| 160 | operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); |
| 161 | template <class Rep1, class Period1, class Rep2, class Period2> |
| 162 | constexpr |
| 163 | typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type |
| 164 | operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); |
| 165 | template <class Rep1, class Period, class Rep2> |
| 166 | constexpr |
| 167 | duration<typename common_type<Rep1, Rep2>::type, Period> |
| 168 | operator*(const duration<Rep1, Period>& d, const Rep2& s); |
| 169 | template <class Rep1, class Period, class Rep2> |
| 170 | constexpr |
| 171 | duration<typename common_type<Rep1, Rep2>::type, Period> |
| 172 | operator*(const Rep1& s, const duration<Rep2, Period>& d); |
| 173 | template <class Rep1, class Period, class Rep2> |
| 174 | constexpr |
| 175 | duration<typename common_type<Rep1, Rep2>::type, Period> |
| 176 | operator/(const duration<Rep1, Period>& d, const Rep2& s); |
| 177 | template <class Rep1, class Period1, class Rep2, class Period2> |
| 178 | constexpr |
| 179 | typename common_type<Rep1, Rep2>::type |
| 180 | operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); |
| 181 | |
| 182 | // duration comparisons |
| 183 | template <class Rep1, class Period1, class Rep2, class Period2> |
| 184 | constexpr |
| 185 | bool operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); |
| 186 | template <class Rep1, class Period1, class Rep2, class Period2> |
| 187 | constexpr |
| 188 | bool operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); |
| 189 | template <class Rep1, class Period1, class Rep2, class Period2> |
| 190 | constexpr |
| 191 | bool operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); |
| 192 | template <class Rep1, class Period1, class Rep2, class Period2> |
| 193 | constexpr |
| 194 | bool operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); |
| 195 | template <class Rep1, class Period1, class Rep2, class Period2> |
| 196 | constexpr |
| 197 | bool operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); |
| 198 | template <class Rep1, class Period1, class Rep2, class Period2> |
| 199 | constexpr |
| 200 | bool operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); |
| 201 | |
| 202 | // duration_cast |
| 203 | template <class ToDuration, class Rep, class Period> |
| 204 | ToDuration duration_cast(const duration<Rep, Period>& d); |
| 205 | |
| 206 | template <class ToDuration, class Rep, class Period> |
| 207 | constexpr ToDuration floor(const duration<Rep, Period>& d); // C++17 |
| 208 | template <class ToDuration, class Rep, class Period> |
| 209 | constexpr ToDuration ceil(const duration<Rep, Period>& d); // C++17 |
| 210 | template <class ToDuration, class Rep, class Period> |
| 211 | constexpr ToDuration round(const duration<Rep, Period>& d); // C++17 |
| 212 | |
| 213 | // duration I/O is elsewhere |
| 214 | |
| 215 | // time_point arithmetic (all constexpr in C++14) |
| 216 | template <class Clock, class Duration1, class Rep2, class Period2> |
| 217 | time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type> |
| 218 | operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs); |
| 219 | template <class Rep1, class Period1, class Clock, class Duration2> |
| 220 | time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type> |
| 221 | operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs); |
| 222 | template <class Clock, class Duration1, class Rep2, class Period2> |
| 223 | time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type> |
| 224 | operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs); |
| 225 | template <class Clock, class Duration1, class Duration2> |
| 226 | typename common_type<Duration1, Duration2>::type |
| 227 | operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); |
| 228 | |
| 229 | // time_point comparisons (all constexpr in C++14) |
| 230 | template <class Clock, class Duration1, class Duration2> |
| 231 | bool operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); |
| 232 | template <class Clock, class Duration1, class Duration2> |
| 233 | bool operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); |
| 234 | template <class Clock, class Duration1, class Duration2> |
| 235 | bool operator< (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); |
| 236 | template <class Clock, class Duration1, class Duration2> |
| 237 | bool operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); |
| 238 | template <class Clock, class Duration1, class Duration2> |
| 239 | bool operator> (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); |
| 240 | template <class Clock, class Duration1, class Duration2> |
| 241 | bool operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); |
| 242 | |
| 243 | // time_point_cast (constexpr in C++14) |
| 244 | |
| 245 | template <class ToDuration, class Clock, class Duration> |
| 246 | time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t); |
| 247 | |
| 248 | template <class ToDuration, class Clock, class Duration> |
| 249 | constexpr time_point<Clock, ToDuration> |
| 250 | floor(const time_point<Clock, Duration>& tp); // C++17 |
| 251 | |
| 252 | template <class ToDuration, class Clock, class Duration> |
| 253 | constexpr time_point<Clock, ToDuration> |
| 254 | ceil(const time_point<Clock, Duration>& tp); // C++17 |
| 255 | |
| 256 | template <class ToDuration, class Clock, class Duration> |
| 257 | constexpr time_point<Clock, ToDuration> |
| 258 | round(const time_point<Clock, Duration>& tp); // C++17 |
| 259 | |
| 260 | template <class Rep, class Period> |
| 261 | constexpr duration<Rep, Period> abs(duration<Rep, Period> d); // C++17 |
| 262 | |
| 263 | // Clocks |
| 264 | |
| 265 | class system_clock |
| 266 | { |
| 267 | public: |
| 268 | typedef microseconds duration; |
| 269 | typedef duration::rep rep; |
| 270 | typedef duration::period period; |
| 271 | typedef chrono::time_point<system_clock> time_point; |
| 272 | static const bool is_steady = false; // constexpr in C++14 |
| 273 | |
| 274 | static time_point now() noexcept; |
| 275 | static time_t to_time_t (const time_point& __t) noexcept; |
| 276 | static time_point from_time_t(time_t __t) noexcept; |
| 277 | }; |
| 278 | |
| 279 | template <class Duration> |
| 280 | using sys_time = time_point<system_clock, Duration>; // C++20 |
| 281 | using sys_seconds = sys_time<seconds>; // C++20 |
| 282 | using sys_days = sys_time<days>; // C++20 |
| 283 | |
| 284 | class utc_clock; // C++20 |
| 285 | |
| 286 | template <class Duration> |
| 287 | using utc_time = time_point<utc_clock, Duration>; // C++20 |
| 288 | using utc_seconds = utc_time<seconds>; // C++20 |
| 289 | |
| 290 | class tai_clock; // C++20 |
| 291 | |
| 292 | template <class Duration> |
| 293 | using tai_time = time_point<tai_clock, Duration>; // C++20 |
| 294 | using tai_seconds = tai_time<seconds>; // C++20 |
| 295 | |
| 296 | class file_clock; // C++20 |
| 297 | |
| 298 | template<class Duration> |
| 299 | using file_time = time_point<file_clock, Duration>; // C++20 |
| 300 | |
| 301 | class steady_clock |
| 302 | { |
| 303 | public: |
| 304 | typedef nanoseconds duration; |
| 305 | typedef duration::rep rep; |
| 306 | typedef duration::period period; |
| 307 | typedef chrono::time_point<steady_clock, duration> time_point; |
| 308 | static const bool is_steady = true; // constexpr in C++14 |
| 309 | |
| 310 | static time_point now() noexcept; |
| 311 | }; |
| 312 | |
| 313 | typedef steady_clock high_resolution_clock; |
| 314 | |
| 315 | // 25.7.8, local time // C++20 |
| 316 | struct local_t {}; |
| 317 | template<class Duration> |
| 318 | using local_time = time_point<local_t, Duration>; |
| 319 | using local_seconds = local_time<seconds>; |
| 320 | using local_days = local_time<days>; |
| 321 | |
| 322 | // 25.7.9, time_point conversions template<class DestClock, class SourceClock> // C++20 |
| 323 | struct clock_time_conversion; |
| 324 | |
| 325 | template<class DestClock, class SourceClock, class Duration> |
| 326 | auto clock_cast(const time_point<SourceClock, Duration>& t); |
| 327 | |
| 328 | // 25.8.2, class last_spec // C++20 |
| 329 | struct last_spec; |
| 330 | |
| 331 | // 25.8.3, class day // C++20 |
| 332 | |
| 333 | class day; |
| 334 | constexpr bool operator==(const day& x, const day& y) noexcept; |
| 335 | constexpr bool operator!=(const day& x, const day& y) noexcept; |
| 336 | constexpr bool operator< (const day& x, const day& y) noexcept; |
| 337 | constexpr bool operator> (const day& x, const day& y) noexcept; |
| 338 | constexpr bool operator<=(const day& x, const day& y) noexcept; |
| 339 | constexpr bool operator>=(const day& x, const day& y) noexcept; |
| 340 | constexpr day operator+(const day& x, const days& y) noexcept; |
| 341 | constexpr day operator+(const days& x, const day& y) noexcept; |
| 342 | constexpr day operator-(const day& x, const days& y) noexcept; |
| 343 | constexpr days operator-(const day& x, const day& y) noexcept; |
| 344 | |
| 345 | // 25.8.4, class month // C++20 |
| 346 | class month; |
| 347 | constexpr bool operator==(const month& x, const month& y) noexcept; |
| 348 | constexpr bool operator!=(const month& x, const month& y) noexcept; |
| 349 | constexpr bool operator< (const month& x, const month& y) noexcept; |
| 350 | constexpr bool operator> (const month& x, const month& y) noexcept; |
| 351 | constexpr bool operator<=(const month& x, const month& y) noexcept; |
| 352 | constexpr bool operator>=(const month& x, const month& y) noexcept; |
| 353 | constexpr month operator+(const month& x, const months& y) noexcept; |
| 354 | constexpr month operator+(const months& x, const month& y) noexcept; |
| 355 | constexpr month operator-(const month& x, const months& y) noexcept; |
| 356 | constexpr months operator-(const month& x, const month& y) noexcept; |
| 357 | |
| 358 | // 25.8.5, class year // C++20 |
| 359 | class year; |
| 360 | constexpr bool operator==(const year& x, const year& y) noexcept; |
| 361 | constexpr bool operator!=(const year& x, const year& y) noexcept; |
| 362 | constexpr bool operator< (const year& x, const year& y) noexcept; |
| 363 | constexpr bool operator> (const year& x, const year& y) noexcept; |
| 364 | constexpr bool operator<=(const year& x, const year& y) noexcept; |
| 365 | constexpr bool operator>=(const year& x, const year& y) noexcept; |
| 366 | constexpr year operator+(const year& x, const years& y) noexcept; |
| 367 | constexpr year operator+(const years& x, const year& y) noexcept; |
| 368 | constexpr year operator-(const year& x, const years& y) noexcept; |
| 369 | constexpr years operator-(const year& x, const year& y) noexcept; |
| 370 | |
| 371 | // 25.8.6, class weekday // C++20 |
| 372 | class weekday; |
| 373 | |
| 374 | constexpr bool operator==(const weekday& x, const weekday& y) noexcept; |
| 375 | constexpr bool operator!=(const weekday& x, const weekday& y) noexcept; |
| 376 | constexpr weekday operator+(const weekday& x, const days& y) noexcept; |
| 377 | constexpr weekday operator+(const days& x, const weekday& y) noexcept; |
| 378 | constexpr weekday operator-(const weekday& x, const days& y) noexcept; |
| 379 | constexpr days operator-(const weekday& x, const weekday& y) noexcept; |
| 380 | |
| 381 | // 25.8.7, class weekday_indexed // C++20 |
| 382 | |
| 383 | class weekday_indexed; |
| 384 | constexpr bool operator==(const weekday_indexed& x, const weekday_indexed& y) noexcept; |
| 385 | constexpr bool operator!=(const weekday_indexed& x, const weekday_indexed& y) noexcept; |
| 386 | |
| 387 | // 25.8.8, class weekday_last // C++20 |
| 388 | class weekday_last; |
| 389 | |
| 390 | constexpr bool operator==(const weekday_last& x, const weekday_last& y) noexcept; |
| 391 | constexpr bool operator!=(const weekday_last& x, const weekday_last& y) noexcept; |
| 392 | |
| 393 | // 25.8.9, class month_day // C++20 |
| 394 | class month_day; |
| 395 | |
| 396 | constexpr bool operator==(const month_day& x, const month_day& y) noexcept; |
| 397 | constexpr bool operator!=(const month_day& x, const month_day& y) noexcept; |
| 398 | constexpr bool operator< (const month_day& x, const month_day& y) noexcept; |
| 399 | constexpr bool operator> (const month_day& x, const month_day& y) noexcept; |
| 400 | constexpr bool operator<=(const month_day& x, const month_day& y) noexcept; |
| 401 | constexpr bool operator>=(const month_day& x, const month_day& y) noexcept; |
| 402 | |
| 403 | |
| 404 | // 25.8.10, class month_day_last // C++20 |
| 405 | class month_day_last; |
| 406 | |
| 407 | constexpr bool operator==(const month_day_last& x, const month_day_last& y) noexcept; |
| 408 | constexpr bool operator!=(const month_day_last& x, const month_day_last& y) noexcept; |
| 409 | constexpr bool operator< (const month_day_last& x, const month_day_last& y) noexcept; |
| 410 | constexpr bool operator> (const month_day_last& x, const month_day_last& y) noexcept; |
| 411 | constexpr bool operator<=(const month_day_last& x, const month_day_last& y) noexcept; |
| 412 | constexpr bool operator>=(const month_day_last& x, const month_day_last& y) noexcept; |
| 413 | |
| 414 | // 25.8.11, class month_weekday // C++20 |
| 415 | class month_weekday; |
| 416 | |
| 417 | constexpr bool operator==(const month_weekday& x, const month_weekday& y) noexcept; |
| 418 | constexpr bool operator!=(const month_weekday& x, const month_weekday& y) noexcept; |
| 419 | |
| 420 | // 25.8.12, class month_weekday_last // C++20 |
| 421 | class month_weekday_last; |
| 422 | |
| 423 | constexpr bool operator==(const month_weekday_last& x, const month_weekday_last& y) noexcept; |
| 424 | constexpr bool operator!=(const month_weekday_last& x, const month_weekday_last& y) noexcept; |
| 425 | |
| 426 | |
| 427 | // 25.8.13, class year_month // C++20 |
| 428 | class year_month; |
| 429 | |
| 430 | constexpr bool operator==(const year_month& x, const year_month& y) noexcept; |
| 431 | constexpr bool operator!=(const year_month& x, const year_month& y) noexcept; |
| 432 | constexpr bool operator< (const year_month& x, const year_month& y) noexcept; |
| 433 | constexpr bool operator> (const year_month& x, const year_month& y) noexcept; |
| 434 | constexpr bool operator<=(const year_month& x, const year_month& y) noexcept; |
| 435 | constexpr bool operator>=(const year_month& x, const year_month& y) noexcept; |
| 436 | |
| 437 | constexpr year_month operator+(const year_month& ym, const months& dm) noexcept; |
| 438 | constexpr year_month operator+(const months& dm, const year_month& ym) noexcept; |
| 439 | constexpr year_month operator-(const year_month& ym, const months& dm) noexcept; |
| 440 | constexpr months operator-(const year_month& x, const year_month& y) noexcept; |
| 441 | constexpr year_month operator+(const year_month& ym, const years& dy) noexcept; |
| 442 | constexpr year_month operator+(const years& dy, const year_month& ym) noexcept; |
| 443 | constexpr year_month operator-(const year_month& ym, const years& dy) noexcept; |
| 444 | |
| 445 | // 25.8.14, class year_month_day class // C++20 |
| 446 | year_month_day; |
| 447 | |
| 448 | constexpr bool operator==(const year_month_day& x, const year_month_day& y) noexcept; |
| 449 | constexpr bool operator!=(const year_month_day& x, const year_month_day& y) noexcept; |
| 450 | constexpr bool operator< (const year_month_day& x, const year_month_day& y) noexcept; |
| 451 | constexpr bool operator> (const year_month_day& x, const year_month_day& y) noexcept; |
| 452 | constexpr bool operator<=(const year_month_day& x, const year_month_day& y) noexcept; |
| 453 | constexpr bool operator>=(const year_month_day& x, const year_month_day& y) noexcept; |
| 454 | |
| 455 | constexpr year_month_day operator+(const year_month_day& ymd, const months& dm) noexcept; |
| 456 | constexpr year_month_day operator+(const months& dm, const year_month_day& ymd) noexcept; |
| 457 | constexpr year_month_day operator+(const year_month_day& ymd, const years& dy) noexcept; |
| 458 | constexpr year_month_day operator+(const years& dy, const year_month_day& ymd) noexcept; |
| 459 | constexpr year_month_day operator-(const year_month_day& ymd, const months& dm) noexcept; |
| 460 | constexpr year_month_day operator-(const year_month_day& ymd, const years& dy) noexcept; |
| 461 | |
| 462 | |
| 463 | // 25.8.15, class year_month_day_last // C++20 |
| 464 | class year_month_day_last; |
| 465 | |
| 466 | constexpr bool operator==(const year_month_day_last& x, |
| 467 | const year_month_day_last& y) noexcept; |
| 468 | constexpr bool operator!=(const year_month_day_last& x, |
| 469 | const year_month_day_last& y) noexcept; |
| 470 | constexpr bool operator< (const year_month_day_last& x, |
| 471 | const year_month_day_last& y) noexcept; |
| 472 | constexpr bool operator> (const year_month_day_last& x, |
| 473 | const year_month_day_last& y) noexcept; |
| 474 | constexpr bool operator<=(const year_month_day_last& x, |
| 475 | const year_month_day_last& y) noexcept; |
| 476 | constexpr bool operator>=(const year_month_day_last& x, |
| 477 | const year_month_day_last& y) noexcept; |
| 478 | |
| 479 | constexpr year_month_day_last |
| 480 | operator+(const year_month_day_last& ymdl, const months& dm) noexcept; |
| 481 | constexpr year_month_day_last |
| 482 | operator+(const months& dm, const year_month_day_last& ymdl) noexcept; |
| 483 | constexpr year_month_day_last |
| 484 | operator+(const year_month_day_last& ymdl, const years& dy) noexcept; |
| 485 | constexpr year_month_day_last |
| 486 | operator+(const years& dy, const year_month_day_last& ymdl) noexcept; |
| 487 | constexpr year_month_day_last |
| 488 | operator-(const year_month_day_last& ymdl, const months& dm) noexcept; |
| 489 | constexpr year_month_day_last |
| 490 | operator-(const year_month_day_last& ymdl, const years& dy) noexcept; |
| 491 | |
| 492 | // 25.8.16, class year_month_weekday // C++20 |
| 493 | class year_month_weekday; |
| 494 | |
| 495 | constexpr bool operator==(const year_month_weekday& x, |
| 496 | const year_month_weekday& y) noexcept; |
| 497 | constexpr bool operator!=(const year_month_weekday& x, |
| 498 | const year_month_weekday& y) noexcept; |
| 499 | |
| 500 | constexpr year_month_weekday |
| 501 | operator+(const year_month_weekday& ymwd, const months& dm) noexcept; |
| 502 | constexpr year_month_weekday |
| 503 | operator+(const months& dm, const year_month_weekday& ymwd) noexcept; |
| 504 | constexpr year_month_weekday |
| 505 | operator+(const year_month_weekday& ymwd, const years& dy) noexcept; |
| 506 | constexpr year_month_weekday |
| 507 | operator+(const years& dy, const year_month_weekday& ymwd) noexcept; |
| 508 | constexpr year_month_weekday |
| 509 | operator-(const year_month_weekday& ymwd, const months& dm) noexcept; |
| 510 | constexpr year_month_weekday |
| 511 | operator-(const year_month_weekday& ymwd, const years& dy) noexcept; |
| 512 | |
| 513 | // 25.8.17, class year_month_weekday_last // C++20 |
| 514 | class year_month_weekday_last; |
| 515 | |
| 516 | constexpr bool operator==(const year_month_weekday_last& x, |
| 517 | const year_month_weekday_last& y) noexcept; |
| 518 | constexpr bool operator!=(const year_month_weekday_last& x, |
| 519 | const year_month_weekday_last& y) noexcept; |
| 520 | constexpr year_month_weekday_last |
| 521 | operator+(const year_month_weekday_last& ymwdl, const months& dm) noexcept; |
| 522 | constexpr year_month_weekday_last |
| 523 | operator+(const months& dm, const year_month_weekday_last& ymwdl) noexcept; |
| 524 | constexpr year_month_weekday_last |
| 525 | operator+(const year_month_weekday_last& ymwdl, const years& dy) noexcept; |
| 526 | constexpr year_month_weekday_last |
| 527 | operator+(const years& dy, const year_month_weekday_last& ymwdl) noexcept; |
| 528 | constexpr year_month_weekday_last |
| 529 | operator-(const year_month_weekday_last& ymwdl, const months& dm) noexcept; |
| 530 | constexpr year_month_weekday_last |
| 531 | operator-(const year_month_weekday_last& ymwdl, const years& dy) noexcept; |
| 532 | |
| 533 | // 25.8.18, civil calendar conventional syntax operators // C++20 |
| 534 | constexpr year_month |
| 535 | operator/(const year& y, const month& m) noexcept; |
| 536 | constexpr year_month |
| 537 | operator/(const year& y, int m) noexcept; |
| 538 | constexpr month_day |
| 539 | operator/(const month& m, const day& d) noexcept; |
| 540 | constexpr month_day |
| 541 | operator/(const month& m, int d) noexcept; |
| 542 | constexpr month_day |
| 543 | operator/(int m, const day& d) noexcept; |
| 544 | constexpr month_day |
| 545 | operator/(const day& d, const month& m) noexcept; |
| 546 | constexpr month_day |
| 547 | operator/(const day& d, int m) noexcept; |
| 548 | constexpr month_day_last |
| 549 | operator/(const month& m, last_spec) noexcept; |
| 550 | constexpr month_day_last |
| 551 | operator/(int m, last_spec) noexcept; |
| 552 | constexpr month_day_last |
| 553 | operator/(last_spec, const month& m) noexcept; |
| 554 | constexpr month_day_last |
| 555 | operator/(last_spec, int m) noexcept; |
| 556 | constexpr month_weekday |
| 557 | operator/(const month& m, const weekday_indexed& wdi) noexcept; |
| 558 | constexpr month_weekday |
| 559 | operator/(int m, const weekday_indexed& wdi) noexcept; |
| 560 | constexpr month_weekday |
| 561 | operator/(const weekday_indexed& wdi, const month& m) noexcept; |
| 562 | constexpr month_weekday |
| 563 | operator/(const weekday_indexed& wdi, int m) noexcept; |
| 564 | constexpr month_weekday_last |
| 565 | operator/(const month& m, const weekday_last& wdl) noexcept; |
| 566 | constexpr month_weekday_last |
| 567 | operator/(int m, const weekday_last& wdl) noexcept; |
| 568 | constexpr month_weekday_last |
| 569 | operator/(const weekday_last& wdl, const month& m) noexcept; |
| 570 | constexpr month_weekday_last |
| 571 | operator/(const weekday_last& wdl, int m) noexcept; |
| 572 | constexpr year_month_day |
| 573 | operator/(const year_month& ym, const day& d) noexcept; |
| 574 | constexpr year_month_day |
| 575 | operator/(const year_month& ym, int d) noexcept; |
| 576 | constexpr year_month_day |
| 577 | operator/(const year& y, const month_day& md) noexcept; |
| 578 | constexpr year_month_day |
| 579 | operator/(int y, const month_day& md) noexcept; |
| 580 | constexpr year_month_day |
| 581 | operator/(const month_day& md, const year& y) noexcept; |
| 582 | constexpr year_month_day |
| 583 | operator/(const month_day& md, int y) noexcept; |
| 584 | constexpr year_month_day_last |
| 585 | operator/(const year_month& ym, last_spec) noexcept; |
| 586 | constexpr year_month_day_last |
| 587 | operator/(const year& y, const month_day_last& mdl) noexcept; |
| 588 | constexpr year_month_day_last |
| 589 | operator/(int y, const month_day_last& mdl) noexcept; |
| 590 | constexpr year_month_day_last |
| 591 | operator/(const month_day_last& mdl, const year& y) noexcept; |
| 592 | constexpr year_month_day_last |
| 593 | operator/(const month_day_last& mdl, int y) noexcept; |
| 594 | constexpr year_month_weekday |
| 595 | operator/(const year_month& ym, const weekday_indexed& wdi) noexcept; |
| 596 | constexpr year_month_weekday |
| 597 | operator/(const year& y, const month_weekday& mwd) noexcept; |
| 598 | constexpr year_month_weekday |
| 599 | operator/(int y, const month_weekday& mwd) noexcept; |
| 600 | constexpr year_month_weekday |
| 601 | operator/(const month_weekday& mwd, const year& y) noexcept; |
| 602 | constexpr year_month_weekday |
| 603 | operator/(const month_weekday& mwd, int y) noexcept; |
| 604 | constexpr year_month_weekday_last |
| 605 | operator/(const year_month& ym, const weekday_last& wdl) noexcept; |
| 606 | constexpr year_month_weekday_last |
| 607 | operator/(const year& y, const month_weekday_last& mwdl) noexcept; |
| 608 | constexpr year_month_weekday_last |
| 609 | operator/(int y, const month_weekday_last& mwdl) noexcept; |
| 610 | constexpr year_month_weekday_last |
| 611 | operator/(const month_weekday_last& mwdl, const year& y) noexcept; |
| 612 | constexpr year_month_weekday_last |
| 613 | operator/(const month_weekday_last& mwdl, int y) noexcept; |
| 614 | |
| 615 | // 26.9, class template hh_mm_ss |
| 616 | template <class Duration> |
| 617 | class hh_mm_ss |
| 618 | { |
| 619 | bool is_neg; // exposition only |
| 620 | chrono::hours h; // exposition only |
| 621 | chrono::minutes m; // exposition only |
| 622 | chrono::seconds s; // exposition only |
| 623 | precision ss; // exposition only |
| 624 | |
| 625 | public: |
| 626 | static unsigned constexpr fractional_width = see below; |
| 627 | using precision = see below; |
| 628 | |
| 629 | constexpr hh_mm_ss() noexcept : hh_mm_ss{Duration::zero()} {} |
| 630 | constexpr explicit hh_mm_ss(Duration d) noexcept; |
| 631 | |
| 632 | constexpr bool is_negative() const noexcept; |
| 633 | constexpr chrono::hours hours() const noexcept; |
| 634 | constexpr chrono::minutes minutes() const noexcept; |
| 635 | constexpr chrono::seconds seconds() const noexcept; |
| 636 | constexpr precision subseconds() const noexcept; |
| 637 | |
| 638 | constexpr explicit operator precision() const noexcept; |
| 639 | constexpr precision to_duration() const noexcept; |
| 640 | }; |
| 641 | |
| 642 | template <class charT, class traits, class Duration> |
| 643 | basic_ostream<charT, traits>& |
| 644 | operator<<(basic_ostream<charT, traits>& os, hh_mm_ss<Duration> const& hms); |
| 645 | |
| 646 | // 26.10, 12/24 hour functions |
| 647 | constexpr bool is_am(hours const& h) noexcept; |
| 648 | constexpr bool is_pm(hours const& h) noexcept; |
| 649 | constexpr hours make12(const hours& h) noexcept; |
| 650 | constexpr hours make24(const hours& h, bool is_pm) noexcept; |
| 651 | |
| 652 | |
| 653 | // 25.10.2, time zone database // C++20 |
| 654 | struct tzdb; |
| 655 | class tzdb_list; |
| 656 | |
| 657 | // 25.10.2.3, time zone database access // C++20 |
| 658 | const tzdb& get_tzdb(); |
| 659 | tzdb_list& get_tzdb_list(); |
| 660 | const time_zone* locate_zone(string_view tz_name); |
| 661 | const time_zone* current_zone(); |
| 662 | |
| 663 | // 25.10.2.4, remote time zone database support // C++20 |
| 664 | const tzdb& reload_tzdb(); |
| 665 | string remote_version(); |
| 666 | |
| 667 | // 25.10.3, exception classes // C++20 |
| 668 | class nonexistent_local_time; |
| 669 | class ambiguous_local_time; |
| 670 | |
| 671 | // 25.10.4, information classes // C++20 |
| 672 | struct sys_info; |
| 673 | struct local_info; |
| 674 | |
| 675 | // 25.10.5, class time_zone // C++20 |
| 676 | enum class choose {earliest, latest}; |
| 677 | class time_zone; |
| 678 | bool operator==(const time_zone& x, const time_zone& y) noexcept; |
| 679 | bool operator!=(const time_zone& x, const time_zone& y) noexcept; |
| 680 | bool operator<(const time_zone& x, const time_zone& y) noexcept; |
| 681 | bool operator>(const time_zone& x, const time_zone& y) noexcept; |
| 682 | bool operator<=(const time_zone& x, const time_zone& y) noexcept; |
| 683 | bool operator>=(const time_zone& x, const time_zone& y) noexcept; |
| 684 | |
| 685 | // 25.10.6, class template zoned_traits // C++20 |
| 686 | template<class T> struct zoned_traits; |
| 687 | |
| 688 | // 25.10.7, class template zoned_time // C++20 |
| 689 | template<class Duration, class TimeZonePtr = const time_zone*> class zoned_time; |
| 690 | using zoned_seconds = zoned_time<seconds>; |
| 691 | |
| 692 | template<class Duration1, class Duration2, class TimeZonePtr> |
| 693 | bool operator==(const zoned_time<Duration1, TimeZonePtr>& x, |
| 694 | const zoned_time<Duration2, TimeZonePtr>& y); |
| 695 | template<class Duration1, class Duration2, class TimeZonePtr> |
| 696 | bool operator!=(const zoned_time<Duration1, TimeZonePtr>& x, |
| 697 | const zoned_time<Duration2, TimeZonePtr>& y); |
| 698 | |
| 699 | // 25.10.8, leap second support // C++20 |
| 700 | class leap; |
| 701 | |
| 702 | bool operator==(const leap& x, const leap& y); |
| 703 | bool operator!=(const leap& x, const leap& y); |
| 704 | bool operator< (const leap& x, const leap& y); |
| 705 | bool operator> (const leap& x, const leap& y); |
| 706 | bool operator<=(const leap& x, const leap& y); |
| 707 | bool operator>=(const leap& x, const leap& y); |
| 708 | template<class Duration> |
| 709 | bool operator==(const leap& x, const sys_time<Duration>& y); |
| 710 | template<class Duration> |
| 711 | bool operator==(const sys_time<Duration>& x, const leap& y); |
| 712 | template<class Duration> |
| 713 | bool operator!=(const leap& x, const sys_time<Duration>& y); |
| 714 | template<class Duration> |
| 715 | bool operator!=(const sys_time<Duration>& x, const leap& y); |
| 716 | template<class Duration> |
| 717 | bool operator< (const leap& x, const sys_time<Duration>& y); |
| 718 | template<class Duration> |
| 719 | bool operator< (const sys_time<Duration>& x, const leap& y); |
| 720 | template<class Duration> |
| 721 | bool operator> (const leap& x, const sys_time<Duration>& y); |
| 722 | template<class Duration> |
| 723 | bool operator> (const sys_time<Duration>& x, const leap& y); |
| 724 | template<class Duration> |
| 725 | bool operator<=(const leap& x, const sys_time<Duration>& y); |
| 726 | template<class Duration> |
| 727 | bool operator<=(const sys_time<Duration>& x, const leap& y); |
| 728 | template<class Duration> |
| 729 | bool operator>=(const leap& x, const sys_time<Duration>& y); |
| 730 | template<class Duration> |
| 731 | bool operator>=(const sys_time<Duration>& x, const leap& y); |
| 732 | |
| 733 | // 25.10.9, class link // C++20 |
| 734 | class link; |
| 735 | bool operator==(const link& x, const link& y); |
| 736 | bool operator!=(const link& x, const link& y); |
| 737 | bool operator< (const link& x, const link& y); |
| 738 | bool operator> (const link& x, const link& y); |
| 739 | bool operator<=(const link& x, const link& y); |
| 740 | bool operator>=(const link& x, const link& y); |
| 741 | |
| 742 | // 25.11, formatting // C++20 |
| 743 | template<class charT, class Streamable> |
| 744 | basic_string<charT> |
| 745 | format(const charT* fmt, const Streamable& s); |
| 746 | |
| 747 | template<class charT, class Streamable> |
| 748 | basic_string<charT> |
| 749 | format(const locale& loc, const charT* fmt, const Streamable& s); |
| 750 | |
| 751 | template<class charT, class traits, class Alloc, class Streamable> |
| 752 | basic_string<charT, traits, Alloc> |
| 753 | format(const basic_string<charT, traits, Alloc>& fmt, const Streamable& s); |
| 754 | |
| 755 | template<class charT, class traits, class Alloc, class Streamable> |
| 756 | basic_string<charT, traits, Alloc> |
| 757 | format(const locale& loc, const basic_string<charT, traits, Alloc>& fmt, |
| 758 | const Streamable& s); |
| 759 | |
| 760 | // 25.12, parsing // C++20 |
| 761 | template<class charT, class traits, class Alloc, class Parsable> |
| 762 | unspecified |
| 763 | parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp); |
| 764 | |
| 765 | template<class charT, class traits, class Alloc, class Parsable> |
| 766 | unspecified |
| 767 | parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp, |
| 768 | basic_string<charT, traits, Alloc>& abbrev); |
| 769 | |
| 770 | template<class charT, class traits, class Alloc, class Parsable> |
| 771 | unspecified |
| 772 | parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp, |
| 773 | minutes& offset); |
| 774 | |
| 775 | template<class charT, class traits, class Alloc, class Parsable> |
| 776 | unspecified |
| 777 | parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp, |
| 778 | basic_string<charT, traits, Alloc>& abbrev, minutes& offset); |
| 779 | |
| 780 | // calendrical constants |
| 781 | inline constexpr last_spec last{}; // C++20 |
| 782 | inline constexpr chrono::weekday Sunday{0}; // C++20 |
| 783 | inline constexpr chrono::weekday Monday{1}; // C++20 |
| 784 | inline constexpr chrono::weekday Tuesday{2}; // C++20 |
| 785 | inline constexpr chrono::weekday Wednesday{3}; // C++20 |
| 786 | inline constexpr chrono::weekday Thursday{4}; // C++20 |
| 787 | inline constexpr chrono::weekday Friday{5}; // C++20 |
| 788 | inline constexpr chrono::weekday Saturday{6}; // C++20 |
| 789 | |
| 790 | inline constexpr chrono::month January{1}; // C++20 |
| 791 | inline constexpr chrono::month February{2}; // C++20 |
| 792 | inline constexpr chrono::month March{3}; // C++20 |
| 793 | inline constexpr chrono::month April{4}; // C++20 |
| 794 | inline constexpr chrono::month May{5}; // C++20 |
| 795 | inline constexpr chrono::month June{6}; // C++20 |
| 796 | inline constexpr chrono::month July{7}; // C++20 |
| 797 | inline constexpr chrono::month August{8}; // C++20 |
| 798 | inline constexpr chrono::month September{9}; // C++20 |
| 799 | inline constexpr chrono::month October{10}; // C++20 |
| 800 | inline constexpr chrono::month November{11}; // C++20 |
| 801 | inline constexpr chrono::month December{12}; // C++20 |
| 802 | } // chrono |
| 803 | |
| 804 | inline namespace literals { |
| 805 | inline namespace chrono_literals { |
| 806 | constexpr chrono::hours operator ""h(unsigned long long); // C++14 |
| 807 | constexpr chrono::duration<unspecified , ratio<3600,1>> operator ""h(long double); // C++14 |
| 808 | constexpr chrono::minutes operator ""min(unsigned long long); // C++14 |
| 809 | constexpr chrono::duration<unspecified , ratio<60,1>> operator ""min(long double); // C++14 |
| 810 | constexpr chrono::seconds operator ""s(unsigned long long); // C++14 |
| 811 | constexpr chrono::duration<unspecified > operator ""s(long double); // C++14 |
| 812 | constexpr chrono::milliseconds operator ""ms(unsigned long long); // C++14 |
| 813 | constexpr chrono::duration<unspecified , milli> operator ""ms(long double); // C++14 |
| 814 | constexpr chrono::microseconds operator ""us(unsigned long long); // C++14 |
| 815 | constexpr chrono::duration<unspecified , micro> operator ""us(long double); // C++14 |
| 816 | constexpr chrono::nanoseconds operator ""ns(unsigned long long); // C++14 |
| 817 | constexpr chrono::duration<unspecified , nano> operator ""ns(long double); // C++14 |
| 818 | constexpr chrono::day operator ""d(unsigned long long d) noexcept; // C++20 |
| 819 | constexpr chrono::year operator ""y(unsigned long long y) noexcept; // C++20 |
| 820 | } // chrono_literals |
| 821 | } // literals |
| 822 | |
| 823 | } // std |
| 824 | */ |
| 825 | |
| 826 | #include <__availability> |
| 827 | #include <__config> |
| 828 | #include <compare> |
| 829 | #include <ctime> |
| 830 | #include <limits> |
| 831 | #include <ratio> |
| 832 | #include <type_traits> |
| 833 | #include <version> |
| 834 | |
| 835 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 836 | #pragma GCC system_header |
| 837 | #endif |
| 838 | |
| 839 | _LIBCPP_PUSH_MACROSpush_macro("min") push_macro("max") |
| 840 | #include <__undef_macros> |
| 841 | |
| 842 | #ifndef _LIBCPP_CXX03_LANG |
| 843 | _LIBCPP_BEGIN_NAMESPACE_FILESYSTEMnamespace std { inline namespace __1 { namespace __fs { namespace filesystem { |
| 844 | struct _FilesystemClock; |
| 845 | _LIBCPP_END_NAMESPACE_FILESYSTEM} } } } |
| 846 | #endif // !_LIBCPP_CXX03_LANG |
| 847 | |
| 848 | _LIBCPP_BEGIN_NAMESPACE_STDnamespace std { inline namespace __1 { |
| 849 | |
| 850 | namespace chrono |
| 851 | { |
| 852 | |
| 853 | template <class _Rep, class _Period = ratio<1> > class _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) duration; |
| 854 | |
| 855 | template <class _Tp> |
| 856 | struct __is_duration : false_type {}; |
| 857 | |
| 858 | template <class _Rep, class _Period> |
| 859 | struct __is_duration<duration<_Rep, _Period> > : true_type {}; |
| 860 | |
| 861 | template <class _Rep, class _Period> |
| 862 | struct __is_duration<const duration<_Rep, _Period> > : true_type {}; |
| 863 | |
| 864 | template <class _Rep, class _Period> |
| 865 | struct __is_duration<volatile duration<_Rep, _Period> > : true_type {}; |
| 866 | |
| 867 | template <class _Rep, class _Period> |
| 868 | struct __is_duration<const volatile duration<_Rep, _Period> > : true_type {}; |
| 869 | |
| 870 | } // chrono |
| 871 | |
| 872 | template <class _Rep1, class _Period1, class _Rep2, class _Period2> |
| 873 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) common_type<chrono::duration<_Rep1, _Period1>, |
| 874 | chrono::duration<_Rep2, _Period2> > |
| 875 | { |
| 876 | typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type, |
| 877 | typename __ratio_gcd<_Period1, _Period2>::type> type; |
| 878 | }; |
| 879 | |
| 880 | namespace chrono { |
| 881 | |
| 882 | // duration_cast |
| 883 | |
| 884 | template <class _FromDuration, class _ToDuration, |
| 885 | class _Period = typename ratio_divide<typename _FromDuration::period, typename _ToDuration::period>::type, |
| 886 | bool = _Period::num == 1, |
| 887 | bool = _Period::den == 1> |
| 888 | struct __duration_cast; |
| 889 | |
| 890 | template <class _FromDuration, class _ToDuration, class _Period> |
| 891 | struct __duration_cast<_FromDuration, _ToDuration, _Period, true, true> |
| 892 | { |
| 893 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPRconstexpr |
| 894 | _ToDuration operator()(const _FromDuration& __fd) const |
| 895 | { |
| 896 | return _ToDuration(static_cast<typename _ToDuration::rep>(__fd.count())); |
| 897 | } |
| 898 | }; |
| 899 | |
| 900 | template <class _FromDuration, class _ToDuration, class _Period> |
| 901 | struct __duration_cast<_FromDuration, _ToDuration, _Period, true, false> |
| 902 | { |
| 903 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPRconstexpr |
| 904 | _ToDuration operator()(const _FromDuration& __fd) const |
| 905 | { |
| 906 | typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct; |
| 907 | return _ToDuration(static_cast<typename _ToDuration::rep>( |
| 908 | static_cast<_Ct>(__fd.count()) / static_cast<_Ct>(_Period::den))); |
| 909 | } |
| 910 | }; |
| 911 | |
| 912 | template <class _FromDuration, class _ToDuration, class _Period> |
| 913 | struct __duration_cast<_FromDuration, _ToDuration, _Period, false, true> |
| 914 | { |
| 915 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPRconstexpr |
| 916 | _ToDuration operator()(const _FromDuration& __fd) const |
| 917 | { |
| 918 | typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct; |
| 919 | return _ToDuration(static_cast<typename _ToDuration::rep>( |
| 920 | static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num))); |
| 921 | } |
| 922 | }; |
| 923 | |
| 924 | template <class _FromDuration, class _ToDuration, class _Period> |
| 925 | struct __duration_cast<_FromDuration, _ToDuration, _Period, false, false> |
| 926 | { |
| 927 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPRconstexpr |
| 928 | _ToDuration operator()(const _FromDuration& __fd) const |
| 929 | { |
| 930 | typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct; |
| 931 | return _ToDuration(static_cast<typename _ToDuration::rep>( |
| 932 | static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num) |
| 933 | / static_cast<_Ct>(_Period::den))); |
| 934 | } |
| 935 | }; |
| 936 | |
| 937 | template <class _ToDuration, class _Rep, class _Period> |
| 938 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 939 | _LIBCPP_CONSTEXPRconstexpr |
| 940 | typename enable_if |
| 941 | < |
| 942 | __is_duration<_ToDuration>::value, |
| 943 | _ToDuration |
| 944 | >::type |
| 945 | duration_cast(const duration<_Rep, _Period>& __fd) |
| 946 | { |
| 947 | return __duration_cast<duration<_Rep, _Period>, _ToDuration>()(__fd); |
| 948 | } |
| 949 | |
| 950 | template <class _Rep> |
| 951 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) treat_as_floating_point : is_floating_point<_Rep> {}; |
| 952 | |
| 953 | #if _LIBCPP_STD_VER14 > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) |
| 954 | template <class _Rep> |
| 955 | _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPRconstexpr bool treat_as_floating_point_v |
| 956 | = treat_as_floating_point<_Rep>::value; |
| 957 | #endif |
| 958 | |
| 959 | template <class _Rep> |
| 960 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) duration_values |
| 961 | { |
| 962 | public: |
| 963 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) static _LIBCPP_CONSTEXPRconstexpr _Rep zero() _NOEXCEPTnoexcept {return _Rep(0);} |
| 964 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) static _LIBCPP_CONSTEXPRconstexpr _Rep max() _NOEXCEPTnoexcept {return numeric_limits<_Rep>::max();} |
| 965 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) static _LIBCPP_CONSTEXPRconstexpr _Rep min() _NOEXCEPTnoexcept {return numeric_limits<_Rep>::lowest();} |
| 966 | }; |
| 967 | |
| 968 | #if _LIBCPP_STD_VER14 > 14 |
| 969 | template <class _ToDuration, class _Rep, class _Period> |
| 970 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPRconstexpr |
| 971 | typename enable_if |
| 972 | < |
| 973 | __is_duration<_ToDuration>::value, |
| 974 | _ToDuration |
| 975 | >::type |
| 976 | floor(const duration<_Rep, _Period>& __d) |
| 977 | { |
| 978 | _ToDuration __t = duration_cast<_ToDuration>(__d); |
| 979 | if (__t > __d) |
| 980 | __t = __t - _ToDuration{1}; |
| 981 | return __t; |
| 982 | } |
| 983 | |
| 984 | template <class _ToDuration, class _Rep, class _Period> |
| 985 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPRconstexpr |
| 986 | typename enable_if |
| 987 | < |
| 988 | __is_duration<_ToDuration>::value, |
| 989 | _ToDuration |
| 990 | >::type |
| 991 | ceil(const duration<_Rep, _Period>& __d) |
| 992 | { |
| 993 | _ToDuration __t = duration_cast<_ToDuration>(__d); |
| 994 | if (__t < __d) |
| 995 | __t = __t + _ToDuration{1}; |
| 996 | return __t; |
| 997 | } |
| 998 | |
| 999 | template <class _ToDuration, class _Rep, class _Period> |
| 1000 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPRconstexpr |
| 1001 | typename enable_if |
| 1002 | < |
| 1003 | __is_duration<_ToDuration>::value, |
| 1004 | _ToDuration |
| 1005 | >::type |
| 1006 | round(const duration<_Rep, _Period>& __d) |
| 1007 | { |
| 1008 | _ToDuration __lower = floor<_ToDuration>(__d); |
| 1009 | _ToDuration __upper = __lower + _ToDuration{1}; |
| 1010 | auto __lowerDiff = __d - __lower; |
| 1011 | auto __upperDiff = __upper - __d; |
| 1012 | if (__lowerDiff < __upperDiff) |
| 1013 | return __lower; |
| 1014 | if (__lowerDiff > __upperDiff) |
| 1015 | return __upper; |
| 1016 | return __lower.count() & 1 ? __upper : __lower; |
| 1017 | } |
| 1018 | #endif |
| 1019 | |
| 1020 | // duration |
| 1021 | |
| 1022 | template <class _Rep, class _Period> |
| 1023 | class _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) duration |
| 1024 | { |
| 1025 | static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration"); |
| 1026 | static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio"); |
| 1027 | static_assert(_Period::num > 0, "duration period must be positive"); |
| 1028 | |
| 1029 | template <class _R1, class _R2> |
| 1030 | struct __no_overflow |
| 1031 | { |
| 1032 | private: |
| 1033 | static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value; |
| 1034 | static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value; |
| 1035 | static const intmax_t __n1 = _R1::num / __gcd_n1_n2; |
| 1036 | static const intmax_t __d1 = _R1::den / __gcd_d1_d2; |
| 1037 | static const intmax_t __n2 = _R2::num / __gcd_n1_n2; |
| 1038 | static const intmax_t __d2 = _R2::den / __gcd_d1_d2; |
| 1039 | static const intmax_t max = -((intmax_t(1) << (sizeof(intmax_t) * CHAR_BIT8 - 1)) + 1); |
| 1040 | |
| 1041 | template <intmax_t _Xp, intmax_t _Yp, bool __overflow> |
| 1042 | struct __mul // __overflow == false |
| 1043 | { |
| 1044 | static const intmax_t value = _Xp * _Yp; |
| 1045 | }; |
| 1046 | |
| 1047 | template <intmax_t _Xp, intmax_t _Yp> |
| 1048 | struct __mul<_Xp, _Yp, true> |
| 1049 | { |
| 1050 | static const intmax_t value = 1; |
| 1051 | }; |
| 1052 | |
| 1053 | public: |
| 1054 | static const bool value = (__n1 <= max / __d2) && (__n2 <= max / __d1); |
| 1055 | typedef ratio<__mul<__n1, __d2, !value>::value, |
| 1056 | __mul<__n2, __d1, !value>::value> type; |
| 1057 | }; |
| 1058 | |
| 1059 | public: |
| 1060 | typedef _Rep rep; |
| 1061 | typedef typename _Period::type period; |
| 1062 | private: |
| 1063 | rep __rep_; |
| 1064 | public: |
| 1065 | |
| 1066 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPRconstexpr |
| 1067 | #ifndef _LIBCPP_CXX03_LANG |
| 1068 | duration() = default; |
| 1069 | #else |
| 1070 | duration() {} |
| 1071 | #endif |
| 1072 | |
| 1073 | template <class _Rep2> |
| 1074 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPRconstexpr |
| 1075 | explicit duration(const _Rep2& __r, |
| 1076 | typename enable_if |
| 1077 | < |
| 1078 | is_convertible<_Rep2, rep>::value && |
| 1079 | (treat_as_floating_point<rep>::value || |
| 1080 | !treat_as_floating_point<_Rep2>::value) |
| 1081 | >::type* = nullptr) |
| 1082 | : __rep_(__r) {} |
| 1083 | |
| 1084 | // conversions |
| 1085 | template <class _Rep2, class _Period2> |
| 1086 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPRconstexpr |
| 1087 | duration(const duration<_Rep2, _Period2>& __d, |
| 1088 | typename enable_if |
| 1089 | < |
| 1090 | __no_overflow<_Period2, period>::value && ( |
| 1091 | treat_as_floating_point<rep>::value || |
| 1092 | (__no_overflow<_Period2, period>::type::den == 1 && |
| 1093 | !treat_as_floating_point<_Rep2>::value)) |
| 1094 | >::type* = nullptr) |
| 1095 | : __rep_(chrono::duration_cast<duration>(__d).count()) {} |
| 1096 | |
| 1097 | // observer |
| 1098 | |
| 1099 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPRconstexpr rep count() const {return __rep_;} |
| 1100 | |
| 1101 | // arithmetic |
| 1102 | |
| 1103 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPRconstexpr typename common_type<duration>::type operator+() const {return typename common_type<duration>::type(*this);} |
| 1104 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPRconstexpr typename common_type<duration>::type operator-() const {return typename common_type<duration>::type(-__rep_);} |
| 1105 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator++() {++__rep_; return *this;} |
| 1106 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPR_AFTER_CXX14 duration operator++(int) {return duration(__rep_++);} |
| 1107 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator--() {--__rep_; return *this;} |
| 1108 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPR_AFTER_CXX14 duration operator--(int) {return duration(__rep_--);} |
| 1109 | |
| 1110 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;} |
| 1111 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;} |
| 1112 | |
| 1113 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator*=(const rep& rhs) {__rep_ *= rhs; return *this;} |
| 1114 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator/=(const rep& rhs) {__rep_ /= rhs; return *this;} |
| 1115 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator%=(const rep& rhs) {__rep_ %= rhs; return *this;} |
| 1116 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator%=(const duration& rhs) {__rep_ %= rhs.count(); return *this;} |
| 1117 | |
| 1118 | // special values |
| 1119 | |
| 1120 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) static _LIBCPP_CONSTEXPRconstexpr duration zero() _NOEXCEPTnoexcept {return duration(duration_values<rep>::zero());} |
| 1121 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) static _LIBCPP_CONSTEXPRconstexpr duration min() _NOEXCEPTnoexcept {return duration(duration_values<rep>::min());} |
| 1122 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) static _LIBCPP_CONSTEXPRconstexpr duration max() _NOEXCEPTnoexcept {return duration(duration_values<rep>::max());} |
| 1123 | }; |
| 1124 | |
| 1125 | typedef duration<long long, nano> nanoseconds; |
| 1126 | typedef duration<long long, micro> microseconds; |
| 1127 | typedef duration<long long, milli> milliseconds; |
| 1128 | typedef duration<long long > seconds; |
| 1129 | typedef duration< long, ratio< 60> > minutes; |
| 1130 | typedef duration< long, ratio<3600> > hours; |
| 1131 | #if _LIBCPP_STD_VER14 > 17 |
| 1132 | typedef duration< int, ratio_multiply<ratio<24>, hours::period>> days; |
| 1133 | typedef duration< int, ratio_multiply<ratio<7>, days::period>> weeks; |
| 1134 | typedef duration< int, ratio_multiply<ratio<146097, 400>, days::period>> years; |
| 1135 | typedef duration< int, ratio_divide<years::period, ratio<12>>> months; |
| 1136 | #endif |
| 1137 | // Duration == |
| 1138 | |
| 1139 | template <class _LhsDuration, class _RhsDuration> |
| 1140 | struct __duration_eq |
| 1141 | { |
| 1142 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPRconstexpr |
| 1143 | bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const |
| 1144 | { |
| 1145 | typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct; |
| 1146 | return _Ct(__lhs).count() == _Ct(__rhs).count(); |
| 1147 | } |
| 1148 | }; |
| 1149 | |
| 1150 | template <class _LhsDuration> |
| 1151 | struct __duration_eq<_LhsDuration, _LhsDuration> |
| 1152 | { |
| 1153 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPRconstexpr |
| 1154 | bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const |
| 1155 | {return __lhs.count() == __rhs.count();} |
| 1156 | }; |
| 1157 | |
| 1158 | template <class _Rep1, class _Period1, class _Rep2, class _Period2> |
| 1159 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 1160 | _LIBCPP_CONSTEXPRconstexpr |
| 1161 | bool |
| 1162 | operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) |
| 1163 | { |
| 1164 | return __duration_eq<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs); |
| 1165 | } |
| 1166 | |
| 1167 | // Duration != |
| 1168 | |
| 1169 | template <class _Rep1, class _Period1, class _Rep2, class _Period2> |
| 1170 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 1171 | _LIBCPP_CONSTEXPRconstexpr |
| 1172 | bool |
| 1173 | operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) |
| 1174 | { |
| 1175 | return !(__lhs == __rhs); |
| 1176 | } |
| 1177 | |
| 1178 | // Duration < |
| 1179 | |
| 1180 | template <class _LhsDuration, class _RhsDuration> |
| 1181 | struct __duration_lt |
| 1182 | { |
| 1183 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPRconstexpr |
| 1184 | bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const |
| 1185 | { |
| 1186 | typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct; |
| 1187 | return _Ct(__lhs).count() < _Ct(__rhs).count(); |
| 1188 | } |
| 1189 | }; |
| 1190 | |
| 1191 | template <class _LhsDuration> |
| 1192 | struct __duration_lt<_LhsDuration, _LhsDuration> |
| 1193 | { |
| 1194 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPRconstexpr |
| 1195 | bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const |
| 1196 | {return __lhs.count() < __rhs.count();} |
| 1197 | }; |
| 1198 | |
| 1199 | template <class _Rep1, class _Period1, class _Rep2, class _Period2> |
| 1200 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 1201 | _LIBCPP_CONSTEXPRconstexpr |
| 1202 | bool |
| 1203 | operator< (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) |
| 1204 | { |
| 1205 | return __duration_lt<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs); |
| 1206 | } |
| 1207 | |
| 1208 | // Duration > |
| 1209 | |
| 1210 | template <class _Rep1, class _Period1, class _Rep2, class _Period2> |
| 1211 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 1212 | _LIBCPP_CONSTEXPRconstexpr |
| 1213 | bool |
| 1214 | operator> (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) |
| 1215 | { |
| 1216 | return __rhs < __lhs; |
| 1217 | } |
| 1218 | |
| 1219 | // Duration <= |
| 1220 | |
| 1221 | template <class _Rep1, class _Period1, class _Rep2, class _Period2> |
| 1222 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 1223 | _LIBCPP_CONSTEXPRconstexpr |
| 1224 | bool |
| 1225 | operator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) |
| 1226 | { |
| 1227 | return !(__rhs < __lhs); |
| 1228 | } |
| 1229 | |
| 1230 | // Duration >= |
| 1231 | |
| 1232 | template <class _Rep1, class _Period1, class _Rep2, class _Period2> |
| 1233 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 1234 | _LIBCPP_CONSTEXPRconstexpr |
| 1235 | bool |
| 1236 | operator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) |
| 1237 | { |
| 1238 | return !(__lhs < __rhs); |
| 1239 | } |
| 1240 | |
| 1241 | // Duration + |
| 1242 | |
| 1243 | template <class _Rep1, class _Period1, class _Rep2, class _Period2> |
| 1244 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 1245 | _LIBCPP_CONSTEXPRconstexpr |
| 1246 | typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type |
| 1247 | operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) |
| 1248 | { |
| 1249 | typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd; |
| 1250 | return _Cd(_Cd(__lhs).count() + _Cd(__rhs).count()); |
| 1251 | } |
| 1252 | |
| 1253 | // Duration - |
| 1254 | |
| 1255 | template <class _Rep1, class _Period1, class _Rep2, class _Period2> |
| 1256 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 1257 | _LIBCPP_CONSTEXPRconstexpr |
| 1258 | typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type |
| 1259 | operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) |
| 1260 | { |
| 1261 | typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd; |
| 1262 | return _Cd(_Cd(__lhs).count() - _Cd(__rhs).count()); |
| 1263 | } |
| 1264 | |
| 1265 | // Duration * |
| 1266 | |
| 1267 | template <class _Rep1, class _Period, class _Rep2> |
| 1268 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 1269 | _LIBCPP_CONSTEXPRconstexpr |
| 1270 | typename enable_if |
| 1271 | < |
| 1272 | is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value, |
| 1273 | duration<typename common_type<_Rep1, _Rep2>::type, _Period> |
| 1274 | >::type |
| 1275 | operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s) |
| 1276 | { |
| 1277 | typedef typename common_type<_Rep1, _Rep2>::type _Cr; |
| 1278 | typedef duration<_Cr, _Period> _Cd; |
| 1279 | return _Cd(_Cd(__d).count() * static_cast<_Cr>(__s)); |
| 1280 | } |
| 1281 | |
| 1282 | template <class _Rep1, class _Period, class _Rep2> |
| 1283 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 1284 | _LIBCPP_CONSTEXPRconstexpr |
| 1285 | typename enable_if |
| 1286 | < |
| 1287 | is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value, |
| 1288 | duration<typename common_type<_Rep1, _Rep2>::type, _Period> |
| 1289 | >::type |
| 1290 | operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d) |
| 1291 | { |
| 1292 | return __d * __s; |
| 1293 | } |
| 1294 | |
| 1295 | // Duration / |
| 1296 | |
| 1297 | template <class _Rep1, class _Period, class _Rep2> |
| 1298 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 1299 | _LIBCPP_CONSTEXPRconstexpr |
| 1300 | typename enable_if |
| 1301 | < |
| 1302 | !__is_duration<_Rep2>::value && |
| 1303 | is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value, |
| 1304 | duration<typename common_type<_Rep1, _Rep2>::type, _Period> |
| 1305 | >::type |
| 1306 | operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s) |
| 1307 | { |
| 1308 | typedef typename common_type<_Rep1, _Rep2>::type _Cr; |
| 1309 | typedef duration<_Cr, _Period> _Cd; |
| 1310 | return _Cd(_Cd(__d).count() / static_cast<_Cr>(__s)); |
| 1311 | } |
| 1312 | |
| 1313 | template <class _Rep1, class _Period1, class _Rep2, class _Period2> |
| 1314 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 1315 | _LIBCPP_CONSTEXPRconstexpr |
| 1316 | typename common_type<_Rep1, _Rep2>::type |
| 1317 | operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) |
| 1318 | { |
| 1319 | typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Ct; |
| 1320 | return _Ct(__lhs).count() / _Ct(__rhs).count(); |
| 1321 | } |
| 1322 | |
| 1323 | // Duration % |
| 1324 | |
| 1325 | template <class _Rep1, class _Period, class _Rep2> |
| 1326 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 1327 | _LIBCPP_CONSTEXPRconstexpr |
| 1328 | typename enable_if |
| 1329 | < |
| 1330 | !__is_duration<_Rep2>::value && |
| 1331 | is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value, |
| 1332 | duration<typename common_type<_Rep1, _Rep2>::type, _Period> |
| 1333 | >::type |
| 1334 | operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s) |
| 1335 | { |
| 1336 | typedef typename common_type<_Rep1, _Rep2>::type _Cr; |
| 1337 | typedef duration<_Cr, _Period> _Cd; |
| 1338 | return _Cd(_Cd(__d).count() % static_cast<_Cr>(__s)); |
| 1339 | } |
| 1340 | |
| 1341 | template <class _Rep1, class _Period1, class _Rep2, class _Period2> |
| 1342 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 1343 | _LIBCPP_CONSTEXPRconstexpr |
| 1344 | typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type |
| 1345 | operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) |
| 1346 | { |
| 1347 | typedef typename common_type<_Rep1, _Rep2>::type _Cr; |
| 1348 | typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd; |
| 1349 | return _Cd(static_cast<_Cr>(_Cd(__lhs).count()) % static_cast<_Cr>(_Cd(__rhs).count())); |
| 1350 | } |
| 1351 | |
| 1352 | ////////////////////////////////////////////////////////// |
| 1353 | ///////////////////// time_point ///////////////////////// |
| 1354 | ////////////////////////////////////////////////////////// |
| 1355 | |
| 1356 | template <class _Clock, class _Duration = typename _Clock::duration> |
| 1357 | class _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) time_point |
| 1358 | { |
| 1359 | static_assert(__is_duration<_Duration>::value, |
| 1360 | "Second template parameter of time_point must be a std::chrono::duration"); |
| 1361 | public: |
| 1362 | typedef _Clock clock; |
| 1363 | typedef _Duration duration; |
| 1364 | typedef typename duration::rep rep; |
| 1365 | typedef typename duration::period period; |
| 1366 | private: |
| 1367 | duration __d_; |
| 1368 | |
| 1369 | public: |
| 1370 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPR_AFTER_CXX11constexpr time_point() : __d_(duration::zero()) {} |
| 1371 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPR_AFTER_CXX11constexpr explicit time_point(const duration& __d) : __d_(__d) {} |
| 1372 | |
| 1373 | // conversions |
| 1374 | template <class _Duration2> |
| 1375 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPR_AFTER_CXX11constexpr |
| 1376 | time_point(const time_point<clock, _Duration2>& t, |
| 1377 | typename enable_if |
| 1378 | < |
| 1379 | is_convertible<_Duration2, duration>::value |
| 1380 | >::type* = nullptr) |
| 1381 | : __d_(t.time_since_epoch()) {} |
| 1382 | |
| 1383 | // observer |
| 1384 | |
| 1385 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPR_AFTER_CXX11constexpr duration time_since_epoch() const {return __d_;} |
| 1386 | |
| 1387 | // arithmetic |
| 1388 | |
| 1389 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPR_AFTER_CXX14 time_point& operator+=(const duration& __d) {__d_ += __d; return *this;} |
| 1390 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPR_AFTER_CXX14 time_point& operator-=(const duration& __d) {__d_ -= __d; return *this;} |
| 1391 | |
| 1392 | // special values |
| 1393 | |
| 1394 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) static _LIBCPP_CONSTEXPRconstexpr time_point min() _NOEXCEPTnoexcept {return time_point(duration::min());} |
| 1395 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) static _LIBCPP_CONSTEXPRconstexpr time_point max() _NOEXCEPTnoexcept {return time_point(duration::max());} |
| 1396 | }; |
| 1397 | |
| 1398 | } // chrono |
| 1399 | |
| 1400 | template <class _Clock, class _Duration1, class _Duration2> |
| 1401 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) common_type<chrono::time_point<_Clock, _Duration1>, |
| 1402 | chrono::time_point<_Clock, _Duration2> > |
| 1403 | { |
| 1404 | typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type; |
| 1405 | }; |
| 1406 | |
| 1407 | namespace chrono { |
| 1408 | |
| 1409 | template <class _ToDuration, class _Clock, class _Duration> |
| 1410 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPR_AFTER_CXX11constexpr |
| 1411 | time_point<_Clock, _ToDuration> |
| 1412 | time_point_cast(const time_point<_Clock, _Duration>& __t) |
| 1413 | { |
| 1414 | return time_point<_Clock, _ToDuration>(chrono::duration_cast<_ToDuration>(__t.time_since_epoch())); |
| 1415 | } |
| 1416 | |
| 1417 | #if _LIBCPP_STD_VER14 > 14 |
| 1418 | template <class _ToDuration, class _Clock, class _Duration> |
| 1419 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPRconstexpr |
| 1420 | typename enable_if |
| 1421 | < |
| 1422 | __is_duration<_ToDuration>::value, |
| 1423 | time_point<_Clock, _ToDuration> |
| 1424 | >::type |
| 1425 | floor(const time_point<_Clock, _Duration>& __t) |
| 1426 | { |
| 1427 | return time_point<_Clock, _ToDuration>{floor<_ToDuration>(__t.time_since_epoch())}; |
| 1428 | } |
| 1429 | |
| 1430 | template <class _ToDuration, class _Clock, class _Duration> |
| 1431 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPRconstexpr |
| 1432 | typename enable_if |
| 1433 | < |
| 1434 | __is_duration<_ToDuration>::value, |
| 1435 | time_point<_Clock, _ToDuration> |
| 1436 | >::type |
| 1437 | ceil(const time_point<_Clock, _Duration>& __t) |
| 1438 | { |
| 1439 | return time_point<_Clock, _ToDuration>{ceil<_ToDuration>(__t.time_since_epoch())}; |
| 1440 | } |
| 1441 | |
| 1442 | template <class _ToDuration, class _Clock, class _Duration> |
| 1443 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPRconstexpr |
| 1444 | typename enable_if |
| 1445 | < |
| 1446 | __is_duration<_ToDuration>::value, |
| 1447 | time_point<_Clock, _ToDuration> |
| 1448 | >::type |
| 1449 | round(const time_point<_Clock, _Duration>& __t) |
| 1450 | { |
| 1451 | return time_point<_Clock, _ToDuration>{round<_ToDuration>(__t.time_since_epoch())}; |
| 1452 | } |
| 1453 | |
| 1454 | template <class _Rep, class _Period> |
| 1455 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPRconstexpr |
| 1456 | typename enable_if |
| 1457 | < |
| 1458 | numeric_limits<_Rep>::is_signed, |
| 1459 | duration<_Rep, _Period> |
| 1460 | >::type |
| 1461 | abs(duration<_Rep, _Period> __d) |
| 1462 | { |
| 1463 | return __d >= __d.zero() ? +__d : -__d; |
| 1464 | } |
| 1465 | #endif |
| 1466 | |
| 1467 | // time_point == |
| 1468 | |
| 1469 | template <class _Clock, class _Duration1, class _Duration2> |
| 1470 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPR_AFTER_CXX11constexpr |
| 1471 | bool |
| 1472 | operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) |
| 1473 | { |
| 1474 | return __lhs.time_since_epoch() == __rhs.time_since_epoch(); |
| 1475 | } |
| 1476 | |
| 1477 | // time_point != |
| 1478 | |
| 1479 | template <class _Clock, class _Duration1, class _Duration2> |
| 1480 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPR_AFTER_CXX11constexpr |
| 1481 | bool |
| 1482 | operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) |
| 1483 | { |
| 1484 | return !(__lhs == __rhs); |
| 1485 | } |
| 1486 | |
| 1487 | // time_point < |
| 1488 | |
| 1489 | template <class _Clock, class _Duration1, class _Duration2> |
| 1490 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPR_AFTER_CXX11constexpr |
| 1491 | bool |
| 1492 | operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) |
| 1493 | { |
| 1494 | return __lhs.time_since_epoch() < __rhs.time_since_epoch(); |
| 1495 | } |
| 1496 | |
| 1497 | // time_point > |
| 1498 | |
| 1499 | template <class _Clock, class _Duration1, class _Duration2> |
| 1500 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPR_AFTER_CXX11constexpr |
| 1501 | bool |
| 1502 | operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) |
| 1503 | { |
| 1504 | return __rhs < __lhs; |
| 1505 | } |
| 1506 | |
| 1507 | // time_point <= |
| 1508 | |
| 1509 | template <class _Clock, class _Duration1, class _Duration2> |
| 1510 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPR_AFTER_CXX11constexpr |
| 1511 | bool |
| 1512 | operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) |
| 1513 | { |
| 1514 | return !(__rhs < __lhs); |
| 1515 | } |
| 1516 | |
| 1517 | // time_point >= |
| 1518 | |
| 1519 | template <class _Clock, class _Duration1, class _Duration2> |
| 1520 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPR_AFTER_CXX11constexpr |
| 1521 | bool |
| 1522 | operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) |
| 1523 | { |
| 1524 | return !(__lhs < __rhs); |
| 1525 | } |
| 1526 | |
| 1527 | // time_point operator+(time_point x, duration y); |
| 1528 | |
| 1529 | template <class _Clock, class _Duration1, class _Rep2, class _Period2> |
| 1530 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPR_AFTER_CXX11constexpr |
| 1531 | time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> |
| 1532 | operator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs) |
| 1533 | { |
| 1534 | typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Tr; |
| 1535 | return _Tr (__lhs.time_since_epoch() + __rhs); |
| 1536 | } |
| 1537 | |
| 1538 | // time_point operator+(duration x, time_point y); |
| 1539 | |
| 1540 | template <class _Rep1, class _Period1, class _Clock, class _Duration2> |
| 1541 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPR_AFTER_CXX11constexpr |
| 1542 | time_point<_Clock, typename common_type<duration<_Rep1, _Period1>, _Duration2>::type> |
| 1543 | operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) |
| 1544 | { |
| 1545 | return __rhs + __lhs; |
| 1546 | } |
| 1547 | |
| 1548 | // time_point operator-(time_point x, duration y); |
| 1549 | |
| 1550 | template <class _Clock, class _Duration1, class _Rep2, class _Period2> |
| 1551 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPR_AFTER_CXX11constexpr |
| 1552 | time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> |
| 1553 | operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs) |
| 1554 | { |
| 1555 | typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Ret; |
| 1556 | return _Ret(__lhs.time_since_epoch() -__rhs); |
| 1557 | } |
| 1558 | |
| 1559 | // duration operator-(time_point x, time_point y); |
| 1560 | |
| 1561 | template <class _Clock, class _Duration1, class _Duration2> |
| 1562 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) _LIBCPP_CONSTEXPR_AFTER_CXX11constexpr |
| 1563 | typename common_type<_Duration1, _Duration2>::type |
| 1564 | operator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) |
| 1565 | { |
| 1566 | return __lhs.time_since_epoch() - __rhs.time_since_epoch(); |
| 1567 | } |
| 1568 | |
| 1569 | ////////////////////////////////////////////////////////// |
| 1570 | /////////////////////// clocks /////////////////////////// |
| 1571 | ////////////////////////////////////////////////////////// |
| 1572 | |
| 1573 | class _LIBCPP_TYPE_VIS__attribute__ ((__visibility__("default"))) system_clock |
| 1574 | { |
| 1575 | public: |
| 1576 | typedef microseconds duration; |
| 1577 | typedef duration::rep rep; |
| 1578 | typedef duration::period period; |
| 1579 | typedef chrono::time_point<system_clock> time_point; |
| 1580 | static _LIBCPP_CONSTEXPR_AFTER_CXX11constexpr const bool is_steady = false; |
| 1581 | |
| 1582 | static time_point now() _NOEXCEPTnoexcept; |
| 1583 | static time_t to_time_t (const time_point& __t) _NOEXCEPTnoexcept; |
| 1584 | static time_point from_time_t(time_t __t) _NOEXCEPTnoexcept; |
| 1585 | }; |
| 1586 | |
| 1587 | #ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK |
| 1588 | class _LIBCPP_TYPE_VIS__attribute__ ((__visibility__("default"))) steady_clock |
| 1589 | { |
| 1590 | public: |
| 1591 | typedef nanoseconds duration; |
| 1592 | typedef duration::rep rep; |
| 1593 | typedef duration::period period; |
| 1594 | typedef chrono::time_point<steady_clock, duration> time_point; |
| 1595 | static _LIBCPP_CONSTEXPR_AFTER_CXX11constexpr const bool is_steady = true; |
| 1596 | |
| 1597 | static time_point now() _NOEXCEPTnoexcept; |
| 1598 | }; |
| 1599 | |
| 1600 | typedef steady_clock high_resolution_clock; |
| 1601 | #else |
| 1602 | typedef system_clock high_resolution_clock; |
| 1603 | #endif |
| 1604 | |
| 1605 | #if _LIBCPP_STD_VER14 > 17 |
| 1606 | // [time.clock.file], type file_clock |
| 1607 | using file_clock = _VSTD_FSstd::__1::__fs::filesystem::_FilesystemClock; |
| 1608 | |
| 1609 | template<class _Duration> |
| 1610 | using file_time = time_point<file_clock, _Duration>; |
| 1611 | |
| 1612 | |
| 1613 | template <class _Duration> |
| 1614 | using sys_time = time_point<system_clock, _Duration>; |
| 1615 | using sys_seconds = sys_time<seconds>; |
| 1616 | using sys_days = sys_time<days>; |
| 1617 | |
| 1618 | struct local_t {}; |
| 1619 | template<class Duration> |
| 1620 | using local_time = time_point<local_t, Duration>; |
| 1621 | using local_seconds = local_time<seconds>; |
| 1622 | using local_days = local_time<days>; |
| 1623 | |
| 1624 | |
| 1625 | struct last_spec { explicit last_spec() = default; }; |
| 1626 | |
| 1627 | class day { |
| 1628 | private: |
| 1629 | unsigned char __d; |
| 1630 | public: |
| 1631 | day() = default; |
| 1632 | explicit inline constexpr day(unsigned __val) noexcept : __d(static_cast<unsigned char>(__val)) {} |
| 1633 | inline constexpr day& operator++() noexcept { ++__d; return *this; } |
| 1634 | inline constexpr day operator++(int) noexcept { day __tmp = *this; ++(*this); return __tmp; } |
| 1635 | inline constexpr day& operator--() noexcept { --__d; return *this; } |
| 1636 | inline constexpr day operator--(int) noexcept { day __tmp = *this; --(*this); return __tmp; } |
| 1637 | constexpr day& operator+=(const days& __dd) noexcept; |
| 1638 | constexpr day& operator-=(const days& __dd) noexcept; |
| 1639 | explicit inline constexpr operator unsigned() const noexcept { return __d; } |
| 1640 | inline constexpr bool ok() const noexcept { return __d >= 1 && __d <= 31; } |
| 1641 | }; |
| 1642 | |
| 1643 | |
| 1644 | inline constexpr |
| 1645 | bool operator==(const day& __lhs, const day& __rhs) noexcept |
| 1646 | { return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); } |
| 1647 | |
| 1648 | inline constexpr |
| 1649 | bool operator!=(const day& __lhs, const day& __rhs) noexcept |
| 1650 | { return !(__lhs == __rhs); } |
| 1651 | |
| 1652 | inline constexpr |
| 1653 | bool operator< (const day& __lhs, const day& __rhs) noexcept |
| 1654 | { return static_cast<unsigned>(__lhs) < static_cast<unsigned>(__rhs); } |
| 1655 | |
| 1656 | inline constexpr |
| 1657 | bool operator> (const day& __lhs, const day& __rhs) noexcept |
| 1658 | { return __rhs < __lhs; } |
| 1659 | |
| 1660 | inline constexpr |
| 1661 | bool operator<=(const day& __lhs, const day& __rhs) noexcept |
| 1662 | { return !(__rhs < __lhs);} |
| 1663 | |
| 1664 | inline constexpr |
| 1665 | bool operator>=(const day& __lhs, const day& __rhs) noexcept |
| 1666 | { return !(__lhs < __rhs); } |
| 1667 | |
| 1668 | inline constexpr |
| 1669 | day operator+ (const day& __lhs, const days& __rhs) noexcept |
| 1670 | { return day(static_cast<unsigned>(__lhs) + __rhs.count()); } |
| 1671 | |
| 1672 | inline constexpr |
| 1673 | day operator+ (const days& __lhs, const day& __rhs) noexcept |
| 1674 | { return __rhs + __lhs; } |
| 1675 | |
| 1676 | inline constexpr |
| 1677 | day operator- (const day& __lhs, const days& __rhs) noexcept |
| 1678 | { return __lhs + -__rhs; } |
| 1679 | |
| 1680 | inline constexpr |
| 1681 | days operator-(const day& __lhs, const day& __rhs) noexcept |
| 1682 | { return days(static_cast<int>(static_cast<unsigned>(__lhs)) - |
| 1683 | static_cast<int>(static_cast<unsigned>(__rhs))); } |
| 1684 | |
| 1685 | inline constexpr day& day::operator+=(const days& __dd) noexcept |
| 1686 | { *this = *this + __dd; return *this; } |
| 1687 | |
| 1688 | inline constexpr day& day::operator-=(const days& __dd) noexcept |
| 1689 | { *this = *this - __dd; return *this; } |
| 1690 | |
| 1691 | |
| 1692 | class month { |
| 1693 | private: |
| 1694 | unsigned char __m; |
| 1695 | public: |
| 1696 | month() = default; |
| 1697 | explicit inline constexpr month(unsigned __val) noexcept : __m(static_cast<unsigned char>(__val)) {} |
| 1698 | inline constexpr month& operator++() noexcept { ++__m; return *this; } |
| 1699 | inline constexpr month operator++(int) noexcept { month __tmp = *this; ++(*this); return __tmp; } |
| 1700 | inline constexpr month& operator--() noexcept { --__m; return *this; } |
| 1701 | inline constexpr month operator--(int) noexcept { month __tmp = *this; --(*this); return __tmp; } |
| 1702 | constexpr month& operator+=(const months& __m1) noexcept; |
| 1703 | constexpr month& operator-=(const months& __m1) noexcept; |
| 1704 | explicit inline constexpr operator unsigned() const noexcept { return __m; } |
| 1705 | inline constexpr bool ok() const noexcept { return __m >= 1 && __m <= 12; } |
| 1706 | }; |
| 1707 | |
| 1708 | |
| 1709 | inline constexpr |
| 1710 | bool operator==(const month& __lhs, const month& __rhs) noexcept |
| 1711 | { return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); } |
| 1712 | |
| 1713 | inline constexpr |
| 1714 | bool operator!=(const month& __lhs, const month& __rhs) noexcept |
| 1715 | { return !(__lhs == __rhs); } |
| 1716 | |
| 1717 | inline constexpr |
| 1718 | bool operator< (const month& __lhs, const month& __rhs) noexcept |
| 1719 | { return static_cast<unsigned>(__lhs) < static_cast<unsigned>(__rhs); } |
| 1720 | |
| 1721 | inline constexpr |
| 1722 | bool operator> (const month& __lhs, const month& __rhs) noexcept |
| 1723 | { return __rhs < __lhs; } |
| 1724 | |
| 1725 | inline constexpr |
| 1726 | bool operator<=(const month& __lhs, const month& __rhs) noexcept |
| 1727 | { return !(__rhs < __lhs); } |
| 1728 | |
| 1729 | inline constexpr |
| 1730 | bool operator>=(const month& __lhs, const month& __rhs) noexcept |
| 1731 | { return !(__lhs < __rhs); } |
| 1732 | |
| 1733 | inline constexpr |
| 1734 | month operator+ (const month& __lhs, const months& __rhs) noexcept |
| 1735 | { |
| 1736 | auto const __mu = static_cast<long long>(static_cast<unsigned>(__lhs)) + (__rhs.count() - 1); |
| 1737 | auto const __yr = (__mu >= 0 ? __mu : __mu - 11) / 12; |
| 1738 | return month{static_cast<unsigned>(__mu - __yr * 12 + 1)}; |
| 1739 | } |
| 1740 | |
| 1741 | inline constexpr |
| 1742 | month operator+ (const months& __lhs, const month& __rhs) noexcept |
| 1743 | { return __rhs + __lhs; } |
| 1744 | |
| 1745 | inline constexpr |
| 1746 | month operator- (const month& __lhs, const months& __rhs) noexcept |
| 1747 | { return __lhs + -__rhs; } |
| 1748 | |
| 1749 | inline constexpr |
| 1750 | months operator-(const month& __lhs, const month& __rhs) noexcept |
| 1751 | { |
| 1752 | auto const __dm = static_cast<unsigned>(__lhs) - static_cast<unsigned>(__rhs); |
| 1753 | return months(__dm <= 11 ? __dm : __dm + 12); |
| 1754 | } |
| 1755 | |
| 1756 | inline constexpr month& month::operator+=(const months& __dm) noexcept |
| 1757 | { *this = *this + __dm; return *this; } |
| 1758 | |
| 1759 | inline constexpr month& month::operator-=(const months& __dm) noexcept |
| 1760 | { *this = *this - __dm; return *this; } |
| 1761 | |
| 1762 | |
| 1763 | class year { |
| 1764 | private: |
| 1765 | short __y; |
| 1766 | public: |
| 1767 | year() = default; |
| 1768 | explicit inline constexpr year(int __val) noexcept : __y(static_cast<short>(__val)) {} |
| 1769 | |
| 1770 | inline constexpr year& operator++() noexcept { ++__y; return *this; } |
| 1771 | inline constexpr year operator++(int) noexcept { year __tmp = *this; ++(*this); return __tmp; } |
| 1772 | inline constexpr year& operator--() noexcept { --__y; return *this; } |
| 1773 | inline constexpr year operator--(int) noexcept { year __tmp = *this; --(*this); return __tmp; } |
| 1774 | constexpr year& operator+=(const years& __dy) noexcept; |
| 1775 | constexpr year& operator-=(const years& __dy) noexcept; |
| 1776 | inline constexpr year operator+() const noexcept { return *this; } |
| 1777 | inline constexpr year operator-() const noexcept { return year{-__y}; } |
| 1778 | |
| 1779 | inline constexpr bool is_leap() const noexcept { return __y % 4 == 0 && (__y % 100 != 0 || __y % 400 == 0); } |
| 1780 | explicit inline constexpr operator int() const noexcept { return __y; } |
| 1781 | constexpr bool ok() const noexcept; |
| 1782 | static inline constexpr year min() noexcept { return year{-32767}; } |
| 1783 | static inline constexpr year max() noexcept { return year{ 32767}; } |
| 1784 | }; |
| 1785 | |
| 1786 | |
| 1787 | inline constexpr |
| 1788 | bool operator==(const year& __lhs, const year& __rhs) noexcept |
| 1789 | { return static_cast<int>(__lhs) == static_cast<int>(__rhs); } |
| 1790 | |
| 1791 | inline constexpr |
| 1792 | bool operator!=(const year& __lhs, const year& __rhs) noexcept |
| 1793 | { return !(__lhs == __rhs); } |
| 1794 | |
| 1795 | inline constexpr |
| 1796 | bool operator< (const year& __lhs, const year& __rhs) noexcept |
| 1797 | { return static_cast<int>(__lhs) < static_cast<int>(__rhs); } |
| 1798 | |
| 1799 | inline constexpr |
| 1800 | bool operator> (const year& __lhs, const year& __rhs) noexcept |
| 1801 | { return __rhs < __lhs; } |
| 1802 | |
| 1803 | inline constexpr |
| 1804 | bool operator<=(const year& __lhs, const year& __rhs) noexcept |
| 1805 | { return !(__rhs < __lhs); } |
| 1806 | |
| 1807 | inline constexpr |
| 1808 | bool operator>=(const year& __lhs, const year& __rhs) noexcept |
| 1809 | { return !(__lhs < __rhs); } |
| 1810 | |
| 1811 | inline constexpr |
| 1812 | year operator+ (const year& __lhs, const years& __rhs) noexcept |
| 1813 | { return year(static_cast<int>(__lhs) + __rhs.count()); } |
| 1814 | |
| 1815 | inline constexpr |
| 1816 | year operator+ (const years& __lhs, const year& __rhs) noexcept |
| 1817 | { return __rhs + __lhs; } |
| 1818 | |
| 1819 | inline constexpr |
| 1820 | year operator- (const year& __lhs, const years& __rhs) noexcept |
| 1821 | { return __lhs + -__rhs; } |
| 1822 | |
| 1823 | inline constexpr |
| 1824 | years operator-(const year& __lhs, const year& __rhs) noexcept |
| 1825 | { return years{static_cast<int>(__lhs) - static_cast<int>(__rhs)}; } |
| 1826 | |
| 1827 | |
| 1828 | inline constexpr year& year::operator+=(const years& __dy) noexcept |
| 1829 | { *this = *this + __dy; return *this; } |
| 1830 | |
| 1831 | inline constexpr year& year::operator-=(const years& __dy) noexcept |
| 1832 | { *this = *this - __dy; return *this; } |
| 1833 | |
| 1834 | inline constexpr bool year::ok() const noexcept |
| 1835 | { return static_cast<int>(min()) <= __y && __y <= static_cast<int>(max()); } |
| 1836 | |
| 1837 | class weekday_indexed; |
| 1838 | class weekday_last; |
| 1839 | |
| 1840 | class weekday { |
| 1841 | private: |
| 1842 | unsigned char __wd; |
| 1843 | public: |
| 1844 | weekday() = default; |
| 1845 | inline explicit constexpr weekday(unsigned __val) noexcept : __wd(static_cast<unsigned char>(__val == 7 ? 0 : __val)) {} |
| 1846 | inline constexpr weekday(const sys_days& __sysd) noexcept |
| 1847 | : __wd(__weekday_from_days(__sysd.time_since_epoch().count())) {} |
| 1848 | inline explicit constexpr weekday(const local_days& __locd) noexcept |
| 1849 | : __wd(__weekday_from_days(__locd.time_since_epoch().count())) {} |
| 1850 | |
| 1851 | inline constexpr weekday& operator++() noexcept { __wd = (__wd == 6 ? 0 : __wd + 1); return *this; } |
| 1852 | inline constexpr weekday operator++(int) noexcept { weekday __tmp = *this; ++(*this); return __tmp; } |
| 1853 | inline constexpr weekday& operator--() noexcept { __wd = (__wd == 0 ? 6 : __wd - 1); return *this; } |
| 1854 | inline constexpr weekday operator--(int) noexcept { weekday __tmp = *this; --(*this); return __tmp; } |
| 1855 | constexpr weekday& operator+=(const days& __dd) noexcept; |
| 1856 | constexpr weekday& operator-=(const days& __dd) noexcept; |
| 1857 | inline constexpr unsigned c_encoding() const noexcept { return __wd; } |
| 1858 | inline constexpr unsigned iso_encoding() const noexcept { return __wd == 0u ? 7 : __wd; } |
| 1859 | inline constexpr bool ok() const noexcept { return __wd <= 6; } |
| 1860 | constexpr weekday_indexed operator[](unsigned __index) const noexcept; |
| 1861 | constexpr weekday_last operator[](last_spec) const noexcept; |
| 1862 | |
| 1863 | // TODO: Make private? |
| 1864 | static constexpr unsigned char __weekday_from_days(int __days) noexcept; |
| 1865 | }; |
| 1866 | |
| 1867 | |
| 1868 | // https://howardhinnant.github.io/date_algorithms.html#weekday_from_days |
| 1869 | inline constexpr |
| 1870 | unsigned char weekday::__weekday_from_days(int __days) noexcept |
| 1871 | { |
| 1872 | return static_cast<unsigned char>( |
| 1873 | static_cast<unsigned>(__days >= -4 ? (__days+4) % 7 : (__days+5) % 7 + 6) |
| 1874 | ); |
| 1875 | } |
| 1876 | |
| 1877 | inline constexpr |
| 1878 | bool operator==(const weekday& __lhs, const weekday& __rhs) noexcept |
| 1879 | { return __lhs.c_encoding() == __rhs.c_encoding(); } |
| 1880 | |
| 1881 | inline constexpr |
| 1882 | bool operator!=(const weekday& __lhs, const weekday& __rhs) noexcept |
| 1883 | { return !(__lhs == __rhs); } |
| 1884 | |
| 1885 | inline constexpr |
| 1886 | bool operator< (const weekday& __lhs, const weekday& __rhs) noexcept |
| 1887 | { return __lhs.c_encoding() < __rhs.c_encoding(); } |
| 1888 | |
| 1889 | inline constexpr |
| 1890 | bool operator> (const weekday& __lhs, const weekday& __rhs) noexcept |
| 1891 | { return __rhs < __lhs; } |
| 1892 | |
| 1893 | inline constexpr |
| 1894 | bool operator<=(const weekday& __lhs, const weekday& __rhs) noexcept |
| 1895 | { return !(__rhs < __lhs);} |
| 1896 | |
| 1897 | inline constexpr |
| 1898 | bool operator>=(const weekday& __lhs, const weekday& __rhs) noexcept |
| 1899 | { return !(__lhs < __rhs); } |
| 1900 | |
| 1901 | constexpr weekday operator+(const weekday& __lhs, const days& __rhs) noexcept |
| 1902 | { |
| 1903 | auto const __mu = static_cast<long long>(__lhs.c_encoding()) + __rhs.count(); |
| 1904 | auto const __yr = (__mu >= 0 ? __mu : __mu - 6) / 7; |
| 1905 | return weekday{static_cast<unsigned>(__mu - __yr * 7)}; |
| 1906 | } |
| 1907 | |
| 1908 | constexpr weekday operator+(const days& __lhs, const weekday& __rhs) noexcept |
| 1909 | { return __rhs + __lhs; } |
| 1910 | |
| 1911 | constexpr weekday operator-(const weekday& __lhs, const days& __rhs) noexcept |
| 1912 | { return __lhs + -__rhs; } |
| 1913 | |
| 1914 | constexpr days operator-(const weekday& __lhs, const weekday& __rhs) noexcept |
| 1915 | { |
| 1916 | const int __wdu = __lhs.c_encoding() - __rhs.c_encoding(); |
| 1917 | const int __wk = (__wdu >= 0 ? __wdu : __wdu-6) / 7; |
| 1918 | return days{__wdu - __wk * 7}; |
| 1919 | } |
| 1920 | |
| 1921 | inline constexpr weekday& weekday::operator+=(const days& __dd) noexcept |
| 1922 | { *this = *this + __dd; return *this; } |
| 1923 | |
| 1924 | inline constexpr weekday& weekday::operator-=(const days& __dd) noexcept |
| 1925 | { *this = *this - __dd; return *this; } |
| 1926 | |
| 1927 | |
| 1928 | class weekday_indexed { |
| 1929 | private: |
| 1930 | chrono::weekday __wd; |
| 1931 | unsigned char __idx; |
| 1932 | public: |
| 1933 | weekday_indexed() = default; |
| 1934 | inline constexpr weekday_indexed(const chrono::weekday& __wdval, unsigned __idxval) noexcept |
| 1935 | : __wd{__wdval}, __idx(__idxval) {} |
| 1936 | inline constexpr chrono::weekday weekday() const noexcept { return __wd; } |
| 1937 | inline constexpr unsigned index() const noexcept { return __idx; } |
| 1938 | inline constexpr bool ok() const noexcept { return __wd.ok() && __idx >= 1 && __idx <= 5; } |
| 1939 | }; |
| 1940 | |
| 1941 | inline constexpr |
| 1942 | bool operator==(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept |
| 1943 | { return __lhs.weekday() == __rhs.weekday() && __lhs.index() == __rhs.index(); } |
| 1944 | |
| 1945 | inline constexpr |
| 1946 | bool operator!=(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept |
| 1947 | { return !(__lhs == __rhs); } |
| 1948 | |
| 1949 | |
| 1950 | class weekday_last { |
| 1951 | private: |
| 1952 | chrono::weekday __wd; |
| 1953 | public: |
| 1954 | explicit constexpr weekday_last(const chrono::weekday& __val) noexcept |
| 1955 | : __wd{__val} {} |
| 1956 | constexpr chrono::weekday weekday() const noexcept { return __wd; } |
| 1957 | constexpr bool ok() const noexcept { return __wd.ok(); } |
| 1958 | }; |
| 1959 | |
| 1960 | inline constexpr |
| 1961 | bool operator==(const weekday_last& __lhs, const weekday_last& __rhs) noexcept |
| 1962 | { return __lhs.weekday() == __rhs.weekday(); } |
| 1963 | |
| 1964 | inline constexpr |
| 1965 | bool operator!=(const weekday_last& __lhs, const weekday_last& __rhs) noexcept |
| 1966 | { return !(__lhs == __rhs); } |
| 1967 | |
| 1968 | inline constexpr |
| 1969 | weekday_indexed weekday::operator[](unsigned __index) const noexcept { return weekday_indexed{*this, __index}; } |
| 1970 | |
| 1971 | inline constexpr |
| 1972 | weekday_last weekday::operator[](last_spec) const noexcept { return weekday_last{*this}; } |
| 1973 | |
| 1974 | |
| 1975 | inline constexpr last_spec last{}; |
| 1976 | inline constexpr weekday Sunday{0}; |
| 1977 | inline constexpr weekday Monday{1}; |
| 1978 | inline constexpr weekday Tuesday{2}; |
| 1979 | inline constexpr weekday Wednesday{3}; |
| 1980 | inline constexpr weekday Thursday{4}; |
| 1981 | inline constexpr weekday Friday{5}; |
| 1982 | inline constexpr weekday Saturday{6}; |
| 1983 | |
| 1984 | inline constexpr month January{1}; |
| 1985 | inline constexpr month February{2}; |
| 1986 | inline constexpr month March{3}; |
| 1987 | inline constexpr month April{4}; |
| 1988 | inline constexpr month May{5}; |
| 1989 | inline constexpr month June{6}; |
| 1990 | inline constexpr month July{7}; |
| 1991 | inline constexpr month August{8}; |
| 1992 | inline constexpr month September{9}; |
| 1993 | inline constexpr month October{10}; |
| 1994 | inline constexpr month November{11}; |
| 1995 | inline constexpr month December{12}; |
| 1996 | |
| 1997 | |
| 1998 | class month_day { |
| 1999 | private: |
| 2000 | chrono::month __m; |
| 2001 | chrono::day __d; |
| 2002 | public: |
| 2003 | month_day() = default; |
| 2004 | constexpr month_day(const chrono::month& __mval, const chrono::day& __dval) noexcept |
| 2005 | : __m{__mval}, __d{__dval} {} |
| 2006 | inline constexpr chrono::month month() const noexcept { return __m; } |
| 2007 | inline constexpr chrono::day day() const noexcept { return __d; } |
| 2008 | constexpr bool ok() const noexcept; |
| 2009 | }; |
| 2010 | |
| 2011 | inline constexpr |
| 2012 | bool month_day::ok() const noexcept |
| 2013 | { |
| 2014 | if (!__m.ok()) return false; |
| 2015 | const unsigned __dval = static_cast<unsigned>(__d); |
| 2016 | if (__dval < 1 || __dval > 31) return false; |
| 2017 | if (__dval <= 29) return true; |
| 2018 | // Now we've got either 30 or 31 |
| 2019 | const unsigned __mval = static_cast<unsigned>(__m); |
| 2020 | if (__mval == 2) return false; |
| 2021 | if (__mval == 4 || __mval == 6 || __mval == 9 || __mval == 11) |
| 2022 | return __dval == 30; |
| 2023 | return true; |
| 2024 | } |
| 2025 | |
| 2026 | inline constexpr |
| 2027 | bool operator==(const month_day& __lhs, const month_day& __rhs) noexcept |
| 2028 | { return __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); } |
| 2029 | |
| 2030 | inline constexpr |
| 2031 | bool operator!=(const month_day& __lhs, const month_day& __rhs) noexcept |
| 2032 | { return !(__lhs == __rhs); } |
| 2033 | |
| 2034 | inline constexpr |
| 2035 | month_day operator/(const month& __lhs, const day& __rhs) noexcept |
| 2036 | { return month_day{__lhs, __rhs}; } |
| 2037 | |
| 2038 | constexpr |
| 2039 | month_day operator/(const day& __lhs, const month& __rhs) noexcept |
| 2040 | { return __rhs / __lhs; } |
| 2041 | |
| 2042 | inline constexpr |
| 2043 | month_day operator/(const month& __lhs, int __rhs) noexcept |
| 2044 | { return __lhs / day(__rhs); } |
| 2045 | |
| 2046 | constexpr |
| 2047 | month_day operator/(int __lhs, const day& __rhs) noexcept |
| 2048 | { return month(__lhs) / __rhs; } |
| 2049 | |
| 2050 | constexpr |
| 2051 | month_day operator/(const day& __lhs, int __rhs) noexcept |
| 2052 | { return month(__rhs) / __lhs; } |
| 2053 | |
| 2054 | |
| 2055 | inline constexpr |
| 2056 | bool operator< (const month_day& __lhs, const month_day& __rhs) noexcept |
| 2057 | { return __lhs.month() != __rhs.month() ? __lhs.month() < __rhs.month() : __lhs.day() < __rhs.day(); } |
| 2058 | |
| 2059 | inline constexpr |
| 2060 | bool operator> (const month_day& __lhs, const month_day& __rhs) noexcept |
| 2061 | { return __rhs < __lhs; } |
| 2062 | |
| 2063 | inline constexpr |
| 2064 | bool operator<=(const month_day& __lhs, const month_day& __rhs) noexcept |
| 2065 | { return !(__rhs < __lhs);} |
| 2066 | |
| 2067 | inline constexpr |
| 2068 | bool operator>=(const month_day& __lhs, const month_day& __rhs) noexcept |
| 2069 | { return !(__lhs < __rhs); } |
| 2070 | |
| 2071 | |
| 2072 | |
| 2073 | class month_day_last { |
| 2074 | private: |
| 2075 | chrono::month __m; |
| 2076 | public: |
| 2077 | explicit constexpr month_day_last(const chrono::month& __val) noexcept |
| 2078 | : __m{__val} {} |
| 2079 | inline constexpr chrono::month month() const noexcept { return __m; } |
| 2080 | inline constexpr bool ok() const noexcept { return __m.ok(); } |
| 2081 | }; |
| 2082 | |
| 2083 | inline constexpr |
| 2084 | bool operator==(const month_day_last& __lhs, const month_day_last& __rhs) noexcept |
| 2085 | { return __lhs.month() == __rhs.month(); } |
| 2086 | |
| 2087 | inline constexpr |
| 2088 | bool operator!=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept |
| 2089 | { return !(__lhs == __rhs); } |
| 2090 | |
| 2091 | inline constexpr |
| 2092 | bool operator< (const month_day_last& __lhs, const month_day_last& __rhs) noexcept |
| 2093 | { return __lhs.month() < __rhs.month(); } |
| 2094 | |
| 2095 | inline constexpr |
| 2096 | bool operator> (const month_day_last& __lhs, const month_day_last& __rhs) noexcept |
| 2097 | { return __rhs < __lhs; } |
| 2098 | |
| 2099 | inline constexpr |
| 2100 | bool operator<=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept |
| 2101 | { return !(__rhs < __lhs);} |
| 2102 | |
| 2103 | inline constexpr |
| 2104 | bool operator>=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept |
| 2105 | { return !(__lhs < __rhs); } |
| 2106 | |
| 2107 | inline constexpr |
| 2108 | month_day_last operator/(const month& __lhs, last_spec) noexcept |
| 2109 | { return month_day_last{__lhs}; } |
| 2110 | |
| 2111 | inline constexpr |
| 2112 | month_day_last operator/(last_spec, const month& __rhs) noexcept |
| 2113 | { return month_day_last{__rhs}; } |
| 2114 | |
| 2115 | inline constexpr |
| 2116 | month_day_last operator/(int __lhs, last_spec) noexcept |
| 2117 | { return month_day_last{month(__lhs)}; } |
| 2118 | |
| 2119 | inline constexpr |
| 2120 | month_day_last operator/(last_spec, int __rhs) noexcept |
| 2121 | { return month_day_last{month(__rhs)}; } |
| 2122 | |
| 2123 | |
| 2124 | class month_weekday { |
| 2125 | private: |
| 2126 | chrono::month __m; |
| 2127 | chrono::weekday_indexed __wdi; |
| 2128 | public: |
| 2129 | month_weekday() = default; |
| 2130 | constexpr month_weekday(const chrono::month& __mval, const chrono::weekday_indexed& __wdival) noexcept |
| 2131 | : __m{__mval}, __wdi{__wdival} {} |
| 2132 | inline constexpr chrono::month month() const noexcept { return __m; } |
| 2133 | inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi; } |
| 2134 | inline constexpr bool ok() const noexcept { return __m.ok() && __wdi.ok(); } |
| 2135 | }; |
| 2136 | |
| 2137 | inline constexpr |
| 2138 | bool operator==(const month_weekday& __lhs, const month_weekday& __rhs) noexcept |
| 2139 | { return __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); } |
| 2140 | |
| 2141 | inline constexpr |
| 2142 | bool operator!=(const month_weekday& __lhs, const month_weekday& __rhs) noexcept |
| 2143 | { return !(__lhs == __rhs); } |
| 2144 | |
| 2145 | inline constexpr |
| 2146 | month_weekday operator/(const month& __lhs, const weekday_indexed& __rhs) noexcept |
| 2147 | { return month_weekday{__lhs, __rhs}; } |
| 2148 | |
| 2149 | inline constexpr |
| 2150 | month_weekday operator/(int __lhs, const weekday_indexed& __rhs) noexcept |
| 2151 | { return month_weekday{month(__lhs), __rhs}; } |
| 2152 | |
| 2153 | inline constexpr |
| 2154 | month_weekday operator/(const weekday_indexed& __lhs, const month& __rhs) noexcept |
| 2155 | { return month_weekday{__rhs, __lhs}; } |
| 2156 | |
| 2157 | inline constexpr |
| 2158 | month_weekday operator/(const weekday_indexed& __lhs, int __rhs) noexcept |
| 2159 | { return month_weekday{month(__rhs), __lhs}; } |
| 2160 | |
| 2161 | |
| 2162 | class month_weekday_last { |
| 2163 | chrono::month __m; |
| 2164 | chrono::weekday_last __wdl; |
| 2165 | public: |
| 2166 | constexpr month_weekday_last(const chrono::month& __mval, const chrono::weekday_last& __wdlval) noexcept |
| 2167 | : __m{__mval}, __wdl{__wdlval} {} |
| 2168 | inline constexpr chrono::month month() const noexcept { return __m; } |
| 2169 | inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl; } |
| 2170 | inline constexpr bool ok() const noexcept { return __m.ok() && __wdl.ok(); } |
| 2171 | }; |
| 2172 | |
| 2173 | inline constexpr |
| 2174 | bool operator==(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept |
| 2175 | { return __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); } |
| 2176 | |
| 2177 | inline constexpr |
| 2178 | bool operator!=(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept |
| 2179 | { return !(__lhs == __rhs); } |
| 2180 | |
| 2181 | |
| 2182 | inline constexpr |
| 2183 | month_weekday_last operator/(const month& __lhs, const weekday_last& __rhs) noexcept |
| 2184 | { return month_weekday_last{__lhs, __rhs}; } |
| 2185 | |
| 2186 | inline constexpr |
| 2187 | month_weekday_last operator/(int __lhs, const weekday_last& __rhs) noexcept |
| 2188 | { return month_weekday_last{month(__lhs), __rhs}; } |
| 2189 | |
| 2190 | inline constexpr |
| 2191 | month_weekday_last operator/(const weekday_last& __lhs, const month& __rhs) noexcept |
| 2192 | { return month_weekday_last{__rhs, __lhs}; } |
| 2193 | |
| 2194 | inline constexpr |
| 2195 | month_weekday_last operator/(const weekday_last& __lhs, int __rhs) noexcept |
| 2196 | { return month_weekday_last{month(__rhs), __lhs}; } |
| 2197 | |
| 2198 | |
| 2199 | class year_month { |
| 2200 | chrono::year __y; |
| 2201 | chrono::month __m; |
| 2202 | public: |
| 2203 | year_month() = default; |
| 2204 | constexpr year_month(const chrono::year& __yval, const chrono::month& __mval) noexcept |
| 2205 | : __y{__yval}, __m{__mval} {} |
| 2206 | inline constexpr chrono::year year() const noexcept { return __y; } |
| 2207 | inline constexpr chrono::month month() const noexcept { return __m; } |
| 2208 | inline constexpr year_month& operator+=(const months& __dm) noexcept { this->__m += __dm; return *this; } |
| 2209 | inline constexpr year_month& operator-=(const months& __dm) noexcept { this->__m -= __dm; return *this; } |
| 2210 | inline constexpr year_month& operator+=(const years& __dy) noexcept { this->__y += __dy; return *this; } |
| 2211 | inline constexpr year_month& operator-=(const years& __dy) noexcept { this->__y -= __dy; return *this; } |
| 2212 | inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok(); } |
| 2213 | }; |
| 2214 | |
| 2215 | inline constexpr |
| 2216 | year_month operator/(const year& __y, const month& __m) noexcept { return year_month{__y, __m}; } |
| 2217 | |
| 2218 | inline constexpr |
| 2219 | year_month operator/(const year& __y, int __m) noexcept { return year_month{__y, month(__m)}; } |
| 2220 | |
| 2221 | inline constexpr |
| 2222 | bool operator==(const year_month& __lhs, const year_month& __rhs) noexcept |
| 2223 | { return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month(); } |
| 2224 | |
| 2225 | inline constexpr |
| 2226 | bool operator!=(const year_month& __lhs, const year_month& __rhs) noexcept |
| 2227 | { return !(__lhs == __rhs); } |
| 2228 | |
| 2229 | inline constexpr |
| 2230 | bool operator< (const year_month& __lhs, const year_month& __rhs) noexcept |
| 2231 | { return __lhs.year() != __rhs.year() ? __lhs.year() < __rhs.year() : __lhs.month() < __rhs.month(); } |
| 2232 | |
| 2233 | inline constexpr |
| 2234 | bool operator> (const year_month& __lhs, const year_month& __rhs) noexcept |
| 2235 | { return __rhs < __lhs; } |
| 2236 | |
| 2237 | inline constexpr |
| 2238 | bool operator<=(const year_month& __lhs, const year_month& __rhs) noexcept |
| 2239 | { return !(__rhs < __lhs);} |
| 2240 | |
| 2241 | inline constexpr |
| 2242 | bool operator>=(const year_month& __lhs, const year_month& __rhs) noexcept |
| 2243 | { return !(__lhs < __rhs); } |
| 2244 | |
| 2245 | constexpr year_month operator+(const year_month& __lhs, const months& __rhs) noexcept |
| 2246 | { |
| 2247 | int __dmi = static_cast<int>(static_cast<unsigned>(__lhs.month())) - 1 + __rhs.count(); |
| 2248 | const int __dy = (__dmi >= 0 ? __dmi : __dmi-11) / 12; |
| 2249 | __dmi = __dmi - __dy * 12 + 1; |
| 2250 | return (__lhs.year() + years(__dy)) / month(static_cast<unsigned>(__dmi)); |
| 2251 | } |
| 2252 | |
| 2253 | constexpr year_month operator+(const months& __lhs, const year_month& __rhs) noexcept |
| 2254 | { return __rhs + __lhs; } |
| 2255 | |
| 2256 | constexpr year_month operator+(const year_month& __lhs, const years& __rhs) noexcept |
| 2257 | { return (__lhs.year() + __rhs) / __lhs.month(); } |
| 2258 | |
| 2259 | constexpr year_month operator+(const years& __lhs, const year_month& __rhs) noexcept |
| 2260 | { return __rhs + __lhs; } |
| 2261 | |
| 2262 | constexpr months operator-(const year_month& __lhs, const year_month& __rhs) noexcept |
| 2263 | { return (__lhs.year() - __rhs.year()) + months(static_cast<unsigned>(__lhs.month()) - static_cast<unsigned>(__rhs.month())); } |
| 2264 | |
| 2265 | constexpr year_month operator-(const year_month& __lhs, const months& __rhs) noexcept |
| 2266 | { return __lhs + -__rhs; } |
| 2267 | |
| 2268 | constexpr year_month operator-(const year_month& __lhs, const years& __rhs) noexcept |
| 2269 | { return __lhs + -__rhs; } |
| 2270 | |
| 2271 | class year_month_day_last; |
| 2272 | |
| 2273 | class year_month_day { |
| 2274 | private: |
| 2275 | chrono::year __y; |
| 2276 | chrono::month __m; |
| 2277 | chrono::day __d; |
| 2278 | public: |
| 2279 | year_month_day() = default; |
| 2280 | inline constexpr year_month_day( |
| 2281 | const chrono::year& __yval, const chrono::month& __mval, const chrono::day& __dval) noexcept |
| 2282 | : __y{__yval}, __m{__mval}, __d{__dval} {} |
| 2283 | constexpr year_month_day(const year_month_day_last& __ymdl) noexcept; |
| 2284 | inline constexpr year_month_day(const sys_days& __sysd) noexcept |
| 2285 | : year_month_day(__from_days(__sysd.time_since_epoch())) {} |
| 2286 | inline explicit constexpr year_month_day(const local_days& __locd) noexcept |
| 2287 | : year_month_day(__from_days(__locd.time_since_epoch())) {} |
| 2288 | |
| 2289 | constexpr year_month_day& operator+=(const months& __dm) noexcept; |
| 2290 | constexpr year_month_day& operator-=(const months& __dm) noexcept; |
| 2291 | constexpr year_month_day& operator+=(const years& __dy) noexcept; |
| 2292 | constexpr year_month_day& operator-=(const years& __dy) noexcept; |
| 2293 | |
| 2294 | inline constexpr chrono::year year() const noexcept { return __y; } |
| 2295 | inline constexpr chrono::month month() const noexcept { return __m; } |
| 2296 | inline constexpr chrono::day day() const noexcept { return __d; } |
| 2297 | inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; } |
| 2298 | inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; } |
| 2299 | |
| 2300 | constexpr bool ok() const noexcept; |
| 2301 | |
| 2302 | static constexpr year_month_day __from_days(days __d) noexcept; |
| 2303 | constexpr days __to_days() const noexcept; |
| 2304 | }; |
| 2305 | |
| 2306 | |
| 2307 | // https://howardhinnant.github.io/date_algorithms.html#civil_from_days |
| 2308 | inline constexpr |
| 2309 | year_month_day |
| 2310 | year_month_day::__from_days(days __d) noexcept |
| 2311 | { |
| 2312 | static_assert(numeric_limits<unsigned>::digits >= 18, ""); |
| 2313 | static_assert(numeric_limits<int>::digits >= 20 , ""); |
| 2314 | const int __z = __d.count() + 719468; |
| 2315 | const int __era = (__z >= 0 ? __z : __z - 146096) / 146097; |
| 2316 | const unsigned __doe = static_cast<unsigned>(__z - __era * 146097); // [0, 146096] |
| 2317 | const unsigned __yoe = (__doe - __doe/1460 + __doe/36524 - __doe/146096) / 365; // [0, 399] |
| 2318 | const int __yr = static_cast<int>(__yoe) + __era * 400; |
| 2319 | const unsigned __doy = __doe - (365 * __yoe + __yoe/4 - __yoe/100); // [0, 365] |
| 2320 | const unsigned __mp = (5 * __doy + 2)/153; // [0, 11] |
| 2321 | const unsigned __dy = __doy - (153 * __mp + 2)/5 + 1; // [1, 31] |
| 2322 | const unsigned __mth = __mp + (__mp < 10 ? 3 : -9); // [1, 12] |
| 2323 | return year_month_day{chrono::year{__yr + (__mth <= 2)}, chrono::month{__mth}, chrono::day{__dy}}; |
| 2324 | } |
| 2325 | |
| 2326 | // https://howardhinnant.github.io/date_algorithms.html#days_from_civil |
| 2327 | inline constexpr days year_month_day::__to_days() const noexcept |
| 2328 | { |
| 2329 | static_assert(numeric_limits<unsigned>::digits >= 18, ""); |
| 2330 | static_assert(numeric_limits<int>::digits >= 20 , ""); |
| 2331 | |
| 2332 | const int __yr = static_cast<int>(__y) - (__m <= February); |
| 2333 | const unsigned __mth = static_cast<unsigned>(__m); |
| 2334 | const unsigned __dy = static_cast<unsigned>(__d); |
| 2335 | |
| 2336 | const int __era = (__yr >= 0 ? __yr : __yr - 399) / 400; |
| 2337 | const unsigned __yoe = static_cast<unsigned>(__yr - __era * 400); // [0, 399] |
| 2338 | const unsigned __doy = (153 * (__mth + (__mth > 2 ? -3 : 9)) + 2) / 5 + __dy-1; // [0, 365] |
| 2339 | const unsigned __doe = __yoe * 365 + __yoe/4 - __yoe/100 + __doy; // [0, 146096] |
| 2340 | return days{__era * 146097 + static_cast<int>(__doe) - 719468}; |
| 2341 | } |
| 2342 | |
| 2343 | inline constexpr |
| 2344 | bool operator==(const year_month_day& __lhs, const year_month_day& __rhs) noexcept |
| 2345 | { return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); } |
| 2346 | |
| 2347 | inline constexpr |
| 2348 | bool operator!=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept |
| 2349 | { return !(__lhs == __rhs); } |
| 2350 | |
| 2351 | inline constexpr |
| 2352 | bool operator< (const year_month_day& __lhs, const year_month_day& __rhs) noexcept |
| 2353 | { |
| 2354 | if (__lhs.year() < __rhs.year()) return true; |
| 2355 | if (__lhs.year() > __rhs.year()) return false; |
| 2356 | if (__lhs.month() < __rhs.month()) return true; |
| 2357 | if (__lhs.month() > __rhs.month()) return false; |
| 2358 | return __lhs.day() < __rhs.day(); |
| 2359 | } |
| 2360 | |
| 2361 | inline constexpr |
| 2362 | bool operator> (const year_month_day& __lhs, const year_month_day& __rhs) noexcept |
| 2363 | { return __rhs < __lhs; } |
| 2364 | |
| 2365 | inline constexpr |
| 2366 | bool operator<=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept |
| 2367 | { return !(__rhs < __lhs);} |
| 2368 | |
| 2369 | inline constexpr |
| 2370 | bool operator>=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept |
| 2371 | { return !(__lhs < __rhs); } |
| 2372 | |
| 2373 | inline constexpr |
| 2374 | year_month_day operator/(const year_month& __lhs, const day& __rhs) noexcept |
| 2375 | { return year_month_day{__lhs.year(), __lhs.month(), __rhs}; } |
| 2376 | |
| 2377 | inline constexpr |
| 2378 | year_month_day operator/(const year_month& __lhs, int __rhs) noexcept |
| 2379 | { return __lhs / day(__rhs); } |
| 2380 | |
| 2381 | inline constexpr |
| 2382 | year_month_day operator/(const year& __lhs, const month_day& __rhs) noexcept |
| 2383 | { return __lhs / __rhs.month() / __rhs.day(); } |
| 2384 | |
| 2385 | inline constexpr |
| 2386 | year_month_day operator/(int __lhs, const month_day& __rhs) noexcept |
| 2387 | { return year(__lhs) / __rhs; } |
| 2388 | |
| 2389 | inline constexpr |
| 2390 | year_month_day operator/(const month_day& __lhs, const year& __rhs) noexcept |
| 2391 | { return __rhs / __lhs; } |
| 2392 | |
| 2393 | inline constexpr |
| 2394 | year_month_day operator/(const month_day& __lhs, int __rhs) noexcept |
| 2395 | { return year(__rhs) / __lhs; } |
| 2396 | |
| 2397 | |
| 2398 | inline constexpr |
| 2399 | year_month_day operator+(const year_month_day& __lhs, const months& __rhs) noexcept |
| 2400 | { return (__lhs.year()/__lhs.month() + __rhs)/__lhs.day(); } |
| 2401 | |
| 2402 | inline constexpr |
| 2403 | year_month_day operator+(const months& __lhs, const year_month_day& __rhs) noexcept |
| 2404 | { return __rhs + __lhs; } |
| 2405 | |
| 2406 | inline constexpr |
| 2407 | year_month_day operator-(const year_month_day& __lhs, const months& __rhs) noexcept |
| 2408 | { return __lhs + -__rhs; } |
| 2409 | |
| 2410 | inline constexpr |
| 2411 | year_month_day operator+(const year_month_day& __lhs, const years& __rhs) noexcept |
| 2412 | { return (__lhs.year() + __rhs) / __lhs.month() / __lhs.day(); } |
| 2413 | |
| 2414 | inline constexpr |
| 2415 | year_month_day operator+(const years& __lhs, const year_month_day& __rhs) noexcept |
| 2416 | { return __rhs + __lhs; } |
| 2417 | |
| 2418 | inline constexpr |
| 2419 | year_month_day operator-(const year_month_day& __lhs, const years& __rhs) noexcept |
| 2420 | { return __lhs + -__rhs; } |
| 2421 | |
| 2422 | inline constexpr year_month_day& year_month_day::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; } |
| 2423 | inline constexpr year_month_day& year_month_day::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; } |
| 2424 | inline constexpr year_month_day& year_month_day::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; } |
| 2425 | inline constexpr year_month_day& year_month_day::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; } |
| 2426 | |
| 2427 | class year_month_day_last { |
| 2428 | private: |
| 2429 | chrono::year __y; |
| 2430 | chrono::month_day_last __mdl; |
| 2431 | public: |
| 2432 | constexpr year_month_day_last(const year& __yval, const month_day_last& __mdlval) noexcept |
| 2433 | : __y{__yval}, __mdl{__mdlval} {} |
| 2434 | |
| 2435 | constexpr year_month_day_last& operator+=(const months& __m) noexcept; |
| 2436 | constexpr year_month_day_last& operator-=(const months& __m) noexcept; |
| 2437 | constexpr year_month_day_last& operator+=(const years& __y) noexcept; |
| 2438 | constexpr year_month_day_last& operator-=(const years& __y) noexcept; |
| 2439 | |
| 2440 | inline constexpr chrono::year year() const noexcept { return __y; } |
| 2441 | inline constexpr chrono::month month() const noexcept { return __mdl.month(); } |
| 2442 | inline constexpr chrono::month_day_last month_day_last() const noexcept { return __mdl; } |
| 2443 | constexpr chrono::day day() const noexcept; |
| 2444 | inline constexpr operator sys_days() const noexcept { return sys_days{year()/month()/day()}; } |
| 2445 | inline explicit constexpr operator local_days() const noexcept { return local_days{year()/month()/day()}; } |
| 2446 | inline constexpr bool ok() const noexcept { return __y.ok() && __mdl.ok(); } |
| 2447 | }; |
| 2448 | |
| 2449 | inline constexpr |
| 2450 | chrono::day year_month_day_last::day() const noexcept |
| 2451 | { |
| 2452 | constexpr chrono::day __d[] = |
| 2453 | { |
| 2454 | chrono::day(31), chrono::day(28), chrono::day(31), |
| 2455 | chrono::day(30), chrono::day(31), chrono::day(30), |
| 2456 | chrono::day(31), chrono::day(31), chrono::day(30), |
| 2457 | chrono::day(31), chrono::day(30), chrono::day(31) |
| 2458 | }; |
| 2459 | return (month() != February || !__y.is_leap()) && month().ok() ? |
| 2460 | __d[static_cast<unsigned>(month()) - 1] : chrono::day{29}; |
| 2461 | } |
| 2462 | |
| 2463 | inline constexpr |
| 2464 | bool operator==(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept |
| 2465 | { return __lhs.year() == __rhs.year() && __lhs.month_day_last() == __rhs.month_day_last(); } |
| 2466 | |
| 2467 | inline constexpr |
| 2468 | bool operator!=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept |
| 2469 | { return !(__lhs == __rhs); } |
| 2470 | |
| 2471 | inline constexpr |
| 2472 | bool operator< (const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept |
| 2473 | { |
| 2474 | if (__lhs.year() < __rhs.year()) return true; |
| 2475 | if (__lhs.year() > __rhs.year()) return false; |
| 2476 | return __lhs.month_day_last() < __rhs.month_day_last(); |
| 2477 | } |
| 2478 | |
| 2479 | inline constexpr |
| 2480 | bool operator> (const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept |
| 2481 | { return __rhs < __lhs; } |
| 2482 | |
| 2483 | inline constexpr |
| 2484 | bool operator<=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept |
| 2485 | { return !(__rhs < __lhs);} |
| 2486 | |
| 2487 | inline constexpr |
| 2488 | bool operator>=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept |
| 2489 | { return !(__lhs < __rhs); } |
| 2490 | |
| 2491 | inline constexpr year_month_day_last operator/(const year_month& __lhs, last_spec) noexcept |
| 2492 | { return year_month_day_last{__lhs.year(), month_day_last{__lhs.month()}}; } |
| 2493 | |
| 2494 | inline constexpr year_month_day_last operator/(const year& __lhs, const month_day_last& __rhs) noexcept |
| 2495 | { return year_month_day_last{__lhs, __rhs}; } |
| 2496 | |
| 2497 | inline constexpr year_month_day_last operator/(int __lhs, const month_day_last& __rhs) noexcept |
| 2498 | { return year_month_day_last{year{__lhs}, __rhs}; } |
| 2499 | |
| 2500 | inline constexpr year_month_day_last operator/(const month_day_last& __lhs, const year& __rhs) noexcept |
| 2501 | { return __rhs / __lhs; } |
| 2502 | |
| 2503 | inline constexpr year_month_day_last operator/(const month_day_last& __lhs, int __rhs) noexcept |
| 2504 | { return year{__rhs} / __lhs; } |
| 2505 | |
| 2506 | |
| 2507 | inline constexpr |
| 2508 | year_month_day_last operator+(const year_month_day_last& __lhs, const months& __rhs) noexcept |
| 2509 | { return (__lhs.year() / __lhs.month() + __rhs) / last; } |
| 2510 | |
| 2511 | inline constexpr |
| 2512 | year_month_day_last operator+(const months& __lhs, const year_month_day_last& __rhs) noexcept |
| 2513 | { return __rhs + __lhs; } |
| 2514 | |
| 2515 | inline constexpr |
| 2516 | year_month_day_last operator-(const year_month_day_last& __lhs, const months& __rhs) noexcept |
| 2517 | { return __lhs + (-__rhs); } |
| 2518 | |
| 2519 | inline constexpr |
| 2520 | year_month_day_last operator+(const year_month_day_last& __lhs, const years& __rhs) noexcept |
| 2521 | { return year_month_day_last{__lhs.year() + __rhs, __lhs.month_day_last()}; } |
| 2522 | |
| 2523 | inline constexpr |
| 2524 | year_month_day_last operator+(const years& __lhs, const year_month_day_last& __rhs) noexcept |
| 2525 | { return __rhs + __lhs; } |
| 2526 | |
| 2527 | inline constexpr |
| 2528 | year_month_day_last operator-(const year_month_day_last& __lhs, const years& __rhs) noexcept |
| 2529 | { return __lhs + (-__rhs); } |
| 2530 | |
| 2531 | inline constexpr year_month_day_last& year_month_day_last::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; } |
| 2532 | inline constexpr year_month_day_last& year_month_day_last::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; } |
| 2533 | inline constexpr year_month_day_last& year_month_day_last::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; } |
| 2534 | inline constexpr year_month_day_last& year_month_day_last::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; } |
| 2535 | |
| 2536 | inline constexpr year_month_day::year_month_day(const year_month_day_last& __ymdl) noexcept |
| 2537 | : __y{__ymdl.year()}, __m{__ymdl.month()}, __d{__ymdl.day()} {} |
| 2538 | |
| 2539 | inline constexpr bool year_month_day::ok() const noexcept |
| 2540 | { |
| 2541 | if (!__y.ok() || !__m.ok()) return false; |
| 2542 | return chrono::day{1} <= __d && __d <= (__y / __m / last).day(); |
| 2543 | } |
| 2544 | |
| 2545 | class year_month_weekday { |
| 2546 | chrono::year __y; |
| 2547 | chrono::month __m; |
| 2548 | chrono::weekday_indexed __wdi; |
| 2549 | public: |
| 2550 | year_month_weekday() = default; |
| 2551 | constexpr year_month_weekday(const chrono::year& __yval, const chrono::month& __mval, |
| 2552 | const chrono::weekday_indexed& __wdival) noexcept |
| 2553 | : __y{__yval}, __m{__mval}, __wdi{__wdival} {} |
| 2554 | constexpr year_month_weekday(const sys_days& __sysd) noexcept |
| 2555 | : year_month_weekday(__from_days(__sysd.time_since_epoch())) {} |
| 2556 | inline explicit constexpr year_month_weekday(const local_days& __locd) noexcept |
| 2557 | : year_month_weekday(__from_days(__locd.time_since_epoch())) {} |
| 2558 | constexpr year_month_weekday& operator+=(const months& m) noexcept; |
| 2559 | constexpr year_month_weekday& operator-=(const months& m) noexcept; |
| 2560 | constexpr year_month_weekday& operator+=(const years& y) noexcept; |
| 2561 | constexpr year_month_weekday& operator-=(const years& y) noexcept; |
| 2562 | |
| 2563 | inline constexpr chrono::year year() const noexcept { return __y; } |
| 2564 | inline constexpr chrono::month month() const noexcept { return __m; } |
| 2565 | inline constexpr chrono::weekday weekday() const noexcept { return __wdi.weekday(); } |
| 2566 | inline constexpr unsigned index() const noexcept { return __wdi.index(); } |
| 2567 | inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi; } |
| 2568 | |
| 2569 | inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; } |
| 2570 | inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; } |
| 2571 | inline constexpr bool ok() const noexcept |
| 2572 | { |
| 2573 | if (!__y.ok() || !__m.ok() || !__wdi.ok()) return false; |
| 2574 | if (__wdi.index() <= 4) return true; |
| 2575 | auto __nth_weekday_day = |
| 2576 | __wdi.weekday() - |
| 2577 | chrono::weekday{static_cast<sys_days>(__y / __m / 1)} + |
| 2578 | days{(__wdi.index() - 1) * 7 + 1}; |
| 2579 | return static_cast<unsigned>(__nth_weekday_day.count()) <= |
| 2580 | static_cast<unsigned>((__y / __m / last).day()); |
| 2581 | } |
| 2582 | |
| 2583 | static constexpr year_month_weekday __from_days(days __d) noexcept; |
| 2584 | constexpr days __to_days() const noexcept; |
| 2585 | }; |
| 2586 | |
| 2587 | inline constexpr |
| 2588 | year_month_weekday year_month_weekday::__from_days(days __d) noexcept |
| 2589 | { |
| 2590 | const sys_days __sysd{__d}; |
| 2591 | const chrono::weekday __wd = chrono::weekday(__sysd); |
| 2592 | const year_month_day __ymd = year_month_day(__sysd); |
| 2593 | return year_month_weekday{__ymd.year(), __ymd.month(), |
| 2594 | __wd[(static_cast<unsigned>(__ymd.day())-1)/7+1]}; |
| 2595 | } |
| 2596 | |
| 2597 | inline constexpr |
| 2598 | days year_month_weekday::__to_days() const noexcept |
| 2599 | { |
| 2600 | const sys_days __sysd = sys_days(__y/__m/1); |
| 2601 | return (__sysd + (__wdi.weekday() - chrono::weekday(__sysd) + days{(__wdi.index()-1)*7})) |
| 2602 | .time_since_epoch(); |
| 2603 | } |
| 2604 | |
| 2605 | inline constexpr |
| 2606 | bool operator==(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept |
| 2607 | { return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); } |
| 2608 | |
| 2609 | inline constexpr |
| 2610 | bool operator!=(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept |
| 2611 | { return !(__lhs == __rhs); } |
| 2612 | |
| 2613 | inline constexpr |
| 2614 | year_month_weekday operator/(const year_month& __lhs, const weekday_indexed& __rhs) noexcept |
| 2615 | { return year_month_weekday{__lhs.year(), __lhs.month(), __rhs}; } |
| 2616 | |
| 2617 | inline constexpr |
| 2618 | year_month_weekday operator/(const year& __lhs, const month_weekday& __rhs) noexcept |
| 2619 | { return year_month_weekday{__lhs, __rhs.month(), __rhs.weekday_indexed()}; } |
| 2620 | |
| 2621 | inline constexpr |
| 2622 | year_month_weekday operator/(int __lhs, const month_weekday& __rhs) noexcept |
| 2623 | { return year(__lhs) / __rhs; } |
| 2624 | |
| 2625 | inline constexpr |
| 2626 | year_month_weekday operator/(const month_weekday& __lhs, const year& __rhs) noexcept |
| 2627 | { return __rhs / __lhs; } |
| 2628 | |
| 2629 | inline constexpr |
| 2630 | year_month_weekday operator/(const month_weekday& __lhs, int __rhs) noexcept |
| 2631 | { return year(__rhs) / __lhs; } |
| 2632 | |
| 2633 | |
| 2634 | inline constexpr |
| 2635 | year_month_weekday operator+(const year_month_weekday& __lhs, const months& __rhs) noexcept |
| 2636 | { return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_indexed(); } |
| 2637 | |
| 2638 | inline constexpr |
| 2639 | year_month_weekday operator+(const months& __lhs, const year_month_weekday& __rhs) noexcept |
| 2640 | { return __rhs + __lhs; } |
| 2641 | |
| 2642 | inline constexpr |
| 2643 | year_month_weekday operator-(const year_month_weekday& __lhs, const months& __rhs) noexcept |
| 2644 | { return __lhs + (-__rhs); } |
| 2645 | |
| 2646 | inline constexpr |
| 2647 | year_month_weekday operator+(const year_month_weekday& __lhs, const years& __rhs) noexcept |
| 2648 | { return year_month_weekday{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_indexed()}; } |
| 2649 | |
| 2650 | inline constexpr |
| 2651 | year_month_weekday operator+(const years& __lhs, const year_month_weekday& __rhs) noexcept |
| 2652 | { return __rhs + __lhs; } |
| 2653 | |
| 2654 | inline constexpr |
| 2655 | year_month_weekday operator-(const year_month_weekday& __lhs, const years& __rhs) noexcept |
| 2656 | { return __lhs + (-__rhs); } |
| 2657 | |
| 2658 | |
| 2659 | inline constexpr year_month_weekday& year_month_weekday::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; } |
| 2660 | inline constexpr year_month_weekday& year_month_weekday::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; } |
| 2661 | inline constexpr year_month_weekday& year_month_weekday::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; } |
| 2662 | inline constexpr year_month_weekday& year_month_weekday::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; } |
| 2663 | |
| 2664 | class year_month_weekday_last { |
| 2665 | private: |
| 2666 | chrono::year __y; |
| 2667 | chrono::month __m; |
| 2668 | chrono::weekday_last __wdl; |
| 2669 | public: |
| 2670 | constexpr year_month_weekday_last(const chrono::year& __yval, const chrono::month& __mval, |
| 2671 | const chrono::weekday_last& __wdlval) noexcept |
| 2672 | : __y{__yval}, __m{__mval}, __wdl{__wdlval} {} |
| 2673 | constexpr year_month_weekday_last& operator+=(const months& __dm) noexcept; |
| 2674 | constexpr year_month_weekday_last& operator-=(const months& __dm) noexcept; |
| 2675 | constexpr year_month_weekday_last& operator+=(const years& __dy) noexcept; |
| 2676 | constexpr year_month_weekday_last& operator-=(const years& __dy) noexcept; |
| 2677 | |
| 2678 | inline constexpr chrono::year year() const noexcept { return __y; } |
| 2679 | inline constexpr chrono::month month() const noexcept { return __m; } |
| 2680 | inline constexpr chrono::weekday weekday() const noexcept { return __wdl.weekday(); } |
| 2681 | inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl; } |
| 2682 | inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; } |
| 2683 | inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; } |
| 2684 | inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok() && __wdl.ok(); } |
| 2685 | |
| 2686 | constexpr days __to_days() const noexcept; |
| 2687 | |
| 2688 | }; |
| 2689 | |
| 2690 | inline constexpr |
| 2691 | days year_month_weekday_last::__to_days() const noexcept |
| 2692 | { |
| 2693 | const sys_days __last = sys_days{__y/__m/last}; |
| 2694 | return (__last - (chrono::weekday{__last} - __wdl.weekday())).time_since_epoch(); |
| 2695 | |
| 2696 | } |
| 2697 | |
| 2698 | inline constexpr |
| 2699 | bool operator==(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept |
| 2700 | { return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); } |
| 2701 | |
| 2702 | inline constexpr |
| 2703 | bool operator!=(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept |
| 2704 | { return !(__lhs == __rhs); } |
| 2705 | |
| 2706 | |
| 2707 | inline constexpr |
| 2708 | year_month_weekday_last operator/(const year_month& __lhs, const weekday_last& __rhs) noexcept |
| 2709 | { return year_month_weekday_last{__lhs.year(), __lhs.month(), __rhs}; } |
| 2710 | |
| 2711 | inline constexpr |
| 2712 | year_month_weekday_last operator/(const year& __lhs, const month_weekday_last& __rhs) noexcept |
| 2713 | { return year_month_weekday_last{__lhs, __rhs.month(), __rhs.weekday_last()}; } |
| 2714 | |
| 2715 | inline constexpr |
| 2716 | year_month_weekday_last operator/(int __lhs, const month_weekday_last& __rhs) noexcept |
| 2717 | { return year(__lhs) / __rhs; } |
| 2718 | |
| 2719 | inline constexpr |
| 2720 | year_month_weekday_last operator/(const month_weekday_last& __lhs, const year& __rhs) noexcept |
| 2721 | { return __rhs / __lhs; } |
| 2722 | |
| 2723 | inline constexpr |
| 2724 | year_month_weekday_last operator/(const month_weekday_last& __lhs, int __rhs) noexcept |
| 2725 | { return year(__rhs) / __lhs; } |
| 2726 | |
| 2727 | |
| 2728 | inline constexpr |
| 2729 | year_month_weekday_last operator+(const year_month_weekday_last& __lhs, const months& __rhs) noexcept |
| 2730 | { return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_last(); } |
| 2731 | |
| 2732 | inline constexpr |
| 2733 | year_month_weekday_last operator+(const months& __lhs, const year_month_weekday_last& __rhs) noexcept |
| 2734 | { return __rhs + __lhs; } |
| 2735 | |
| 2736 | inline constexpr |
| 2737 | year_month_weekday_last operator-(const year_month_weekday_last& __lhs, const months& __rhs) noexcept |
| 2738 | { return __lhs + (-__rhs); } |
| 2739 | |
| 2740 | inline constexpr |
| 2741 | year_month_weekday_last operator+(const year_month_weekday_last& __lhs, const years& __rhs) noexcept |
| 2742 | { return year_month_weekday_last{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_last()}; } |
| 2743 | |
| 2744 | inline constexpr |
| 2745 | year_month_weekday_last operator+(const years& __lhs, const year_month_weekday_last& __rhs) noexcept |
| 2746 | { return __rhs + __lhs; } |
| 2747 | |
| 2748 | inline constexpr |
| 2749 | year_month_weekday_last operator-(const year_month_weekday_last& __lhs, const years& __rhs) noexcept |
| 2750 | { return __lhs + (-__rhs); } |
| 2751 | |
| 2752 | inline constexpr year_month_weekday_last& year_month_weekday_last::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; } |
| 2753 | inline constexpr year_month_weekday_last& year_month_weekday_last::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; } |
| 2754 | inline constexpr year_month_weekday_last& year_month_weekday_last::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; } |
| 2755 | inline constexpr year_month_weekday_last& year_month_weekday_last::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; } |
| 2756 | |
| 2757 | |
| 2758 | template <class _Duration> |
| 2759 | class hh_mm_ss |
| 2760 | { |
| 2761 | private: |
| 2762 | static_assert(__is_duration<_Duration>::value, "template parameter of hh_mm_ss must be a std::chrono::duration"); |
| 2763 | using __CommonType = common_type_t<_Duration, chrono::seconds>; |
| 2764 | |
| 2765 | static constexpr uint64_t __pow10(unsigned __exp) |
| 2766 | { |
| 2767 | uint64_t __ret = 1; |
| 2768 | for (unsigned __i = 0; __i < __exp; ++__i) |
| 2769 | __ret *= 10U; |
| 2770 | return __ret; |
| 2771 | } |
| 2772 | |
| 2773 | static constexpr unsigned __width(uint64_t __n, uint64_t __d = 10, unsigned __w = 0) |
| 2774 | { |
| 2775 | if (__n >= 2 && __d != 0 && __w < 19) |
| 2776 | return 1 + __width(__n, __d % __n * 10, __w+1); |
| 2777 | return 0; |
| 2778 | } |
| 2779 | |
| 2780 | public: |
| 2781 | static unsigned constexpr fractional_width = __width(__CommonType::period::den) < 19 ? |
| 2782 | __width(__CommonType::period::den) : 6u; |
| 2783 | using precision = duration<typename __CommonType::rep, ratio<1, __pow10(fractional_width)>>; |
| 2784 | |
| 2785 | constexpr hh_mm_ss() noexcept : hh_mm_ss{_Duration::zero()} {} |
| 2786 | |
| 2787 | constexpr explicit hh_mm_ss(_Duration __d) noexcept : |
| 2788 | __is_neg(__d < _Duration(0)), |
| 2789 | __h(duration_cast<chrono::hours> (abs(__d))), |
| 2790 | __m(duration_cast<chrono::minutes>(abs(__d) - hours())), |
| 2791 | __s(duration_cast<chrono::seconds>(abs(__d) - hours() - minutes())), |
| 2792 | __f(duration_cast<precision> (abs(__d) - hours() - minutes() - seconds())) |
| 2793 | {} |
| 2794 | |
| 2795 | constexpr bool is_negative() const noexcept { return __is_neg; } |
| 2796 | constexpr chrono::hours hours() const noexcept { return __h; } |
| 2797 | constexpr chrono::minutes minutes() const noexcept { return __m; } |
| 2798 | constexpr chrono::seconds seconds() const noexcept { return __s; } |
| 2799 | constexpr precision subseconds() const noexcept { return __f; } |
| 2800 | |
| 2801 | constexpr precision to_duration() const noexcept |
| 2802 | { |
| 2803 | auto __dur = __h + __m + __s + __f; |
| 2804 | return __is_neg ? -__dur : __dur; |
| 2805 | } |
| 2806 | |
| 2807 | constexpr explicit operator precision() const noexcept { return to_duration(); } |
| 2808 | |
| 2809 | private: |
| 2810 | bool __is_neg; |
| 2811 | chrono::hours __h; |
| 2812 | chrono::minutes __m; |
| 2813 | chrono::seconds __s; |
| 2814 | precision __f; |
| 2815 | }; |
| 2816 | |
| 2817 | constexpr bool is_am(const hours& __h) noexcept { return __h >= hours( 0) && __h < hours(12); } |
| 2818 | constexpr bool is_pm(const hours& __h) noexcept { return __h >= hours(12) && __h < hours(24); } |
| 2819 | |
| 2820 | constexpr hours make12(const hours& __h) noexcept |
| 2821 | { |
| 2822 | if (__h == hours( 0)) return hours(12); |
| 2823 | else if (__h <= hours(12)) return __h; |
| 2824 | else return __h - hours(12); |
| 2825 | } |
| 2826 | |
| 2827 | constexpr hours make24(const hours& __h, bool __is_pm) noexcept |
| 2828 | { |
| 2829 | if (__is_pm) |
| 2830 | return __h == hours(12) ? __h : __h + hours(12); |
| 2831 | else |
| 2832 | return __h == hours(12) ? hours(0) : __h; |
| 2833 | } |
| 2834 | |
| 2835 | #endif // _LIBCPP_STD_VER > 17 |
| 2836 | } // chrono |
| 2837 | |
| 2838 | #if _LIBCPP_STD_VER14 > 11 |
| 2839 | // Suffixes for duration literals [time.duration.literals] |
| 2840 | inline namespace literals |
| 2841 | { |
| 2842 | inline namespace chrono_literals |
| 2843 | { |
| 2844 | |
| 2845 | constexpr chrono::hours operator""h(unsigned long long __h) |
| 2846 | { |
| 2847 | return chrono::hours(static_cast<chrono::hours::rep>(__h)); |
| 2848 | } |
| 2849 | |
| 2850 | constexpr chrono::duration<long double, ratio<3600,1>> operator""h(long double __h) |
| 2851 | { |
| 2852 | return chrono::duration<long double, ratio<3600,1>>(__h); |
| 2853 | } |
| 2854 | |
| 2855 | |
| 2856 | constexpr chrono::minutes operator""min(unsigned long long __m) |
| 2857 | { |
| 2858 | return chrono::minutes(static_cast<chrono::minutes::rep>(__m)); |
| 2859 | } |
| 2860 | |
| 2861 | constexpr chrono::duration<long double, ratio<60,1>> operator""min(long double __m) |
| 2862 | { |
| 2863 | return chrono::duration<long double, ratio<60,1>> (__m); |
| 2864 | } |
| 2865 | |
| 2866 | |
| 2867 | constexpr chrono::seconds operator""s(unsigned long long __s) |
| 2868 | { |
| 2869 | return chrono::seconds(static_cast<chrono::seconds::rep>(__s)); |
| 2870 | } |
| 2871 | |
| 2872 | constexpr chrono::duration<long double> operator""s(long double __s) |
| 2873 | { |
| 2874 | return chrono::duration<long double> (__s); |
| 2875 | } |
| 2876 | |
| 2877 | |
| 2878 | constexpr chrono::milliseconds operator""ms(unsigned long long __ms) |
| 2879 | { |
| 2880 | return chrono::milliseconds(static_cast<chrono::milliseconds::rep>(__ms)); |
| 2881 | } |
| 2882 | |
| 2883 | constexpr chrono::duration<long double, milli> operator""ms(long double __ms) |
| 2884 | { |
| 2885 | return chrono::duration<long double, milli>(__ms); |
| 2886 | } |
| 2887 | |
| 2888 | |
| 2889 | constexpr chrono::microseconds operator""us(unsigned long long __us) |
| 2890 | { |
| 2891 | return chrono::microseconds(static_cast<chrono::microseconds::rep>(__us)); |
| 2892 | } |
| 2893 | |
| 2894 | constexpr chrono::duration<long double, micro> operator""us(long double __us) |
| 2895 | { |
| 2896 | return chrono::duration<long double, micro> (__us); |
| 2897 | } |
| 2898 | |
| 2899 | |
| 2900 | constexpr chrono::nanoseconds operator""ns(unsigned long long __ns) |
| 2901 | { |
| 2902 | return chrono::nanoseconds(static_cast<chrono::nanoseconds::rep>(__ns)); |
| 2903 | } |
| 2904 | |
| 2905 | constexpr chrono::duration<long double, nano> operator""ns(long double __ns) |
| 2906 | { |
| 2907 | return chrono::duration<long double, nano> (__ns); |
| 2908 | } |
| 2909 | |
| 2910 | #if _LIBCPP_STD_VER14 > 17 && !defined(_LIBCPP_HAS_NO_CXX20_CHRONO_LITERALS) |
| 2911 | constexpr chrono::day operator ""d(unsigned long long __d) noexcept |
| 2912 | { |
| 2913 | return chrono::day(static_cast<unsigned>(__d)); |
| 2914 | } |
| 2915 | |
| 2916 | constexpr chrono::year operator ""y(unsigned long long __y) noexcept |
| 2917 | { |
| 2918 | return chrono::year(static_cast<int>(__y)); |
| 2919 | } |
| 2920 | #endif |
| 2921 | }} |
| 2922 | |
| 2923 | namespace chrono { // hoist the literals into namespace std::chrono |
| 2924 | using namespace literals::chrono_literals; |
| 2925 | } |
| 2926 | |
| 2927 | #endif |
| 2928 | |
| 2929 | _LIBCPP_END_NAMESPACE_STD} } |
| 2930 | |
| 2931 | #ifndef _LIBCPP_CXX03_LANG |
| 2932 | _LIBCPP_BEGIN_NAMESPACE_FILESYSTEMnamespace std { inline namespace __1 { namespace __fs { namespace filesystem { |
| 2933 | struct _FilesystemClock { |
| 2934 | #if !defined(_LIBCPP_HAS_NO_INT128) |
| 2935 | typedef __int128_t rep; |
| 2936 | typedef nano period; |
| 2937 | #else |
| 2938 | typedef long long rep; |
| 2939 | typedef nano period; |
| 2940 | #endif |
| 2941 | |
| 2942 | typedef chrono::duration<rep, period> duration; |
| 2943 | typedef chrono::time_point<_FilesystemClock> time_point; |
| 2944 | |
| 2945 | _LIBCPP_EXPORTED_FROM_ABI__attribute__((__visibility__("default"))) |
| 2946 | static _LIBCPP_CONSTEXPR_AFTER_CXX11constexpr const bool is_steady = false; |
| 2947 | |
| 2948 | _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_FUNC_VIS__attribute__ ((__visibility__("default"))) static time_point now() noexcept; |
| 2949 | |
| 2950 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 2951 | static time_t to_time_t(const time_point& __t) noexcept { |
| 2952 | typedef chrono::duration<rep> __secs; |
| 2953 | return time_t( |
| 2954 | chrono::duration_cast<__secs>(__t.time_since_epoch()).count()); |
| 2955 | } |
| 2956 | |
| 2957 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 2958 | static time_point from_time_t(time_t __t) noexcept { |
| 2959 | typedef chrono::duration<rep> __secs; |
| 2960 | return time_point(__secs(__t)); |
| 2961 | } |
| 2962 | }; |
| 2963 | _LIBCPP_END_NAMESPACE_FILESYSTEM} } } } |
| 2964 | #endif // !_LIBCPP_CXX03_LANG |
| 2965 | |
| 2966 | _LIBCPP_POP_MACROSpop_macro("min") pop_macro("max") |
| 2967 | |
| 2968 | #endif // _LIBCPP_CHRONO |