diff --git a/api/icsneoc/icsneoc.cpp b/api/icsneoc/icsneoc.cpp index b255edb..35eceaf 100644 --- a/api/icsneoc/icsneoc.cpp +++ b/api/icsneoc/icsneoc.cpp @@ -642,7 +642,7 @@ bool icsneo_getDigitalIO(const neodevice_t* device, neoio_t type, uint32_t numbe return false; } - const optional val = device->device->getDigitalIO(static_cast(type), number); + const std::optional val = device->device->getDigitalIO(static_cast(type), number); if(!val.has_value()) return false; diff --git a/communication/communication.cpp b/communication/communication.cpp index a4d49fd..4e67c11 100644 --- a/communication/communication.cpp +++ b/communication/communication.cpp @@ -150,22 +150,22 @@ std::shared_ptr Communication::getSerialNumberSync(std::chr return std::dynamic_pointer_cast(m51); } -optional< std::vector< optional > > Communication::getVersionsSync(std::chrono::milliseconds timeout) { +std::optional< std::vector< std::optional > > Communication::getVersionsSync(std::chrono::milliseconds timeout) { static const std::shared_ptr filter = std::make_shared(Message::Type::DeviceVersion); - std::vector< optional > ret; + std::vector< std::optional > ret; std::shared_ptr msg = waitForMessageSync([this]() { return sendCommand(Command::GetMainVersion); }, filter, timeout); if(!msg) // Did not receive a message - return nullopt; + return std::nullopt; auto ver = std::dynamic_pointer_cast(msg); if(!ver) // Could not upcast for some reason - return nullopt; + return std::nullopt; if(ver->ForChip != VersionMessage::MainChip || ver->Versions.size() != 1) - return nullopt; + return std::nullopt; ret.push_back(ver->Versions.front()); diff --git a/communication/packet/canpacket.cpp b/communication/packet/canpacket.cpp index b9b42de..ed3c753 100644 --- a/communication/packet/canpacket.cpp +++ b/communication/packet/canpacket.cpp @@ -1,10 +1,9 @@ #include "icsneo/communication/packet/canpacket.h" #include "icsneo/communication/message/canerrorcountmessage.h" -#include "icsneo/platform/optional.h" using namespace icsneo; -static optional CAN_DLCToLength(uint8_t length, bool fd) { +static std::optional CAN_DLCToLength(uint8_t length, bool fd) { if (length <= 8) return length; @@ -27,10 +26,10 @@ static optional CAN_DLCToLength(uint8_t length, bool fd) { } } - return nullopt; + return std::nullopt; } -static optional CAN_LengthToDLC(size_t dataLength, bool fd) +static std::optional CAN_LengthToDLC(size_t dataLength, bool fd) { if (dataLength <= 8) return uint8_t(dataLength); @@ -52,7 +51,7 @@ static optional CAN_LengthToDLC(size_t dataLength, bool fd) return uint8_t(0xF); } - return nullopt; + return std::nullopt; } std::shared_ptr HardwareCANPacket::DecodeToMessage(const std::vector& bytestream) { @@ -94,7 +93,7 @@ std::shared_ptr HardwareCANPacket::DecodeToMessage(const std::vectorisCANFD = true; msg->baudrateSwitch = data->header.BRS; // CAN FD Baudrate Switch msg->errorStateIndicator = data->header.ESI; - const optional lenFromDLC = CAN_DLCToLength(length, true); + const std::optional lenFromDLC = CAN_DLCToLength(length, true); if (lenFromDLC) length = *lenFromDLC; } else if(length > 8) { // This is a standard CAN frame with a length of more than 8 @@ -133,7 +132,7 @@ bool HardwareCANPacket::EncodeFromMessage(const CANMessage& message, std::vector } const size_t dataSize = message.data.size(); - optional dlc = CAN_LengthToDLC(dataSize, message.isCANFD); + std::optional dlc = CAN_LengthToDLC(dataSize, message.isCANFD); if (!dlc.has_value()) { report(APIEvent::Type::MessageMaxLengthExceeded, APIEvent::Severity::Error); return false; // Too much data for the protocol diff --git a/communication/packet/versionpacket.cpp b/communication/packet/versionpacket.cpp index 7450c1f..d4d1940 100644 --- a/communication/packet/versionpacket.cpp +++ b/communication/packet/versionpacket.cpp @@ -9,7 +9,7 @@ std::shared_ptr HardwareVersionPacket::DecodeMainToMessage(const auto msg = std::make_shared(VersionMessage::MainChip); msg->Versions.emplace_back(); - optional& version = msg->Versions.back(); + std::optional& version = msg->Versions.back(); version.emplace(); version->major = bytestream[1]; version->minor = bytestream[2]; @@ -26,7 +26,7 @@ std::shared_ptr HardwareVersionPacket::DecodeSecondaryToMessage( while(bytesLeft >= 3) { const bool versionValid = bytestream[bytestream.size() - bytesLeft + 0]; msg->Versions.emplace_back(); - optional& version = msg->Versions.back(); + std::optional& version = msg->Versions.back(); if(versionValid) { version.emplace(); version->major = bytestream[bytestream.size() - bytesLeft + 1]; diff --git a/device/device.cpp b/device/device.cpp index a5d5653..092f221 100644 --- a/device/device.cpp +++ b/device/device.cpp @@ -3,7 +3,6 @@ #include "icsneo/api/eventmanager.h" #include "icsneo/communication/command.h" #include "icsneo/device/extensions/deviceextension.h" -#include "icsneo/platform/optional.h" #include "icsneo/disk/fat.h" #include "icsneo/communication/packet/wivicommandpacket.h" #include "icsneo/communication/message/wiviresponsemessage.h" @@ -477,15 +476,15 @@ Network Device::getNetworkByNumber(Network::Type type, size_t index) const { return Network::NetID::Invalid; } -optional Device::readLogicalDisk(uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout) { +std::optional Device::readLogicalDisk(uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout) { if(!into || timeout <= std::chrono::milliseconds(0)) { report(APIEvent::Type::RequiredParameterNull, APIEvent::Severity::Error); - return nullopt; + return std::nullopt; } if(!isOpen()) { report(APIEvent::Type::DeviceCurrentlyClosed, APIEvent::Severity::Error); - return nullopt; + return std::nullopt; } std::lock_guard lk(diskLock); @@ -499,7 +498,7 @@ optional Device::readLogicalDisk(uint64_t pos, uint8_t* into, uint64_t return ret; }); if(!offset.has_value()) - return nullopt; + return std::nullopt; diskReadDriver->setVSAOffset(*offset); } @@ -509,25 +508,25 @@ optional Device::readLogicalDisk(uint64_t pos, uint8_t* into, uint64_t return diskReadDriver->readLogicalDisk(*com, report, pos, into, amount, timeout); } -optional Device::writeLogicalDisk(uint64_t pos, const uint8_t* from, uint64_t amount, std::chrono::milliseconds timeout) { +std::optional Device::writeLogicalDisk(uint64_t pos, const uint8_t* from, uint64_t amount, std::chrono::milliseconds timeout) { if(!from || timeout <= std::chrono::milliseconds(0)) { report(APIEvent::Type::RequiredParameterNull, APIEvent::Severity::Error); - return nullopt; + return std::nullopt; } if(!isOpen()) { report(APIEvent::Type::DeviceCurrentlyClosed, APIEvent::Severity::Error); - return nullopt; + return std::nullopt; } std::lock_guard lk(diskLock); return diskWriteDriver->writeLogicalDisk(*com, report, *diskReadDriver, pos, from, amount, timeout); } -optional Device::isLogicalDiskConnected() { +std::optional Device::isLogicalDiskConnected() { if(!isOpen()) { report(APIEvent::Type::DeviceCurrentlyClosed, APIEvent::Severity::Error); - return nullopt; + return std::nullopt; } // This doesn't *really* make sense here but because the disk read redirects the parser until it is done, we'll lock this @@ -536,16 +535,16 @@ optional Device::isLogicalDiskConnected() { const auto info = com->getLogicalDiskInfoSync(); if (!info) { report(APIEvent::Type::Timeout, APIEvent::Severity::Error); - return nullopt; + return std::nullopt; } return info->connected; } -optional Device::getLogicalDiskSize() { +std::optional Device::getLogicalDiskSize() { if(!isOpen()) { report(APIEvent::Type::DeviceCurrentlyClosed, APIEvent::Severity::Error); - return nullopt; + return std::nullopt; } // This doesn't *really* make sense here but because the disk read redirects the parser until it is done, we'll lock this @@ -554,16 +553,16 @@ optional Device::getLogicalDiskSize() { const auto info = com->getLogicalDiskInfoSync(); if (!info) { report(APIEvent::Type::Timeout, APIEvent::Severity::Error); - return nullopt; + return std::nullopt; } return info->getReportedSize(); } -optional Device::getVSAOffsetInLogicalDisk() { +std::optional Device::getVSAOffsetInLogicalDisk() { if(!isOpen()) { report(APIEvent::Type::DeviceCurrentlyClosed, APIEvent::Severity::Error); - return nullopt; + return std::nullopt; } std::lock_guard lk(diskLock); @@ -575,7 +574,7 @@ optional Device::getVSAOffsetInLogicalDisk() { return diskReadDriver->readLogicalDisk(*com, report, pos, into, amount); }); if(!offset.has_value()) - return nullopt; + return std::nullopt; if(diskReadDriver->getAccess() == Disk::Access::EntireCard && diskWriteDriver->getAccess() == Disk::Access::VSA) { // We have mismatched drivers, we need to add an offset to the diskReadDriver @@ -585,7 +584,7 @@ optional Device::getVSAOffsetInLogicalDisk() { return *offset; } -optional Device::getDigitalIO(IO type, size_t number /* = 1 */) { +std::optional Device::getDigitalIO(IO type, size_t number /* = 1 */) { if(number == 0) { // Start counting from 1 report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error); return false; @@ -672,7 +671,7 @@ optional Device::getDigitalIO(IO type, size_t number /* = 1 */) { }; report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error); - return nullopt; + return std::nullopt; } bool Device::setDigitalIO(IO type, size_t number, bool value) { @@ -730,7 +729,7 @@ bool Device::setDigitalIO(IO type, size_t number, bool value) { return false; } -optional Device::getAnalogIO(IO type, size_t number /* = 1 */) { +std::optional Device::getAnalogIO(IO type, size_t number /* = 1 */) { if(number == 0) { // Start counting from 1 report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error); return false; @@ -786,7 +785,7 @@ optional Device::getAnalogIO(IO type, size_t number /* = 1 */) { }; report(APIEvent::Type::ParameterOutOfRange, APIEvent::Severity::Error); - return nullopt; + return std::nullopt; } void Device::wiviThreadBody() { @@ -1001,15 +1000,15 @@ Lifetime Device::addSleepRequestedCallback(SleepRequestedCallback cb) { }); } -optional Device::isSleepRequested() const { +std::optional Device::isSleepRequested() const { if(!isOpen()) { report(APIEvent::Type::DeviceCurrentlyClosed, APIEvent::Severity::Error); - return nullopt; + return std::nullopt; } if(!supportsWiVI()) { report(APIEvent::Type::WiVINotSupported, APIEvent::Severity::Error); - return nullopt; + return std::nullopt; } static std::shared_ptr filter = std::make_shared(Message::Type::WiVICommandResponse); @@ -1026,13 +1025,13 @@ optional Device::isSleepRequested() const { if(!generic || generic->type != Message::Type::WiVICommandResponse) { report(APIEvent::Type::NoDeviceResponse, APIEvent::Severity::Error); - return nullopt; + return std::nullopt; } const auto resp = std::static_pointer_cast(generic); if(!resp->success || !resp->value.has_value()) { report(APIEvent::Type::ValueNotYetPresent, APIEvent::Severity::Error); - return nullopt; + return std::nullopt; } return *resp->value; @@ -1188,18 +1187,18 @@ void Device::updateLEDState() { com->sendCommand(Command::UpdateLEDState, args); } -optional Device::sendEthPhyMsg(const EthPhyMessage& message, std::chrono::milliseconds timeout) { +std::optional Device::sendEthPhyMsg(const EthPhyMessage& message, std::chrono::milliseconds timeout) { if(!isOpen()) { report(APIEvent::Type::DeviceCurrentlyClosed, APIEvent::Severity::Error); - return nullopt; + return std::nullopt; } if(!getEthPhyRegControlSupported()) { report(APIEvent::Type::EthPhyRegisterControlNotAvailable, APIEvent::Severity::Error); - return nullopt; + return std::nullopt; } if(!isOnline()) { report(APIEvent::Type::DeviceCurrentlyOffline, APIEvent::Severity::Error); - return nullopt; + return std::nullopt; } std::vector bytes; @@ -1210,11 +1209,11 @@ optional Device::sendEthPhyMsg(const EthPhyMessage& message, std: if(!response) { report(APIEvent::Type::NoDeviceResponse, APIEvent::Severity::Error); - return nullopt; + return std::nullopt; } auto retMsg = std::static_pointer_cast(response); if(!retMsg) { - return nullopt; + return std::nullopt; } - return make_optional(*retMsg); + return std::make_optional(*retMsg); } \ No newline at end of file diff --git a/device/idevicesettings.cpp b/device/idevicesettings.cpp index 52494df..2a6e6fd 100644 --- a/device/idevicesettings.cpp +++ b/device/idevicesettings.cpp @@ -4,11 +4,11 @@ using namespace icsneo; -optional IDeviceSettings::CalculateGSChecksum(const std::vector& settings, optional knownSize) { +std::optional IDeviceSettings::CalculateGSChecksum(const std::vector& settings, std::optional knownSize) { const uint16_t* p = reinterpret_cast(settings.data()); size_t words = std::min(knownSize.value_or(0), settings.size()); if(words % 2 == 1) - return nullopt; // Somehow settings is not word aligned + return std::nullopt; // Somehow settings is not word aligned words /= 2; uint16_t gsCrc = 0; @@ -215,7 +215,7 @@ bool IDeviceSettings::apply(bool temporary) { bytestream[2] = GS_VERSION >> 8; bytestream[3] = (uint8_t)settings.size(); bytestream[4] = (uint8_t)(settings.size() >> 8); - optional gsChecksum = CalculateGSChecksum(settings); + std::optional gsChecksum = CalculateGSChecksum(settings); if(!gsChecksum) { // Could not calculate the checksum for some reason report(APIEvent::Type::SettingsChecksumError, APIEvent::Severity::Error); @@ -321,7 +321,7 @@ bool IDeviceSettings::applyDefaults(bool temporary) { bytestream[2] = GS_VERSION >> 8; bytestream[3] = (uint8_t)settings.size(); bytestream[4] = (uint8_t)(settings.size() >> 8); - const optional gsChecksum = CalculateGSChecksum(settings); + const std::optional gsChecksum = CalculateGSChecksum(settings); if(!gsChecksum) { // Could not calculate the checksum for some reason report(APIEvent::Type::SettingsChecksumError, APIEvent::Severity::Error); @@ -638,27 +638,27 @@ bool IDeviceSettings::canTerminationBeEnabledFor(Network net) const { return false; } -optional IDeviceSettings::isTerminationEnabledFor(Network net) const { +std::optional IDeviceSettings::isTerminationEnabledFor(Network net) const { if(!settingsLoaded) { report(APIEvent::Type::SettingsReadError, APIEvent::Severity::Error); - return nullopt; + return std::nullopt; } if(disabled) { report(APIEvent::Type::SettingsNotAvailable, APIEvent::Severity::Error); - return nullopt; + return std::nullopt; } ICSNEO_UNALIGNED(const uint64_t*) terminationEnables = getTerminationEnables(); if(terminationEnables == nullptr) { report(APIEvent::Type::TerminationNotSupportedDevice, APIEvent::Severity::Error); - return nullopt; + return std::nullopt; } const auto cmNet = net.getCoreMini(); if(!cmNet.has_value() || uint64_t(*cmNet) >= 64 || !isTerminationSupportedFor(net)) { report(APIEvent::Type::TerminationNotSupportedNetwork, APIEvent::Severity::Error); - return nullopt; + return std::nullopt; } return (*terminationEnables >> uint64_t(*cmNet)) & 0x1; diff --git a/disk/diskreaddriver.cpp b/disk/diskreaddriver.cpp index 52fbf6d..be15e32 100644 --- a/disk/diskreaddriver.cpp +++ b/disk/diskreaddriver.cpp @@ -4,7 +4,7 @@ using namespace icsneo; using namespace icsneo::Disk; -optional ReadDriver::readLogicalDisk(Communication& com, device_eventhandler_t report, +std::optional ReadDriver::readLogicalDisk(Communication& com, device_eventhandler_t report, uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout) { if(amount == 0) return 0; @@ -12,7 +12,7 @@ optional ReadDriver::readLogicalDisk(Communication& com, device_eventh pos += vsaOffset; // First read from the cache - optional ret = readFromCache(pos, into, amount); + std::optional ret = readFromCache(pos, into, amount); if(ret == amount) // Full cache hit, we're done return ret; @@ -99,15 +99,15 @@ void ReadDriver::invalidateCache(uint64_t pos, uint64_t amount) { cache.clear(); } -optional ReadDriver::readFromCache(uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds staleAfter) { +std::optional ReadDriver::readFromCache(uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds staleAfter) { if(cache.empty()) - return nullopt; // Nothing in the cache + return std::nullopt; // Nothing in the cache if(cachedAt + staleAfter < std::chrono::steady_clock::now()) - return nullopt; // Cache is stale + return std::nullopt; // Cache is stale if(pos > cachePos + cache.size() || pos < cachePos) - return nullopt; // Cache miss + return std::nullopt; // Cache miss const auto cacheOffset = pos - cachePos; const auto copyAmount = std::min(cache.size() - cacheOffset, amount); diff --git a/disk/diskwritedriver.cpp b/disk/diskwritedriver.cpp index 3c89918..b1763c0 100644 --- a/disk/diskwritedriver.cpp +++ b/disk/diskwritedriver.cpp @@ -7,12 +7,12 @@ using namespace icsneo::Disk; const uint64_t WriteDriver::RetryAtomic = std::numeric_limits::max(); const APIEvent::Severity WriteDriver::NonatomicSeverity = APIEvent::Severity::EventInfo; -optional WriteDriver::writeLogicalDisk(Communication& com, device_eventhandler_t report, ReadDriver& readDriver, +std::optional WriteDriver::writeLogicalDisk(Communication& com, device_eventhandler_t report, ReadDriver& readDriver, uint64_t pos, const uint8_t* from, uint64_t amount, std::chrono::milliseconds timeout) { if(amount == 0) return 0; - optional ret; + std::optional ret; const uint32_t idealBlockSize = getBlockSizeBounds().second; diff --git a/disk/extextractordiskreaddriver.cpp b/disk/extextractordiskreaddriver.cpp index c1b8846..f0857a7 100644 --- a/disk/extextractordiskreaddriver.cpp +++ b/disk/extextractordiskreaddriver.cpp @@ -12,19 +12,19 @@ using namespace icsneo; using namespace icsneo::Disk; -optional ExtExtractorDiskReadDriver::readLogicalDiskAligned(Communication& com, device_eventhandler_t report, +std::optional ExtExtractorDiskReadDriver::readLogicalDiskAligned(Communication& com, device_eventhandler_t report, uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout) { if(amount > getBlockSizeBounds().second) - return nullopt; + return std::nullopt; if(amount % getBlockSizeBounds().first != 0) - return nullopt; + return std::nullopt; if(pos % getBlockSizeBounds().first != 0) - return nullopt; + return std::nullopt; - optional ret; + std::optional ret; unsigned int attempts = 4; while (attempts-- > 0) { @@ -35,7 +35,7 @@ optional ExtExtractorDiskReadDriver::readLogicalDiskAligned(Communicat return ret; } -optional ExtExtractorDiskReadDriver::attemptReadLogicalDiskAligned(Communication& com, device_eventhandler_t report, +std::optional ExtExtractorDiskReadDriver::attemptReadLogicalDiskAligned(Communication& com, device_eventhandler_t report, uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout) { static std::shared_ptr NeoMemorySDRead = std::make_shared(Network::NetID::NeoMemorySDRead); @@ -44,7 +44,7 @@ optional ExtExtractorDiskReadDriver::attemptReadLogicalDiskAligned(Com uint64_t largeSectorCount = amount / SectorSize; uint32_t sectorCount = uint32_t(largeSectorCount); if (largeSectorCount != uint64_t(sectorCount)) - return nullopt; + return std::nullopt; std::mutex m; std::condition_variable cv; @@ -181,7 +181,7 @@ optional ExtExtractorDiskReadDriver::attemptReadLogicalDiskAligned(Com Lifetime clearRedirect([&com, &lk] { lk.unlock(); com.clearRedirectRead(); }); if(error) - return nullopt; + return std::nullopt; error = !com.sendCommand(ExtendedCommand::Extract, { uint8_t(sector & 0xff), @@ -198,11 +198,11 @@ optional ExtExtractorDiskReadDriver::attemptReadLogicalDiskAligned(Com uint8_t((sectorCount >> 24) & 0xff), }); if(error) - return nullopt; + return std::nullopt; bool hitTimeout = !cv.wait_for(lk, timeout, [&]() { return error || amount == received; }); if(hitTimeout || error) - return nullopt; + return std::nullopt; return amount; } diff --git a/disk/fat.cpp b/disk/fat.cpp index 301bf68..9c4c4ab 100644 --- a/disk/fat.cpp +++ b/disk/fat.cpp @@ -8,7 +8,7 @@ using namespace icsneo; // The FAT driver can only be accessed by one caller at a time, since it relies on globals static std::mutex fatDriverMutex; -static std::function< optional(uint64_t pos, uint8_t* into, uint64_t amount) > diskReadFn; +static std::function< std::optional(uint64_t pos, uint8_t* into, uint64_t amount) > diskReadFn; extern "C" DRESULT disk_read(BYTE, BYTE* buff, LBA_t sector, UINT count) { static_assert(Disk::SectorSize == 512, "FatFs expects 512 byte sectors"); @@ -32,17 +32,17 @@ static uint64_t ClusterToSector(const FATFS& fs, DWORD cluster) { return fs.database + (LBA_t)fs.csize * (cluster - 2); } -optional Disk::FindVSAInFAT(std::function< optional(uint64_t pos, uint8_t* into, uint64_t amount) > diskRead) { +std::optional Disk::FindVSAInFAT(std::function< std::optional(uint64_t pos, uint8_t* into, uint64_t amount) > diskRead) { std::lock_guard lk(fatDriverMutex); diskReadFn = diskRead; FATFS fs = {}; if (f_mount(&fs, (const TCHAR*)_TEXT(""), 0) != FR_OK) - return nullopt; + return std::nullopt; FIL logData = {}; if (f_open(&logData, (const TCHAR*)_TEXT("0:\\LOG_DATA.VSA"), FA_READ) != FR_OK) - return nullopt; + return std::nullopt; return ClusterToSector(fs, logData.obj.sclust) * uint64_t(Disk::SectorSize); } \ No newline at end of file diff --git a/disk/neomemorydiskdriver.cpp b/disk/neomemorydiskdriver.cpp index a43f86c..7ea5e06 100644 --- a/disk/neomemorydiskdriver.cpp +++ b/disk/neomemorydiskdriver.cpp @@ -5,15 +5,15 @@ using namespace icsneo; using namespace icsneo::Disk; -optional NeoMemoryDiskDriver::readLogicalDiskAligned(Communication& com, device_eventhandler_t report, +std::optional NeoMemoryDiskDriver::readLogicalDiskAligned(Communication& com, device_eventhandler_t report, uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout) { static std::shared_ptr NeoMemorySDRead = std::make_shared(Network::NetID::NeoMemorySDRead); if(pos % SectorSize != 0) - return nullopt; + return std::nullopt; if(amount != SectorSize) - return nullopt; + return std::nullopt; const uint64_t currentSector = pos / SectorSize; auto msg = com.waitForMessageSync([¤tSector, &com] { @@ -36,23 +36,23 @@ optional NeoMemoryDiskDriver::readLogicalDiskAligned(Communication& co const auto sdmsg = std::dynamic_pointer_cast(msg); if(!sdmsg || sdmsg->data.size() != SectorSize) { report(APIEvent::Type::PacketDecodingError, APIEvent::Severity::Error); - return nullopt; + return std::nullopt; } memcpy(into, sdmsg->data.data(), SectorSize); return SectorSize; } -optional NeoMemoryDiskDriver::writeLogicalDiskAligned(Communication& com, device_eventhandler_t report, +std::optional NeoMemoryDiskDriver::writeLogicalDiskAligned(Communication& com, device_eventhandler_t report, uint64_t pos, const uint8_t* atomicBuf, const uint8_t* from, uint64_t amount, std::chrono::milliseconds timeout) { static std::shared_ptr NeoMemoryDone = std::make_shared(Network::NetID::NeoMemoryWriteDone); if(pos % SectorSize != 0) - return nullopt; + return std::nullopt; if(amount != SectorSize) - return nullopt; + return std::nullopt; // Requesting an atomic operation, but neoMemory does not support it // Continue on anyway but warn the caller @@ -75,7 +75,7 @@ optional NeoMemoryDiskDriver::writeLogicalDiskAligned(Communication& c }, NeoMemoryDone, timeout); if(!msg) - return nullopt; + return std::nullopt; return SectorSize; } \ No newline at end of file diff --git a/disk/nulldiskdriver.cpp b/disk/nulldiskdriver.cpp index bb44845..d3342b7 100644 --- a/disk/nulldiskdriver.cpp +++ b/disk/nulldiskdriver.cpp @@ -3,26 +3,26 @@ using namespace icsneo; using namespace icsneo::Disk; -optional NullDriver::readLogicalDisk(Communication&, device_eventhandler_t report, +std::optional NullDriver::readLogicalDisk(Communication&, device_eventhandler_t report, uint64_t, uint8_t*, uint64_t, std::chrono::milliseconds) { report(APIEvent::Type::DiskNotSupported, APIEvent::Severity::Error); - return nullopt; + return std::nullopt; } -optional NullDriver::readLogicalDiskAligned(Communication&, device_eventhandler_t report, +std::optional NullDriver::readLogicalDiskAligned(Communication&, device_eventhandler_t report, uint64_t, uint8_t*, uint64_t, std::chrono::milliseconds) { report(APIEvent::Type::DiskNotSupported, APIEvent::Severity::Error); - return nullopt; + return std::nullopt; } -optional NullDriver::writeLogicalDisk(Communication&, device_eventhandler_t report, ReadDriver&, +std::optional NullDriver::writeLogicalDisk(Communication&, device_eventhandler_t report, ReadDriver&, uint64_t, const uint8_t*, uint64_t, std::chrono::milliseconds) { report(APIEvent::Type::DiskNotSupported, APIEvent::Severity::Error); - return nullopt; + return std::nullopt; } -optional NullDriver::writeLogicalDiskAligned(Communication&, device_eventhandler_t report, +std::optional NullDriver::writeLogicalDiskAligned(Communication&, device_eventhandler_t report, uint64_t, const uint8_t*, const uint8_t*, uint64_t, std::chrono::milliseconds) { report(APIEvent::Type::DiskNotSupported, APIEvent::Severity::Error); - return nullopt; + return std::nullopt; } \ No newline at end of file diff --git a/disk/plasiondiskreaddriver.cpp b/disk/plasiondiskreaddriver.cpp index 56748b8..7bd4328 100644 --- a/disk/plasiondiskreaddriver.cpp +++ b/disk/plasiondiskreaddriver.cpp @@ -6,23 +6,23 @@ using namespace icsneo; using namespace icsneo::Disk; -optional PlasionDiskReadDriver::readLogicalDiskAligned(Communication& com, device_eventhandler_t report, +std::optional PlasionDiskReadDriver::readLogicalDiskAligned(Communication& com, device_eventhandler_t report, uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout) { static std::shared_ptr NeoMemorySDRead = std::make_shared(Network::NetID::NeoMemorySDRead); if(amount > getBlockSizeBounds().second) - return nullopt; + return std::nullopt; if(amount % getBlockSizeBounds().first != 0) - return nullopt; + return std::nullopt; if(pos % getBlockSizeBounds().first != 0) - return nullopt; + return std::nullopt; uint64_t largeSector = pos / SectorSize; uint32_t sector = uint32_t(largeSector); if (largeSector != uint64_t(sector)) - return nullopt; + return std::nullopt; std::mutex m; std::condition_variable cv; @@ -62,7 +62,7 @@ optional PlasionDiskReadDriver::readLogicalDiskAligned(Communication& com.removeMessageCallback(cb); if(hitTimeout) - return nullopt; + return std::nullopt; return amount; } \ No newline at end of file diff --git a/examples/cpp/simple/src/SimpleExample.cpp b/examples/cpp/simple/src/SimpleExample.cpp index e7c7738..588864a 100644 --- a/examples/cpp/simple/src/SimpleExample.cpp +++ b/examples/cpp/simple/src/SimpleExample.cpp @@ -289,7 +289,7 @@ int main() { if(!emisc.empty()) { std::cout << "\tReading EMisc values..." << std::endl; for(const auto& io : emisc) { - icsneo::optional val = device->getAnalogIO(icsneo::IO::EMisc, io.number); + std::optional val = device->getAnalogIO(icsneo::IO::EMisc, io.number); std::cout << "\t\tEMISC" << io.number; if(val.has_value()) std::cout << " - OK (" << val.value() << "V)" << std::endl; diff --git a/include/icsneo/communication/communication.h b/include/icsneo/communication/communication.h index 72336ca..782a93a 100644 --- a/include/icsneo/communication/communication.h +++ b/include/icsneo/communication/communication.h @@ -56,7 +56,7 @@ public: bool sendCommand(ExtendedCommand cmd, std::vector arguments = {}); bool getSettingsSync(std::vector& data, std::chrono::milliseconds timeout = std::chrono::milliseconds(50)); std::shared_ptr getSerialNumberSync(std::chrono::milliseconds timeout = std::chrono::milliseconds(50)); - optional< std::vector< optional > > getVersionsSync(std::chrono::milliseconds timeout = std::chrono::milliseconds(50)); + std::optional< std::vector< std::optional > > getVersionsSync(std::chrono::milliseconds timeout = std::chrono::milliseconds(50)); std::shared_ptr getLogicalDiskInfoSync(std::chrono::milliseconds timeout = std::chrono::milliseconds(50)); int addMessageCallback(const MessageCallback& cb); diff --git a/include/icsneo/communication/message/resetstatusmessage.h b/include/icsneo/communication/message/resetstatusmessage.h index 0a1b2f1..81a4eca 100644 --- a/include/icsneo/communication/message/resetstatusmessage.h +++ b/include/icsneo/communication/message/resetstatusmessage.h @@ -5,7 +5,7 @@ #include "icsneo/communication/message/main51message.h" #include "icsneo/communication/command.h" -#include "icsneo/platform/optional.h" +#include #include namespace icsneo { @@ -29,8 +29,8 @@ public: bool cmTooBig; bool hidUsbState; bool fpgaUsbState; - icsneo::optional busVoltage; - icsneo::optional deviceTemperature; + std::optional busVoltage; + std::optional deviceTemperature; }; } diff --git a/include/icsneo/communication/message/versionmessage.h b/include/icsneo/communication/message/versionmessage.h index 8775b93..c7ac1b0 100644 --- a/include/icsneo/communication/message/versionmessage.h +++ b/include/icsneo/communication/message/versionmessage.h @@ -5,7 +5,7 @@ #include "icsneo/communication/message/message.h" #include "icsneo/device/deviceversion.h" -#include "icsneo/platform/optional.h" +#include namespace icsneo { @@ -19,7 +19,7 @@ public: VersionMessage(Chip chip) : Message(Message::Type::DeviceVersion), ForChip(chip) {} // nullopt here indicates invalid - std::vector< optional > Versions; + std::vector< std::optional > Versions; // What chips the versions are for const Chip ForChip; diff --git a/include/icsneo/communication/message/wiviresponsemessage.h b/include/icsneo/communication/message/wiviresponsemessage.h index 0e0c1bb..cf3343c 100644 --- a/include/icsneo/communication/message/wiviresponsemessage.h +++ b/include/icsneo/communication/message/wiviresponsemessage.h @@ -5,8 +5,8 @@ #include "icsneo/communication/message/message.h" #include "icsneo/communication/command.h" -#include "icsneo/platform/optional.h" #include "icsneo/communication/packet/wivicommandpacket.h" +#include #include namespace icsneo { @@ -24,9 +24,9 @@ class ResponseMessage : public Message { public: ResponseMessage() : Message(Message::Type::WiVICommandResponse) {} bool success = true; - optional responseTo; - optional value; - optional info; + std::optional responseTo; + std::optional value; + std::optional info; }; } // namespace WiVI diff --git a/include/icsneo/communication/network.h b/include/icsneo/communication/network.h index 71f99b8..37fe974 100644 --- a/include/icsneo/communication/network.h +++ b/include/icsneo/communication/network.h @@ -8,7 +8,7 @@ typedef uint8_t neonettype_t; #ifdef __cplusplus #include -#include "icsneo/platform/optional.h" +#include namespace icsneo { @@ -546,7 +546,7 @@ public: } return "Invalid Network"; } - static optional GetCoreMiniNetworkFromNetID(NetID netid) { + static std::optional GetCoreMiniNetworkFromNetID(NetID netid) { switch(netid) { case NetID::HSCAN: return CoreMini::HSCAN; @@ -665,7 +665,7 @@ public: case NetID::Ethernet2: return CoreMini::Ethernet2; default: - return nullopt; + return std::nullopt; } } static NetID GetNetIDFromCoreMiniNetwork(CoreMini cm) { @@ -796,7 +796,7 @@ public: Network(CoreMini cm) { setValue(GetNetIDFromCoreMiniNetwork(cm)); } NetID getNetID() const { return value; } Type getType() const { return type; } - optional getCoreMini() const { return GetCoreMiniNetworkFromNetID(getNetID()); } + std::optional getCoreMini() const { return GetCoreMiniNetworkFromNetID(getNetID()); } friend std::ostream& operator<<(std::ostream& os, const Network& network) { os << GetNetIDString(network.getNetID()); return os; diff --git a/include/icsneo/communication/packet/canpacket.h b/include/icsneo/communication/packet/canpacket.h index 4e8597c..8d0c64a 100644 --- a/include/icsneo/communication/packet/canpacket.h +++ b/include/icsneo/communication/packet/canpacket.h @@ -7,6 +7,7 @@ #include "icsneo/api/eventmanager.h" #include #include +#include namespace icsneo { diff --git a/include/icsneo/device/device.h b/include/icsneo/device/device.h index 03abb4e..7eebf50 100644 --- a/include/icsneo/device/device.h +++ b/include/icsneo/device/device.h @@ -10,6 +10,7 @@ #include #include #include +#include #include "icsneo/api/eventmanager.h" #include "icsneo/api/lifetime.h" #include "icsneo/device/neodevice.h" @@ -32,7 +33,6 @@ #include "icsneo/communication/message/flexray/control/flexraycontrolmessage.h" #include "icsneo/communication/message/ethphymessage.h" #include "icsneo/third-party/concurrentqueue/concurrentqueue.h" -#include "icsneo/platform/optional.h" #include "icsneo/platform/nodiscard.h" #define ICSNEO_FINDABLE_DEVICE_BASE(className, type) \ @@ -114,10 +114,10 @@ public: Progress }; - using OpenStatusHandler = std::function progress)>; + using OpenStatusHandler = std::function progress)>; bool open(OpenFlags flags = {}, OpenStatusHandler handler = - [](OpenStatusType, const std::string&, optional) { return Device::OpenDirective::Continue; }); + [](OpenStatusType, const std::string&, std::optional) { return Device::OpenDirective::Continue; }); virtual bool close(); virtual bool isOnline() const { return online; } virtual bool isOpen() const { return com->isOpen(); } @@ -172,7 +172,7 @@ public: * Upon failure, icsneo::nullopt will be returned and an error will be * set in icsneo::GetLastError(). */ - optional readLogicalDisk(uint64_t pos, uint8_t* into, uint64_t amount, + std::optional readLogicalDisk(uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout = Disk::DefaultTimeout); /** @@ -189,7 +189,7 @@ public: * Upon failure, icsneo::nullopt will be returned and an error will be * set in icsneo::GetLastError(). */ - optional writeLogicalDisk(uint64_t pos, const uint8_t* from, uint64_t amount, + std::optional writeLogicalDisk(uint64_t pos, const uint8_t* from, uint64_t amount, std::chrono::milliseconds timeout = Disk::DefaultTimeout); /** @@ -202,7 +202,7 @@ public: * `icsneo::nullopt` will be returned if the device does not respond in a * timely manner. */ - optional isLogicalDiskConnected(); + std::optional isLogicalDiskConnected(); /** * Get the size of the connected logical disk in bytes. @@ -212,7 +212,7 @@ public: * `icsneo::nullopt` will be returned if the device does not respond in a * timely manner, or if the disk is disconnected/improperly configured. */ - optional getLogicalDiskSize(); + std::optional getLogicalDiskSize(); /** * Get the offset to the VSA filesystem within the logical disk, represented @@ -224,7 +224,7 @@ public: * `icsneo::nullopt` will be returned if the device does not respond in a * timely manner, or if the disk is disconnected/improperly configured. */ - optional getVSAOffsetInLogicalDisk(); + std::optional getVSAOffsetInLogicalDisk(); /** * Retrieve the number of Ethernet (DoIP) Activation lines present @@ -264,7 +264,7 @@ public: * The index number starts counting at 1 to keep the numbers in sync * with the numbering on the device, and is set to 1 by default. */ - optional getDigitalIO(IO type, size_t number = 1); + std::optional getDigitalIO(IO type, size_t number = 1); /** * Set a digital IO to either a 1, if value is true, or 0 otherwise. @@ -288,7 +288,7 @@ public: * The index number starts counting at 1 to keep the numbers in sync * with the numbering on the device, and is set to 1 by default. */ - optional getAnalogIO(IO type, size_t number = 1); + std::optional getAnalogIO(IO type, size_t number = 1); typedef std::function< void(uint32_t startSector, uint32_t endSector) > NewCaptureCallback; @@ -319,7 +319,7 @@ public: /** * Check whether sleep has been requested by a VSSAL Wireless neoVI script. */ - optional isSleepRequested() const; + std::optional isSleepRequested() const; /** * Signal to a running VSSAL Wireless neoVI script that we are ready for @@ -345,7 +345,7 @@ public: /** * For use by extensions only. A more stable API will be provided in the future. */ - const std::vector>& getVersions() const { return versions; } + const std::vector>& getVersions() const { return versions; } /** * Some alternate communication protocols do not support DFU @@ -365,7 +365,7 @@ public: */ virtual bool supportsWiVI() const { return false; } - optional sendEthPhyMsg(const EthPhyMessage& message, std::chrono::milliseconds timeout = std::chrono::milliseconds(50)); + std::optional sendEthPhyMsg(const EthPhyMessage& message, std::chrono::milliseconds timeout = std::chrono::milliseconds(50)); std::shared_ptr com; std::unique_ptr settings; @@ -377,12 +377,12 @@ protected: device_eventhandler_t report; std::mutex ioMutex; - optional ethActivationStatus; - optional usbHostPowerStatus; - optional backupPowerEnabled; - optional backupPowerGood; - std::array, 6> miscDigital; - std::array, 2> miscAnalog; + std::optional ethActivationStatus; + std::optional usbHostPowerStatus; + std::optional backupPowerEnabled; + std::optional backupPowerGood; + std::array, 6> miscDigital; + std::array, 2> miscAnalog; // START Initialization Functions Device(neodevice_t neodevice) : data(neodevice) { @@ -478,7 +478,7 @@ protected: private: neodevice_t data; std::shared_ptr latestResetStatus; - std::vector> versions; + std::vector> versions; mutable std::mutex diskLock; std::unique_ptr diskReadDriver; diff --git a/include/icsneo/device/deviceversion.h b/include/icsneo/device/deviceversion.h index 3a6fa48..2b2b7b7 100644 --- a/include/icsneo/device/deviceversion.h +++ b/include/icsneo/device/deviceversion.h @@ -3,7 +3,7 @@ #ifdef __cplusplus -#include "icsneo/platform/optional.h" +#include #include #include diff --git a/include/icsneo/device/idevicesettings.h b/include/icsneo/device/idevicesettings.h index 25e7042..624deed 100644 --- a/include/icsneo/device/idevicesettings.h +++ b/include/icsneo/device/idevicesettings.h @@ -601,7 +601,7 @@ typedef struct { #ifdef __cplusplus #include "icsneo/communication/communication.h" -#include "icsneo/platform/optional.h" +#include #include #include @@ -612,7 +612,7 @@ public: using TerminationGroup = std::vector; static constexpr uint16_t GS_VERSION = 5; - static optional CalculateGSChecksum(const std::vector& settings, optional knownSize = nullopt); + static std::optional CalculateGSChecksum(const std::vector& settings, std::optional knownSize = std::nullopt); static CANBaudrate GetEnumValueForBaudrate(int64_t baudrate); static int64_t GetBaudrateValueForEnum(CANBaudrate enumValue); @@ -710,7 +710,7 @@ public: * applied to the device, the current device status will be * reflected here rather than the pending status. */ - optional isTerminationEnabledFor(Network net) const; + std::optional isTerminationEnabledFor(Network net) const; /** * Enable or disable software switchable termination for a diff --git a/include/icsneo/disk/diskreaddriver.h b/include/icsneo/disk/diskreaddriver.h index d77aac6..c14d2f2 100644 --- a/include/icsneo/disk/diskreaddriver.h +++ b/include/icsneo/disk/diskreaddriver.h @@ -3,10 +3,10 @@ #ifdef __cplusplus -#include "icsneo/platform/optional.h" #include "icsneo/communication/communication.h" #include "icsneo/api/eventmanager.h" #include "icsneo/disk/diskdriver.h" +#include #include #include @@ -19,7 +19,7 @@ namespace Disk { */ class ReadDriver : public virtual Driver { public: - virtual optional readLogicalDisk(Communication& com, device_eventhandler_t report, + virtual std::optional readLogicalDisk(Communication& com, device_eventhandler_t report, uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout = DefaultTimeout); void invalidateCache(uint64_t pos = 0, @@ -32,7 +32,7 @@ protected: * The `pos` requested must be sector-aligned, and the `amount` must be * within the block size bounds provided by the driver. */ - virtual optional readLogicalDiskAligned(Communication& com, device_eventhandler_t report, + virtual std::optional readLogicalDiskAligned(Communication& com, device_eventhandler_t report, uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout) = 0; private: @@ -42,7 +42,7 @@ private: static constexpr const std::chrono::milliseconds CacheTime = std::chrono::milliseconds(1000); - optional readFromCache(uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds staleAfter = CacheTime); + std::optional readFromCache(uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds staleAfter = CacheTime); }; } // namespace Disk diff --git a/include/icsneo/disk/diskwritedriver.h b/include/icsneo/disk/diskwritedriver.h index 2c5f112..cb9f26c 100644 --- a/include/icsneo/disk/diskwritedriver.h +++ b/include/icsneo/disk/diskwritedriver.h @@ -3,12 +3,12 @@ #ifdef __cplusplus -#include "icsneo/platform/optional.h" #include "icsneo/communication/communication.h" #include "icsneo/api/eventmanager.h" #include "icsneo/disk/diskreaddriver.h" #include #include +#include namespace icsneo { @@ -19,7 +19,7 @@ namespace Disk { */ class WriteDriver : public virtual Driver { public: - virtual optional writeLogicalDisk(Communication& com, device_eventhandler_t report, ReadDriver& readDriver, + virtual std::optional writeLogicalDisk(Communication& com, device_eventhandler_t report, ReadDriver& readDriver, uint64_t pos, const uint8_t* from, uint64_t amount, std::chrono::milliseconds timeout = DefaultTimeout); protected: @@ -53,7 +53,7 @@ protected: * is non-null, an APIEvent::AtomicOperationCompletedNonatomically * should be reported with `NonatomicSeverity`. */ - virtual optional writeLogicalDiskAligned(Communication& com, device_eventhandler_t report, + virtual std::optional writeLogicalDiskAligned(Communication& com, device_eventhandler_t report, uint64_t pos, const uint8_t* atomicBuf, const uint8_t* from, uint64_t amount, std::chrono::milliseconds timeout) = 0; }; diff --git a/include/icsneo/disk/extextractordiskreaddriver.h b/include/icsneo/disk/extextractordiskreaddriver.h index 46befb7..c218b1e 100644 --- a/include/icsneo/disk/extextractordiskreaddriver.h +++ b/include/icsneo/disk/extextractordiskreaddriver.h @@ -28,10 +28,10 @@ private: Access getPossibleAccess() const override { return Access::EntireCard; } - optional readLogicalDiskAligned(Communication& com, device_eventhandler_t report, + std::optional readLogicalDiskAligned(Communication& com, device_eventhandler_t report, uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout) override; - optional attemptReadLogicalDiskAligned(Communication& com, device_eventhandler_t report, + std::optional attemptReadLogicalDiskAligned(Communication& com, device_eventhandler_t report, uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout); }; diff --git a/include/icsneo/disk/fat.h b/include/icsneo/disk/fat.h index c462448..14654c5 100644 --- a/include/icsneo/disk/fat.h +++ b/include/icsneo/disk/fat.h @@ -3,7 +3,7 @@ #ifdef __cplusplus -#include "icsneo/platform/optional.h" +#include #include #include @@ -11,7 +11,7 @@ namespace icsneo { namespace Disk { -optional FindVSAInFAT(std::function< optional(uint64_t pos, uint8_t* into, uint64_t amount) > diskRead); +std::optional FindVSAInFAT(std::function< std::optional(uint64_t pos, uint8_t* into, uint64_t amount) > diskRead); } // namespace Disk diff --git a/include/icsneo/disk/neomemorydiskdriver.h b/include/icsneo/disk/neomemorydiskdriver.h index a6b2e66..95250cc 100644 --- a/include/icsneo/disk/neomemorydiskdriver.h +++ b/include/icsneo/disk/neomemorydiskdriver.h @@ -30,10 +30,10 @@ private: Access getPossibleAccess() const override { return Access::VSA; } - optional readLogicalDiskAligned(Communication& com, device_eventhandler_t report, + std::optional readLogicalDiskAligned(Communication& com, device_eventhandler_t report, uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout) override; - optional writeLogicalDiskAligned(Communication& com, device_eventhandler_t report, + std::optional writeLogicalDiskAligned(Communication& com, device_eventhandler_t report, uint64_t pos, const uint8_t* atomicBuf, const uint8_t* from, uint64_t amount, std::chrono::milliseconds timeout) override; }; diff --git a/include/icsneo/disk/nulldiskdriver.h b/include/icsneo/disk/nulldiskdriver.h index e45815d..666114f 100644 --- a/include/icsneo/disk/nulldiskdriver.h +++ b/include/icsneo/disk/nulldiskdriver.h @@ -18,9 +18,9 @@ namespace Disk { */ class NullDriver : public ReadDriver, public WriteDriver { public: - optional readLogicalDisk(Communication& com, device_eventhandler_t report, + std::optional readLogicalDisk(Communication& com, device_eventhandler_t report, uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout = DefaultTimeout) override; - optional writeLogicalDisk(Communication& com, device_eventhandler_t report, ReadDriver& readDriver, + std::optional writeLogicalDisk(Communication& com, device_eventhandler_t report, ReadDriver& readDriver, uint64_t pos, const uint8_t* from, uint64_t amount, std::chrono::milliseconds timeout = DefaultTimeout) override; std::pair getBlockSizeBounds() const override { static_assert(SectorSize <= std::numeric_limits::max(), "Incorrect sector size"); @@ -31,9 +31,9 @@ public: private: Access getPossibleAccess() const override { return Access::None; } - optional readLogicalDiskAligned(Communication& com, device_eventhandler_t report, + std::optional readLogicalDiskAligned(Communication& com, device_eventhandler_t report, uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout) override; - optional writeLogicalDiskAligned(Communication& com, device_eventhandler_t report, + std::optional writeLogicalDiskAligned(Communication& com, device_eventhandler_t report, uint64_t pos, const uint8_t* atomicBuf, const uint8_t* from, uint64_t amount, std::chrono::milliseconds timeout) override; }; diff --git a/include/icsneo/disk/plasiondiskreaddriver.h b/include/icsneo/disk/plasiondiskreaddriver.h index 00a16d8..c97d0c5 100644 --- a/include/icsneo/disk/plasiondiskreaddriver.h +++ b/include/icsneo/disk/plasiondiskreaddriver.h @@ -27,7 +27,7 @@ private: Access getPossibleAccess() const override { return Access::EntireCard; } - optional readLogicalDiskAligned(Communication& com, device_eventhandler_t report, + std::optional readLogicalDiskAligned(Communication& com, device_eventhandler_t report, uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout) override; }; diff --git a/include/icsneo/platform/optional.h b/include/icsneo/platform/optional.h deleted file mode 100644 index f629915..0000000 --- a/include/icsneo/platform/optional.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef __ICSNEO_OPTIONAL_H_ -#define __ICSNEO_OPTIONAL_H_ - -#include "icsneo/third-party/optional-lite/include/nonstd/optional.hpp" - -/** - * We use icsneo::optional throughout the C++ API to allow for polyfilling - * std::optional into C++11 and C++14 environments. In a C++17 or better - * environment, icsneo::optional will be an alias of std::optional. - */ - -namespace icsneo { - - using nonstd::optional; - using nonstd::bad_optional_access; - using nonstd::make_optional; - - using nonstd::nullopt; - using nonstd::nullopt_t; - -} // namespace icsneo - -#endif \ No newline at end of file diff --git a/include/icsneo/platform/posix/cdcacm.h b/include/icsneo/platform/posix/cdcacm.h index 505ca25..ff14917 100644 --- a/include/icsneo/platform/posix/cdcacm.h +++ b/include/icsneo/platform/posix/cdcacm.h @@ -6,7 +6,7 @@ #include "icsneo/communication/driver.h" #include "icsneo/device/neodevice.h" #include "icsneo/api/eventmanager.h" -#include "icsneo/platform/optional.h" +#include #include #include #include @@ -39,7 +39,7 @@ public: private: neodevice_t& device; int fd = -1; - optional disallowedInode; + std::optional disallowedInode; std::atomic modeChanging{false}; std::thread modeChangeThread; std::mutex modeChangeMutex; diff --git a/include/icsneo/platform/posix/firmio.h b/include/icsneo/platform/posix/firmio.h index e7dbebd..6fcaf5d 100644 --- a/include/icsneo/platform/posix/firmio.h +++ b/include/icsneo/platform/posix/firmio.h @@ -7,7 +7,7 @@ #include "icsneo/device/founddevice.h" #include "icsneo/communication/driver.h" #include "icsneo/api/eventmanager.h" -#include "icsneo/platform/optional.h" +#include #include namespace icsneo { @@ -127,11 +127,11 @@ private: uint8_t* vbase = nullptr; volatile ComHeader* header = nullptr; - optional in; + std::optional in; std::mutex outMutex; - optional out; - optional outMemory; + std::optional out; + std::optional outMemory; }; } diff --git a/include/icsneo/third-party/optional-lite/.buckconfig b/include/icsneo/third-party/optional-lite/.buckconfig deleted file mode 100644 index e69de29..0000000 diff --git a/include/icsneo/third-party/optional-lite/.editorconfig b/include/icsneo/third-party/optional-lite/.editorconfig deleted file mode 100644 index accf57a..0000000 --- a/include/icsneo/third-party/optional-lite/.editorconfig +++ /dev/null @@ -1,31 +0,0 @@ -# Configuration file for EditorConfig, see https://EditorConfig.org - -# Ignore any other files further up in the file system -root = true - -# All files: -[*] -# Let git determine line ending: end_of_line = lf -charset = utf-8 -indent_size = 4 -indent_style = space -insert_final_newline = true -trim_trailing_whitespace = true - -# Markdown files: keep trailing space-pair as line-break -[*.md] -trim_trailing_whitespace = false - -# Python scripts: -[*.py] - -# YAML scripts: -[*.yml] -indent_size = 2 - -# Makefiles: Tab indentation (no size specified) -[Makefile] -indent_style = tab - -# C, C++ source files: -[*.{h,hpp,c,cpp}] diff --git a/include/icsneo/third-party/optional-lite/.gitattributes b/include/icsneo/third-party/optional-lite/.gitattributes deleted file mode 100644 index fb147c0..0000000 --- a/include/icsneo/third-party/optional-lite/.gitattributes +++ /dev/null @@ -1,26 +0,0 @@ -# Auto detect text files and perform LF normalization -* text=auto - -# Custom for CodeBlocks -*.cbp text eol=lf -*.workspace text eol=lf - -# Custom for Visual Studio -*.cs diff=csharp -*.sln merge=union -*.csproj merge=union -*.vbproj merge=union -*.fsproj merge=union -*.dbproj merge=union - -# Standard to msysgit -*.doc diff=astextplain -*.DOC diff=astextplain -*.docx diff=astextplain -*.DOCX diff=astextplain -*.dot diff=astextplain -*.DOT diff=astextplain -*.pdf diff=astextplain -*.PDF diff=astextplain -*.rtf diff=astextplain -*.RTF diff=astextplain diff --git a/include/icsneo/third-party/optional-lite/.gitignore b/include/icsneo/third-party/optional-lite/.gitignore deleted file mode 100644 index dd37f45..0000000 --- a/include/icsneo/third-party/optional-lite/.gitignore +++ /dev/null @@ -1,47 +0,0 @@ -# Compiled Object files -*.slo -*.lo -*.o -*.obj - -# Precompiled Headers -*.gch -*.pch - -# Compiled Dynamic libraries -*.so -*.dylib -*.dll - -# Fortran module files -*.mod - -# Compiled Static libraries -*.lai -*.la -*.a -*.lib - -# Executables -*.exe -*.out -*.app - -# Buck -/buck-out/ -/.buckd/ -/buckaroo/ -.buckconfig.local -BUCKAROO_DEPS - -# Build folder -/build/ - -# CodeBlocks IDE files -*.layout - -# Visual Studio Code -/.vscode/ - -# Visual Studio -/.vs/ diff --git a/include/icsneo/third-party/optional-lite/.tgitconfig b/include/icsneo/third-party/optional-lite/.tgitconfig deleted file mode 100644 index e4ccf38..0000000 --- a/include/icsneo/third-party/optional-lite/.tgitconfig +++ /dev/null @@ -1,4 +0,0 @@ -[bugtraq] - url = https://github.com/martinmoene/optional-lite/issues/%BUGID% - number = true - logregex = "(\\s*(,|and)?\\s*#\\d+)+\n(\\d+)" diff --git a/include/icsneo/third-party/optional-lite/.travis.yml b/include/icsneo/third-party/optional-lite/.travis.yml deleted file mode 100644 index 706d5ef..0000000 --- a/include/icsneo/third-party/optional-lite/.travis.yml +++ /dev/null @@ -1,161 +0,0 @@ -os: linux -dist: trusty -sudo: false -group: travis_latest -language: c++ -cache: ccache - -addons: - apt: - sources: &apt_sources - - ubuntu-toolchain-r-test - - llvm-toolchain-precise-3.5 - - llvm-toolchain-precise-3.6 - - llvm-toolchain-precise-3.7 - - llvm-toolchain-precise-3.8 - - llvm-toolchain-trusty-3.9 - - llvm-toolchain-trusty-4.0 - - llvm-toolchain-trusty-5.0 - - llvm-toolchain-trusty-6.0 - -matrix: - include: - - os: linux - env: COMPILER=g++-4.8 - compiler: gcc - addons: &gcc4_8 - apt: - packages: ["g++-4.8", "python3-pip", "lcov"] - sources: *apt_sources - - - os: linux - env: COMPILER=g++-4.9 - compiler: gcc - addons: &gcc4_9 - apt: - packages: ["g++-4.9", "python3-pip", "lcov"] - sources: *apt_sources - - - os: linux - env: COMPILER=g++-5 - compiler: gcc - addons: &gcc5 - apt: - packages: ["g++-5", "python3-pip", "lcov"] - sources: *apt_sources - - - os: linux - env: COMPILER=g++-6 - compiler: gcc - addons: &gcc6 - apt: - packages: ["g++-6", "python3-pip", "lcov"] - sources: *apt_sources - - - os: linux - env: COMPILER=g++-7 - compiler: gcc - addons: &gcc7 - apt: - packages: ["g++-7", "python3-pip", "lcov"] - sources: *apt_sources - - - os: linux - env: COMPILER=g++-8 - compiler: gcc - addons: &gcc8 - apt: - packages: ["g++-8", "python3-pip", "lcov"] - sources: *apt_sources - - - os: linux - env: COMPILER=clang++-3.5 - compiler: clang - addons: &clang3_5 - apt: - packages: ["clang-3.5", "g++-7", "python3-pip", "lcov"] - sources: *apt_sources - - - os: linux - env: COMPILER=clang++-3.6 - compiler: clang - addons: &clang3_6 - apt: - packages: ["clang-3.6", "g++-7", "python3-pip", "lcov"] - sources: *apt_sources - - - os: linux - env: COMPILER=clang++-3.7 - compiler: clang - addons: &clang3-7 - apt: - packages: ["clang-3.7", "g++-7", "python3-pip", "lcov"] - sources: *apt_sources - - - os: linux - env: COMPILER=clang++-3.8 - compiler: clang - addons: &clang3_8 - apt: - packages: ["clang-3.8", "g++-7", "python3-pip", "lcov"] - sources: *apt_sources - - - os: linux - env: COMPILER=clang++-3.9 - compiler: clang - addons: &clang3_9 - apt: - packages: ["clang-3.9", "g++-7", "python3-pip", "lcov"] - sources: *apt_sources - - - os: linux - env: COMPILER=clang++-4.0 - compiler: clang - addons: &clang4_0 - apt: - packages: ["clang-4.0", "g++-7", "python3-pip", "lcov"] - sources: *apt_sources - - - os: linux - env: COMPILER=clang++-5.0 - compiler: clang - addons: &clang5_0 - apt: - packages: ["clang-5.0", "g++-7", "python3-pip", "lcov"] - sources: *apt_sources - - - os: linux - env: COMPILER=clang++-6.0 - compiler: clang - addons: &clang6_0 - apt: - packages: ["clang-6.0", "g++-7", "python3-pip", "lcov"] - sources: *apt_sources - - - os: osx - osx_image: xcode7.3 - compiler: clang - env: COMPILER='clang++' - - - os: osx - osx_image: xcode8 - compiler: clang - env: COMPILER='clang++' - - - os: osx - osx_image: xcode9 - compiler: clang - env: COMPILER='clang++' - - - os: osx - osx_image: xcode10 - compiler: clang - env: COMPILER='clang++' - -script: - - export CXX=${COMPILER} - - JOBS=2 # Travis machines have 2 cores. - - mkdir build && cd build - - cmake -G "Unix Makefiles" -DOPTIONAL_LITE_OPT_SELECT_NONSTD=ON -DOPTIONAL_LITE_OPT_BUILD_TESTS=ON -DOPTIONAL_LITE_OPT_BUILD_EXAMPLES=OFF .. - - cmake --build . -- -j${JOBS} - - ctest --output-on-failure -j${JOBS} diff --git a/include/icsneo/third-party/optional-lite/BUCK b/include/icsneo/third-party/optional-lite/BUCK deleted file mode 100644 index c274339..0000000 --- a/include/icsneo/third-party/optional-lite/BUCK +++ /dev/null @@ -1,11 +0,0 @@ -prebuilt_cxx_library( - name = 'optional-lite', - header_namespace = '', - header_only = True, - exported_headers = subdir_glob([ - ('include/nonstd', '**/*.hpp'), - ]), - visibility = [ - 'PUBLIC', - ], -) diff --git a/include/icsneo/third-party/optional-lite/CHANGES.txt b/include/icsneo/third-party/optional-lite/CHANGES.txt deleted file mode 100644 index 99247a4..0000000 --- a/include/icsneo/third-party/optional-lite/CHANGES.txt +++ /dev/null @@ -1,13 +0,0 @@ -Changes for Optional Lite – A single-file header-only [type-safe C++17-like any, a] type-safe container for single values of any type for C++98, C++11 and later - -1.0.2 - 2015-04-14 - -- This release fixes the declaration of nullopt and updates lest_cpp03.hpp to version 1.22.0. - -1.0.1 - 2014-12-23 - -- This release contains several small changes and corrections. - -1.0.0 - 2014-12-21 - -- This is the initial release of optional lite. diff --git a/include/icsneo/third-party/optional-lite/CMakeLists.txt b/include/icsneo/third-party/optional-lite/CMakeLists.txt deleted file mode 100644 index d7ef559..0000000 --- a/include/icsneo/third-party/optional-lite/CMakeLists.txt +++ /dev/null @@ -1,129 +0,0 @@ -# Copyright 2016-2018 by Martin Moene -# -# https://github.com/martinmoene/optional-lite -# -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -cmake_minimum_required( VERSION 3.5 FATAL_ERROR ) - -# optional-lite project and version, updated by script/update-version.py: - -project( - optional_lite - VERSION 3.4.0 -# DESCRIPTION "A C++17-like optional, a nullable object for C++98, C++11 and later in a single-file header-only library" -# HOMEPAGE_URL "https://github.com/martinmoene/optional-lite" - LANGUAGES CXX ) - -# Package information: - -set( unit_name "optional" ) -set( package_nspace "nonstd" ) -set( package_name "${unit_name}-lite" ) -set( package_version "${${PROJECT_NAME}_VERSION}" ) - -message( STATUS "Project '${PROJECT_NAME}', package '${package_name}' version: '${package_version}'") - -# Toplevel or subproject: - -if ( CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME ) - set( optional_IS_TOPLEVEL_PROJECT TRUE ) -else() - set( optional_IS_TOPLEVEL_PROJECT FALSE ) -endif() - -# If toplevel project, enable building and performing of tests, disable building of examples: - -option( OPTIONAL_LITE_OPT_BUILD_TESTS "Build and perform optional-lite tests" ${optional_IS_TOPLEVEL_PROJECT} ) -option( OPTIONAL_LITE_OPT_BUILD_EXAMPLES "Build optional-lite examples" OFF ) - -option( OPTIONAL_LITE_OPT_SELECT_STD "Select std::optional" OFF ) -option( OPTIONAL_LITE_OPT_SELECT_NONSTD "Select nonstd::optional" OFF ) - -# If requested, build and perform tests, build examples: - -if ( OPTIONAL_LITE_OPT_BUILD_TESTS ) - enable_testing() - add_subdirectory( test ) -endif() - -if ( OPTIONAL_LITE_OPT_BUILD_EXAMPLES ) - add_subdirectory( example ) -endif() - -# -# Interface, installation and packaging -# - -# CMake helpers: - -include( GNUInstallDirs ) -include( CMakePackageConfigHelpers ) - -# Interface library: - -add_library( - ${package_name} INTERFACE ) - -add_library( - ${package_nspace}::${package_name} ALIAS ${package_name} ) - -target_include_directories( - ${package_name} - INTERFACE - "$" - "$" ) - -# Package configuration: -# Note: package_name and package_target are used in package_config_in - -set( package_folder "${package_name}" ) -set( package_target "${package_name}-targets" ) -set( package_config "${package_name}-config.cmake" ) -set( package_config_in "${package_name}-config.cmake.in" ) -set( package_config_version "${package_name}-config-version.cmake" ) - -configure_package_config_file( - "${CMAKE_CURRENT_SOURCE_DIR}/cmake/${package_config_in}" - "${CMAKE_CURRENT_BINARY_DIR}/${package_config}" - INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${package_folder}" -) - -configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/cmake/${package_config_version}.in" - "${CMAKE_CURRENT_BINARY_DIR}/${package_config_version}" @ONLY -) - -# Installation: - -install( - TARGETS ${package_name} - EXPORT ${package_target} -# INCLUDES DESTINATION "${...}" # already set via target_include_directories() -) - -install( - EXPORT ${package_target} - NAMESPACE ${package_nspace}:: - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${package_folder}" -) - -install( - FILES "${CMAKE_CURRENT_BINARY_DIR}/${package_config}" - "${CMAKE_CURRENT_BINARY_DIR}/${package_config_version}" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${package_folder}" -) - -install( - DIRECTORY "include/" - DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" -) - -export( - EXPORT ${package_target} - NAMESPACE ${package_nspace}:: - FILE "${CMAKE_CURRENT_BINARY_DIR}/${package_name}-targets.cmake" -) - -# end of file diff --git a/include/icsneo/third-party/optional-lite/LICENSE.txt b/include/icsneo/third-party/optional-lite/LICENSE.txt deleted file mode 100644 index 36b7cd9..0000000 --- a/include/icsneo/third-party/optional-lite/LICENSE.txt +++ /dev/null @@ -1,23 +0,0 @@ -Boost Software License - Version 1.0 - August 17th, 2003 - -Permission is hereby granted, free of charge, to any person or organization -obtaining a copy of the software and accompanying documentation covered by -this license (the "Software") to use, reproduce, display, distribute, -execute, and transmit the Software, and to prepare derivative works of the -Software, and to permit third-parties to whom the Software is furnished to -do so, all subject to the following: - -The copyright notices in the Software and this entire statement, including -the above license grant, this restriction and the following disclaimer, -must be included in all copies of the Software, in whole or in part, and -all derivative works of the Software, unless such copies or derivative -works are solely in the form of machine-executable object code generated by -a source language processor. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/include/icsneo/third-party/optional-lite/README.md b/include/icsneo/third-party/optional-lite/README.md deleted file mode 100644 index 1d85233..0000000 --- a/include/icsneo/third-party/optional-lite/README.md +++ /dev/null @@ -1,480 +0,0 @@ -# optional lite: A single-file header-only version of a C++17-like optional, a nullable object for C++98, C++11 and later - -[![Language](https://img.shields.io/badge/C%2B%2B-98/11-blue.svg)](https://en.wikipedia.org/wiki/C%2B%2B#Standardization) [![License](https://img.shields.io/badge/license-BSL-blue.svg)](https://opensource.org/licenses/BSL-1.0) [![Build Status](https://travis-ci.org/martinmoene/optional-lite.svg?branch=master)](https://travis-ci.org/martinmoene/optional-lite) [![Build status](https://ci.appveyor.com/api/projects/status/1oq5gjm7bufrv6ib?svg=true)](https://ci.appveyor.com/project/martinmoene/optional-lite) [![Version](https://badge.fury.io/gh/martinmoene%2Foptional-lite.svg)](https://github.com/martinmoene/optional-lite/releases) [![download](https://img.shields.io/badge/latest-download-blue.svg)](https://raw.githubusercontent.com/martinmoene/optional-lite/master/include/nonstd/optional.hpp) [![Conan](https://img.shields.io/badge/on-conan-blue.svg)](https://conan.io/center/optional-lite) [![Try it online](https://img.shields.io/badge/on-wandbox-blue.svg)](https://wandbox.org/permlink/bfZdDT4WerPNZi6b) [![Try it on godbolt online](https://img.shields.io/badge/on-godbolt-blue.svg)](https://godbolt.org/z/3tecRa) - -**Contents** -- [Example usage](#example-usage) -- [In a nutshell](#in-a-nutshell) -- [License](#license) -- [Dependencies](#dependencies) -- [Installation](#installation) -- [Synopsis](#synopsis) -- [Comparison of std::optional, optional lite and Boost.Optional](#comparison-of-stdoptional-optional-lite-and-boostoptional) -- [Reported to work with](#reported-to-work-with) -- [Building the tests](#building-the-tests) -- [Implementation notes](#implementation-notes) -- [Other implementations of optional](#other-implementations-of-optional) -- [Notes and references](#notes-and-references) -- [Appendix](#appendix) - - -Example usage -------------- - -```Cpp -#include "nonstd/optional.hpp" - -#include -#include - -using nonstd::optional; -using nonstd::nullopt; - -optional to_int( char const * const text ) -{ - char * pos = NULL; - const int value = strtol( text, &pos, 0 ); - - return pos == text ? nullopt : optional( value ); -} - -int main( int argc, char * argv[] ) -{ - char const * text = argc > 1 ? argv[1] : "42"; - - optional oi = to_int( text ); - - if ( oi ) std::cout << "'" << text << "' is " << *oi; - else std::cout << "'" << text << "' isn't a number"; -} -``` -### Compile and run -``` -prompt>g++ -Wall -Wextra -std=c++03 -I../include -o 01-to_int.exe 01-to_int.cpp && 01-to_int x1 -'x1' isn't a number -``` - -In a nutshell ---------------- -**optional lite** is a single-file header-only library to represent optional (nullable) objects and pass them by value. The library aims to provide a [C++17-like optional](http://en.cppreference.com/w/cpp/utility/optional) for use with C++98 and later. If available, std::optional is used. There's also a simpler version, [*optional bare*](https://github.com/martinmoene/optional-bare). Unlike *optional lite*, *optional bare* is limited to default-constructible and copyable types. - -**Features and properties of optional lite** are ease of installation (single header), freedom of dependencies other than the standard library and control over object alignment (if needed). *optional lite* shares the approach to in-place tags with [any-lite](https://github.com/martinmoene/any-lite), [expected-lite](https://github.com/martinmoene/expected-lite) and with [variant-lite](https://github.com/martinmoene/variant-lite) and these libraries can be used together. - -**Not provided** are reference-type optionals. *optional lite* doesn't handle overloaded *address of* operators. - -For more examples, see [this answer on StackOverflow](http://stackoverflow.com/a/16861022) [8] and the [quick start guide](http://www.boost.org/doc/libs/1_57_0/libs/optional/doc/html/boost_optional/quick_start.html) [9] of Boost.Optional (note that its interface differs from *optional lite*). - - -License -------- -*optional lite* is distributed under the [Boost Software License](LICENSE.txt). - - -Dependencies ------------- -*optional lite* has no other dependencies than the [C++ standard library](http://en.cppreference.com/w/cpp/header). - - -Installation ------------- - -*optional lite* is a single-file header-only library. Put `optional.hpp` in the [include](include) folder directly into the project source tree or somewhere reachable from your project. - -Or, if you use the [conan package manager](https://www.conan.io/), you might follow these steps: - -1. Create source file `./main.cpp`, e.g. with the contents of the example code above. - -2. Create `./conanfile.txt` file with a reference to *variant-lite* in the *requires* section: - ```Conan - [requires] - optional-lite/3.2.0 # 3.3.0 when available - - [generators] - cmake - ``` - -3. Create `./CMakeLists.txt`: - ```CMake - cmake_minimum_required(VERSION 3.1) - project(optional-example CXX) - - include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) - conan_basic_setup() - - add_executable(${PROJECT_NAME} main.cpp) - target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS}) - ``` - -4. Run the following commands: - ```Text - mkdir build && cd build - conan install .. --settings arch=x86 --settings compiler=gcc - cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release - cmake --build . --config Release - ``` - - -Synopsis --------- - -**Contents** -[Types in namespace nonstd](#types-in-namespace-nonstd) -[Interface of *optional lite*](#interface-of-optional-lite) -[Algorithms for *optional lite*](#algorithms-for-optional-lite) -[Configuration](#configuration) - -### Types and values in namespace nonstd - -| Purpose | Type / value | Object | -|-----------------------|--------------|--------| -| To be, or not | template< typename T >
class **optional**; | | -| Disengaging | struct **nullopt_t**; | nullopt_t nullopt; | -| Error reporting | class **bad_optional_access**; |  | -| In-place construction | struct **in_place_tag** |   | -|   | **in_place** | select type or index for in-place construction | -|   | **in_place_type** | select type for in-place construction | -|  (variant) | **in_place_index** | select index for in-place construction | -|   | **nonstd_lite_in_place_type_t**( T) | macro for alias template in_place_type_t<T> | -|  (variant) | **nonstd_lite_in_place_index_t**( T )| macro for alias template in_place_index_t<T> | - -### Interface of *optional lite* - -| Kind | Std | Method | Result | -|--------------|------|---------------------------------------------|--------| -| Construction | | **optional**() noexcept | default construct a nulled object | -|   | | **optional**( nullopt_t ) noexcept | explicitly construct a nulled object | -|   | | **optional**( optional const & rhs ) | move-construct from an other optional | -|   | C++11| **optional**( optional && rhs ) noexcept(...) | move-construct from an other optional | -|   | | **optional**( value_type const & value ) | copy-construct from a value | -|   | C++11| **optional**( value_type && value ) | move-construct from a value | -|   | C++11| **explicit optional**( in_place_type_t<T>, Args&&... args ) | in-place-construct type T | -|   | C++11| **explicit optional**( in_place_type_t<T>, std::initializer_list<U> il, Args&&... args ) | in-place-construct type T | -| Destruction | | **~optional**() | destruct current content, if any | -| Assignment | | optional & **operator=**( nullopt_t ) | null the object;
destruct current content, if any | -|   | | optional & **operator=**( optional const & rhs ) | copy-assign from other optional;
destruct current content, if any | -|   | C++11| optional & **operator=**( optional && rhs ) | move-assign from other optional;
destruct current content, if any | -|   | C++11| template< class U, ...>
**optional & operator=( U && v ) | move-assign from a value;
destruct current content, if any | -|   | C++11| template< class... Args >
T & **emplace**( Args&&... args ) | emplace type T | -|   | C++11| template< class U, class... Args >
T & **emplace**( std::initializer_list<U> il, Args&&... args ) | emplace type T | -| Swap | | void **swap**( optional & rhs ) noexcept(...) | swap with rhs | -| Content | | value_type const \* **operator ->**() const | pointer to current content (const);
must contain value | -|   | | value_type \* **operator ->**() | pointer to current content (non-const);
must contain value | -|   | | value_type const & **operator \***() & | the current content (const ref);
must contain value | -|   | | value_type & **operator \***() & | the current content (non-const ref);
must contain value | -|   | C++11| value_type const & **operator \***() && | the current content (const ref);
must contain value | -|   | C++11| value_type & **operator \***() && | the current content (non-const ref);
must contain value | -| State | | operator **bool**() const | true if content is present | -|   | | bool **has_value**() const | true if content is present | -|   | | value_type const & **value**() & | the current content (const ref);
throws bad_optional_access if nulled | -|   | | value_type & **value**() & | the current content (non-const ref);
throws bad_optional_access if nulled | -|   | C++11| value_type const & **value**() && | the current content (const ref);
throws bad_optional_access if nulled | -|   | C++11| value_type & **value**() && | the current content (non-const ref);
throws bad_optional_access if nulled | -|   |value_type must be copy-constructible | -|   | C++11| value_type **value_or**( value_type && default_value ) & | the value, or default_value if nulled
value_type must be copy-constructible | -|   | C++11| value_type **value_or**( value_type && default_value ) && | the value, or default_value if nulled
value_type must be copy-constructible | -| Modifiers | | void **reset**() noexcept | make empty | - - -### Algorithms for *optional lite* - -| Kind | Std | Function | -|--------------------------|------|----------| -| Relational operators | |   | -| == | | template< typename T >
bool **operator==**( optional const & x, optional const & y ) | -| != | | template< typename T >
bool **operator!=**( optional const & x, optional const & y ) | -| < | | template< typename T >
bool **operator<**( optional const & x, optional const & y ) | -| > | | template< typename T >
bool **operator>**( optional const & x, optional const & y ) | -| <= | | template< typename T >
bool **operator<=*( optional const & x, optional const & y ) | -| >= | | template< typename T >
bool **operator>=*( optional const & x, optional const & y ) | -| Comparison with nullopt | |   | -| == | | template< typename T >
bool **operator==**( optional const & x, nullopt_t ) noexcept | -|   | | template< typename T >
bool **operator==**( nullopt_t, optional const & x ) noexcept | -| != | | template< typename T >
bool **operator!=**( optional const & x, nullopt_t ) noexcept | -|   | | template< typename T >
bool **operator!=**( nullopt_t, optional const & x ) noexcept | -| < | | template< typename T >
bool **operator<**( optional const &, nullopt_t ) noexcept | -|   | | template< typename T >
bool **operator<**( nullopt_t, optional const & x ) noexcept | -| <= | | template< typename T >
bool **operator<=**( optional const & x, nullopt_t ) noexcept | -|   | | template< typename T >
bool **operator<=**( nullopt_t, optional const & ) noexcept | -| > | | template< typename T >
bool **operator>**( optional const & x, nullopt_t ) noexcept | -|   | | template< typename T >
bool **operator>**( nullopt_t, optional const & ) noexcept | -| >= | | template< typename T >
bool **operator>=**( optional const &, nullopt_t ) noexcept | -|   | | template< typename T >
bool **operator>=**( nullopt_t, optional const & x ) noexcept | -| Comparison with T | |   | -| == | | template< typename T >
bool **operator==**( optional const & x, const T& v ) | -|   | | template< typename T >
bool **operator==**( T const & v, optional const & x ) | -| != | | template< typename T >
bool **operator!=**( optional const & x, const T& v ) | -|   | | template< typename T >
bool **operator!=**( T const & v, optional const & x ) | -| < | | template< typename T >
bool **operator<**( optional const & x, const T& v ) | -|   | | template< typename T >
bool **operator<**( T const & v, optional const & x ) | -| <= | | template< typename T >
bool **operator<=**( optional const & x, const T& v ) | -|   | | template< typename T >
bool **operator<=**( T const & v, optional const & x ) | -| > | | template< typename T >
bool **operator>**( optional const & x, const T& v ) | -|   | | template< typename T >
bool **operator>**( T const & v, optional const & x ) | -| >= | | template< typename T >
bool **operator>=**( optional const & x, const T& v ) | -|   | | template< typename T >
bool **operator>=**( T const & v, optional const & x ) | -| Specialized algorithms | |   | -| swap | | template< typename T >
void **swap**( optional & x, optional & y ) noexcept(...) | -| create |
optional<T> **make_optional**( T const & v ) | -|   | C++11| template< class T >
optional< typename std::decay<T>::type > **make_optional**( T && v ) | -|   | C++11| template< class T, class...Args >
optional<T> **make_optional**( Args&&... args ) | -|   | C++11| template< class T, class U, class... Args >
optional<T> **make_optional**( std::initializer_list<U> il, Args&&... args ) | -| hash | C++11| template< class T >
class **hash**< nonstd::optional<T> > | - - -### Configuration - -#### Tweak header - -If the compiler supports [`__has_include()`](https://en.cppreference.com/w/cpp/preprocessor/include), *optional lite* supports the [tweak header](https://vector-of-bool.github.io/2020/10/04/lib-configuration.html) mechanism. Provide your *tweak header* as `nonstd/optional.tweak.hpp` in a folder in the include-search-path. In the tweak header, provide definitions as documented below, like `#define optional_CPLUSPLUS 201103L`. - -#### Standard selection macro -\-Doptional\_CPLUSPLUS=199711L -Define this macro to override the auto-detection of the supported C++ standard, if your compiler does not set the `__cplusplus` macro correctly. - -#### Select `std::optional` or `nonstd::optional` -At default, *optional lite* uses `std::optional` if it is available and lets you use it via namespace `nonstd`. You can however override this default and explicitly request to use `std::optional` or optional lite's `nonstd::optional` as `nonstd::optional` via the following macros. - --Doptional\_CONFIG\_SELECT\_OPTIONAL=optional_OPTIONAL_DEFAULT -Define this to `optional_OPTIONAL_STD` to select `std::optional` as `nonstd::optional`. Define this to `optional_OPTIONAL_NONSTD` to select `nonstd::optional` as `nonstd::optional`. Default is undefined, which has the same effect as defining to `optional_OPTIONAL_DEFAULT`. - -#### Disable exceptions --Doptional_CONFIG_NO_EXCEPTIONS=0 -Define this to 1 if you want to compile without exceptions. If not defined, the header tries and detect if exceptions have been disabled (e.g. via `-fno-exceptions`). Default is undefined. - -#### Macros to control alignment - -If *optional lite* is compiled as C++11 or later, C++11 alignment facilities are used for storage of the underlying object. When compiled as pre-C++11, *optional lite* tries to determine proper alignment itself. If this doesn't work out, you can control alignment via the following macros. See also section [Implementation notes](#implementation-notes). - --Doptional_CONFIG_MAX_ALIGN_HACK=0 -Define this to 1 to use the *max align hack* for alignment. Default is 0. - --Doptional_CONFIG_ALIGN_AS=*pod-type* -Define this to the *pod-type* you want to align to (no default). - --Doptional_CONFIG_ALIGN_AS_FALLBACK=*pod-type* -Define this to the *pod-type* to use for alignment if the algorithm of *optional lite* cannot find a suitable POD type to use for alignment. Default is double. - - -Comparison of std::optional, optional lite and Boost.Optional -------------------------------------------------------------- - -*optional lite* is inspired on std::optional, which in turn is inspired on Boost.Optional. Here are the significant differences. - -| Aspect | std::optional | optional lite | Boost.Optional | -|-----------------------------------|-----------------------|----------------------|----------------| -| Move semantics | yes | C++11 | no | -| noexcept | yes | C++11 | no | -| Hash support | yes | C++11 | no | -| Throwing value accessor | yes | yes | no | -| Literal type | partially | C++11/14 | no | -| In-place construction | emplace, tag in_place | emplace, tag in_place| utility in_place_factory | -| Disengaged state tag | nullopt | nullopt | none | -| optional references | no | no | yes | -| Conversion from optional<U\>
to optional<T\> | no | no | yes | -| Duplicated interface functions 1) | no | no | yes | -| Explicit convert to ptr (get_ptr) | no | no | yes | - -1) is_initialized(), reset(), get(). - - -Reported to work with ---------------------- -The table below mentions the compiler versions *optional lite* is reported to work with. - -OS | Compiler | Versions | ----------:|:-----------|:---------| -Windows | Clang/LLVM | ? | -  | GCC | 5.2.0 | -  | Visual C++
(Visual Studio)| 8 (2005), 10 (2010), 11 (2012),
12 (2013), 14 (2015), 14 (2017) | -GNU/Linux | Clang/LLVM | 3.5.0, 3.6.0, 7.0.0 | -  | GCC | 4.8.4, 5, 6, 8 | -  | ICC | 19 | -macOS | Xcode | 8.3, 9, 10, 11 | - - -Building the tests ------------------- -To build the tests you need: - -- [CMake](http://cmake.org), version 2.8.12 or later to be installed and in your PATH. -- A [suitable compiler](#reported-to-work-with). - -The [*lest* test framework](https://github.com/martinmoene/lest) is included in the [test folder](test). - -The following steps assume that the [*optional lite* source code](https://github.com/martinmoene/optional-lite) has been cloned into a directory named `c:\optional-lite`. - -1. Create a directory for the build outputs for a particular architecture. -Here we use c:\optional-lite\build-win-x86-vc10. - - cd c:\optional-lite - md build-win-x86-vc10 - cd build-win-x86-vc10 - -2. Configure CMake to use the compiler of your choice (run `cmake --help` for a list). - - cmake -G "Visual Studio 10 2010" -DOPTIONAL_LITE_OPT_BUILD_TESTS=ON .. - -3. Build the test suite in the Debug configuration (alternatively use Release). - - cmake --build . --config Debug - -4. Run the test suite. - - ctest -V -C Debug - -All tests should pass, indicating your platform is supported and you are ready to use *optional lite*. - - -Implementation notes --------------------- - -### Object allocation and alignment - -*optional lite* reserves POD-type storage for an object of the underlying type inside a union to prevent unwanted construction and uses placement new to construct the object when required. Using non-placement new (malloc) to obtain storage, ensures that the memory is properly aligned for the object's type, whereas that's not the case with placement new. - -If you access data that's not properly aligned, it 1) may take longer than when it is properly aligned (on x86 processors), or 2) it may terminate the program immediately (many other processors). - -Although the C++ standard does not guarantee that all user-defined types have the alignment of some POD type, in practice it's likely they do [8, part 2]. - -If *optional lite* is compiled as C++11 or later, C++11 alignment facilities are used for storage of the underlying object. When compiling as pre-C++11, *optional lite* tries to determine proper alignment using meta programming. If this doesn't work out, you can control alignment via three macros. - -*optional lite* uses the following rules for alignment: - -1. If the program compiles as C++11 or later, C++11 alignment facilities are used. - -2. If you define -Doptional_CONFIG_MAX_ALIGN_HACK=1 the underlying type is aligned as the most restricted type in `struct max_align_t`. This potentially wastes many bytes per optional if the actually required alignment is much less, e.g. 24 bytes used instead of the 2 bytes required. - -3. If you define -Doptional_CONFIG_ALIGN_AS=*pod-type* the underlying type is aligned as *pod-type*. It's your obligation to specify a type with proper alignment. - -4. If you define -Doptional_CONFIG_ALIGN_AS_FALLBACK=*pod-type* the fallback type for alignment of rule 5 below becomes *pod-type*. It's your obligation to specify a type with proper alignment. - -5. At default, *optional lite* tries to find a POD type with the same alignment as the underlying type. - - The algorithm for alignment of 5. is: - - Determine the alignment A of the underlying type using `alignment_of<>`. - - Find a POD type from the list `alignment_types` with exactly alignment A. - - If no such POD type is found, use a type with a relatively strict alignment requirement such as double; this type is specified in `optional_CONFIG_ALIGN_AS_FALLBACK` (default double). - -Note that the algorithm of 5. differs from the one Andrei Alexandrescu uses in [8, part 2]. - -The class template `alignment_of<>` is gleaned from [Boost.TypeTraits, alignment_of](http://www.boost.org/doc/libs/1_57_0/libs/type_traits/doc/html/boost_typetraits/reference/alignment_of.html) [11]. The storage type `storage_t<>` is adapted from the one I created for [spike-expected, expected lite](https://github.com/martinmoene/spike-expected) [13]. - -For more information on constructed unions and alignment, see [8-12]. - - -Other implementations of optional ---------------------------------- -- Isabella Muerte. [MNMLSTC Core](https://github.com/mnmlstc/core) (C++11). -- Andrzej KrzemieÅ„ski. [optional (nullable) objects for C++14](https://github.com/akrzemi1/Optional). Reference implementation. -- Simon Brand. [C++11/14/17 std::optional with functional-style extensions](https://github.com/TartanLlama/optional). - -Notes and references --------------------- -[1] CppReference. [Optional](http://en.cppreference.com/w/cpp/utility/optional). - -[2] ISO/IEC WG21. [N4606, section 20.6 Optional objects](http://wg21.link/n4606). July 2016. - -[3] Fernando Cacciola, Andrzej KrzemieÅ„ski. [A proposal to add a utility class to represent optional objects (Revision 5)](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3793.html). - -[4] Andrzej KrzemieÅ„ski. [optional (nullable) objects for C++14](https://github.com/akrzemi1/Optional). Reference implementation on GitHub. - -[5] Simon Brand. [P0798R0: Monadic operations for std::optional](https://wg21.tartanllama.xyz/monadic-optional). - -[6] Simon Brand. [C++11/14/17 std::optional with functional-style extensions ](https://github.com/TartanLlama/optional). Reference implementation on GitHub. - -[7] Fernando Cacciola. [Boost.Optional library](http://www.boost.org/doc/libs/1_49_0/libs/optional/doc/html/index.html). - -[8] StackOverflow. [How should one use std::optional?](http://stackoverflow.com/a/16861022). Answer by Timothy Shields. 31 May 2013. - -[9] Fernando Cacciola. [Boost.Optional Quick start guide](http://www.boost.org/doc/libs/1_57_0/libs/optional/doc/html/boost_optional/quick_start.html). - -[10] Andrei Alexandrescu. [Generic: Discriminated Unions part 1](http://collaboration.cmc.ec.gc.ca/science/rpn/biblio/ddj/Website/articles/CUJ/2002/cexp2004/alexandr/alexandr.htm), [part 2](http://collaboration.cmc.ec.gc.ca/science/rpn/biblio/ddj/Website/articles/CUJ/2002/cexp2006/alexandr/alexandr.htm), [part 3](http://collaboration.cmc.ec.gc.ca/science/rpn/biblio/ddj/Website/articles/CUJ/2002/cexp2008/alexandr/alexandr.htm). April 2002. - -[11] Herb Sutter. [Style Case Study #3: Construction Unions](http://www.gotw.ca/gotw/085.htm). GotW #85. 2009 - -[12] Kevin T. Manley. [Using Constructed Types in C++ Unions](http://collaboration.cmc.ec.gc.ca/science/rpn/biblio/ddj/Website/articles/CUJ/2002/0208/manley/manley.htm). C/C++ Users Journal, 20(8), August 2002. - -[13] StackOverflow. [Determining maximum possible alignment in C++](http://stackoverflow.com/a/3126992). - -[14] [Boost.TypeTraits, alignment_of](http://www.boost.org/doc/libs/1_57_0/libs/type_traits/doc/html/boost_typetraits/reference/alignment_of.html) ( [code](http://www.boost.org/doc/libs/1_57_0/boost/type_traits/alignment_of.hpp) ). - -[15] Martin Moene. [spike-expected](https://github.com/martinmoene/spike-expected) ([expected-lite.hpp](https://github.com/martinmoene/spike-expected/blob/master/exception_ptr_lite.hpp)). - - -Appendix --------- - -### A.1 Compile-time information - -The version of *optional lite* is available via tag `[.version]`. The following tags are available for information on the compiler and on the C++ standard library used: `[.compiler]`, `[.stdc++]`, `[.stdlanguage]` and `[.stdlibrary]`. - -### A.2 Optional Lite test specification - -``` -union: A C++03 union can only contain POD types -optional: Allows to default construct an empty optional (1a) -optional: Allows to explicitly construct a disengaged, empty optional via nullopt (1b) -optional: Allows to default construct an empty optional with a non-default-constructible (1a) -optional: Allows to copy-construct from empty optional (2) -optional: Allows to move-construct from empty optional (C++11, 3) -optional: Allows to copy-construct from empty optional, explicit converting (C++11, 4a) -optional: Allows to copy-construct from empty optional, non-explicit converting (4b) -optional: Allows to move-construct from empty optional, explicit converting (C++11, 5a) -optional: Allows to move-construct from empty optional, non-explicit converting (C++11, 5a) -optional: Allows to copy-construct from non-empty optional (2) -optional: Allows to copy-construct from non-empty optional, explicit converting (C++11, 4a) -optional: Allows to copy-construct from non-empty optional, non-explicit converting (4b) -optional: Allows to move-construct from non-empty optional (C++11, 3) -optional: Allows to move-construct from non-empty optional, explicit converting (C++11, 5a) -optional: Allows to move-construct from non-empty optional, non-explicit converting (C++11, 5b) -optional: Allows to copy-construct from literal value (8) -optional: Allows to copy-construct from literal value, converting (8) -optional: Allows to copy-construct from value (8) -optional: Allows to copy-construct from value, converting (8) -optional: Allows to move-construct from value (C++11, 8b) -optional: Allows to move-construct from value, explicit converting (C++11, 8a) -optional: Allows to move-construct from value, non-explicit converting (C++11, 8b) -optional: Allows to in-place construct from literal value (C++11, 6) -optional: Allows to in-place copy-construct from value (C++11, 6) -optional: Allows to in-place move-construct from value (C++11, 6) -optional: Allows to in-place copy-construct from initializer-list (C++11, 7) -optional: Allows to in-place move-construct from initializer-list (C++11, 7) -optional: Allows to assign nullopt to disengage (1) -optional: Allows to copy-assign from/to engaged and disengaged optionals (2) -optional: Allows to move-assign from/to engaged and disengaged optionals (C++11, 3) -optional: Allows to copy-assign from/to engaged and disengaged optionals, converting, (5) -optional: Allows to move-assign from/to engaged and disengaged optionals, converting (C++11, 6) -optional: Allows to copy-assign from literal value (4) -optional: Allows to copy-assign from value (4) -optional: Allows to move-assign from value (C++11, 4) -optional: Allows to copy-emplace content from arguments (C++11, 7) -optional: Allows to move-emplace content from arguments (C++11, 7) -optional: Allows to copy-emplace content from intializer-list and arguments (C++11, 8) -optional: Allows to move-emplace content from intializer-list and arguments (C++11, 8) -optional: Allows to swap with other optional (member) -optional: Allows to obtain value via operator->() -optional: Allows to obtain moved-value via operator->() (C++11) -optional: Allows to obtain value via operator*() -optional: Allows to obtain moved-value via operator*() (C++11) -optional: Allows to obtain has_value() via operator bool() -optional: Allows to obtain value via value() -optional: Allows to obtain moved-value via value() (C++11) -optional: Allows to obtain value or default via value_or() -optional: Allows to obtain moved-value or moved-default via value_or() (C++11) -optional: Throws bad_optional_access at disengaged access -optional: Throws bad_optional_access with non-empty what() -optional: Allows to reset content -optional: Ensure object is destructed only once (C++11) -optional: Ensure balanced construction-destruction (C++98) -optional: Allows to swaps engage state and values (non-member) -optional: Provides relational operators (non-member) -optional: Provides mixed-type relational operators (non-member) -make_optional: Allows to copy-construct optional -make_optional: Allows to move-construct optional (C++11) -make_optional: Allows to in-place copy-construct optional from arguments (C++11) -make_optional: Allows to in-place move-construct optional from arguments (C++11) -make_optional: Allows to in-place copy-construct optional from initializer-list and arguments (C++11) -make_optional: Allows to in-place move-construct optional from initializer-list and arguments (C++11) -std::hash<>: Allows to obtain hash (C++11) -tweak header: reads tweak header if supported [tweak] -``` diff --git a/include/icsneo/third-party/optional-lite/appveyor.yml b/include/icsneo/third-party/optional-lite/appveyor.yml deleted file mode 100644 index 95ec45b..0000000 --- a/include/icsneo/third-party/optional-lite/appveyor.yml +++ /dev/null @@ -1,82 +0,0 @@ -version: "{branch} #{build}" - -shallow_clone: true - -image: - - Visual Studio 2019 - - Visual Studio 2017 - - Visual Studio 2015 - -platform: - - Win32 - - x64 - -configuration: - - Debug - - Release - -build: - parallel: true - -environment: - matrix: - - generator: "Visual Studio 16 2019" - select_sv: -DOPTIONAL_LITE_OPT_SELECT_STD=ON - - generator: "Visual Studio 16 2019" - select_sv: -DOPTIONAL_LITE_OPT_SELECT_NONSTD=ON - - generator: "Visual Studio 15 2017" - select_sv: -DOPTIONAL_LITE_OPT_SELECT_STD=ON - - generator: "Visual Studio 15 2017" - select_sv: -DOPTIONAL_LITE_OPT_SELECT_NONSTD=ON - - generator: "Visual Studio 14 2015" - - generator: "Visual Studio 12 2013" - - generator: "Visual Studio 11 2012" - - generator: "Visual Studio 10 2010" - - generator: "Visual Studio 9 2008" - -matrix: - exclude: - - image: Visual Studio 2015 - generator: "Visual Studio 16 2019" - - image: Visual Studio 2019 - generator: "Visual Studio 15 2017" - - image: Visual Studio 2019 - generator: "Visual Studio 14 2015" - - image: Visual Studio 2019 - generator: "Visual Studio 12 2013" - - image: Visual Studio 2019 - generator: "Visual Studio 11 2012" - - image: Visual Studio 2019 - generator: "Visual Studio 10 2010" - - image: Visual Studio 2019 - generator: "Visual Studio 9 2008" - - image: Visual Studio 2015 - generator: "Visual Studio 15 2017" - - image: Visual Studio 2017 - generator: "Visual Studio 16 2019" - - image: Visual Studio 2017 - generator: "Visual Studio 14 2015" - - image: Visual Studio 2017 - generator: "Visual Studio 12 2013" - - image: Visual Studio 2017 - generator: "Visual Studio 11 2012" - - image: Visual Studio 2017 - generator: "Visual Studio 10 2010" - - image: Visual Studio 2017 - generator: "Visual Studio 9 2008" - - image: Visual Studio 2015 - platform: x64 - generator: "Visual Studio 9 2008" - - image: Visual Studio 2019 - platform: x64 - generator: "Visual Studio 9 2008" - -before_build: - - mkdir build && cd build - - cmake -A %platform% -G "%generator%" "%select_sv%" -DOPTIONAL_LITE_OPT_BUILD_TESTS=ON -DOPTIONAL_LITE_OPT_BUILD_EXAMPLES=OFF .. - -build_script: - - cmake --build . --config %configuration% - -test_script: - - ctest --output-on-failure -C %configuration% diff --git a/include/icsneo/third-party/optional-lite/cmake/optional-lite-config-version.cmake.in b/include/icsneo/third-party/optional-lite/cmake/optional-lite-config-version.cmake.in deleted file mode 100644 index d94242a..0000000 --- a/include/icsneo/third-party/optional-lite/cmake/optional-lite-config-version.cmake.in +++ /dev/null @@ -1,24 +0,0 @@ -# Adapted from write_basic_package_version_file(... COMPATIBILITY SameMajorVersion) output -# ARCH_INDEPENDENT is only present in cmake 3.14 and onwards - -set( PACKAGE_VERSION "@package_version@" ) - -if( PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION ) - set( PACKAGE_VERSION_COMPATIBLE FALSE ) -else() - if( "@package_version@" MATCHES "^([0-9]+)\\." ) - set( CVF_VERSION_MAJOR "${CMAKE_MATCH_1}" ) - else() - set( CVF_VERSION_MAJOR "@package_version@" ) - endif() - - if( PACKAGE_FIND_VERSION_MAJOR STREQUAL CVF_VERSION_MAJOR ) - set( PACKAGE_VERSION_COMPATIBLE TRUE ) - else() - set( PACKAGE_VERSION_COMPATIBLE FALSE ) - endif() - - if( PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION ) - set( PACKAGE_VERSION_EXACT TRUE ) - endif() -endif() diff --git a/include/icsneo/third-party/optional-lite/cmake/optional-lite-config.cmake.in b/include/icsneo/third-party/optional-lite/cmake/optional-lite-config.cmake.in deleted file mode 100644 index 9749760..0000000 --- a/include/icsneo/third-party/optional-lite/cmake/optional-lite-config.cmake.in +++ /dev/null @@ -1,7 +0,0 @@ -@PACKAGE_INIT@ - -# Only include targets once: - -if( NOT TARGET @package_name@::@package_name@ ) - include( "${CMAKE_CURRENT_LIST_DIR}/@package_target@.cmake" ) -endif() diff --git a/include/icsneo/third-party/optional-lite/conanfile.py b/include/icsneo/third-party/optional-lite/conanfile.py deleted file mode 100644 index b8ee6c4..0000000 --- a/include/icsneo/third-party/optional-lite/conanfile.py +++ /dev/null @@ -1,27 +0,0 @@ -from conans import ConanFile, CMake - -class OptionalLiteConan(ConanFile): - version = "3.4.0" - name = "optional-lite" - description = "A single-file header-only version of a C++17-like optional, a nullable object for C++98, C++11 and later" - license = "Boost Software License - Version 1.0. http://www.boost.org/LICENSE_1_0.txt" - url = "https://github.com/martinmoene/optional-lite.git" - exports_sources = "include/nonstd/*", "CMakeLists.txt", "cmake/*", "LICENSE.txt" - settings = "compiler", "build_type", "arch" - build_policy = "missing" - author = "Martin Moene" - - def build(self): - """Avoid warning on build step""" - pass - - def package(self): - """Run CMake install""" - cmake = CMake(self) - cmake.definitions["OPTIONAL_LITE_OPT_BUILD_TESTS"] = "OFF" - cmake.definitions["OPTIONAL_LITE_OPT_BUILD_EXAMPLES"] = "OFF" - cmake.configure() - cmake.install() - - def package_info(self): - self.info.header_only() diff --git a/include/icsneo/third-party/optional-lite/example/01-to_int.cpp b/include/icsneo/third-party/optional-lite/example/01-to_int.cpp deleted file mode 100644 index 7267d71..0000000 --- a/include/icsneo/third-party/optional-lite/example/01-to_int.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "nonstd/optional.hpp" - -#include -#include - -using nonstd::optional; -using nonstd::nullopt; - -optional to_int( char const * const text ) -{ - char * pos = NULL; - const int value = static_cast( strtol( text, &pos, 0 ) ); - - return pos == text ? nullopt : optional( value ); -} - -int main( int argc, char * argv[] ) -{ - const char * text = argc > 1 ? argv[1] : "42"; - - optional oi = to_int( text ); - - if ( oi ) std::cout << "'" << text << "' is " << *oi << std::endl; - else std::cout << "'" << text << "' isn't a number" << std::endl; -} - -// cl -nologo -W3 -EHsc -I../include to_int.cpp && to_int x1 -// g++ -Wall -Wextra -std=c++03 -I../include -o to_int.exe to_int.cpp && to_int x1 diff --git a/include/icsneo/third-party/optional-lite/example/02-nodefltctor.cpp b/include/icsneo/third-party/optional-lite/example/02-nodefltctor.cpp deleted file mode 100644 index 59139b0..0000000 --- a/include/icsneo/third-party/optional-lite/example/02-nodefltctor.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "nonstd/optional.hpp" - -#include -#include - -using nonstd::optional; - -struct V -{ - int v; - - V( int v ) - : v( v ) {} -}; - -int main() -{ - try - { - int x = 42; -// V s; // V has no default constructor - V t(x); // Ok - - std::vector< optional > v(3); - v[0] = t; - - std::cout << "v[0].value().v: " << v[0].value().v << "\n"; - std::cout << "v[1].value().v: " << v[1].value().v << "\n"; - } - catch( std::exception const & e ) - { - std::cout << "Error: " << e.what() << "\n"; - } -} - -// cl -nologo -W3 -EHsc -I../include 00-nodefltctor.cpp && 00-nodefltctor diff --git a/include/icsneo/third-party/optional-lite/example/04-any-optional-variant.cpp b/include/icsneo/third-party/optional-lite/example/04-any-optional-variant.cpp deleted file mode 100644 index 39d8069..0000000 --- a/include/icsneo/third-party/optional-lite/example/04-any-optional-variant.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include "nonstd/any.hpp" -#include "nonstd/optional.hpp" -#include "nonstd/variant.hpp" - -#include -#include - -using namespace nonstd; - -int main() -{ - std::string hello = "hello, world"; - { - optional< int > var; - - assert( ! var ); - - var = 7 ; assert( *var == 7 ); - var = 7 ; assert( var.value() == 7 ); - }{ - any var; - - assert( ! var.has_value() ); - - var = 'v' ; assert( any_cast( var ) == 'v' ); - var = 7 ; assert( any_cast( var ) == 7 ); - var = 42L ; assert( any_cast( var ) == 42L ); - var = hello; assert( any_cast( var ) == hello ); - }{ - variant< char, int, long, std::string > var; - - assert( ! var.valueless_by_exception() ); - - assert( get< 0 >( var ) == char() ); - var = 'v' ; assert( get( var ) == 'v' ); - var = 7 ; assert( get( var ) == 7 ); - var = 42L ; assert( get( var ) == 42L ); - var = hello; assert( get( var ) == hello ); - } -} - -// cl -nologo -EHsc -I../../any-lite/include -I../../optional-lite/include -I../../variant-lite/include 04-any-optional-variant.cpp && 04-any-optional-variant -// g++ -Wall -I../../any-lite/include -I../../optional-lite/include -I../../variant-lite/include -o 04-any-optional-variant 04-any-optional-variant.cpp && 04-any-optional-variant diff --git a/include/icsneo/third-party/optional-lite/example/05-no-exceptions.cpp b/include/icsneo/third-party/optional-lite/example/05-no-exceptions.cpp deleted file mode 100644 index 98eda8a..0000000 --- a/include/icsneo/third-party/optional-lite/example/05-no-exceptions.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "nonstd/optional.hpp" - -using nonstd::optional; - -int main() -{ - optional v; - - v.value(); // asserts (normally throws) -} - -// cl -nologo -I../include 05-no-exceptions.cpp && 05-no-exceptions -// g++ -Wall -fno-exceptions -I../include -o 05-no-exceptions 05-no-exceptions.cpp && 05-no-exceptions diff --git a/include/icsneo/third-party/optional-lite/example/BUCK b/include/icsneo/third-party/optional-lite/example/BUCK deleted file mode 100644 index 614d13a..0000000 --- a/include/icsneo/third-party/optional-lite/example/BUCK +++ /dev/null @@ -1,38 +0,0 @@ -cxx_binary( - name = '01-to_int', - srcs = [ - '01-to_int.cpp', - ], - compiler_flags = [ - '-std=c++11', - ], - deps = [ - '//:optional-lite', - ], -) - -cxx_binary( - name = '02-nodefltctor', - srcs = [ - '02-nodefltctor.cpp', - ], - compiler_flags = [ - '-std=c++11', - ], - deps = [ - '//:optional-lite', - ], -) - -cxx_binary( - name = '04-any-optional-variant', - srcs = [ - '04-any-optional-variant.cpp', - ], - compiler_flags = [ - '-std=c++11', - ], - deps = [ - '//:optional-lite', - ], -) diff --git a/include/icsneo/third-party/optional-lite/example/CMakeLists.txt b/include/icsneo/third-party/optional-lite/example/CMakeLists.txt deleted file mode 100644 index 5ee2695..0000000 --- a/include/icsneo/third-party/optional-lite/example/CMakeLists.txt +++ /dev/null @@ -1,60 +0,0 @@ -# Copyright 2017-2018 by Martin Moene -# -# https://github.com/martinmoene/optional-lite -# -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -if( NOT DEFINED CMAKE_MINIMUM_REQUIRED_VERSION ) - cmake_minimum_required( VERSION 3.5 FATAL_ERROR ) -endif() - -project( example LANGUAGES CXX ) - -set( unit_name "optional" ) -set( PACKAGE ${unit_name}-lite ) -set( PROGRAM ${unit_name}-lite ) - -message( STATUS "Subproject '${PROJECT_NAME}', examples '${PROGRAM}-*'") - -set( OPTIONS "" ) - -if( MSVC ) - message( STATUS "Matched: MSVC") - - set( BASE_OPTIONS -W3 ) - set( EXCEPTIONS_OPTIONS ${BASE_OPTIONS} -EHsc ) - set( NO_EXCEPTIONS_OPTIONS ${BASE_OPTIONS} ) - -elseif( CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang" ) - message( STATUS "CompilerId: '${CMAKE_CXX_COMPILER_ID}'") - - set( BASE_OPTIONS -Wall -Wextra -Wconversion -Wsign-conversion -Wno-missing-braces -fno-elide-constructors ) - set( EXCEPTIONS_OPTIONS ${BASE_OPTIONS} ) - set( NO_EXCEPTIONS_OPTIONS -fno-exceptions ) - -elseif( CMAKE_CXX_COMPILER_ID MATCHES "Intel" ) - # as is - message( STATUS "Matched: Intel") -else() - # as is - message( STATUS "Matched: nothing") -endif() - -function( make_target name no_exceptions ) - add_executable ( ${PROGRAM}-${name} ${name}.cpp ) - target_link_libraries ( ${PROGRAM}-${name} PRIVATE ${PACKAGE} ) - if ( no_exceptions ) - target_compile_options ( ${PROGRAM}-${name} PRIVATE ${NO_EXCEPTIONS_OPTIONS} ) - else() - target_compile_options ( ${PROGRAM}-${name} PRIVATE ${EXCEPTIONS_OPTIONS} ) - endif() - -endfunction() - -make_target( 01-to_int FALSE ) -make_target( 02-nodefltctor FALSE ) -# 04-any-optional-variant also requires variant-lite. -make_target( 05-no-exceptions TRUE ) - -# end of file diff --git a/include/icsneo/third-party/optional-lite/extra/gdb/nonstd_optional_printer.py b/include/icsneo/third-party/optional-lite/extra/gdb/nonstd_optional_printer.py deleted file mode 100644 index 918bf94..0000000 --- a/include/icsneo/third-party/optional-lite/extra/gdb/nonstd_optional_printer.py +++ /dev/null @@ -1,26 +0,0 @@ -# gdb pretty-printer contributed by @bas524, Alexander B. -# -# register with: -# libstdcxx_printer.add_version('nonstd::optional_lite::', 'optional', NonStdOptionalPrinter) - -class NonStdOptionalPrinter(SingleObjContainerPrinter): - "Print a nonstd::optional" - - def __init__ (self, typename, val): - alternatives = get_template_arg_list(val.type) - valtype = self._recognize (val.type.template_argument(0)) - self.typename = strip_versioned_namespace(typename) - self.typename = re.sub('^nonstd::(optional_lite::|)(optional::|)(.*)', r'nonstd::\1\3<%s>' % valtype, self.typename, 1) - self.val = val - self.contained_type = alternatives[0] - addr = val['contained']['data']['__data'].address - contained_value = addr.cast(self.contained_type.pointer()).dereference() - visualizer = gdb.default_visualizer (contained_value) - super (NonStdOptionalPrinter, self).__init__ (contained_value, visualizer) - - def to_string (self): - if self.contained_value is None: - return "%s [no contained value]" % self.typename - if self.visualizer: - return "%s containing %s" % (self.typename, self.visualizer.to_string()) - return self.typename diff --git a/include/icsneo/third-party/optional-lite/include/nonstd/optional.hpp b/include/icsneo/third-party/optional-lite/include/nonstd/optional.hpp deleted file mode 100644 index aa54e93..0000000 --- a/include/icsneo/third-party/optional-lite/include/nonstd/optional.hpp +++ /dev/null @@ -1,1791 +0,0 @@ -// -// Copyright (c) 2014-2018 Martin Moene -// -// https://github.com/martinmoene/optional-lite -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -#pragma once - -#ifndef NONSTD_OPTIONAL_LITE_HPP -#define NONSTD_OPTIONAL_LITE_HPP - -#define optional_lite_MAJOR 3 -#define optional_lite_MINOR 4 -#define optional_lite_PATCH 0 - -#define optional_lite_VERSION optional_STRINGIFY(optional_lite_MAJOR) "." optional_STRINGIFY(optional_lite_MINOR) "." optional_STRINGIFY(optional_lite_PATCH) - -#define optional_STRINGIFY( x ) optional_STRINGIFY_( x ) -#define optional_STRINGIFY_( x ) #x - -// optional-lite configuration: - -#define optional_OPTIONAL_DEFAULT 0 -#define optional_OPTIONAL_NONSTD 1 -#define optional_OPTIONAL_STD 2 - -// tweak header support: - -#ifdef __has_include -# if __has_include() -# include -# endif -#define optional_HAVE_TWEAK_HEADER 1 -#else -#define optional_HAVE_TWEAK_HEADER 0 -//# pragma message("optional.hpp: Note: Tweak header not supported.") -#endif - -// optional selection and configuration: - -#if !defined( optional_CONFIG_SELECT_OPTIONAL ) -# define optional_CONFIG_SELECT_OPTIONAL ( optional_HAVE_STD_OPTIONAL ? optional_OPTIONAL_STD : optional_OPTIONAL_NONSTD ) -#endif - -// Control presence of exception handling (try and auto discover): - -#ifndef optional_CONFIG_NO_EXCEPTIONS -# if _MSC_VER -# include // for _HAS_EXCEPTIONS -# endif -# if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || (_HAS_EXCEPTIONS) -# define optional_CONFIG_NO_EXCEPTIONS 0 -# else -# define optional_CONFIG_NO_EXCEPTIONS 1 -# endif -#endif - -// C++ language version detection (C++20 is speculative): -// Note: VC14.0/1900 (VS2015) lacks too much from C++14. - -#ifndef optional_CPLUSPLUS -# if defined(_MSVC_LANG ) && !defined(__clang__) -# define optional_CPLUSPLUS (_MSC_VER == 1900 ? 201103L : _MSVC_LANG ) -# else -# define optional_CPLUSPLUS __cplusplus -# endif -#endif - -#define optional_CPP98_OR_GREATER ( optional_CPLUSPLUS >= 199711L ) -#define optional_CPP11_OR_GREATER ( optional_CPLUSPLUS >= 201103L ) -#define optional_CPP11_OR_GREATER_ ( optional_CPLUSPLUS >= 201103L ) -#define optional_CPP14_OR_GREATER ( optional_CPLUSPLUS >= 201402L ) -#define optional_CPP17_OR_GREATER ( optional_CPLUSPLUS >= 201703L ) -#define optional_CPP20_OR_GREATER ( optional_CPLUSPLUS >= 202000L ) - -// C++ language version (represent 98 as 3): - -#define optional_CPLUSPLUS_V ( optional_CPLUSPLUS / 100 - (optional_CPLUSPLUS > 200000 ? 2000 : 1994) ) - -// Use C++17 std::optional if available and requested: - -#if optional_CPP17_OR_GREATER && defined(__has_include ) -# if __has_include( ) -# define optional_HAVE_STD_OPTIONAL 1 -# else -# define optional_HAVE_STD_OPTIONAL 0 -# endif -#else -# define optional_HAVE_STD_OPTIONAL 0 -#endif - -#define optional_USES_STD_OPTIONAL ( (optional_CONFIG_SELECT_OPTIONAL == optional_OPTIONAL_STD) || ((optional_CONFIG_SELECT_OPTIONAL == optional_OPTIONAL_DEFAULT) && optional_HAVE_STD_OPTIONAL) ) - -// -// in_place: code duplicated in any-lite, expected-lite, optional-lite, value-ptr-lite, variant-lite: -// - -#ifndef nonstd_lite_HAVE_IN_PLACE_TYPES -#define nonstd_lite_HAVE_IN_PLACE_TYPES 1 - -// C++17 std::in_place in : - -#if optional_CPP17_OR_GREATER - -#include - -namespace nonstd { - -using std::in_place; -using std::in_place_type; -using std::in_place_index; -using std::in_place_t; -using std::in_place_type_t; -using std::in_place_index_t; - -#define nonstd_lite_in_place_t( T) std::in_place_t -#define nonstd_lite_in_place_type_t( T) std::in_place_type_t -#define nonstd_lite_in_place_index_t(K) std::in_place_index_t - -#define nonstd_lite_in_place( T) std::in_place_t{} -#define nonstd_lite_in_place_type( T) std::in_place_type_t{} -#define nonstd_lite_in_place_index(K) std::in_place_index_t{} - -} // namespace nonstd - -#else // optional_CPP17_OR_GREATER - -#include - -namespace nonstd { -namespace detail { - -template< class T > -struct in_place_type_tag {}; - -template< std::size_t K > -struct in_place_index_tag {}; - -} // namespace detail - -struct in_place_t {}; - -template< class T > -inline in_place_t in_place( detail::in_place_type_tag /*unused*/ = detail::in_place_type_tag() ) -{ - return in_place_t(); -} - -template< std::size_t K > -inline in_place_t in_place( detail::in_place_index_tag /*unused*/ = detail::in_place_index_tag() ) -{ - return in_place_t(); -} - -template< class T > -inline in_place_t in_place_type( detail::in_place_type_tag /*unused*/ = detail::in_place_type_tag() ) -{ - return in_place_t(); -} - -template< std::size_t K > -inline in_place_t in_place_index( detail::in_place_index_tag /*unused*/ = detail::in_place_index_tag() ) -{ - return in_place_t(); -} - -// mimic templated typedef: - -#define nonstd_lite_in_place_t( T) nonstd::in_place_t(&)( nonstd::detail::in_place_type_tag ) -#define nonstd_lite_in_place_type_t( T) nonstd::in_place_t(&)( nonstd::detail::in_place_type_tag ) -#define nonstd_lite_in_place_index_t(K) nonstd::in_place_t(&)( nonstd::detail::in_place_index_tag ) - -#define nonstd_lite_in_place( T) nonstd::in_place_type -#define nonstd_lite_in_place_type( T) nonstd::in_place_type -#define nonstd_lite_in_place_index(K) nonstd::in_place_index - -} // namespace nonstd - -#endif // optional_CPP17_OR_GREATER -#endif // nonstd_lite_HAVE_IN_PLACE_TYPES - -// -// Using std::optional: -// - -#if optional_USES_STD_OPTIONAL - -#include - -namespace nonstd { - - using std::optional; - using std::bad_optional_access; - using std::hash; - - using std::nullopt; - using std::nullopt_t; - - using std::operator==; - using std::operator!=; - using std::operator<; - using std::operator<=; - using std::operator>; - using std::operator>=; - using std::make_optional; - using std::swap; -} - -#else // optional_USES_STD_OPTIONAL - -#include -#include - -// optional-lite alignment configuration: - -#ifndef optional_CONFIG_MAX_ALIGN_HACK -# define optional_CONFIG_MAX_ALIGN_HACK 0 -#endif - -#ifndef optional_CONFIG_ALIGN_AS -// no default, used in #if defined() -#endif - -#ifndef optional_CONFIG_ALIGN_AS_FALLBACK -# define optional_CONFIG_ALIGN_AS_FALLBACK double -#endif - -// Compiler warning suppression: - -#if defined(__clang__) -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wundef" -#elif defined(__GNUC__) -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wundef" -#elif defined(_MSC_VER ) -# pragma warning( push ) -#endif - -// half-open range [lo..hi): -#define optional_BETWEEN( v, lo, hi ) ( (lo) <= (v) && (v) < (hi) ) - -// Compiler versions: -// -// MSVC++ 6.0 _MSC_VER == 1200 optional_COMPILER_MSVC_VERSION == 60 (Visual Studio 6.0) -// MSVC++ 7.0 _MSC_VER == 1300 optional_COMPILER_MSVC_VERSION == 70 (Visual Studio .NET 2002) -// MSVC++ 7.1 _MSC_VER == 1310 optional_COMPILER_MSVC_VERSION == 71 (Visual Studio .NET 2003) -// MSVC++ 8.0 _MSC_VER == 1400 optional_COMPILER_MSVC_VERSION == 80 (Visual Studio 2005) -// MSVC++ 9.0 _MSC_VER == 1500 optional_COMPILER_MSVC_VERSION == 90 (Visual Studio 2008) -// MSVC++ 10.0 _MSC_VER == 1600 optional_COMPILER_MSVC_VERSION == 100 (Visual Studio 2010) -// MSVC++ 11.0 _MSC_VER == 1700 optional_COMPILER_MSVC_VERSION == 110 (Visual Studio 2012) -// MSVC++ 12.0 _MSC_VER == 1800 optional_COMPILER_MSVC_VERSION == 120 (Visual Studio 2013) -// MSVC++ 14.0 _MSC_VER == 1900 optional_COMPILER_MSVC_VERSION == 140 (Visual Studio 2015) -// MSVC++ 14.1 _MSC_VER >= 1910 optional_COMPILER_MSVC_VERSION == 141 (Visual Studio 2017) -// MSVC++ 14.2 _MSC_VER >= 1920 optional_COMPILER_MSVC_VERSION == 142 (Visual Studio 2019) - -#if defined(_MSC_VER ) && !defined(__clang__) -# define optional_COMPILER_MSVC_VER (_MSC_VER ) -# define optional_COMPILER_MSVC_VERSION (_MSC_VER / 10 - 10 * ( 5 + (_MSC_VER < 1900 ) ) ) -#else -# define optional_COMPILER_MSVC_VER 0 -# define optional_COMPILER_MSVC_VERSION 0 -#endif - -#define optional_COMPILER_VERSION( major, minor, patch ) ( 10 * (10 * (major) + (minor) ) + (patch) ) - -#if defined(__GNUC__) && !defined(__clang__) -# define optional_COMPILER_GNUC_VERSION optional_COMPILER_VERSION(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) -#else -# define optional_COMPILER_GNUC_VERSION 0 -#endif - -#if defined(__clang__) -# define optional_COMPILER_CLANG_VERSION optional_COMPILER_VERSION(__clang_major__, __clang_minor__, __clang_patchlevel__) -#else -# define optional_COMPILER_CLANG_VERSION 0 -#endif - -#if optional_BETWEEN(optional_COMPILER_MSVC_VERSION, 70, 140 ) -# pragma warning( disable: 4345 ) // initialization behavior changed -#endif - -#if optional_BETWEEN(optional_COMPILER_MSVC_VERSION, 70, 150 ) -# pragma warning( disable: 4814 ) // in C++14 'constexpr' will not imply 'const' -#endif - -// Presence of language and library features: - -#define optional_HAVE(FEATURE) ( optional_HAVE_##FEATURE ) - -#ifdef _HAS_CPP0X -# define optional_HAS_CPP0X _HAS_CPP0X -#else -# define optional_HAS_CPP0X 0 -#endif - -// Unless defined otherwise below, consider VC14 as C++11 for optional-lite: - -#if optional_COMPILER_MSVC_VER >= 1900 -# undef optional_CPP11_OR_GREATER -# define optional_CPP11_OR_GREATER 1 -#endif - -#define optional_CPP11_90 (optional_CPP11_OR_GREATER_ || optional_COMPILER_MSVC_VER >= 1500) -#define optional_CPP11_100 (optional_CPP11_OR_GREATER_ || optional_COMPILER_MSVC_VER >= 1600) -#define optional_CPP11_110 (optional_CPP11_OR_GREATER_ || optional_COMPILER_MSVC_VER >= 1700) -#define optional_CPP11_120 (optional_CPP11_OR_GREATER_ || optional_COMPILER_MSVC_VER >= 1800) -#define optional_CPP11_140 (optional_CPP11_OR_GREATER_ || optional_COMPILER_MSVC_VER >= 1900) -#define optional_CPP11_141 (optional_CPP11_OR_GREATER_ || optional_COMPILER_MSVC_VER >= 1910) - -#define optional_CPP14_000 (optional_CPP14_OR_GREATER) -#define optional_CPP17_000 (optional_CPP17_OR_GREATER) - -// clang >= 2.9, gcc >= 4.9, msvc >= vc14.0/1900 (vs15): -#define optional_CPP11_140_C290_G490 ((optional_CPP11_OR_GREATER_ && (optional_COMPILER_CLANG_VERSION >= 290 || optional_COMPILER_GNUC_VERSION >= 490)) || (optional_COMPILER_MSVC_VER >= 1900)) - -// clang >= 3.5, msvc >= vc11 (vs12): -#define optional_CPP11_110_C350 ( optional_CPP11_110 && !optional_BETWEEN( optional_COMPILER_CLANG_VERSION, 1, 350 ) ) - -// clang >= 3.5, gcc >= 5.0, msvc >= vc11 (vs12): -#define optional_CPP11_110_C350_G500 \ - ( optional_CPP11_110 && \ - !( optional_BETWEEN( optional_COMPILER_CLANG_VERSION, 1, 350 ) \ - || optional_BETWEEN( optional_COMPILER_GNUC_VERSION , 1, 500 ) ) ) - -// Presence of C++11 language features: - -#define optional_HAVE_CONSTEXPR_11 optional_CPP11_140 -#define optional_HAVE_IS_DEFAULT optional_CPP11_140 -#define optional_HAVE_NOEXCEPT optional_CPP11_140 -#define optional_HAVE_NULLPTR optional_CPP11_100 -#define optional_HAVE_REF_QUALIFIER optional_CPP11_140_C290_G490 -#define optional_HAVE_INITIALIZER_LIST optional_CPP11_140 - -// Presence of C++14 language features: - -#define optional_HAVE_CONSTEXPR_14 optional_CPP14_000 - -// Presence of C++17 language features: - -#define optional_HAVE_NODISCARD optional_CPP17_000 - -// Presence of C++ library features: - -#define optional_HAVE_CONDITIONAL optional_CPP11_120 -#define optional_HAVE_REMOVE_CV optional_CPP11_120 -#define optional_HAVE_TYPE_TRAITS optional_CPP11_90 - -#define optional_HAVE_TR1_TYPE_TRAITS (!! optional_COMPILER_GNUC_VERSION ) -#define optional_HAVE_TR1_ADD_POINTER (!! optional_COMPILER_GNUC_VERSION ) - -#define optional_HAVE_IS_ASSIGNABLE optional_CPP11_110_C350 -#define optional_HAVE_IS_MOVE_CONSTRUCTIBLE optional_CPP11_110_C350 -#define optional_HAVE_IS_NOTHROW_MOVE_ASSIGNABLE optional_CPP11_110_C350 -#define optional_HAVE_IS_NOTHROW_MOVE_CONSTRUCTIBLE optional_CPP11_110_C350 -#define optional_HAVE_IS_TRIVIALLY_COPY_CONSTRUCTIBLE optional_CPP11_110_C350_G500 -#define optional_HAVE_IS_TRIVIALLY_MOVE_CONSTRUCTIBLE optional_CPP11_110_C350_G500 - -// C++ feature usage: - -#if optional_HAVE( CONSTEXPR_11 ) -# define optional_constexpr constexpr -#else -# define optional_constexpr /*constexpr*/ -#endif - -#if optional_HAVE( IS_DEFAULT ) -# define optional_is_default = default; -#else -# define optional_is_default {} -#endif - -#if optional_HAVE( CONSTEXPR_14 ) -# define optional_constexpr14 constexpr -#else -# define optional_constexpr14 /*constexpr*/ -#endif - -#if optional_HAVE( NODISCARD ) -# define optional_nodiscard [[nodiscard]] -#else -# define optional_nodiscard /*[[nodiscard]]*/ -#endif - -#if optional_HAVE( NOEXCEPT ) -# define optional_noexcept noexcept -#else -# define optional_noexcept /*noexcept*/ -#endif - -#if optional_HAVE( NULLPTR ) -# define optional_nullptr nullptr -#else -# define optional_nullptr NULL -#endif - -#if optional_HAVE( REF_QUALIFIER ) -// NOLINTNEXTLINE( bugprone-macro-parentheses ) -# define optional_ref_qual & -# define optional_refref_qual && -#else -# define optional_ref_qual /*&*/ -# define optional_refref_qual /*&&*/ -#endif - -// additional includes: - -#if optional_CONFIG_NO_EXCEPTIONS -// already included: -#else -# include -#endif - -#if optional_CPP11_OR_GREATER -# include -#endif - -#if optional_HAVE( INITIALIZER_LIST ) -# include -#endif - -#if optional_HAVE( TYPE_TRAITS ) -# include -#elif optional_HAVE( TR1_TYPE_TRAITS ) -# include -#endif - -// Method enabling - -#if optional_CPP11_OR_GREATER - -#define optional_REQUIRES_0(...) \ - template< bool B = (__VA_ARGS__), typename std::enable_if::type = 0 > - -#define optional_REQUIRES_T(...) \ - , typename std::enable_if< (__VA_ARGS__), int >::type = 0 - -#define optional_REQUIRES_R(R, ...) \ - typename std::enable_if< (__VA_ARGS__), R>::type - -#define optional_REQUIRES_A(...) \ - , typename std::enable_if< (__VA_ARGS__), void*>::type = nullptr - -#endif - -// -// optional: -// - -namespace nonstd { namespace optional_lite { - -namespace std11 { - -template< class T, T v > struct integral_constant { enum { value = v }; }; -template< bool B > struct bool_constant : integral_constant{}; - -typedef bool_constant< true > true_type; -typedef bool_constant< false > false_type; - -#if optional_CPP11_OR_GREATER - using std::move; -#else - template< typename T > T & move( T & t ) { return t; } -#endif - -#if optional_HAVE( CONDITIONAL ) - using std::conditional; -#else - template< bool B, typename T, typename F > struct conditional { typedef T type; }; - template< typename T, typename F > struct conditional { typedef F type; }; -#endif // optional_HAVE_CONDITIONAL - -#if optional_HAVE( IS_ASSIGNABLE ) - using std::is_assignable; -#else - template< class T, class U > struct is_assignable : std11::true_type{}; -#endif - -#if optional_HAVE( IS_MOVE_CONSTRUCTIBLE ) - using std::is_move_constructible; -#else - template< class T > struct is_move_constructible : std11::true_type{}; -#endif - -#if optional_HAVE( IS_NOTHROW_MOVE_ASSIGNABLE ) - using std::is_nothrow_move_assignable; -#else - template< class T > struct is_nothrow_move_assignable : std11::true_type{}; -#endif - -#if optional_HAVE( IS_NOTHROW_MOVE_CONSTRUCTIBLE ) - using std::is_nothrow_move_constructible; -#else - template< class T > struct is_nothrow_move_constructible : std11::true_type{}; -#endif - -#if optional_HAVE( IS_TRIVIALLY_COPY_CONSTRUCTIBLE ) - using std::is_trivially_copy_constructible; -#else - template< class T > struct is_trivially_copy_constructible : std11::true_type{}; -#endif - -#if optional_HAVE( IS_TRIVIALLY_MOVE_CONSTRUCTIBLE ) - using std::is_trivially_move_constructible; -#else - template< class T > struct is_trivially_move_constructible : std11::true_type{}; -#endif - -} // namespace std11 - -#if optional_CPP11_OR_GREATER - -/// type traits C++17: - -namespace std17 { - -#if optional_CPP17_OR_GREATER - -using std::is_swappable; -using std::is_nothrow_swappable; - -#elif optional_CPP11_OR_GREATER - -namespace detail { - -using std::swap; - -struct is_swappable -{ - template< typename T, typename = decltype( swap( std::declval(), std::declval() ) ) > - static std11::true_type test( int /*unused*/ ); - - template< typename > - static std11::false_type test(...); -}; - -struct is_nothrow_swappable -{ - // wrap noexcept(expr) in separate function as work-around for VC140 (VS2015): - - template< typename T > - static constexpr bool satisfies() - { - return noexcept( swap( std::declval(), std::declval() ) ); - } - - template< typename T > - static auto test( int /*unused*/ ) -> std11::integral_constant()>{} - - template< typename > - static auto test(...) -> std11::false_type; -}; - -} // namespace detail - -// is [nothow] swappable: - -template< typename T > -struct is_swappable : decltype( detail::is_swappable::test(0) ){}; - -template< typename T > -struct is_nothrow_swappable : decltype( detail::is_nothrow_swappable::test(0) ){}; - -#endif // optional_CPP17_OR_GREATER - -} // namespace std17 - -/// type traits C++20: - -namespace std20 { - -template< typename T > -struct remove_cvref -{ - typedef typename std::remove_cv< typename std::remove_reference::type >::type type; -}; - -} // namespace std20 - -#endif // optional_CPP11_OR_GREATER - -/// class optional - -template< typename T > -class optional; - -namespace detail { - -// C++11 emulation: - -struct nulltype{}; - -template< typename Head, typename Tail > -struct typelist -{ - typedef Head head; - typedef Tail tail; -}; - -#if optional_CONFIG_MAX_ALIGN_HACK - -// Max align, use most restricted type for alignment: - -#define optional_UNIQUE( name ) optional_UNIQUE2( name, __LINE__ ) -#define optional_UNIQUE2( name, line ) optional_UNIQUE3( name, line ) -#define optional_UNIQUE3( name, line ) name ## line - -#define optional_ALIGN_TYPE( type ) \ - type optional_UNIQUE( _t ); struct_t< type > optional_UNIQUE( _st ) - -template< typename T > -struct struct_t { T _; }; - -union max_align_t -{ - optional_ALIGN_TYPE( char ); - optional_ALIGN_TYPE( short int ); - optional_ALIGN_TYPE( int ); - optional_ALIGN_TYPE( long int ); - optional_ALIGN_TYPE( float ); - optional_ALIGN_TYPE( double ); - optional_ALIGN_TYPE( long double ); - optional_ALIGN_TYPE( char * ); - optional_ALIGN_TYPE( short int * ); - optional_ALIGN_TYPE( int * ); - optional_ALIGN_TYPE( long int * ); - optional_ALIGN_TYPE( float * ); - optional_ALIGN_TYPE( double * ); - optional_ALIGN_TYPE( long double * ); - optional_ALIGN_TYPE( void * ); - -#ifdef HAVE_LONG_LONG - optional_ALIGN_TYPE( long long ); -#endif - - struct Unknown; - - Unknown ( * optional_UNIQUE(_) )( Unknown ); - Unknown * Unknown::* optional_UNIQUE(_); - Unknown ( Unknown::* optional_UNIQUE(_) )( Unknown ); - - struct_t< Unknown ( * )( Unknown) > optional_UNIQUE(_); - struct_t< Unknown * Unknown::* > optional_UNIQUE(_); - struct_t< Unknown ( Unknown::* )(Unknown) > optional_UNIQUE(_); -}; - -#undef optional_UNIQUE -#undef optional_UNIQUE2 -#undef optional_UNIQUE3 - -#undef optional_ALIGN_TYPE - -#elif defined( optional_CONFIG_ALIGN_AS ) // optional_CONFIG_MAX_ALIGN_HACK - -// Use user-specified type for alignment: - -#define optional_ALIGN_AS( unused ) \ - optional_CONFIG_ALIGN_AS - -#else // optional_CONFIG_MAX_ALIGN_HACK - -// Determine POD type to use for alignment: - -#define optional_ALIGN_AS( to_align ) \ - typename type_of_size< alignment_types, alignment_of< to_align >::value >::type - -template< typename T > -struct alignment_of; - -template< typename T > -struct alignment_of_hack -{ - char c; - T t; - alignment_of_hack(); -}; - -template< size_t A, size_t S > -struct alignment_logic -{ - enum { value = A < S ? A : S }; -}; - -template< typename T > -struct alignment_of -{ - enum { value = alignment_logic< - sizeof( alignment_of_hack ) - sizeof(T), sizeof(T) >::value }; -}; - -template< typename List, size_t N > -struct type_of_size -{ - typedef typename std11::conditional< - N == sizeof( typename List::head ), - typename List::head, - typename type_of_size::type >::type type; -}; - -template< size_t N > -struct type_of_size< nulltype, N > -{ - typedef optional_CONFIG_ALIGN_AS_FALLBACK type; -}; - -template< typename T> -struct struct_t { T _; }; - -#define optional_ALIGN_TYPE( type ) \ - typelist< type , typelist< struct_t< type > - -struct Unknown; - -typedef - optional_ALIGN_TYPE( char ), - optional_ALIGN_TYPE( short ), - optional_ALIGN_TYPE( int ), - optional_ALIGN_TYPE( long ), - optional_ALIGN_TYPE( float ), - optional_ALIGN_TYPE( double ), - optional_ALIGN_TYPE( long double ), - - optional_ALIGN_TYPE( char *), - optional_ALIGN_TYPE( short * ), - optional_ALIGN_TYPE( int * ), - optional_ALIGN_TYPE( long * ), - optional_ALIGN_TYPE( float * ), - optional_ALIGN_TYPE( double * ), - optional_ALIGN_TYPE( long double * ), - - optional_ALIGN_TYPE( Unknown ( * )( Unknown ) ), - optional_ALIGN_TYPE( Unknown * Unknown::* ), - optional_ALIGN_TYPE( Unknown ( Unknown::* )( Unknown ) ), - - nulltype - > > > > > > > > > > > > > > - > > > > > > > > > > > > > > - > > > > > > - alignment_types; - -#undef optional_ALIGN_TYPE - -#endif // optional_CONFIG_MAX_ALIGN_HACK - -/// C++03 constructed union to hold value. - -template< typename T > -union storage_t -{ -//private: -// template< typename > friend class optional; - - typedef T value_type; - - storage_t() optional_is_default - - explicit storage_t( value_type const & v ) - { - construct_value( v ); - } - - void construct_value( value_type const & v ) - { - ::new( value_ptr() ) value_type( v ); - } - -#if optional_CPP11_OR_GREATER - - explicit storage_t( value_type && v ) - { - construct_value( std::move( v ) ); - } - - void construct_value( value_type && v ) - { - ::new( value_ptr() ) value_type( std::move( v ) ); - } - - template< class... Args > - storage_t( nonstd_lite_in_place_t(T), Args&&... args ) - { - emplace( std::forward(args)... ); - } - - template< class... Args > - void emplace( Args&&... args ) - { - ::new( value_ptr() ) value_type( std::forward(args)... ); - } - - template< class U, class... Args > - void emplace( std::initializer_list il, Args&&... args ) - { - ::new( value_ptr() ) value_type( il, std::forward(args)... ); - } - -#endif - - void destruct_value() - { - value_ptr()->~T(); - } - - optional_nodiscard value_type const * value_ptr() const - { - return as(); - } - - value_type * value_ptr() - { - return as(); - } - - optional_nodiscard value_type const & value() const optional_ref_qual - { - return * value_ptr(); - } - - value_type & value() optional_ref_qual - { - return * value_ptr(); - } - -#if optional_HAVE( REF_QUALIFIER ) - - optional_nodiscard value_type const && value() const optional_refref_qual - { - return std::move( value() ); - } - - value_type && value() optional_refref_qual - { - return std::move( value() ); - } - -#endif - -#if optional_CPP11_OR_GREATER - - using aligned_storage_t = typename std::aligned_storage< sizeof(value_type), alignof(value_type) >::type; - aligned_storage_t data; - -#elif optional_CONFIG_MAX_ALIGN_HACK - - typedef struct { unsigned char data[ sizeof(value_type) ]; } aligned_storage_t; - - max_align_t hack; - aligned_storage_t data; - -#else - typedef optional_ALIGN_AS(value_type) align_as_type; - - typedef struct { align_as_type data[ 1 + ( sizeof(value_type) - 1 ) / sizeof(align_as_type) ]; } aligned_storage_t; - aligned_storage_t data; - -# undef optional_ALIGN_AS - -#endif // optional_CONFIG_MAX_ALIGN_HACK - - optional_nodiscard void * ptr() optional_noexcept - { - return &data; - } - - optional_nodiscard void const * ptr() const optional_noexcept - { - return &data; - } - - template - optional_nodiscard U * as() - { - return reinterpret_cast( ptr() ); - } - - template - optional_nodiscard U const * as() const - { - return reinterpret_cast( ptr() ); - } -}; - -} // namespace detail - -/// disengaged state tag - -struct nullopt_t -{ - struct init{}; - explicit optional_constexpr nullopt_t( init /*unused*/ ) optional_noexcept {} -}; - -#if optional_HAVE( CONSTEXPR_11 ) -constexpr nullopt_t nullopt{ nullopt_t::init{} }; -#else -// extra parenthesis to prevent the most vexing parse: -const nullopt_t nullopt(( nullopt_t::init() )); -#endif - -/// optional access error - -#if ! optional_CONFIG_NO_EXCEPTIONS - -class bad_optional_access : public std::logic_error -{ -public: - explicit bad_optional_access() - : logic_error( "bad optional access" ) {} -}; - -#endif //optional_CONFIG_NO_EXCEPTIONS - -/// optional - -template< typename T> -class optional -{ -private: - template< typename > friend class optional; - - typedef void (optional::*safe_bool)() const; - -public: - typedef T value_type; - - // x.x.3.1, constructors - - // 1a - default construct - optional_constexpr optional() optional_noexcept - : has_value_( false ) - , contained() - {} - - // 1b - construct explicitly empty - // NOLINTNEXTLINE( google-explicit-constructor, hicpp-explicit-conversions ) - optional_constexpr optional( nullopt_t /*unused*/ ) optional_noexcept - : has_value_( false ) - , contained() - {} - - // 2 - copy-construct -#if optional_CPP11_OR_GREATER - // template< typename U = T - // optional_REQUIRES_T( - // std::is_copy_constructible::value - // || std11::is_trivially_copy_constructible::value - // ) - // > -#endif - optional_constexpr14 optional( optional const & other ) - : has_value_( other.has_value() ) - { - if ( other.has_value() ) - { - contained.construct_value( other.contained.value() ); - } - } - -#if optional_CPP11_OR_GREATER - - // 3 (C++11) - move-construct from optional - template< typename U = T - optional_REQUIRES_T( - std11::is_move_constructible::value - || std11::is_trivially_move_constructible::value - ) - > - optional_constexpr14 optional( optional && other ) - // NOLINTNEXTLINE( performance-noexcept-move-constructor ) - noexcept( std11::is_nothrow_move_constructible::value ) - : has_value_( other.has_value() ) - { - if ( other.has_value() ) - { - contained.construct_value( std::move( other.contained.value() ) ); - } - } - - // 4a (C++11) - explicit converting copy-construct from optional - template< typename U - optional_REQUIRES_T( - std::is_constructible::value - && !std::is_constructible & >::value - && !std::is_constructible && >::value - && !std::is_constructible const & >::value - && !std::is_constructible const && >::value - && !std::is_convertible< optional & , T>::value - && !std::is_convertible< optional && , T>::value - && !std::is_convertible< optional const & , T>::value - && !std::is_convertible< optional const &&, T>::value - && !std::is_convertible< U const & , T>::value /*=> explicit */ - ) - > - explicit optional( optional const & other ) - : has_value_( other.has_value() ) - { - if ( other.has_value() ) - { - contained.construct_value( T{ other.contained.value() } ); - } - } -#endif // optional_CPP11_OR_GREATER - - // 4b (C++98 and later) - non-explicit converting copy-construct from optional - template< typename U -#if optional_CPP11_OR_GREATER - optional_REQUIRES_T( - std::is_constructible::value - && !std::is_constructible & >::value - && !std::is_constructible && >::value - && !std::is_constructible const & >::value - && !std::is_constructible const && >::value - && !std::is_convertible< optional & , T>::value - && !std::is_convertible< optional && , T>::value - && !std::is_convertible< optional const & , T>::value - && !std::is_convertible< optional const &&, T>::value - && std::is_convertible< U const & , T>::value /*=> non-explicit */ - ) -#endif // optional_CPP11_OR_GREATER - > - // NOLINTNEXTLINE( google-explicit-constructor, hicpp-explicit-conversions ) - /*non-explicit*/ optional( optional const & other ) - : has_value_( other.has_value() ) - { - if ( other.has_value() ) - { - contained.construct_value( other.contained.value() ); - } - } - -#if optional_CPP11_OR_GREATER - - // 5a (C++11) - explicit converting move-construct from optional - template< typename U - optional_REQUIRES_T( - std::is_constructible::value - && !std::is_constructible & >::value - && !std::is_constructible && >::value - && !std::is_constructible const & >::value - && !std::is_constructible const && >::value - && !std::is_convertible< optional & , T>::value - && !std::is_convertible< optional && , T>::value - && !std::is_convertible< optional const & , T>::value - && !std::is_convertible< optional const &&, T>::value - && !std::is_convertible< U &&, T>::value /*=> explicit */ - ) - > - explicit optional( optional && other - ) - : has_value_( other.has_value() ) - { - if ( other.has_value() ) - { - contained.construct_value( T{ std::move( other.contained.value() ) } ); - } - } - - // 5a (C++11) - non-explicit converting move-construct from optional - template< typename U - optional_REQUIRES_T( - std::is_constructible::value - && !std::is_constructible & >::value - && !std::is_constructible && >::value - && !std::is_constructible const & >::value - && !std::is_constructible const && >::value - && !std::is_convertible< optional & , T>::value - && !std::is_convertible< optional && , T>::value - && !std::is_convertible< optional const & , T>::value - && !std::is_convertible< optional const &&, T>::value - && std::is_convertible< U &&, T>::value /*=> non-explicit */ - ) - > - // NOLINTNEXTLINE( google-explicit-constructor, hicpp-explicit-conversions ) - /*non-explicit*/ optional( optional && other ) - : has_value_( other.has_value() ) - { - if ( other.has_value() ) - { - contained.construct_value( std::move( other.contained.value() ) ); - } - } - - // 6 (C++11) - in-place construct - template< typename... Args - optional_REQUIRES_T( - std::is_constructible::value - ) - > - optional_constexpr explicit optional( nonstd_lite_in_place_t(T), Args&&... args ) - : has_value_( true ) - , contained( T( std::forward(args)...) ) - {} - - // 7 (C++11) - in-place construct, initializer-list - template< typename U, typename... Args - optional_REQUIRES_T( - std::is_constructible&, Args&&...>::value - ) - > - optional_constexpr explicit optional( nonstd_lite_in_place_t(T), std::initializer_list il, Args&&... args ) - : has_value_( true ) - , contained( T( il, std::forward(args)...) ) - {} - - // 8a (C++11) - explicit move construct from value - template< typename U = T - optional_REQUIRES_T( - std::is_constructible::value - && !std::is_same::type, nonstd_lite_in_place_t(U)>::value - && !std::is_same::type, optional>::value - && !std::is_convertible::value /*=> explicit */ - ) - > - optional_constexpr explicit optional( U && value ) - : has_value_( true ) - , contained( nonstd_lite_in_place(T), std::forward( value ) ) - {} - - // 8b (C++11) - non-explicit move construct from value - template< typename U = T - optional_REQUIRES_T( - std::is_constructible::value - && !std::is_same::type, nonstd_lite_in_place_t(U)>::value - && !std::is_same::type, optional>::value - && std::is_convertible::value /*=> non-explicit */ - ) - > - // NOLINTNEXTLINE( google-explicit-constructor, hicpp-explicit-conversions ) - optional_constexpr /*non-explicit*/ optional( U && value ) - : has_value_( true ) - , contained( nonstd_lite_in_place(T), std::forward( value ) ) - {} - -#else // optional_CPP11_OR_GREATER - - // 8 (C++98) - optional( value_type const & value ) - : has_value_( true ) - , contained( value ) - {} - -#endif // optional_CPP11_OR_GREATER - - // x.x.3.2, destructor - - ~optional() - { - if ( has_value() ) - { - contained.destruct_value(); - } - } - - // x.x.3.3, assignment - - // 1 (C++98and later) - assign explicitly empty - optional & operator=( nullopt_t /*unused*/) optional_noexcept - { - reset(); - return *this; - } - - // 2 (C++98and later) - copy-assign from optional -#if optional_CPP11_OR_GREATER - // NOLINTNEXTLINE( cppcoreguidelines-c-copy-assignment-signature, misc-unconventional-assign-operator ) - optional_REQUIRES_R( - optional &, - true -// std::is_copy_constructible::value -// && std::is_copy_assignable::value - ) - operator=( optional const & other ) - noexcept( - std11::is_nothrow_move_assignable::value - && std11::is_nothrow_move_constructible::value - ) -#else - optional & operator=( optional const & other ) -#endif - { - if ( (has_value() == true ) && (other.has_value() == false) ) { reset(); } - else if ( (has_value() == false) && (other.has_value() == true ) ) { initialize( *other ); } - else if ( (has_value() == true ) && (other.has_value() == true ) ) { contained.value() = *other; } - return *this; - } - -#if optional_CPP11_OR_GREATER - - // 3 (C++11) - move-assign from optional - // NOLINTNEXTLINE( cppcoreguidelines-c-copy-assignment-signature, misc-unconventional-assign-operator ) - optional_REQUIRES_R( - optional &, - true -// std11::is_move_constructible::value -// && std::is_move_assignable::value - ) - operator=( optional && other ) noexcept - { - if ( (has_value() == true ) && (other.has_value() == false) ) { reset(); } - else if ( (has_value() == false) && (other.has_value() == true ) ) { initialize( std::move( *other ) ); } - else if ( (has_value() == true ) && (other.has_value() == true ) ) { contained.value() = std::move( *other ); } - return *this; - } - - // 4 (C++11) - move-assign from value - template< typename U = T > - // NOLINTNEXTLINE( cppcoreguidelines-c-copy-assignment-signature, misc-unconventional-assign-operator ) - optional_REQUIRES_R( - optional &, - std::is_constructible::value - && std11::is_assignable::value - && !std::is_same::type, nonstd_lite_in_place_t(U)>::value - && !std::is_same::type, optional>::value - && !(std::is_scalar::value && std::is_same::type>::value) - ) - operator=( U && value ) - { - if ( has_value() ) - { - contained.value() = std::forward( value ); - } - else - { - initialize( T( std::forward( value ) ) ); - } - return *this; - } - -#else // optional_CPP11_OR_GREATER - - // 4 (C++98) - copy-assign from value - template< typename U /*= T*/ > - optional & operator=( U const & value ) - { - if ( has_value() ) contained.value() = value; - else initialize( T( value ) ); - return *this; - } - -#endif // optional_CPP11_OR_GREATER - - // 5 (C++98 and later) - converting copy-assign from optional - template< typename U > -#if optional_CPP11_OR_GREATER - // NOLINTNEXTLINE( cppcoreguidelines-c-copy-assignment-signature, misc-unconventional-assign-operator ) - optional_REQUIRES_R( - optional&, - std::is_constructible< T , U const &>::value - && std11::is_assignable< T&, U const &>::value - && !std::is_constructible & >::value - && !std::is_constructible && >::value - && !std::is_constructible const & >::value - && !std::is_constructible const && >::value - && !std::is_convertible< optional & , T>::value - && !std::is_convertible< optional && , T>::value - && !std::is_convertible< optional const & , T>::value - && !std::is_convertible< optional const &&, T>::value - && !std11::is_assignable< T&, optional & >::value - && !std11::is_assignable< T&, optional && >::value - && !std11::is_assignable< T&, optional const & >::value - && !std11::is_assignable< T&, optional const && >::value - ) -#else - optional& -#endif // optional_CPP11_OR_GREATER - operator=( optional const & other ) - { - return *this = optional( other ); - } - -#if optional_CPP11_OR_GREATER - - // 6 (C++11) - converting move-assign from optional - template< typename U > - // NOLINTNEXTLINE( cppcoreguidelines-c-copy-assignment-signature, misc-unconventional-assign-operator ) - optional_REQUIRES_R( - optional&, - std::is_constructible< T , U>::value - && std11::is_assignable< T&, U>::value - && !std::is_constructible & >::value - && !std::is_constructible && >::value - && !std::is_constructible const & >::value - && !std::is_constructible const && >::value - && !std::is_convertible< optional & , T>::value - && !std::is_convertible< optional && , T>::value - && !std::is_convertible< optional const & , T>::value - && !std::is_convertible< optional const &&, T>::value - && !std11::is_assignable< T&, optional & >::value - && !std11::is_assignable< T&, optional && >::value - && !std11::is_assignable< T&, optional const & >::value - && !std11::is_assignable< T&, optional const && >::value - ) - operator=( optional && other ) - { - return *this = optional( std::move( other ) ); - } - - // 7 (C++11) - emplace - template< typename... Args - optional_REQUIRES_T( - std::is_constructible::value - ) - > - T& emplace( Args&&... args ) - { - *this = nullopt; - contained.emplace( std::forward(args)... ); - has_value_ = true; - return contained.value(); - } - - // 8 (C++11) - emplace, initializer-list - template< typename U, typename... Args - optional_REQUIRES_T( - std::is_constructible&, Args&&...>::value - ) - > - T& emplace( std::initializer_list il, Args&&... args ) - { - *this = nullopt; - contained.emplace( il, std::forward(args)... ); - has_value_ = true; - return contained.value(); - } - -#endif // optional_CPP11_OR_GREATER - - // x.x.3.4, swap - - void swap( optional & other ) -#if optional_CPP11_OR_GREATER - noexcept( - std11::is_nothrow_move_constructible::value - && std17::is_nothrow_swappable::value - ) -#endif - { - using std::swap; - if ( (has_value() == true ) && (other.has_value() == true ) ) { swap( **this, *other ); } - else if ( (has_value() == false) && (other.has_value() == true ) ) { initialize( std11::move(*other) ); other.reset(); } - else if ( (has_value() == true ) && (other.has_value() == false) ) { other.initialize( std11::move(**this) ); reset(); } - } - - // x.x.3.5, observers - - optional_constexpr value_type const * operator ->() const - { - return assert( has_value() ), - contained.value_ptr(); - } - - optional_constexpr14 value_type * operator ->() - { - return assert( has_value() ), - contained.value_ptr(); - } - - optional_constexpr value_type const & operator *() const optional_ref_qual - { - return assert( has_value() ), - contained.value(); - } - - optional_constexpr14 value_type & operator *() optional_ref_qual - { - return assert( has_value() ), - contained.value(); - } - -#if optional_HAVE( REF_QUALIFIER ) - - optional_constexpr value_type const && operator *() const optional_refref_qual - { - return std::move( **this ); - } - - optional_constexpr14 value_type && operator *() optional_refref_qual - { - return std::move( **this ); - } - -#endif - -#if optional_CPP11_OR_GREATER - optional_constexpr explicit operator bool() const optional_noexcept - { - return has_value(); - } -#else - optional_constexpr operator safe_bool() const optional_noexcept - { - return has_value() ? &optional::this_type_does_not_support_comparisons : 0; - } -#endif - - // NOLINTNEXTLINE( modernize-use-nodiscard ) - /*optional_nodiscard*/ optional_constexpr bool has_value() const optional_noexcept - { - return has_value_; - } - - // NOLINTNEXTLINE( modernize-use-nodiscard ) - /*optional_nodiscard*/ optional_constexpr14 value_type const & value() const optional_ref_qual - { -#if optional_CONFIG_NO_EXCEPTIONS - assert( has_value() ); -#else - if ( ! has_value() ) - { - throw bad_optional_access(); - } -#endif - return contained.value(); - } - - optional_constexpr14 value_type & value() optional_ref_qual - { -#if optional_CONFIG_NO_EXCEPTIONS - assert( has_value() ); -#else - if ( ! has_value() ) - { - throw bad_optional_access(); - } -#endif - return contained.value(); - } - -#if optional_HAVE( REF_QUALIFIER ) && ( !optional_COMPILER_GNUC_VERSION || optional_COMPILER_GNUC_VERSION >= 490 ) - - // NOLINTNEXTLINE( modernize-use-nodiscard ) - /*optional_nodiscard*/ optional_constexpr value_type const && value() const optional_refref_qual - { - return std::move( value() ); - } - - optional_constexpr14 value_type && value() optional_refref_qual - { - return std::move( value() ); - } - -#endif - -#if optional_HAVE( REF_QUALIFIER ) - - template< typename U > - optional_constexpr value_type value_or( U && v ) const optional_ref_qual - { - return has_value() ? contained.value() : static_cast(std::forward( v ) ); - } - - template< typename U > - optional_constexpr14 value_type value_or( U && v ) optional_refref_qual - { -#if optional_COMPILER_CLANG_VERSION - return has_value() ? /*std::move*/( contained.value() ) : static_cast(std::forward( v ) ); -#else - return has_value() ? std::move( contained.value() ) : static_cast(std::forward( v ) ); -#endif - } - -#else - - template< typename U > - optional_constexpr value_type value_or( U const & v ) const - { - return has_value() ? contained.value() : static_cast( v ); - } - -#endif // optional_CPP11_OR_GREATER - - // x.x.3.6, modifiers - - void reset() optional_noexcept - { - if ( has_value() ) - { - contained.destruct_value(); - } - - has_value_ = false; - } - -private: - void this_type_does_not_support_comparisons() const {} - - template< typename V > - void initialize( V const & value ) - { - assert( ! has_value() ); - contained.construct_value( value ); - has_value_ = true; - } - -#if optional_CPP11_OR_GREATER - template< typename V > - void initialize( V && value ) - { - assert( ! has_value() ); - contained.construct_value( std::move( value ) ); - has_value_ = true; - } - -#endif - -private: - bool has_value_; - detail::storage_t< value_type > contained; - -}; - -// Relational operators - -template< typename T, typename U > -inline optional_constexpr bool operator==( optional const & x, optional const & y ) -{ - return bool(x) != bool(y) ? false : !bool( x ) ? true : *x == *y; -} - -template< typename T, typename U > -inline optional_constexpr bool operator!=( optional const & x, optional const & y ) -{ - return !(x == y); -} - -template< typename T, typename U > -inline optional_constexpr bool operator<( optional const & x, optional const & y ) -{ - return (!y) ? false : (!x) ? true : *x < *y; -} - -template< typename T, typename U > -inline optional_constexpr bool operator>( optional const & x, optional const & y ) -{ - return (y < x); -} - -template< typename T, typename U > -inline optional_constexpr bool operator<=( optional const & x, optional const & y ) -{ - return !(y < x); -} - -template< typename T, typename U > -inline optional_constexpr bool operator>=( optional const & x, optional const & y ) -{ - return !(x < y); -} - -// Comparison with nullopt - -template< typename T > -inline optional_constexpr bool operator==( optional const & x, nullopt_t /*unused*/ ) optional_noexcept -{ - return (!x); -} - -template< typename T > -inline optional_constexpr bool operator==( nullopt_t /*unused*/, optional const & x ) optional_noexcept -{ - return (!x); -} - -template< typename T > -inline optional_constexpr bool operator!=( optional const & x, nullopt_t /*unused*/ ) optional_noexcept -{ - return bool(x); -} - -template< typename T > -inline optional_constexpr bool operator!=( nullopt_t /*unused*/, optional const & x ) optional_noexcept -{ - return bool(x); -} - -template< typename T > -inline optional_constexpr bool operator<( optional const & /*unused*/, nullopt_t /*unused*/ ) optional_noexcept -{ - return false; -} - -template< typename T > -inline optional_constexpr bool operator<( nullopt_t /*unused*/, optional const & x ) optional_noexcept -{ - return bool(x); -} - -template< typename T > -inline optional_constexpr bool operator<=( optional const & x, nullopt_t /*unused*/ ) optional_noexcept -{ - return (!x); -} - -template< typename T > -inline optional_constexpr bool operator<=( nullopt_t /*unused*/, optional const & /*unused*/ ) optional_noexcept -{ - return true; -} - -template< typename T > -inline optional_constexpr bool operator>( optional const & x, nullopt_t /*unused*/ ) optional_noexcept -{ - return bool(x); -} - -template< typename T > -inline optional_constexpr bool operator>( nullopt_t /*unused*/, optional const & /*unused*/ ) optional_noexcept -{ - return false; -} - -template< typename T > -inline optional_constexpr bool operator>=( optional const & /*unused*/, nullopt_t /*unused*/ ) optional_noexcept -{ - return true; -} - -template< typename T > -inline optional_constexpr bool operator>=( nullopt_t /*unused*/, optional const & x ) optional_noexcept -{ - return (!x); -} - -// Comparison with T - -template< typename T, typename U > -inline optional_constexpr bool operator==( optional const & x, U const & v ) -{ - return bool(x) ? *x == v : false; -} - -template< typename T, typename U > -inline optional_constexpr bool operator==( U const & v, optional const & x ) -{ - return bool(x) ? v == *x : false; -} - -template< typename T, typename U > -inline optional_constexpr bool operator!=( optional const & x, U const & v ) -{ - return bool(x) ? *x != v : true; -} - -template< typename T, typename U > -inline optional_constexpr bool operator!=( U const & v, optional const & x ) -{ - return bool(x) ? v != *x : true; -} - -template< typename T, typename U > -inline optional_constexpr bool operator<( optional const & x, U const & v ) -{ - return bool(x) ? *x < v : true; -} - -template< typename T, typename U > -inline optional_constexpr bool operator<( U const & v, optional const & x ) -{ - return bool(x) ? v < *x : false; -} - -template< typename T, typename U > -inline optional_constexpr bool operator<=( optional const & x, U const & v ) -{ - return bool(x) ? *x <= v : true; -} - -template< typename T, typename U > -inline optional_constexpr bool operator<=( U const & v, optional const & x ) -{ - return bool(x) ? v <= *x : false; -} - -template< typename T, typename U > -inline optional_constexpr bool operator>( optional const & x, U const & v ) -{ - return bool(x) ? *x > v : false; -} - -template< typename T, typename U > -inline optional_constexpr bool operator>( U const & v, optional const & x ) -{ - return bool(x) ? v > *x : true; -} - -template< typename T, typename U > -inline optional_constexpr bool operator>=( optional const & x, U const & v ) -{ - return bool(x) ? *x >= v : false; -} - -template< typename T, typename U > -inline optional_constexpr bool operator>=( U const & v, optional const & x ) -{ - return bool(x) ? v >= *x : true; -} - -// Specialized algorithms - -template< typename T -#if optional_CPP11_OR_GREATER - optional_REQUIRES_T( - std11::is_move_constructible::value - && std17::is_swappable::value ) -#endif -> -void swap( optional & x, optional & y ) -#if optional_CPP11_OR_GREATER - noexcept( noexcept( x.swap(y) ) ) -#endif -{ - x.swap( y ); -} - -#if optional_CPP11_OR_GREATER - -template< typename T > -optional_constexpr optional< typename std::decay::type > make_optional( T && value ) -{ - return optional< typename std::decay::type >( std::forward( value ) ); -} - -template< typename T, typename...Args > -optional_constexpr optional make_optional( Args&&... args ) -{ - return optional( nonstd_lite_in_place(T), std::forward(args)...); -} - -template< typename T, typename U, typename... Args > -optional_constexpr optional make_optional( std::initializer_list il, Args&&... args ) -{ - return optional( nonstd_lite_in_place(T), il, std::forward(args)...); -} - -#else - -template< typename T > -optional make_optional( T const & value ) -{ - return optional( value ); -} - -#endif // optional_CPP11_OR_GREATER - -} // namespace optional_lite - -using optional_lite::optional; -using optional_lite::nullopt_t; -using optional_lite::nullopt; - -#if ! optional_CONFIG_NO_EXCEPTIONS -using optional_lite::bad_optional_access; -#endif - -using optional_lite::make_optional; - -} // namespace nonstd - -#if optional_CPP11_OR_GREATER - -// specialize the std::hash algorithm: - -namespace std { - -template< class T > -struct hash< nonstd::optional > -{ -public: - std::size_t operator()( nonstd::optional const & v ) const optional_noexcept - { - return bool( v ) ? std::hash{}( *v ) : 0; - } -}; - -} //namespace std - -#endif // optional_CPP11_OR_GREATER - -#if defined(__clang__) -# pragma clang diagnostic pop -#elif defined(__GNUC__) -# pragma GCC diagnostic pop -#elif defined(_MSC_VER ) -# pragma warning( pop ) -#endif - -#endif // optional_USES_STD_OPTIONAL - -#endif // NONSTD_OPTIONAL_LITE_HPP diff --git a/include/icsneo/third-party/optional-lite/project/CodeBlocks/optional-lite.cbp b/include/icsneo/third-party/optional-lite/project/CodeBlocks/optional-lite.cbp deleted file mode 100644 index 3e81478..0000000 --- a/include/icsneo/third-party/optional-lite/project/CodeBlocks/optional-lite.cbp +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - diff --git a/include/icsneo/third-party/optional-lite/project/CodeBlocks/optional-lite.workspace b/include/icsneo/third-party/optional-lite/project/CodeBlocks/optional-lite.workspace deleted file mode 100644 index d5f5c48..0000000 --- a/include/icsneo/third-party/optional-lite/project/CodeBlocks/optional-lite.workspace +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/include/icsneo/third-party/optional-lite/script/create-cov-rpt.py b/include/icsneo/third-party/optional-lite/script/create-cov-rpt.py deleted file mode 100644 index 88cbabb..0000000 --- a/include/icsneo/third-party/optional-lite/script/create-cov-rpt.py +++ /dev/null @@ -1,220 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2019-2019 by Martin Moene -##!/usr/bin/env python -# -# Copyright 2019-2019 by Martin Moene -# -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -# -# script/create-cov-rpt.py, Python 3.4 and later -# - -import argparse -import os -import re -import sys -import subprocess - -# Configuration: - -cfg_github_project = 'optional-lite' -cfg_github_user = 'martinmoene' -cfg_prj_folder_level = 3 - -tpl_coverage_cmd = 'opencppcoverage --no_aggregate_by_file --sources {src} -- {exe}' - -# End configuration. - -def project_folder( f, args ): - """Project root""" - if args.prj_folder: - return args.prj_folder - return os.path.normpath( os.path.join( os.path.dirname( os.path.abspath(f) ), '../' * args.prj_folder_level ) ) - -def executable_folder( f ): - """Folder where the xecutable is""" - return os.path.dirname( os.path.abspath(f) ) - -def executable_name( f ): - """Folder where the executable is""" - return os.path.basename( f ) - -def createCoverageReport( f, args ): - print( "Creating coverage report for project '{usr}/{prj}', '{file}':". - format( usr=args.user, prj=args.project, file=f ) ) - cmd = tpl_coverage_cmd.format( folder=executable_folder(f), src=project_folder(f, args), exe=executable_name(f) ) - if args.verbose: - print( "> {}".format(cmd) ) - if not args.dry_run: - os.chdir( executable_folder(f) ) - subprocess.call( cmd, shell=False ) - os.chdir( project_folder(f, args) ) - -def createCoverageReports( args ): - for f in args.executable: - createCoverageReport( f, args ) - -def createCoverageReportFromCommandLine(): - """Collect arguments from the commandline and create coverage report.""" - parser = argparse.ArgumentParser( - description='Create coverage report.', - epilog="""""", - formatter_class=argparse.ArgumentDefaultsHelpFormatter) - - parser.add_argument( - 'executable', - metavar='executable', - type=str, - nargs=1, - help='executable to report on') - - parser.add_argument( - '-n', '--dry-run', - action='store_true', - help='do not execute conan commands') - - parser.add_argument( - '-v', '--verbose', - action='count', - default=0, - help='level of progress reporting') - - parser.add_argument( - '--user', - metavar='u', - type=str, - default=cfg_github_user, - help='github user name') - - parser.add_argument( - '--project', - metavar='p', - type=str, - default=cfg_github_project, - help='github project name') - - parser.add_argument( - '--prj-folder', - metavar='f', - type=str, - default=None, - help='project root folder') - - parser.add_argument( - '--prj-folder-level', - metavar='n', - type=int, - default=cfg_prj_folder_level, - help='project root folder level from executable') - - createCoverageReports( parser.parse_args() ) - -if __name__ == '__main__': - createCoverageReportFromCommandLine() - -# end of file - -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -# -# script/create-cov-rpt.py, Python 3.4 and later -# - -import argparse -import os -import re -import sys -import subprocess - -# Configuration: - -cfg_github_project = 'expected-lite' -cfg_github_user = 'martinmoene' - -tpl_coverage_cmd = 'opencppcoverage --no_aggregate_by_file --sources {src} -- {exe}' - -# End configuration. - -def project_folder( f, args ): - """Project root""" - if args.prj_folder: - return args.prj_folder - return os.path.normpath( os.path.join( os.path.dirname( os.path.abspath(f) ), '../../..') ) - -def executable_folder( f ): - """Folder where the xecutable is""" - return os.path.dirname( os.path.abspath(f) ) - -def executable_name( f ): - """Folder where the executable is""" - return os.path.basename( f ) - -def createCoverageReport( f, args ): - print( "Creating coverage report for project '{usr}/{prj}', '{file}':". - format( usr=args.user, prj=args.project, file=f ) ) - cmd = tpl_coverage_cmd.format( folder=executable_folder(f), src=project_folder(f, args), exe=executable_name(f) ) - if args.verbose: - print( "> {}".format(cmd) ) - if not args.dry_run: - os.chdir( executable_folder(f) ) - subprocess.call( cmd, shell=False ) - os.chdir( project_folder(f, args) ) - -def createCoverageReports( args ): - for f in args.executable: - createCoverageReport( f, args ) - -def createCoverageReportFromCommandLine(): - """Collect arguments from the commandline and create coverage report.""" - parser = argparse.ArgumentParser( - description='Create coverage report.', - epilog="""""", - formatter_class=argparse.ArgumentDefaultsHelpFormatter) - - parser.add_argument( - 'executable', - metavar='executable', - type=str, - nargs=1, - help='executable to report on') - - parser.add_argument( - '-n', '--dry-run', - action='store_true', - help='do not execute conan commands') - - parser.add_argument( - '-v', '--verbose', - action='count', - default=0, - help='level of progress reporting') - - parser.add_argument( - '--user', - metavar='u', - type=str, - default=cfg_github_user, - help='github user name') - - parser.add_argument( - '--project', - metavar='p', - type=str, - default=cfg_github_project, - help='github project name') - - parser.add_argument( - '--prj-folder', - metavar='f', - type=str, - default=None, - help='project root folder') - - createCoverageReports( parser.parse_args() ) - -if __name__ == '__main__': - createCoverageReportFromCommandLine() - -# end of file diff --git a/include/icsneo/third-party/optional-lite/script/create-vcpkg.py b/include/icsneo/third-party/optional-lite/script/create-vcpkg.py deleted file mode 100644 index 9a5e65c..0000000 --- a/include/icsneo/third-party/optional-lite/script/create-vcpkg.py +++ /dev/null @@ -1,223 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2019-2019 by Martin Moene -# -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -# -# script/upload-conan.py, Python 3.4 and later -# - -import argparse -import os -import re -import sys -import subprocess - -# Configuration: - -cfg_github_project = 'optional-lite' -cfg_github_user = 'martinmoene' -cfg_description = '(unused)' - -cfg_cmakelists = 'CMakeLists.txt' -cfg_readme = 'Readme.md' -cfg_license = 'LICENSE.txt' -cfg_ref_prefix = 'v' - -cfg_sha512 = 'dadeda' -cfg_vcpkg_description = '(no description found)' -cfg_vcpkg_root = os.environ['VCPKG_ROOT'] - -cfg_cmake_optpfx = "OPTIONAL_LITE" - -# End configuration. - -# vcpkg control and port templates: - -tpl_path_vcpkg_control = '{vcpkg}/ports/{prj}/CONTROL' -tpl_path_vcpkg_portfile = '{vcpkg}/ports/{prj}/portfile.cmake' - -tpl_vcpkg_control =\ -"""Source: {prj} -Version: {ver} -Description: {desc}""" - -tpl_vcpkg_portfile =\ -"""include(vcpkg_common_functions) - -vcpkg_from_github( - OUT_SOURCE_PATH SOURCE_PATH - REPO {usr}/{prj} - REF {ref} - SHA512 {sha} -) - -vcpkg_configure_cmake( - SOURCE_PATH ${{SOURCE_PATH}} - PREFER_NINJA - OPTIONS - -D{optpfx}_OPT_BUILD_TESTS=OFF - -D{optpfx}_OPT_BUILD_EXAMPLES=OFF -) - -vcpkg_install_cmake() - -vcpkg_fixup_cmake_targets( - CONFIG_PATH lib/cmake/${{PORT}} -) - -file(REMOVE_RECURSE - ${{CURRENT_PACKAGES_DIR}}/debug - ${{CURRENT_PACKAGES_DIR}}/lib -) - -file(INSTALL - ${{SOURCE_PATH}}/{lic} DESTINATION ${{CURRENT_PACKAGES_DIR}}/share/${{PORT}} RENAME copyright -)""" - -tpl_vcpkg_note_sha =\ -""" -Next actions: -- Obtain package SHA: 'vcpkg install {prj}', copy SHA mentioned in 'Actual hash: [...]' -- Add SHA to package: 'script\create-vcpkg --sha={sha}' -- Install package : 'vcpkg install {prj}'""" - -tpl_vcpkg_note_install =\ -""" -Next actions: -- Install package: 'vcpkg install {prj}'""" - -# End of vcpkg templates - -def versionFrom( filename ): - """Obtain version from CMakeLists.txt""" - with open( filename, 'r' ) as f: - content = f.read() - version = re.search(r'VERSION\s(\d+\.\d+\.\d+)', content).group(1) - return version - -def descriptionFrom( filename ): - """Obtain description from CMakeLists.txt""" - with open( filename, 'r' ) as f: - content = f.read() - description = re.search(r'DESCRIPTION\s"(.*)"', content).group(1) - return description if description else cfg_vcpkg_description - -def vcpkgRootFrom( path ): - return path if path else './vcpkg' - -def to_ref( version ): - """Add prefix to version/tag, like v1.2.3""" - return cfg_ref_prefix + version - -def control_path( args ): - """Create path like vcpks/ports/_project_/CONTROL""" - return tpl_path_vcpkg_control.format( vcpkg=args.vcpkg_root, prj=args.project ) - -def portfile_path( args ): - """Create path like vcpks/ports/_project_/portfile.cmake""" - return tpl_path_vcpkg_portfile.format( vcpkg=args.vcpkg_root, prj=args.project ) - -def createControl( args ): - """Create vcpkg CONTROL file""" - output = tpl_vcpkg_control.format( - prj=args.project, ver=args.version, desc=args.description ) - if args.verbose: - print( "Creating control file '{f}':".format( f=control_path( args ) ) ) - if args.verbose > 1: - print( output ) - os.makedirs( os.path.dirname( control_path( args ) ), exist_ok=True ) - with open( control_path( args ), 'w') as f: - print( output, file=f ) - -def createPortfile( args ): - """Create vcpkg portfile""" - output = tpl_vcpkg_portfile.format( - optpfx=cfg_cmake_optpfx, usr=args.user, prj=args.project, ref=to_ref(args.version), sha=args.sha, lic=cfg_license ) - if args.verbose: - print( "Creating portfile '{f}':".format( f=portfile_path( args ) ) ) - if args.verbose > 1: - print( output ) - os.makedirs( os.path.dirname( portfile_path( args ) ), exist_ok=True ) - with open( portfile_path( args ), 'w') as f: - print( output, file=f ) - -def printNotes( args ): - if args.sha == cfg_sha512: - print( tpl_vcpkg_note_sha. - format( prj=args.project, sha='...' ) ) - else: - print( tpl_vcpkg_note_install. - format( prj=args.project ) ) - -def createVcpkg( args ): - print( "Creating vcpkg for '{usr}/{prj}', version '{ver}' in folder '{vcpkg}':". - format( usr=args.user, prj=args.project, ver=args.version, vcpkg=args.vcpkg_root, ) ) - createControl( args ) - createPortfile( args ) - printNotes( args ) - -def createVcpkgFromCommandLine(): - """Collect arguments from the commandline and create vcpkg.""" - - parser = argparse.ArgumentParser( - description='Create microsoft vcpkg.', - epilog="""""", - formatter_class=argparse.ArgumentDefaultsHelpFormatter) - - parser.add_argument( - '-v', '--verbose', - action='count', - default=0, - help='level of progress reporting') - - parser.add_argument( - '--user', - metavar='u', - type=str, - default=cfg_github_user, - help='github user name') - - parser.add_argument( - '--project', - metavar='p', - type=str, - default=cfg_github_project, - help='github project name') - - parser.add_argument( - '--description', - metavar='d', - type=str, -# default=cfg_description, - default=descriptionFrom( cfg_cmakelists ), - help='vcpkg description [from ' + cfg_cmakelists + ']') - - parser.add_argument( - '--version', - metavar='v', - type=str, - default=versionFrom( cfg_cmakelists ), - help='version number [from ' + cfg_cmakelists + ']') - - parser.add_argument( - '--sha', - metavar='s', - type=str, - default=cfg_sha512, - help='sha of package') - - parser.add_argument( - '--vcpkg-root', - metavar='r', - type=str, - default=vcpkgRootFrom( cfg_vcpkg_root ), - help='parent folder containing ports to write files to') - - createVcpkg( parser.parse_args() ) - -if __name__ == '__main__': - createVcpkgFromCommandLine() - -# end of file diff --git a/include/icsneo/third-party/optional-lite/script/update-version.py b/include/icsneo/third-party/optional-lite/script/update-version.py deleted file mode 100644 index 5ee2b01..0000000 --- a/include/icsneo/third-party/optional-lite/script/update-version.py +++ /dev/null @@ -1,129 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2017-2018 by Martin Moene -# -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -# -# script/update-version.py -# - -from __future__ import print_function - -import argparse -import os -import re -import sys - -# Configuration: - -table = ( - # path, substitute find, substitute format - ( 'CMakeLists.txt' - , r'\W{2,4}VERSION\W+([0-9]+\.[0-9]+\.[0-9]+)\W*$' - , ' VERSION {major}.{minor}.{patch}' ) - - , ( 'CMakeLists.txt' - , r'set\W+optional_lite_version\W+"([0-9]+\.[0-9]+\.[0-9]+)"\W+$' - , 'set( optional_lite_version "{major}.{minor}.{patch}" )\n' ) - -# , ( 'example/cmake-pkg/CMakeLists.txt' -# , r'set\W+optional_lite_version\W+"([0-9]+\.[0-9]+(\.[0-9]+)?)"\W+$' -# , 'set( optional_lite_version "{major}.{minor}" )\n' ) -# -# , ( 'script/install-xxx-pkg.py' -# , r'\optional_lite_version\s+=\s+"([0-9]+\.[0-9]+\.[0-9]+)"\s*$' -# , 'optional_lite_version = "{major}.{minor}.{patch}"\n' ) - - , ( 'conanfile.py' - , r'version\s+=\s+"([0-9]+\.[0-9]+\.[0-9]+)"\s*$' - , 'version = "{major}.{minor}.{patch}"' ) - - , ( 'include/nonstd/optional.hpp' - , r'\#define\s+optional_lite_MAJOR\s+[0-9]+\s*$' - , '#define optional_lite_MAJOR {major}' ) - - , ( 'include/nonstd/optional.hpp' - , r'\#define\s+optional_lite_MINOR\s+[0-9]+\s*$' - , '#define optional_lite_MINOR {minor}' ) - - , ( 'include/nonstd/optional.hpp' - , r'\#define\s+optional_lite_PATCH\s+[0-9]+\s*$' - , '#define optional_lite_PATCH {patch}\n' ) -) - -# End configuration. - -def readFile( in_path ): - """Return content of file at given path""" - with open( in_path, 'r' ) as in_file: - contents = in_file.read() - return contents - -def writeFile( out_path, contents ): - """Write contents to file at given path""" - with open( out_path, 'w' ) as out_file: - out_file.write( contents ) - -def replaceFile( output_path, input_path ): - # prevent race-condition (Python 3.3): - if sys.version_info >= (3, 3): - os.replace( output_path, input_path ) - else: - os.remove( input_path ) - os.rename( output_path, input_path ) - -def editFileToVersion( version, info, verbose ): - """Update version given file path, version regexp and new version format in info""" - major, minor, patch = version.split('.') - in_path, ver_re, ver_fmt = info - out_path = in_path + '.tmp' - new_text = ver_fmt.format( major=major, minor=minor, patch=patch ) - - if verbose: - print( "- {path} => '{text}':".format( path=in_path, text=new_text.strip('\n') ) ) - - writeFile( - out_path, - re.sub( - ver_re, new_text, readFile( in_path ) - , count=0, flags=re.MULTILINE - ) - ) - replaceFile( out_path, in_path ) - -def editFilesToVersion( version, table, verbose ): - if verbose: - print( "Editing files to version {v}:".format(v=version) ) - for item in table: - editFileToVersion( version, item, verbose ) - -def editFilesToVersionFromCommandLine(): - """Update version number given on command line in paths from configuration table.""" - - parser = argparse.ArgumentParser( - description='Update version number in files.', - epilog="""""", - formatter_class=argparse.RawTextHelpFormatter) - - parser.add_argument( - 'version', - metavar='version', - type=str, - nargs=1, - help='new version number, like 1.2.3') - - parser.add_argument( - '-v', '--verbose', - action='store_true', - help='report the name of the file being processed') - - args = parser.parse_args() - - editFilesToVersion( args.version[0], table, args.verbose ) - - -if __name__ == '__main__': - editFilesToVersionFromCommandLine() - -# end of file diff --git a/include/icsneo/third-party/optional-lite/script/upload-conan.py b/include/icsneo/third-party/optional-lite/script/upload-conan.py deleted file mode 100644 index 0031844..0000000 --- a/include/icsneo/third-party/optional-lite/script/upload-conan.py +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2019-2019 by Martin Moene -# -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -# -# script/upload-conan.py -# - -from __future__ import print_function - -import argparse -import os -import re -import sys -import subprocess - -# Configuration: - -def_conan_project = 'optional-lite' -def_conan_user = 'nonstd-lite' -def_conan_channel = 'stable' -cfg_conanfile = 'conanfile.py' - -tpl_conan_create = 'conan create . {usr}/{chn}' -tpl_conan_upload = 'conan upload --remote {usr} {prj}/{ver}@{usr}/{chn}' - -# End configuration. - -def versionFrom( filename ): - """Obtain version from conanfile.py""" - with open( filename ) as f: - content = f.read() - version = re.search(r'version\s=\s"(.*)"', content).group(1) - return version - -def createConanPackage( args ): - """Create conan package and upload it.""" - cmd = tpl_conan_create.format(usr=args.user, chn=args.channel) - if args.verbose: - print( "> {}".format(cmd) ) - if not args.dry_run: - subprocess.call( cmd, shell=False ) - -def uploadConanPackage( args ): - """Create conan package and upload it.""" - cmd = tpl_conan_upload.format(prj=args.project, usr=args.user, chn=args.channel, ver=args.version) - if args.verbose: - print( "> {}".format(cmd) ) - if not args.dry_run: - subprocess.call( cmd, shell=False ) - -def uploadToConan( args ): - """Create conan package and upload it.""" - print( "Updating project '{prj}' to user '{usr}', channel '{chn}', version {ver}:". - format(prj=args.project, usr=args.user, chn=args.channel, ver=args.version) ) - createConanPackage( args ) - uploadConanPackage( args ) - -def uploadToConanFromCommandLine(): - """Collect arguments from the commandline and create conan package and upload it.""" - - parser = argparse.ArgumentParser( - description='Create conan package and upload it to conan.', - epilog="""""", - formatter_class=argparse.ArgumentDefaultsHelpFormatter) - - parser.add_argument( - '-n', '--dry-run', - action='store_true', - help='do not execute conan commands') - - parser.add_argument( - '-v', '--verbose', - action='count', - default=0, - help='level of progress reporting') - - parser.add_argument( - '--project', - metavar='p', - type=str, - default=def_conan_project, - help='conan project') - - parser.add_argument( - '--user', - metavar='u', - type=str, - default=def_conan_user, - help='conan user') - - parser.add_argument( - '--channel', - metavar='c', - type=str, - default=def_conan_channel, - help='conan channel') - - parser.add_argument( - '--version', - metavar='v', - type=str, - default=versionFrom( cfg_conanfile ), - help='version number [from conanfile.py]') - - uploadToConan( parser.parse_args() ) - - -if __name__ == '__main__': - uploadToConanFromCommandLine() - -# end of file diff --git a/include/icsneo/third-party/optional-lite/test/BUCK b/include/icsneo/third-party/optional-lite/test/BUCK deleted file mode 100644 index d45ecc0..0000000 --- a/include/icsneo/third-party/optional-lite/test/BUCK +++ /dev/null @@ -1,16 +0,0 @@ -cxx_binary( - name = 'test', - header_namespace = '', - headers = glob([ - '*.h', - ]), - srcs = glob([ - '*.cpp', - ]), - compiler_flags = [ - '-std=c++11', - ], - deps = [ - '//:optional-lite', - ], -) diff --git a/include/icsneo/third-party/optional-lite/test/CMakeLists.txt b/include/icsneo/third-party/optional-lite/test/CMakeLists.txt deleted file mode 100644 index 2b65694..0000000 --- a/include/icsneo/third-party/optional-lite/test/CMakeLists.txt +++ /dev/null @@ -1,224 +0,0 @@ -# Copyright 2017-2018 by Martin Moene -# -# https://github.com/martinmoene/optional-lite -# -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -if( NOT DEFINED CMAKE_MINIMUM_REQUIRED_VERSION ) - cmake_minimum_required( VERSION 3.5 FATAL_ERROR ) -endif() - -project( test LANGUAGES CXX ) - -set( unit_name "optional" ) -set( PACKAGE ${unit_name}-lite ) -set( PROGRAM ${unit_name}-lite ) -set( SOURCES ${unit_name}-main.t.cpp ${unit_name}.t.cpp ) -set( TWEAKD "." ) - -message( STATUS "Subproject '${PROJECT_NAME}', programs '${PROGRAM}-*'") - -set( OPTIONS "" ) -set( DEFCMN "" ) - -set( HAS_STD_FLAGS FALSE ) -set( HAS_CPP98_FLAG FALSE ) -set( HAS_CPP11_FLAG FALSE ) -set( HAS_CPP14_FLAG FALSE ) -set( HAS_CPP17_FLAG FALSE ) -set( HAS_CPP20_FLAG FALSE ) -set( HAS_CPPLATEST_FLAG FALSE ) - -if( MSVC ) - message( STATUS "Matched: MSVC") - - set( HAS_STD_FLAGS TRUE ) - - set( OPTIONS -W3 -EHsc ) - set( DEFINITIONS -D_SCL_SECURE_NO_WARNINGS ${DEFCMN} ) - - if( NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.00 ) - set( HAS_CPP14_FLAG TRUE ) - set( HAS_CPPLATEST_FLAG TRUE ) - endif() - if( NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.11 ) - set( HAS_CPP17_FLAG TRUE ) - endif() - -elseif( CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang" ) - message( STATUS "CompilerId: '${CMAKE_CXX_COMPILER_ID}'") - - set( HAS_STD_FLAGS TRUE ) - set( HAS_CPP98_FLAG TRUE ) - - set( OPTIONS -Wall -Wextra -Wconversion -Wsign-conversion -Wno-missing-braces -fno-elide-constructors ) - set( DEFINITIONS ${DEFCMN} ) - - # GNU: available -std flags depends on version - if( CMAKE_CXX_COMPILER_ID MATCHES "GNU" ) - message( STATUS "Matched: GNU") - - if( NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8.0 ) - set( HAS_CPP11_FLAG TRUE ) - endif() - if( NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.2 ) - set( HAS_CPP14_FLAG TRUE ) - endif() - if( NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.1.0 ) - set( HAS_CPP17_FLAG TRUE ) - endif() - - # AppleClang: available -std flags depends on version - elseif( CMAKE_CXX_COMPILER_ID MATCHES "AppleClang" ) - message( STATUS "Matched: AppleClang") - - if( NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0.0 ) - set( HAS_CPP11_FLAG TRUE ) - endif() - if( NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.1.0 ) - set( HAS_CPP14_FLAG TRUE ) - endif() - if( NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.2.0 ) - set( HAS_CPP17_FLAG TRUE ) - endif() - - # Clang: available -std flags depends on version - elseif( CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) - message( STATUS "Matched: Clang") - - if( NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.3.0 ) - set( HAS_CPP11_FLAG TRUE ) - endif() - if( NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4.0 ) - set( HAS_CPP14_FLAG TRUE ) - endif() - if( NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0.0 ) - set( HAS_CPP17_FLAG TRUE ) - endif() - endif() - -elseif( CMAKE_CXX_COMPILER_ID MATCHES "Intel" ) - # as is - message( STATUS "Matched: Intel") -else() - # as is - message( STATUS "Matched: nothing") -endif() - -# enable MS C++ Core Guidelines checker if MSVC: - -function( enable_msvs_guideline_checker target ) - if( MSVC ) - set_target_properties( ${target} PROPERTIES - VS_GLOBAL_EnableCppCoreCheck true - VS_GLOBAL_CodeAnalysisRuleSet CppCoreCheckRules.ruleset - VS_GLOBAL_RunCodeAnalysis true ) - endif() -endfunction() - -# make target, compile for given standard if specified: - -function( make_target target std ) - message( STATUS "Make target: '${std}'" ) - - add_executable ( ${target} ${SOURCES} ) - target_include_directories( ${target} PRIVATE ${TWEAKD} ) - target_link_libraries ( ${target} PRIVATE ${PACKAGE} ) - target_compile_options ( ${target} PRIVATE ${OPTIONS} ) - target_compile_definitions( ${target} PRIVATE ${DEFINITIONS} ) - - if( std ) - if( MSVC ) - target_compile_options( ${target} PRIVATE -std:c++${std} ) - else() - # Necessary for clang 3.x: - target_compile_options( ${target} PRIVATE -std=c++${std} ) - # Ok for clang 4 and later: - # set( CMAKE_CXX_STANDARD ${std} ) - # set( CMAKE_CXX_STANDARD_REQUIRED ON ) - # set( CMAKE_CXX_EXTENSIONS OFF ) - endif() - endif() -endfunction() - -# add generic executable, unless -std flags can be specified: - -if( NOT HAS_STD_FLAGS ) - make_target( ${PROGRAM}.t "" ) -else() - # unconditionally add C++98 variant as MSVC has no option for it: - if( HAS_CPP98_FLAG ) - make_target( ${PROGRAM}-cpp98.t 98 ) - else() - make_target( ${PROGRAM}-cpp98.t "" ) - endif() - - if( HAS_CPP11_FLAG ) - make_target( ${PROGRAM}-cpp11.t 11 ) - endif() - - if( HAS_CPP14_FLAG ) - make_target( ${PROGRAM}-cpp14.t 14 ) - endif() - - if( HAS_CPP17_FLAG ) - set( std17 17 ) - if( CMAKE_CXX_COMPILER_ID MATCHES "AppleClang" ) - set( std17 1z ) - endif() - make_target( ${PROGRAM}-cpp17.t ${std17} ) - enable_msvs_guideline_checker( ${PROGRAM}-cpp17.t ) - endif() - - if( HAS_CPPLATEST_FLAG ) - make_target( ${PROGRAM}-cpplatest.t latest ) - endif() -endif() - -# with C++17, honour explicit request for std::optional or nonstd::optional: - -if( HAS_CPP17_FLAG ) - set( WHICH optional_OPTIONAL_DEFAULT ) - - if( OPTIONAL_LITE_OPT_SELECT_STD ) - set( WHICH optional_OPTIONAL_STD ) - elseif( OPTIONAL_LITE_OPT_SELECT_NONSTD ) - set( WHICH optional_OPTIONAL_NONSTD ) - endif() - - target_compile_definitions( ${PROGRAM}-cpp17.t PRIVATE optional_CONFIG_SELECT_OPTIONAL=${WHICH} ) - - if( HAS_CPPLATEST_FLAG ) - target_compile_definitions( ${PROGRAM}-cpplatest.t PRIVATE optional_CONFIG_SELECT_OPTIONAL=${WHICH} ) - endif() -endif() - -# configure unit tests via CTest: - -enable_testing() - -if( HAS_STD_FLAGS ) - # unconditionally add C++98 variant for MSVC: - add_test( NAME test-cpp98 COMMAND ${PROGRAM}-cpp98.t ) - - if( HAS_CPP11_FLAG ) - add_test( NAME test-cpp11 COMMAND ${PROGRAM}-cpp11.t ) - endif() - if( HAS_CPP14_FLAG ) - add_test( NAME test-cpp14 COMMAND ${PROGRAM}-cpp14.t ) - endif() - if( HAS_CPP17_FLAG ) - add_test( NAME test-cpp17 COMMAND ${PROGRAM}-cpp17.t ) - endif() - if( HAS_CPPLATEST_FLAG ) - add_test( NAME test-cpplatest COMMAND ${PROGRAM}-cpplatest.t ) - endif() -else() - add_test( NAME test COMMAND ${PROGRAM}.t --pass ) - add_test( NAME list_version COMMAND ${PROGRAM}.t --version ) - add_test( NAME list_tags COMMAND ${PROGRAM}.t --list-tags ) - add_test( NAME list_tests COMMAND ${PROGRAM}.t --list-tests ) -endif() - -# end of file diff --git a/include/icsneo/third-party/optional-lite/test/Makefile b/include/icsneo/third-party/optional-lite/test/Makefile deleted file mode 100644 index 5ff84d1..0000000 --- a/include/icsneo/third-party/optional-lite/test/Makefile +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright 2014 by Martin Moene -# -# Distributed under the Boost Software License, Version 1.0. (See accompanying -# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -# -# optional lite is inspired on std::optional by Fernando Cacciola and -# Andrzej Krzemienski and on expected lite by Martin Moene. - -# Usage: gmake [STD=c++03] - -PROGRAM = optional-main.t -SOURCES = $(wildcard *.cpp) -OBJECTS = $(SOURCES:.cpp=.o) - -ifdef STD -STD_OPTION = -std=$(STD) -endif - -CXX = g++ -CXXFLAGS = $(STD_OPTION) -I../include -Wall # -Wextra - -all: $(PROGRAM) - -$(PROGRAM): $(OBJECTS) - $(CXX) -o $@ $^ - -test: $(PROGRAM) - ./$(PROGRAM) - -test-all: $(PROGRAM) - ./$(PROGRAM) @ - -list: test - ./$(PROGRAM) -l - -clean: - $(RM) $(OBJECTS) - $(RM) $(PROGRAM) - diff --git a/include/icsneo/third-party/optional-lite/test/lest_cpp03.hpp b/include/icsneo/third-party/optional-lite/test/lest_cpp03.hpp deleted file mode 100644 index a773c1d..0000000 --- a/include/icsneo/third-party/optional-lite/test/lest_cpp03.hpp +++ /dev/null @@ -1,1531 +0,0 @@ -// Copyright 2013-2018 by Martin Moene -// -// lest is based on ideas by Kevlin Henney, see video at -// http://skillsmatter.com/podcast/agile-testing/kevlin-henney-rethinking-unit-testing-in-c-plus-plus -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -#ifndef LEST_LEST_HPP_INCLUDED -#define LEST_LEST_HPP_INCLUDED - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#define lest_MAJOR 1 -#define lest_MINOR 35 -#define lest_PATCH 1 - -#define lest_VERSION lest_STRINGIFY(lest_MAJOR) "." lest_STRINGIFY(lest_MINOR) "." lest_STRINGIFY(lest_PATCH) - -#ifndef lest_FEATURE_COLOURISE -# define lest_FEATURE_COLOURISE 0 -#endif - -#ifndef lest_FEATURE_LITERAL_SUFFIX -# define lest_FEATURE_LITERAL_SUFFIX 0 -#endif - -#ifndef lest_FEATURE_REGEX_SEARCH -# define lest_FEATURE_REGEX_SEARCH 0 -#endif - -#ifndef lest_FEATURE_TIME -# define lest_FEATURE_TIME 1 -#endif - -#ifndef lest_FEATURE_TIME_PRECISION -#define lest_FEATURE_TIME_PRECISION 0 -#endif - -#ifdef _WIN32 -# define lest_PLATFORM_IS_WINDOWS 1 -#else -# define lest_PLATFORM_IS_WINDOWS 0 -#endif - -#if lest_FEATURE_REGEX_SEARCH -# include -#endif - -#if lest_FEATURE_TIME -# if lest_PLATFORM_IS_WINDOWS -# include -# include -# else -# include -# include -# endif -#endif - -// Compiler warning suppression: - -#if defined (__clang__) -# pragma clang diagnostic ignored "-Waggregate-return" -# pragma clang diagnostic ignored "-Woverloaded-shift-op-parentheses" -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wdate-time" -#elif defined (__GNUC__) -# pragma GCC diagnostic ignored "-Waggregate-return" -# pragma GCC diagnostic push -#endif - -// Suppress shadow and unused-value warning for sections: - -#if defined (__clang__) -# define lest_SUPPRESS_WSHADOW _Pragma( "clang diagnostic push" ) \ - _Pragma( "clang diagnostic ignored \"-Wshadow\"" ) -# define lest_SUPPRESS_WUNUSED _Pragma( "clang diagnostic push" ) \ - _Pragma( "clang diagnostic ignored \"-Wunused-value\"" ) -# define lest_RESTORE_WARNINGS _Pragma( "clang diagnostic pop" ) - -#elif defined (__GNUC__) -# define lest_SUPPRESS_WSHADOW _Pragma( "GCC diagnostic push" ) \ - _Pragma( "GCC diagnostic ignored \"-Wshadow\"" ) -# define lest_SUPPRESS_WUNUSED _Pragma( "GCC diagnostic push" ) \ - _Pragma( "GCC diagnostic ignored \"-Wunused-value\"" ) -# define lest_RESTORE_WARNINGS _Pragma( "GCC diagnostic pop" ) -#else -# define lest_SUPPRESS_WSHADOW /*empty*/ -# define lest_SUPPRESS_WUNUSED /*empty*/ -# define lest_RESTORE_WARNINGS /*empty*/ -#endif - -// Stringify: - -#define lest_STRINGIFY( x ) lest_STRINGIFY_( x ) -#define lest_STRINGIFY_( x ) #x - -// Compiler versions: - -#if defined( _MSC_VER ) && !defined( __clang__ ) -# define lest_COMPILER_MSVC_VERSION ( _MSC_VER / 10 - 10 * ( 5 + ( _MSC_VER < 1900 ) ) ) -#else -# define lest_COMPILER_MSVC_VERSION 0 -#endif - -#define lest_COMPILER_VERSION( major, minor, patch ) ( 10 * ( 10 * major + minor ) + patch ) - -#if defined (__clang__) -# define lest_COMPILER_CLANG_VERSION lest_COMPILER_VERSION( __clang_major__, __clang_minor__, __clang_patchlevel__ ) -#else -# define lest_COMPILER_CLANG_VERSION 0 -#endif - -#if defined (__GNUC__) -# define lest_COMPILER_GNUC_VERSION lest_COMPILER_VERSION( __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__ ) -#else -# define lest_COMPILER_GNUC_VERSION 0 -#endif - -// C++ language version detection (C++20 is speculative): -// Note: VC14.0/1900 (VS2015) lacks too much from C++14. - -#ifndef lest_CPLUSPLUS -# if defined(_MSVC_LANG ) && !defined(__clang__) -# define lest_CPLUSPLUS (_MSC_VER == 1900 ? 201103L : _MSVC_LANG ) -# else -# define lest_CPLUSPLUS __cplusplus -# endif -#endif - -#define lest_CPP98_OR_GREATER ( lest_CPLUSPLUS >= 199711L ) -#define lest_CPP11_OR_GREATER ( lest_CPLUSPLUS >= 201103L || lest_COMPILER_MSVC_VERSION >= 120 ) -#define lest_CPP14_OR_GREATER ( lest_CPLUSPLUS >= 201402L ) -#define lest_CPP17_OR_GREATER ( lest_CPLUSPLUS >= 201703L ) -#define lest_CPP20_OR_GREATER ( lest_CPLUSPLUS >= 202000L ) - -#define lest_CPP11_100 (lest_CPP11_OR_GREATER || lest_COMPILER_MSVC_VERSION >= 100) - -#ifndef __has_cpp_attribute -# define __has_cpp_attribute(name) 0 -#endif - -// Indicate argument as possibly unused, if possible: - -#if __has_cpp_attribute(maybe_unused) && lest_CPP17_OR_GREATER -# define lest_MAYBE_UNUSED(ARG) [[maybe_unused]] ARG -#elif defined (__GNUC__) -# define lest_MAYBE_UNUSED(ARG) ARG __attribute((unused)) -#else -# define lest_MAYBE_UNUSED(ARG) ARG -#endif - -// Presence of language and library features: - -#define lest_HAVE(FEATURE) ( lest_HAVE_##FEATURE ) - -// Presence of C++11 language features: - -#define lest_HAVE_NOEXCEPT ( lest_CPP11_100 ) -#define lest_HAVE_NULLPTR ( lest_CPP11_100 ) - -// C++ feature usage: - -#if lest_HAVE( NULLPTR ) -# define lest_nullptr nullptr -#else -# define lest_nullptr NULL -#endif - -// Additional includes and tie: - -#if lest_CPP11_100 - -# include -# include -# include - -namespace lest -{ - using std::tie; -} - -#else - -# if !defined(__clang__) && defined(__GNUC__) -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Weffc++" -# endif - -namespace lest -{ - // tie: - - template< typename T1, typename T2 > - struct Tie - { - Tie( T1 & first_, T2 & second_) - : first( first_), second( second_) {} - - std::pair const & - operator=( std::pair const & rhs ) - { - first = rhs.first; - second = rhs.second; - return rhs; - } - - private: - void operator=( Tie const & ); - - T1 & first; - T2 & second; - }; - - template< typename T1, typename T2 > - inline Tie tie( T1 & first, T2 & second ) - { - return Tie( first, second ); - } -} - -# if !defined(__clang__) && defined(__GNUC__) -# pragma GCC diagnostic pop -# endif - -#endif // lest_CPP11_100 - -namespace lest -{ - using std::abs; - using std::min; - using std::strtol; - using std::rand; - using std::srand; -} - -#if ! defined( lest_NO_SHORT_MACRO_NAMES ) && ! defined( lest_NO_SHORT_ASSERTION_NAMES ) -# define SETUP lest_SETUP -# define SECTION lest_SECTION - -# define EXPECT lest_EXPECT -# define EXPECT_NOT lest_EXPECT_NOT -# define EXPECT_NO_THROW lest_EXPECT_NO_THROW -# define EXPECT_THROWS lest_EXPECT_THROWS -# define EXPECT_THROWS_AS lest_EXPECT_THROWS_AS - -# define SCENARIO lest_SCENARIO -# define GIVEN lest_GIVEN -# define WHEN lest_WHEN -# define THEN lest_THEN -# define AND_WHEN lest_AND_WHEN -# define AND_THEN lest_AND_THEN -#endif - -#define lest_SCENARIO( specification, sketch ) \ - lest_CASE( specification, lest::text("Scenario: ") + sketch ) -#define lest_GIVEN( context ) lest_SETUP( lest::text(" Given: ") + context ) -#define lest_WHEN( story ) lest_SECTION( lest::text(" When: ") + story ) -#define lest_THEN( story ) lest_SECTION( lest::text(" Then: ") + story ) -#define lest_AND_WHEN( story ) lest_SECTION( lest::text("And then: ") + story ) -#define lest_AND_THEN( story ) lest_SECTION( lest::text("And then: ") + story ) - -#define lest_CASE( specification, proposition ) \ - static void lest_FUNCTION( lest::env & ); \ - namespace { lest::add_test lest_REGISTRAR( specification, lest::test( proposition, lest_FUNCTION ) ); } \ - static void lest_FUNCTION( lest_MAYBE_UNUSED( lest::env & lest_env ) ) - -#define lest_ADD_TEST( specification, test ) \ - specification.push_back( test ) - -#define lest_SETUP( context ) \ - for ( int lest__section = 0, lest__count = 1; lest__section < lest__count; lest__count -= 0==lest__section++ ) \ - for ( lest::ctx lest__ctx_setup( lest_env, context ); lest__ctx_setup; ) - -#define lest_SECTION( proposition ) \ - lest_SUPPRESS_WSHADOW \ - static int lest_UNIQUE( id ) = 0; \ - if ( lest::guard( lest_UNIQUE( id ), lest__section, lest__count ) ) \ - for ( int lest__section = 0, lest__count = 1; lest__section < lest__count; lest__count -= 0==lest__section++ ) \ - for ( lest::ctx lest__ctx_section( lest_env, proposition ); lest__ctx_section; ) \ - lest_RESTORE_WARNINGS - -#define lest_EXPECT( expr ) \ - do { \ - try \ - { \ - if ( lest::result score = lest_DECOMPOSE( expr ) ) \ - throw lest::failure( lest_LOCATION, #expr, score.decomposition ); \ - else if ( lest_env.pass() ) \ - lest::report( lest_env.os, lest::passing( lest_LOCATION, #expr, score.decomposition, lest_env.zen() ), lest_env.context() ); \ - } \ - catch(...) \ - { \ - lest::inform( lest_LOCATION, #expr ); \ - } \ - } while ( lest::is_false() ) - -#define lest_EXPECT_NOT( expr ) \ - do { \ - try \ - { \ - if ( lest::result score = lest_DECOMPOSE( expr ) ) \ - { \ - if ( lest_env.pass() ) \ - lest::report( lest_env.os, lest::passing( lest_LOCATION, lest::not_expr( #expr ), lest::not_expr( score.decomposition ), lest_env.zen() ), lest_env.context() ); \ - } \ - else \ - throw lest::failure( lest_LOCATION, lest::not_expr( #expr ), lest::not_expr( score.decomposition ) ); \ - } \ - catch(...) \ - { \ - lest::inform( lest_LOCATION, lest::not_expr( #expr ) ); \ - } \ - } while ( lest::is_false() ) - -#define lest_EXPECT_NO_THROW( expr ) \ - do \ - { \ - try \ - { \ - lest_SUPPRESS_WUNUSED \ - expr; \ - lest_RESTORE_WARNINGS \ - } \ - catch (...) { lest::inform( lest_LOCATION, #expr ); } \ - if ( lest_env.pass() ) \ - lest::report( lest_env.os, lest::got_none( lest_LOCATION, #expr ), lest_env.context() ); \ - } while ( lest::is_false() ) - -#define lest_EXPECT_THROWS( expr ) \ - do \ - { \ - try \ - { \ - lest_SUPPRESS_WUNUSED \ - expr; \ - lest_RESTORE_WARNINGS \ - } \ - catch (...) \ - { \ - if ( lest_env.pass() ) \ - lest::report( lest_env.os, lest::got( lest_LOCATION, #expr ), lest_env.context() ); \ - break; \ - } \ - throw lest::expected( lest_LOCATION, #expr ); \ - } \ - while ( lest::is_false() ) - -#define lest_EXPECT_THROWS_AS( expr, excpt ) \ - do \ - { \ - try \ - { \ - lest_SUPPRESS_WUNUSED \ - expr; \ - lest_RESTORE_WARNINGS \ - } \ - catch ( excpt & ) \ - { \ - if ( lest_env.pass() ) \ - lest::report( lest_env.os, lest::got( lest_LOCATION, #expr, lest::of_type( #excpt ) ), lest_env.context() ); \ - break; \ - } \ - catch (...) {} \ - throw lest::expected( lest_LOCATION, #expr, lest::of_type( #excpt ) ); \ - } \ - while ( lest::is_false() ) - -#define lest_DECOMPOSE( expr ) ( lest::expression_decomposer() << expr ) - -#define lest_STRING( name ) lest_STRING2( name ) -#define lest_STRING2( name ) #name - -#define lest_UNIQUE( name ) lest_UNIQUE2( name, __LINE__ ) -#define lest_UNIQUE2( name, line ) lest_UNIQUE3( name, line ) -#define lest_UNIQUE3( name, line ) name ## line - -#define lest_LOCATION lest::location(__FILE__, __LINE__) - -#define lest_FUNCTION lest_UNIQUE(__lest_function__ ) -#define lest_REGISTRAR lest_UNIQUE(__lest_registrar__ ) - -#define lest_DIMENSION_OF( a ) ( sizeof(a) / sizeof(0[a]) ) - -namespace lest { - -const int exit_max_value = 255; - -typedef std::string text; -typedef std::vector texts; - -struct env; - -struct test -{ - text name; - void (* behaviour)( env & ); - - test( text name_, void (* behaviour_)( env & ) ) - : name( name_), behaviour( behaviour_) {} -}; - -typedef std::vector tests; -typedef tests test_specification; - -struct add_test -{ - add_test( tests & specification, test const & test_case ) - { - specification.push_back( test_case ); - } -}; - -struct result -{ - const bool passed; - const text decomposition; - - template< typename T > - result( T const & passed_, text decomposition_) - : passed( !!passed_), decomposition( decomposition_) {} - - operator bool() { return ! passed; } -}; - -struct location -{ - const text file; - const int line; - - location( text file_, int line_) - : file( file_), line( line_) {} -}; - -struct comment -{ - const text info; - - comment( text info_) : info( info_) {} - operator bool() { return ! info.empty(); } -}; - -struct message : std::runtime_error -{ - const text kind; - const location where; - const comment note; - -#if ! lest_CPP11_OR_GREATER - ~message() throw() {} -#endif - - message( text kind_, location where_, text expr_, text note_ = "" ) - : std::runtime_error( expr_), kind( kind_), where( where_), note( note_) {} -}; - -struct failure : message -{ - failure( location where_, text expr_, text decomposition_) - : message( "failed", where_, expr_ + " for " + decomposition_) {} -}; - -struct success : message -{ - success( text kind_, location where_, text expr_, text note_ = "" ) - : message( kind_, where_, expr_, note_) {} -}; - -struct passing : success -{ - passing( location where_, text expr_, text decomposition_, bool zen ) - : success( "passed", where_, expr_ + (zen ? "":" for " + decomposition_) ) {} -}; - -struct got_none : success -{ - got_none( location where_, text expr_) - : success( "passed: got no exception", where_, expr_) {} -}; - -struct got : success -{ - got( location where_, text expr_) - : success( "passed: got exception", where_, expr_) {} - - got( location where_, text expr_, text excpt_) - : success( "passed: got exception " + excpt_, where_, expr_) {} -}; - -struct expected : message -{ - expected( location where_, text expr_, text excpt_ = "" ) - : message( "failed: didn't get exception", where_, expr_, excpt_) {} -}; - -struct unexpected : message -{ - unexpected( location where_, text expr_, text note_ = "" ) - : message( "failed: got unexpected exception", where_, expr_, note_) {} -}; - -struct guard -{ - int & id; - int const & section; - - guard( int & id_, int const & section_, int & count ) - : id( id_ ), section( section_ ) - { - if ( section == 0 ) - id = count++ - 1; - } - operator bool() { return id == section; } -}; - -class approx -{ -public: - explicit approx ( double magnitude ) - : epsilon_ ( 100.0 * static_cast( std::numeric_limits::epsilon() ) ) - , scale_ ( 1.0 ) - , magnitude_( magnitude ) {} - - static approx custom() { return approx( 0 ); } - - approx operator()( double new_magnitude ) - { - approx appr( new_magnitude ); - appr.epsilon( epsilon_ ); - appr.scale ( scale_ ); - return appr; - } - - double magnitude() const { return magnitude_; } - - approx & epsilon( double epsilon ) { epsilon_ = epsilon; return *this; } - approx & scale ( double scale ) { scale_ = scale; return *this; } - - friend bool operator == ( double lhs, approx const & rhs ) - { - // Thanks to Richard Harris for his help refining this formula. - return lest::abs( lhs - rhs.magnitude_ ) < rhs.epsilon_ * ( rhs.scale_ + (lest::min)( lest::abs( lhs ), lest::abs( rhs.magnitude_ ) ) ); - } - - friend bool operator == ( approx const & lhs, double rhs ) { return operator==( rhs, lhs ); } - friend bool operator != ( double lhs, approx const & rhs ) { return !operator==( lhs, rhs ); } - friend bool operator != ( approx const & lhs, double rhs ) { return !operator==( rhs, lhs ); } - - friend bool operator <= ( double lhs, approx const & rhs ) { return lhs < rhs.magnitude_ || lhs == rhs; } - friend bool operator <= ( approx const & lhs, double rhs ) { return lhs.magnitude_ < rhs || lhs == rhs; } - friend bool operator >= ( double lhs, approx const & rhs ) { return lhs > rhs.magnitude_ || lhs == rhs; } - friend bool operator >= ( approx const & lhs, double rhs ) { return lhs.magnitude_ > rhs || lhs == rhs; } - -private: - double epsilon_; - double scale_; - double magnitude_; -}; - -inline bool is_false( ) { return false; } -inline bool is_true ( bool flag ) { return flag; } - -inline text not_expr( text message ) -{ - return "! ( " + message + " )"; -} - -inline text with_message( text message ) -{ - return "with message \"" + message + "\""; -} - -inline text of_type( text type ) -{ - return "of type " + type; -} - -inline void inform( location where, text expr ) -{ - try - { - throw; - } - catch( failure const & ) - { - throw; - } - catch( std::exception const & e ) - { - throw unexpected( where, expr, with_message( e.what() ) ); \ - } - catch(...) - { - throw unexpected( where, expr, "of unknown type" ); \ - } -} - -// Expression decomposition: - -inline bool unprintable( char c ) { return 0 <= c && c < ' '; } - -inline std::string to_hex_string(char c) -{ - std::ostringstream os; - os << "\\x" << std::hex << std::setw(2) << std::setfill('0') << static_cast( static_cast(c) ); - return os.str(); -} - -inline std::string transformed( char chr ) -{ - struct Tr { char chr; char const * str; } table[] = - { - {'\\', "\\\\" }, - {'\r', "\\r" }, {'\f', "\\f" }, - {'\n', "\\n" }, {'\t', "\\t" }, - }; - - for ( Tr * pos = table; pos != table + lest_DIMENSION_OF( table ); ++pos ) - { - if ( chr == pos->chr ) - return pos->str; - } - - return unprintable( chr ) ? to_hex_string( chr ) : std::string( 1, chr ); -} - -inline std::string make_tran_string( std::string const & txt ) -{ - std::ostringstream os; - for( std::string::const_iterator pos = txt.begin(); pos != txt.end(); ++pos ) - os << transformed( *pos ); - return os.str(); -} - -template< typename T > -inline std::string to_string( T const & value ); - -#if lest_CPP11_OR_GREATER || lest_COMPILER_MSVC_VERSION >= 100 -inline std::string to_string( std::nullptr_t const & ) { return "nullptr"; } -#endif -inline std::string to_string( std::string const & txt ) { return "\"" + make_tran_string( txt ) + "\""; } -inline std::string to_string( char const * const & txt ) { return "\"" + make_tran_string( txt ) + "\""; } -inline std::string to_string( char const & chr ) { return "'" + make_tran_string( std::string( 1, chr ) ) + "'"; } - -inline std::string to_string( signed char const & chr ) { return to_string( static_cast( chr ) ); } -inline std::string to_string( unsigned char const & chr ) { return to_string( static_cast( chr ) ); } - -inline std::ostream & operator<<( std::ostream & os, approx const & appr ) -{ - return os << appr.magnitude(); -} - -template< typename T > -inline std::string make_string( T const * ptr ) -{ - // Note showbase affects the behavior of /integer/ output; - std::ostringstream os; - os << std::internal << std::hex << std::showbase << std::setw( 2 + 2 * sizeof(T*) ) << std::setfill('0') << reinterpret_cast( ptr ); - return os.str(); -} - -template< typename C, typename R > -inline std::string make_string( R C::* ptr ) -{ - std::ostringstream os; - os << std::internal << std::hex << std::showbase << std::setw( 2 + 2 * sizeof(R C::* ) ) << std::setfill('0') << ptr; - return os.str(); -} - -template< typename T > -struct string_maker -{ - static std::string to_string( T const & value ) - { - std::ostringstream os; os << std::boolalpha << value; - return os.str(); - } -}; - -template< typename T > -struct string_maker< T* > -{ - static std::string to_string( T const * ptr ) - { - return ! ptr ? lest_STRING( lest_nullptr ) : make_string( ptr ); - } -}; - -template< typename C, typename R > -struct string_maker< R C::* > -{ - static std::string to_string( R C::* ptr ) - { - return ! ptr ? lest_STRING( lest_nullptr ) : make_string( ptr ); - } -}; - -template< typename T > -inline std::string to_string( T const & value ) -{ - return string_maker::to_string( value ); -} - -template< typename T1, typename T2 > -std::string to_string( std::pair const & pair ) -{ - std::ostringstream oss; - oss << "{ " << to_string( pair.first ) << ", " << to_string( pair.second ) << " }"; - return oss.str(); -} - -#if lest_CPP11_OR_GREATER - -template< typename TU, std::size_t N > -struct make_tuple_string -{ - static std::string make( TU const & tuple ) - { - std::ostringstream os; - os << to_string( std::get( tuple ) ) << ( N < std::tuple_size::value ? ", ": " "); - return make_tuple_string::make( tuple ) + os.str(); - } -}; - -template< typename TU > -struct make_tuple_string -{ - static std::string make( TU const & ) { return ""; } -}; - -template< typename ...TS > -auto to_string( std::tuple const & tuple ) -> std::string -{ - return "{ " + make_tuple_string, sizeof...(TS)>::make( tuple ) + "}"; -} - -#endif // lest_CPP11_OR_GREATER - -template< typename L, typename R > -std::string to_string( L const & lhs, std::string op, R const & rhs ) -{ - std::ostringstream os; os << to_string( lhs ) << " " << op << " " << to_string( rhs ); return os.str(); -} - -template< typename L > -struct expression_lhs -{ - L lhs; - - expression_lhs( L lhs_) : lhs( lhs_) {} - - operator result() { return result( !!lhs, to_string( lhs ) ); } - - template< typename R > result operator==( R const & rhs ) { return result( lhs == rhs, to_string( lhs, "==", rhs ) ); } - template< typename R > result operator!=( R const & rhs ) { return result( lhs != rhs, to_string( lhs, "!=", rhs ) ); } - template< typename R > result operator< ( R const & rhs ) { return result( lhs < rhs, to_string( lhs, "<" , rhs ) ); } - template< typename R > result operator<=( R const & rhs ) { return result( lhs <= rhs, to_string( lhs, "<=", rhs ) ); } - template< typename R > result operator> ( R const & rhs ) { return result( lhs > rhs, to_string( lhs, ">" , rhs ) ); } - template< typename R > result operator>=( R const & rhs ) { return result( lhs >= rhs, to_string( lhs, ">=", rhs ) ); } -}; - -struct expression_decomposer -{ - template< typename L > - expression_lhs operator<< ( L const & operand ) - { - return expression_lhs( operand ); - } -}; - -// Reporter: - -#if lest_FEATURE_COLOURISE - -inline text red ( text words ) { return "\033[1;31m" + words + "\033[0m"; } -inline text green( text words ) { return "\033[1;32m" + words + "\033[0m"; } -inline text gray ( text words ) { return "\033[1;30m" + words + "\033[0m"; } - -inline bool starts_with( text words, text with ) -{ - return 0 == words.find( with ); -} - -inline text replace( text words, text from, text to ) -{ - size_t pos = words.find( from ); - return pos == std::string::npos ? words : words.replace( pos, from.length(), to ); -} - -inline text colour( text words ) -{ - if ( starts_with( words, "failed" ) ) return replace( words, "failed", red ( "failed" ) ); - else if ( starts_with( words, "passed" ) ) return replace( words, "passed", green( "passed" ) ); - - return replace( words, "for", gray( "for" ) ); -} - -inline bool is_cout( std::ostream & os ) { return &os == &std::cout; } - -struct colourise -{ - const text words; - - colourise( text words ) - : words( words ) {} - - // only colourise for std::cout, not for a stringstream as used in tests: - - std::ostream & operator()( std::ostream & os ) const - { - return is_cout( os ) ? os << colour( words ) : os << words; - } -}; - -inline std::ostream & operator<<( std::ostream & os, colourise words ) { return words( os ); } -#else -inline text colourise( text words ) { return words; } -#endif - -inline text pluralise( text word,int n ) -{ - return n == 1 ? word : word + "s"; -} - -inline std::ostream & operator<<( std::ostream & os, comment note ) -{ - return os << (note ? " " + note.info : "" ); -} - -inline std::ostream & operator<<( std::ostream & os, location where ) -{ -#ifdef __GNUG__ - return os << where.file << ":" << where.line; -#else - return os << where.file << "(" << where.line << ")"; -#endif -} - -inline void report( std::ostream & os, message const & e, text test ) -{ - os << e.where << ": " << colourise( e.kind ) << e.note << ": " << test << ": " << colourise( e.what() ) << std::endl; -} - -// Test runner: - -#if lest_FEATURE_REGEX_SEARCH - inline bool search( text re, text line ) - { - return std::regex_search( line, std::regex( re ) ); - } -#else - inline bool case_insensitive_equal( char a, char b ) - { - return tolower( a ) == tolower( b ); - } - - inline bool search( text part, text line ) - { - return std::search( - line.begin(), line.end(), - part.begin(), part.end(), case_insensitive_equal ) != line.end(); - } -#endif - -inline bool match( texts whats, text line ) -{ - for ( texts::iterator what = whats.begin(); what != whats.end() ; ++what ) - { - if ( search( *what, line ) ) - return true; - } - return false; -} - -inline bool hidden( text name ) -{ -#if lest_FEATURE_REGEX_SEARCH - texts skipped; skipped.push_back( "\\[\\.\\]" ); skipped.push_back( "\\[hide\\]" ); -#else - texts skipped; skipped.push_back( "[." ); skipped.push_back( "[hide]" ); -#endif - return match( skipped, name ); -} - -inline bool none( texts args ) -{ - return args.size() == 0; -} - -inline bool select( text name, texts include ) -{ - if ( none( include ) ) - { - return ! hidden( name ); - } - - bool any = false; - for ( texts::reverse_iterator pos = include.rbegin(); pos != include.rend(); ++pos ) - { - text & part = *pos; - - if ( part == "@" || part == "*" ) - return true; - - if ( search( part, name ) ) - return true; - - if ( '!' == part[0] ) - { - any = true; - if ( search( part.substr(1), name ) ) - return false; - } - else - { - any = false; - } - } - return any && ! hidden( name ); -} - -inline int indefinite( int repeat ) { return repeat == -1; } - -#if lest_CPP11_OR_GREATER -typedef std::mt19937::result_type seed_t; -#else -typedef unsigned int seed_t; -#endif - -struct options -{ - options() - : help(false), abort(false), count(false), list(false), tags(false), time(false) - , pass(false), zen(false), lexical(false), random(false), verbose(false), version(false), repeat(1), seed(0) {} - - bool help; - bool abort; - bool count; - bool list; - bool tags; - bool time; - bool pass; - bool zen; - bool lexical; - bool random; - bool verbose; - bool version; - int repeat; - seed_t seed; -}; - -struct env -{ - std::ostream & os; - options opt; - text testing; - std::vector< text > ctx; - - env( std::ostream & out, options option ) - : os( out ), opt( option ), testing(), ctx() {} - - env & operator()( text test ) - { - clear(); testing = test; return *this; - } - - bool abort() { return opt.abort; } - bool pass() { return opt.pass; } - bool zen() { return opt.zen; } - - void clear() { ctx.clear(); } - void pop() { ctx.pop_back(); } - void push( text proposition ) { ctx.push_back( proposition ); } - - text context() { return testing + sections(); } - - text sections() - { - if ( ! opt.verbose ) - return ""; - - text msg; - for( size_t i = 0; i != ctx.size(); ++i ) - { - msg += "\n " + ctx[i]; - } - return msg; - } -}; - -struct ctx -{ - env & environment; - bool once; - - ctx( env & environment_, text proposition_ ) - : environment( environment_), once( true ) - { - environment.push( proposition_); - } - - ~ctx() - { -#if lest_CPP17_OR_GREATER - if ( std::uncaught_exceptions() == 0 ) -#else - if ( ! std::uncaught_exception() ) -#endif - { - environment.pop(); - } - } - - operator bool() { bool result = once; once = false; return result; } -}; - -struct action -{ - std::ostream & os; - - action( std::ostream & out ) : os( out ) {} - - operator int() { return 0; } - bool abort() { return false; } - action & operator()( test ) { return *this; } - -private: - action( action const & ); - void operator=( action const & ); -}; - -struct print : action -{ - print( std::ostream & out ) : action( out ) {} - - print & operator()( test testing ) - { - os << testing.name << "\n"; return *this; - } -}; - -inline texts tags( text name, texts result = texts() ) -{ - size_t none = std::string::npos; - size_t lb = name.find_first_of( "[" ); - size_t rb = name.find_first_of( "]" ); - - if ( lb == none || rb == none ) - return result; - - result.push_back( name.substr( lb, rb - lb + 1 ) ); - - return tags( name.substr( rb + 1 ), result ); -} - -struct ptags : action -{ - std::set result; - - ptags( std::ostream & out ) : action( out ), result() {} - - ptags & operator()( test testing ) - { - texts tags_( tags( testing.name ) ); - for ( texts::iterator pos = tags_.begin(); pos != tags_.end() ; ++pos ) - result.insert( *pos ); - - return *this; - } - - ~ptags() - { - std::copy( result.begin(), result.end(), std::ostream_iterator( os, "\n" ) ); - } -}; - -struct count : action -{ - int n; - - count( std::ostream & out ) : action( out ), n( 0 ) {} - - count & operator()( test ) { ++n; return *this; } - - ~count() - { - os << n << " selected " << pluralise("test", n) << "\n"; - } -}; - -#if lest_FEATURE_TIME - -#if lest_PLATFORM_IS_WINDOWS -# if ! lest_CPP11_OR_GREATER && ! lest_COMPILER_MSVC_VERSION - typedef unsigned long uint64_t; -# elif lest_COMPILER_MSVC_VERSION >= 60 && lest_COMPILER_MSVC_VERSION < 100 - typedef /*un*/signed __int64 uint64_t; -# else - using ::uint64_t; -# endif -#else -# if ! lest_CPP11_OR_GREATER - typedef unsigned long long uint64_t; -# endif -#endif - -#if lest_PLATFORM_IS_WINDOWS - inline uint64_t current_ticks() - { - static LARGE_INTEGER hz = {{ 0,0 }}, hzo = {{ 0,0 }}; - if ( ! hz.QuadPart ) - { - QueryPerformanceFrequency( &hz ); - QueryPerformanceCounter ( &hzo ); - } - LARGE_INTEGER t = {{ 0,0 }}; QueryPerformanceCounter( &t ); - - return uint64_t( ( ( t.QuadPart - hzo.QuadPart ) * 1000000 ) / hz.QuadPart ); - } -#else - inline uint64_t current_ticks() - { - timeval t; gettimeofday( &t, lest_nullptr ); - return static_cast( t.tv_sec ) * 1000000ull + static_cast( t.tv_usec ); - } -#endif - -struct timer -{ - const uint64_t start_ticks; - - timer() : start_ticks( current_ticks() ) {} - - double elapsed_seconds() const - { - return static_cast( current_ticks() - start_ticks ) / 1e6; - } -}; - -struct times : action -{ - env output; - int selected; - int failures; - - timer total; - - times( std::ostream & out, options option ) - : action( out ), output( out, option ), selected( 0 ), failures( 0 ), total() - { - os << std::setfill(' ') << std::fixed << std::setprecision( lest_FEATURE_TIME_PRECISION ); - } - - operator int() { return failures; } - - bool abort() { return output.abort() && failures > 0; } - - times & operator()( test testing ) - { - timer t; - - try - { - testing.behaviour( output( testing.name ) ); - } - catch( message const & ) - { - ++failures; - } - - os << std::setw(5) << ( 1000 * t.elapsed_seconds() ) << " ms: " << testing.name << "\n"; - - return *this; - } - - ~times() - { - os << "Elapsed time: " << std::setprecision(1) << total.elapsed_seconds() << " s\n"; - } -}; -#else -struct times : action { times( std::ostream & out, options ) : action( out ) {} }; -#endif - -struct confirm : action -{ - env output; - int selected; - int failures; - - confirm( std::ostream & out, options option ) - : action( out ), output( out, option ), selected( 0 ), failures( 0 ) {} - - operator int() { return failures; } - - bool abort() { return output.abort() && failures > 0; } - - confirm & operator()( test testing ) - { - try - { - ++selected; testing.behaviour( output( testing.name ) ); - } - catch( message const & e ) - { - ++failures; report( os, e, output.context() ); - } - return *this; - } - - ~confirm() - { - if ( failures > 0 ) - { - os << failures << " out of " << selected << " selected " << pluralise("test", selected) << " " << colourise( "failed.\n" ); - } - else if ( output.pass() ) - { - os << "All " << selected << " selected " << pluralise("test", selected) << " " << colourise( "passed.\n" ); - } - } -}; - -template< typename Action > -bool abort( Action & perform ) -{ - return perform.abort(); -} - -template< typename Action > -Action & for_test( tests specification, texts in, Action & perform, int n = 1 ) -{ - for ( int i = 0; indefinite( n ) || i < n; ++i ) - { - for ( tests::iterator pos = specification.begin(); pos != specification.end() ; ++pos ) - { - test & testing = *pos; - - if ( select( testing.name, in ) ) - if ( abort( perform( testing ) ) ) - return perform; - } - } - return perform; -} - -inline bool test_less( test const & a, test const & b ) { return a.name < b.name; } - -inline void sort( tests & specification ) -{ - std::sort( specification.begin(), specification.end(), test_less ); -} - -// Use struct to avoid VC6 error C2664 when using free function: - -struct rng { int operator()( int n ) { return lest::rand() % n; } }; - -inline void shuffle( tests & specification, options option ) -{ -#if lest_CPP11_OR_GREATER - std::shuffle( specification.begin(), specification.end(), std::mt19937( option.seed ) ); -#else - lest::srand( option.seed ); - - rng generator; - std::random_shuffle( specification.begin(), specification.end(), generator ); -#endif -} - -inline int stoi( text num ) -{ - return static_cast( lest::strtol( num.c_str(), lest_nullptr, 10 ) ); -} - -inline bool is_number( text arg ) -{ - const text digits = "0123456789"; - return text::npos != arg.find_first_of ( digits ) - && text::npos == arg.find_first_not_of( digits ); -} - -inline seed_t seed( text opt, text arg ) -{ - // std::time_t: implementation dependent - - if ( arg == "time" ) - return static_cast( time( lest_nullptr ) ); - - if ( is_number( arg ) ) - return static_cast( lest::stoi( arg ) ); - - throw std::runtime_error( "expecting 'time' or positive number with option '" + opt + "', got '" + arg + "' (try option --help)" ); -} - -inline int repeat( text opt, text arg ) -{ - const int num = lest::stoi( arg ); - - if ( indefinite( num ) || num >= 0 ) - return num; - - throw std::runtime_error( "expecting '-1' or positive number with option '" + opt + "', got '" + arg + "' (try option --help)" ); -} - -inline std::pair -split_option( text arg ) -{ - text::size_type pos = arg.rfind( '=' ); - - return pos == text::npos - ? std::make_pair( arg, text() ) - : std::make_pair( arg.substr( 0, pos ), arg.substr( pos + 1 ) ); -} - -inline std::pair -split_arguments( texts args ) -{ - options option; texts in; - - bool in_options = true; - - for ( texts::iterator pos = args.begin(); pos != args.end() ; ++pos ) - { - text opt, val, arg = *pos; - tie( opt, val ) = split_option( arg ); - - if ( in_options ) - { - if ( opt[0] != '-' ) { in_options = false; } - else if ( opt == "--" ) { in_options = false; continue; } - else if ( opt == "-h" || "--help" == opt ) { option.help = true; continue; } - else if ( opt == "-a" || "--abort" == opt ) { option.abort = true; continue; } - else if ( opt == "-c" || "--count" == opt ) { option.count = true; continue; } - else if ( opt == "-g" || "--list-tags" == opt ) { option.tags = true; continue; } - else if ( opt == "-l" || "--list-tests" == opt ) { option.list = true; continue; } - else if ( opt == "-t" || "--time" == opt ) { option.time = true; continue; } - else if ( opt == "-p" || "--pass" == opt ) { option.pass = true; continue; } - else if ( opt == "-z" || "--pass-zen" == opt ) { option.zen = true; continue; } - else if ( opt == "-v" || "--verbose" == opt ) { option.verbose = true; continue; } - else if ( "--version" == opt ) { option.version = true; continue; } - else if ( opt == "--order" && "declared" == val ) { /* by definition */ ; continue; } - else if ( opt == "--order" && "lexical" == val ) { option.lexical = true; continue; } - else if ( opt == "--order" && "random" == val ) { option.random = true; continue; } - else if ( opt == "--random-seed" ) { option.seed = seed ( "--random-seed", val ); continue; } - else if ( opt == "--repeat" ) { option.repeat = repeat( "--repeat" , val ); continue; } - else throw std::runtime_error( "unrecognised option '" + opt + "' (try option --help)" ); - } - in.push_back( arg ); - } - option.pass = option.pass || option.zen; - - return std::make_pair( option, in ); -} - -inline int usage( std::ostream & os ) -{ - os << - "\nUsage: test [options] [test-spec ...]\n" - "\n" - "Options:\n" - " -h, --help this help message\n" - " -a, --abort abort at first failure\n" - " -c, --count count selected tests\n" - " -g, --list-tags list tags of selected tests\n" - " -l, --list-tests list selected tests\n" - " -p, --pass also report passing tests\n" - " -z, --pass-zen ... without expansion\n" -#if lest_FEATURE_TIME - " -t, --time list duration of selected tests\n" -#endif - " -v, --verbose also report passing or failing sections\n" - " --order=declared use source code test order (default)\n" - " --order=lexical use lexical sort test order\n" - " --order=random use random test order\n" - " --random-seed=n use n for random generator seed\n" - " --random-seed=time use time for random generator seed\n" - " --repeat=n repeat selected tests n times (-1: indefinite)\n" - " --version report lest version and compiler used\n" - " -- end options\n" - "\n" - "Test specification:\n" - " \"@\", \"*\" all tests, unless excluded\n" - " empty all tests, unless tagged [hide] or [.optional-name]\n" -#if lest_FEATURE_REGEX_SEARCH - " \"re\" select tests that match regular expression\n" - " \"!re\" omit tests that match regular expression\n" -#else - " \"text\" select tests that contain text (case insensitive)\n" - " \"!text\" omit tests that contain text (case insensitive)\n" -#endif - ; - return 0; -} - -inline text compiler() -{ - std::ostringstream os; -#if defined (__clang__ ) - os << "clang " << __clang_version__; -#elif defined (__GNUC__ ) - os << "gcc " << __GNUC__ << "." << __GNUC_MINOR__ << "." << __GNUC_PATCHLEVEL__; -#elif defined ( _MSC_VER ) - os << "MSVC " << lest_COMPILER_MSVC_VERSION << " (" << _MSC_VER << ")"; -#else - os << "[compiler]"; -#endif - return os.str(); -} - -inline int version( std::ostream & os ) -{ - os << "lest version " << lest_VERSION << "\n" - << "Compiled with " << compiler() << " on " << __DATE__ << " at " << __TIME__ << ".\n" - << "For more information, see https://github.com/martinmoene/lest.\n"; - return 0; -} - -inline int run( tests specification, texts arguments, std::ostream & os = std::cout ) -{ - try - { - options option; texts in; - tie( option, in ) = split_arguments( arguments ); - - if ( option.lexical ) { sort( specification ); } - if ( option.random ) { shuffle( specification, option ); } - - if ( option.help ) { return usage ( os ); } - if ( option.version ) { return version( os ); } - if ( option.count ) { count count_( os ); return for_test( specification, in, count_ ); } - if ( option.list ) { print print_( os ); return for_test( specification, in, print_ ); } - if ( option.tags ) { ptags ptags_( os ); return for_test( specification, in, ptags_ ); } - if ( option.time ) { times times_( os, option ); return for_test( specification, in, times_ ); } - - { confirm confirm_( os, option ); return for_test( specification, in, confirm_, option.repeat ); } - } - catch ( std::exception const & e ) - { - os << "Error: " << e.what() << "\n"; - return 1; - } -} - -// VC6: make(first,last) replaces cont(first,last) - -template< typename C, typename T > -C make( T const * first, T const * const last ) -{ - C result; - for ( ; first != last; ++first ) - { - result.push_back( *first ); - } - return result; -} - -inline tests make_tests( test const * first, test const * const last ) -{ - return make( first, last ); -} - -inline texts make_texts( char const * const * first, char const * const * last ) -{ - return make( first, last ); -} - -// Traversal of test[N] (test_specification[N]) set up to also work with MSVC6: - -template< typename C > test const * test_begin( C const & c ) { return &*c; } -template< typename C > test const * test_end( C const & c ) { return test_begin( c ) + lest_DIMENSION_OF( c ); } - -template< typename C > char const * const * text_begin( C const & c ) { return &*c; } -template< typename C > char const * const * text_end( C const & c ) { return text_begin( c ) + lest_DIMENSION_OF( c ); } - -template< typename C > tests make_tests( C const & c ) { return make_tests( test_begin( c ), test_end( c ) ); } -template< typename C > texts make_texts( C const & c ) { return make_texts( text_begin( c ), text_end( c ) ); } - -inline int run( tests const & specification, int argc, char ** argv, std::ostream & os = std::cout ) -{ - return run( specification, make_texts( argv + 1, argv + argc ), os ); -} - -inline int run( tests const & specification, std::ostream & os = std::cout ) -{ - std::cout.sync_with_stdio( false ); - return (min)( run( specification, texts(), os ), exit_max_value ); -} - -template< typename C > -int run( C const & specification, texts args, std::ostream & os = std::cout ) -{ - return run( make_tests( specification ), args, os ); -} - -template< typename C > -int run( C const & specification, int argc, char ** argv, std::ostream & os = std::cout ) -{ - return run( make_tests( specification ), argv, argc, os ); -} - -template< typename C > -int run( C const & specification, std::ostream & os = std::cout ) -{ - return run( make_tests( specification ), os ); -} - -} // namespace lest - -#if defined (__clang__) -# pragma clang diagnostic pop -#elif defined (__GNUC__) -# pragma GCC diagnostic pop -#endif - -#endif // LEST_LEST_HPP_INCLUDED diff --git a/include/icsneo/third-party/optional-lite/test/nonstd/optional.tweak.hpp b/include/icsneo/third-party/optional-lite/test/nonstd/optional.tweak.hpp deleted file mode 100644 index 59992a0..0000000 --- a/include/icsneo/third-party/optional-lite/test/nonstd/optional.tweak.hpp +++ /dev/null @@ -1 +0,0 @@ -#define OPTIONAL_TWEAK_VALUE 42 diff --git a/include/icsneo/third-party/optional-lite/test/optional-main.t.cpp b/include/icsneo/third-party/optional-lite/test/optional-main.t.cpp deleted file mode 100644 index 215d551..0000000 --- a/include/icsneo/third-party/optional-lite/test/optional-main.t.cpp +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright (c) 2016 Martin Moene -// -// https://github.com/martinmoene/optional-lite -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -#include "optional-main.t.hpp" - -#ifndef optional_HAVE -# define optional_HAVE(FEATURE) ( optional_HAVE_##FEATURE ) -#endif - -#define optional_PRESENT( x ) \ - std::cout << #x << ": " << x << "\n" - -#define optional_ABSENT( x ) \ - std::cout << #x << ": (undefined)\n" - -lest::tests & specification() -{ - static lest::tests tests; - return tests; -} - -CASE( "optional-lite version" "[.optional][.version]" ) -{ - optional_PRESENT( optional_lite_MAJOR ); - optional_PRESENT( optional_lite_MINOR ); - optional_PRESENT( optional_lite_PATCH ); - optional_PRESENT( optional_lite_VERSION ); -} - -CASE( "optional-lite configuration" "[.optional][.config]" ) -{ - optional_PRESENT( optional_HAVE_STD_OPTIONAL ); - optional_PRESENT( optional_USES_STD_OPTIONAL ); - optional_PRESENT( optional_OPTIONAL_DEFAULT ); - optional_PRESENT( optional_OPTIONAL_NONSTD ); - optional_PRESENT( optional_OPTIONAL_STD ); - optional_PRESENT( optional_CONFIG_SELECT_OPTIONAL ); - optional_PRESENT( optional_CONFIG_NO_EXCEPTIONS ); - optional_PRESENT( optional_CPLUSPLUS ); -} - -CASE( "__cplusplus" "[.stdc++]" ) -{ - optional_PRESENT( __cplusplus ); -} - -CASE( "compiler version" "[.compiler]" ) -{ -#if optional_USES_STD_OPTIONAL - std::cout << "(Compiler version not available: using std::optional)\n"; -#else - optional_PRESENT( optional_COMPILER_CLANG_VERSION ); - optional_PRESENT( optional_COMPILER_GNUC_VERSION ); - optional_PRESENT( optional_COMPILER_MSVC_VERSION ); -#endif -} - -CASE( "presence of C++ language features" "[.stdlanguage]" ) -{ -#if optional_USES_STD_OPTIONAL - std::cout << "(Presence of C++ language features not available: using std::optional)\n"; -#else - optional_PRESENT( optional_HAVE_CONSTEXPR_11 ); - optional_PRESENT( optional_HAVE_NOEXCEPT ); - optional_PRESENT( optional_HAVE_NULLPTR ); - optional_PRESENT( optional_HAVE_REF_QUALIFIER ); - optional_PRESENT( optional_HAVE_CONSTEXPR_14 ); -#endif -} - -CASE( "presence of C++ library features" "[.stdlibrary]" ) -{ -#if optional_USES_STD_OPTIONAL - std::cout << "(Presence of C++ library features not available: using std::optional)\n"; -#else - optional_PRESENT( optional_HAVE_CONDITIONAL ); - optional_PRESENT( optional_HAVE_REMOVE_CV ); - optional_PRESENT( optional_HAVE_TYPE_TRAITS ); - optional_PRESENT( optional_HAVE_TR1_TYPE_TRAITS ); - optional_PRESENT( optional_HAVE_TR1_ADD_POINTER ); - optional_PRESENT( optional_HAVE_IS_ASSIGNABLE ); - optional_PRESENT( optional_HAVE_IS_MOVE_CONSTRUCTIBLE ); - optional_PRESENT( optional_HAVE_IS_NOTHROW_MOVE_ASSIGNABLE ); - optional_PRESENT( optional_HAVE_IS_NOTHROW_MOVE_CONSTRUCTIBLE ); - optional_PRESENT( optional_HAVE_IS_TRIVIALLY_COPY_CONSTRUCTIBLE ); - optional_PRESENT( optional_HAVE_IS_TRIVIALLY_MOVE_CONSTRUCTIBLE ); -#endif -#ifdef _HAS_CPP0X - optional_PRESENT( _HAS_CPP0X ); -#else - optional_ABSENT( _HAS_CPP0X ); -#endif -} - -int main( int argc, char * argv[] ) -{ - return lest::run( specification(), argc, argv ); -} - -#if 0 -g++ -I../include -o optional-lite.t.exe optional-lite.t.cpp && optional-lite.t.exe --pass -g++ -std=c++98 -I../include -o optional-lite.t.exe optional-lite.t.cpp && optional-lite.t.exe --pass -g++ -std=c++03 -I../include -o optional-lite.t.exe optional-lite.t.cpp && optional-lite.t.exe --pass -g++ -std=c++0x -I../include -o optional-lite.t.exe optional-lite.t.cpp && optional-lite.t.exe --pass -g++ -std=c++11 -I../include -o optional-lite.t.exe optional-lite.t.cpp && optional-lite.t.exe --pass -g++ -std=c++14 -I../include -o optional-lite.t.exe optional-lite.t.cpp && optional-lite.t.exe --pass -g++ -std=c++17 -I../include -o optional-lite.t.exe optional-lite.t.cpp && optional-lite.t.exe --pass - -cl -EHsc -I../include optional-lite.t.cpp && optional-lite.t.exe --pass -#endif - -// end of file diff --git a/include/icsneo/third-party/optional-lite/test/optional-main.t.hpp b/include/icsneo/third-party/optional-lite/test/optional-main.t.hpp deleted file mode 100644 index 6b0e6f6..0000000 --- a/include/icsneo/third-party/optional-lite/test/optional-main.t.hpp +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) 2016 Martin Moene -// -// https://github.com/martinmoene/optional-lite -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -#pragma once - -#ifndef TEST_OPTIONAL_LITE_H_INCLUDED -#define TEST_OPTIONAL_LITE_H_INCLUDED - -#include "nonstd/optional.hpp" - -// Compiler warning suppression for usage of lest: - -#ifdef __clang__ -# pragma clang diagnostic ignored "-Wstring-conversion" -# pragma clang diagnostic ignored "-Wunused-parameter" -# pragma clang diagnostic ignored "-Wunused-template" -# pragma clang diagnostic ignored "-Wunused-function" -# pragma clang diagnostic ignored "-Wunused-member-function" -#elif defined __GNUC__ -# pragma GCC diagnostic ignored "-Wunused-parameter" -# pragma GCC diagnostic ignored "-Wunused-function" -#endif - -#include -namespace lest { template std::ostream & operator<<( std::ostream & os, nonstd::optional const & v ); } - -#include "lest_cpp03.hpp" - -#define CASE( name ) lest_CASE( specification(), name ) - -extern lest::tests & specification(); - -namespace lest { - -template< typename T > -inline std::ostream & operator<<( std::ostream & os, nonstd::optional const & v ) -{ - using lest::to_string; - return os << "[optional:" << (v ? to_string(*v) : "[empty]") << "]"; -} - -} // namespace lest - -#endif // TEST_OPTIONAL_LITE_H_INCLUDED - -// end of file diff --git a/include/icsneo/third-party/optional-lite/test/optional.t.cpp b/include/icsneo/third-party/optional-lite/test/optional.t.cpp deleted file mode 100644 index b29ba47..0000000 --- a/include/icsneo/third-party/optional-lite/test/optional.t.cpp +++ /dev/null @@ -1,1433 +0,0 @@ -// -// Copyright 2014-2018 by Martin Moene -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// -// optional lite is inspired on std::optional by Fernando Cacciola and Andrzej Krzemienski -// and on expected lite by Martin Moene. - -#include "optional-main.t.hpp" - -using namespace nonstd; - -#if optional_USES_STD_OPTIONAL && defined(__APPLE__) -# define opt_value( o ) *o -#else -# define opt_value( o ) o.value() -#endif - -namespace { - -struct nonpod { nonpod(){} }; - -struct Implicit { int x; Implicit(int v) : x(v) {} }; -struct Explicit { int x; explicit Explicit(int v) : x(v) {} }; - -bool operator==( Implicit a, Implicit b ) { return a.x == b.x; } -bool operator==( Explicit a, Explicit b ) { return a.x == b.x; } - -std::ostream & operator<<( std::ostream & os, Implicit i ) { return os << "Implicit:" << i.x; } -std::ostream & operator<<( std::ostream & os, Explicit e ) { return os << "Explicit:" << e.x; } - -// ensure comparison of pointers for lest: - -// const void * lest_nullptr = 0; - -// The following tracer code originates as Oracle from Optional by -// Andrzej Krzemienski, https://github.com/akrzemi1/Optional. - -enum State -{ - /* 0 */ default_constructed, - /* 1 */ value_copy_constructed, - /* 2 */ value_move_constructed, - /* 3 */ copy_constructed, - /* 4 */ move_constructed, - /* 5 */ move_assigned, - /* 6 */ copy_assigned, - /* 7 */ value_copy_assigned, - /* 8 */ value_move_assigned, - /* 9 */ moved_from, - /*10 */ value_constructed -}; - -struct V -{ - State state; - int value; - - V( ) : state( default_constructed ), value( deflt() ) {} - V( int v ) : state( value_constructed ), value( v ) {} - - bool operator==( V const & rhs ) const { return state == rhs.state && value == rhs.value; } - bool operator==( int val ) const { return value == val; } - - static int deflt() { return 42; } -}; - -struct S -{ - State state; - V value; - - S( ) : state( default_constructed ) {} - S( V const & v ) : state( value_copy_constructed ), value( v ) {} - S( S const & s ) : state( copy_constructed ), value( s.value ) {} - - S & operator=( V const & v ) { state = value_copy_assigned; value = v; return *this; } - S & operator=( const S & s ) { state = copy_assigned ; value = s.value; return *this; } - -#if optional_CPP11_OR_GREATER - S( V && v ) : state( value_move_constructed ), value( std::move( v ) ) { v.state = moved_from; } - S( S && s ) : state( move_constructed ), value( std::move( s.value ) ) { s.state = moved_from; } - - S & operator=( V && v ) { state = value_move_assigned ; value = std::move( v ); v.state = moved_from; return *this; } - S & operator=( S && s ) { state = move_assigned ; value = std::move( s.value ); s.state = moved_from; return *this; } -#endif - - bool operator==( S const & rhs ) const { return state == rhs.state && value == rhs.value; } -}; - -inline std::ostream & operator<<( std::ostream & os, V const & v ) -{ - using lest::to_string; - return os << "[V:" << to_string( v.value ) << "]"; -} - -inline std::ostream & operator<<( std::ostream & os, S const & s ) -{ - using lest::to_string; - return os << "[S:" << to_string( s.value ) << "]"; -} - -struct NoDefault -{ - NoDefault( NoDefault const & ) {} - NoDefault & operator=( NoDefault const & ) { return *this; } - -#if optional_CPP11_OR_GREATER - NoDefault( NoDefault && ) = default; - NoDefault & operator=( NoDefault && ) = default; -#endif - -private: - NoDefault(); -}; - -struct CopyOnly -{ - CopyOnly( CopyOnly const & ) {} - CopyOnly & operator=( CopyOnly const & ) { return *this; } - -private: - CopyOnly(); -#if optional_CPP11_OR_GREATER - CopyOnly( CopyOnly && ) = delete; - CopyOnly & operator=( CopyOnly && ) = delete; -#endif -}; - -struct MoveOnly -{ -#if optional_CPP11_OR_GREATER - MoveOnly( MoveOnly && ) = default; - MoveOnly & operator=( MoveOnly && ) = default; -#endif - -private: - MoveOnly(); - MoveOnly( MoveOnly const & ); - MoveOnly & operator=( MoveOnly const & ); -}; - -struct NoDefaultCopyMove -{ - std::string text; - NoDefaultCopyMove( std::string txt ) : text( txt ) {} - -private: - NoDefaultCopyMove(); - NoDefaultCopyMove( NoDefaultCopyMove const & ); - NoDefaultCopyMove & operator=( NoDefaultCopyMove const & ); -#if optional_CPP11_OR_GREATER - NoDefaultCopyMove( NoDefaultCopyMove && ) = delete; - NoDefaultCopyMove & operator=( NoDefaultCopyMove && ) = delete; -#endif -}; - -#if optional_CPP11_OR_GREATER -struct InitList -{ - std::vector vec; - char c; - S s; - - InitList( std::initializer_list il, char k, S const & t ) - : vec( il ), c( k ), s( t ) {} - - InitList( std::initializer_list il, char k, S && t ) - : vec( il ), c( k ), s( std::move( t ) ) {} -}; -#endif - -} // anonymous namespace - -// -// test specification: -// - -CASE( "union: A C++03 union can only contain POD types" ) -{ - union U - { - char c; -#if optional_CPP11_OR_GREATER - nonpod np; -#endif - }; -} - -// -// optional member operations: -// - -// construction: - -CASE( "optional: Allows to default construct an empty optional (1a)" ) -{ - optional a; - - EXPECT( !a ); -} - -CASE( "optional: Allows to explicitly construct a disengaged, empty optional via nullopt (1b)" ) -{ - optional a( nullopt ); - - EXPECT( !a ); -} - -CASE( "optional: Allows to default construct an empty optional with a non-default-constructible (1a)" ) -{ -// FAILS: NoDefault nd; -// FAILS: NoDefaultCopyMove ndcm; - optional ond; - optional oco; - optional omo; - optional ondcm; - - EXPECT( !ond ); - EXPECT( !oco ); - EXPECT( !omo ); - EXPECT( !ondcm ); -} - -CASE( "optional: Allows to copy-construct from empty optional (2)" ) -{ - optional a; - - optional b( a ); - - EXPECT( !b ); -} - -CASE( "optional: Allows to move-construct from empty optional (C++11, 3)" ) -{ -#if optional_CPP11_OR_GREATER - optional a; - - optional b( std::move( a ) ); - - EXPECT( !b ); -#else - EXPECT( !!"optional: move-construction is not available (no C++11)" ); -#endif -} - -CASE( "optional: Allows to copy-construct from empty optional, explicit converting (C++11, 4a)" ) -{ -#if optional_CPP11_OR_GREATER - optional a; - - optional b{ a }; - - EXPECT( !b ); -#else - EXPECT( !!"optional: move-construction is not available (no C++11)" ); -#endif -} - -CASE( "optional: Allows to copy-construct from empty optional, non-explicit converting (4b)" ) -{ - optional a; - - optional b( a ); - - EXPECT( !b ); -} - -CASE( "optional: Allows to move-construct from empty optional, explicit converting (C++11, 5a)" ) -{ -#if optional_CPP11_OR_GREATER - optional a; - - optional b{ std::move( a ) }; - - EXPECT( !b ); -#else - EXPECT( !!"optional: move-construction is not available (no C++11)" ); -#endif -} - -CASE( "optional: Allows to move-construct from empty optional, non-explicit converting (C++11, 5a)" ) -{ -#if optional_CPP11_OR_GREATER - optional a; - - optional b( std::move( a ) ); - - EXPECT( !b ); -#else - EXPECT( !!"optional: move-construction is not available (no C++11)" ); -#endif -} - -CASE( "optional: Allows to copy-construct from non-empty optional (2)" ) -{ - optional a( 7 ); - - optional b( a ); - - EXPECT( b ); - EXPECT( *b == 7 ); -} - -CASE( "optional: Allows to copy-construct from non-empty optional, explicit converting (C++11, 4a)" ) -{ -#if optional_CPP11_OR_GREATER - optional a( 7 ); - - optional b{ a }; - - EXPECT( b ); - EXPECT( *b == Explicit{7} ); -#else - EXPECT( !!"optional: move-construction is not available (no C++11)" ); -#endif -} - -CASE( "optional: Allows to copy-construct from non-empty optional, non-explicit converting (4b)" ) -{ - optional a( 7 ); - - optional b( a ); - - EXPECT( b ); - EXPECT( *b == Implicit(7) ); -} - -CASE( "optional: Allows to move-construct from non-empty optional (C++11, 3)" ) -{ -#if optional_CPP11_OR_GREATER - optional a( 7 ); - - optional b( std::move( a ) ); - - EXPECT( b ); - EXPECT( *b == 7 ); -#else - EXPECT( !!"optional: move-construction is not available (no C++11)" ); -#endif -} - -CASE( "optional: Allows to move-construct from non-empty optional, explicit converting (C++11, 5a)" ) -{ -#if optional_CPP11_OR_GREATER - optional a( 7 ); - - optional b{ std::move( a ) }; - - EXPECT( b ); - EXPECT( *b == Explicit{7} ); -#else - EXPECT( !!"optional: move-construction is not available (no C++11)" ); -#endif -} - -CASE( "optional: Allows to move-construct from non-empty optional, non-explicit converting (C++11, 5b)" ) -{ -#if optional_CPP11_OR_GREATER - optional a( 7 ); - - optional b( std::move( a ) ); - - EXPECT( b ); - EXPECT( *b == Implicit(7) ); -#else - EXPECT( !!"optional: move-construction is not available (no C++11)" ); -#endif -} - -namespace { - -#if optional_CPP11_OR_GREATER - void use_optional( nonstd::optional ) {} -#else - template< typename T > - void use_optional( T ) {} -#endif - -} - -CASE( "optional: Allows to copy-construct from literal value (8)" ) -{ - use_optional( 7 ); - optional a = 7; - - EXPECT( a ); - EXPECT( *a == 7 ); -} - -CASE( "optional: Allows to copy-construct from literal value, converting (8)" ) -{ - use_optional( '7' ); - optional a = '7'; - - EXPECT( a ); - EXPECT( *a == '7' ); -} - -CASE( "optional: Allows to copy-construct from value (8)" ) -{ - const int i = 7; - - use_optional( i ); - optional a( i ); - - EXPECT( a ); - EXPECT( *a == 7 ); -} - -CASE( "optional: Allows to copy-construct from value, converting (8)" ) -{ - const char c = '7'; - - use_optional( c ); - optional a( c ); - - EXPECT( a ); - EXPECT( *a == '7' ); -} - -CASE( "optional: Allows to move-construct from value (C++11, 8b)" ) -{ -#if optional_CPP11_OR_GREATER - S s( 7 ); - - optional a( std::move( s ) ); - - EXPECT( a->value == 7 ); - EXPECT( a->state == move_constructed ); - EXPECT( s.state == moved_from ); -#else - EXPECT( !!"optional: move-construction is not available (no C++11)" ); -#endif -} - -CASE( "optional: Allows to move-construct from value, explicit converting (C++11, 8a)" ) -{ -#if optional_CPP11_OR_GREATER - int seven = 7; - - optional a{ std::move( seven ) }; - - EXPECT( a ); - EXPECT( *a == Explicit{7} ); -#else - EXPECT( !!"optional: move-construction is not available (no C++11)" ); -#endif -} - -CASE( "optional: Allows to move-construct from value, non-explicit converting (C++11, 8b)" ) -{ -#if optional_CPP11_OR_GREATER - int seven = 7; - optional a( std::move( seven ) ); - - EXPECT( a ); - EXPECT( *a == Implicit(7) ); -#else - EXPECT( !!"optional: move-construction is not available (no C++11)" ); -#endif -} - -CASE( "optional: Allows to in-place construct from literal value (C++11, 6)" ) -{ -#if optional_CPP11_OR_GREATER - using pair_t = std::pair; - - optional a( in_place, 'a', 7 ); - - EXPECT( a->first == 'a' ); - EXPECT( a->second == 7 ); -#else - EXPECT( !!"optional: in-place construction is not available (no C++11)" ); -#endif -} - -CASE( "optional: Allows to in-place copy-construct from value (C++11, 6)" ) -{ -#if optional_CPP11_OR_GREATER - char c = 'a'; S s( 7 ); - using pair_t = std::pair; - - optional a( in_place, c, s ); - - EXPECT( a->first == 'a' ); - EXPECT( a->second.value == 7 ); -#if optional_USES_STD_OPTIONAL - EXPECT( a->second.state == copy_constructed ); -#else - EXPECT( a->second.state == move_constructed ); -#endif - EXPECT( s.state != moved_from ); -#else - EXPECT( !!"optional: in-place construction is not available (no C++11)" ); -#endif -} - -CASE( "optional: Allows to in-place move-construct from value (C++11, 6)" ) -{ -#if optional_CPP11_OR_GREATER - char c = 'a'; S s( 7 ); - using pair_t = std::pair; - - optional a( in_place, c, std::move( s ) ); - - EXPECT( a->first == 'a' ); - EXPECT( a->second.value == 7 ); - EXPECT( a->second.state == move_constructed ); - EXPECT( s.state == moved_from ); -#else - EXPECT( !!"optional: in-place construction is not available (no C++11)" ); -#endif -} - -CASE( "optional: Allows to in-place copy-construct from initializer-list (C++11, 7)" ) -{ -#if optional_CPP11_OR_GREATER - S s( 7 ); - optional a( in_place, { 7, 8, 9, }, 'a', s ); - - EXPECT( a->vec[0] == 7 ); - EXPECT( a->vec[1] == 8 ); - EXPECT( a->vec[2] == 9 ); - EXPECT( a->c == 'a'); - EXPECT( a->s.value == 7 ); -#if optional_USES_STD_OPTIONAL - EXPECT( a->s.state == copy_constructed ); -#else - EXPECT( a->s.state == move_constructed ); -#endif - EXPECT( s.state != moved_from ); -#else - EXPECT( !!"optional: in-place construction is not available (no C++11)" ); -#endif -} - -CASE( "optional: Allows to in-place move-construct from initializer-list (C++11, 7)" ) -{ -#if optional_CPP11_OR_GREATER - S s( 7 ); - optional a( in_place, { 7, 8, 9, }, 'a', std::move( s ) ); - - EXPECT( a->vec[0] == 7 ); - EXPECT( a->vec[1] == 8 ); - EXPECT( a->vec[2] == 9 ); - EXPECT( a->c == 'a' ); - EXPECT( a->s.value == 7 ); - EXPECT( a->s.state == move_constructed ); - EXPECT( s.state == moved_from ); -#else - EXPECT( !!"optional: in-place construction is not available (no C++11)" ); -#endif -} - -// assignment: - -CASE( "optional: Allows to assign nullopt to disengage (1)" ) -{ - optional a( 7 ); - - a = nullopt; - - EXPECT( !a ); -} - -CASE( "optional: Allows to copy-assign from/to engaged and disengaged optionals (2)" ) -{ - SETUP( "" ) { - optional d1; - optional d2; - optional e1( 123 ); - optional e2( 987 ); - - SECTION( "a disengaged optional assigned nullopt remains empty" ) { - d1 = nullopt; - EXPECT( !d1 ); - } - SECTION( "a disengaged optional assigned an engaged optional obtains its value" ) { - d1 = e1; - EXPECT( d1 ); - EXPECT( *d1 == 123 ); - } - SECTION( "an engaged optional assigned an engaged optional obtains its value" ) { - e1 = e2; - EXPECT( e1 ); - EXPECT( *e1 == 987 ); - } - SECTION( "an engaged optional assigned nullopt becomes empty" ) { - e1 = nullopt; - EXPECT( !e1 ); - } - SECTION( "a disengaged optional assigned a disengaged optional remains empty" ) { - d1 = d2; - EXPECT( !d1 ); - }} -} - -CASE( "optional: Allows to move-assign from/to engaged and disengaged optionals (C++11, 3)" ) -{ -#if optional_CPP11_OR_GREATER - SETUP( "" ) { - optional d1; - optional d2; - optional e1( 123 ); - optional e2( 987 ); - - SECTION( "a disengaged optional assigned nullopt remains empty" ) { - d1 = std::move( nullopt ); - EXPECT( !d1 ); - } - SECTION( "a disengaged optional assigned an engaged optional obtains its value" ) { - d1 = std::move( e1); - EXPECT( d1 ); - EXPECT( *d1 == 123 ); - } - SECTION( "an engaged optional assigned an engaged optional obtains its value" ) { - e1 = std::move( e2 ); - EXPECT( e1 ); - EXPECT( *e1 == 987 ); - } - SECTION( "an engaged optional assigned nullopt becomes empty" ) { - e1 = std::move( nullopt ); - EXPECT( !e1 ); - } - SECTION( "a disengaged optional assigned a disengaged optional remains empty" ) { - d1 = std::move( d2); - EXPECT( !d1 ); - }} -#else - EXPECT( !!"optional: move-assignment is not available (no C++11)" ); -#endif -} - -CASE( "optional: Allows to copy-assign from/to engaged and disengaged optionals, converting, (5)" ) -{ - SETUP( "" ) { - optional d1; - optional d2; - optional e1( 123 ); - optional e2( '7' ); - - SECTION( "a disengaged optional assigned an engaged optional obtains its value, converting" ) { - d1 = e2; - EXPECT( d1 ); - EXPECT( *d1 == '7' ); - } - SECTION( "an engaged optional assigned an engaged optional obtains its value, converting" ) { - e1 = e2; - EXPECT( e1 ); - EXPECT( *e1 == '7' ); - } - SECTION( "an engaged optional assigned a disengaged optional becomes empty, converting" ) { - e1 = d2; - EXPECT( !e1 ); - } - SECTION( "a disengaged optional assigned a disengaged optional remains empty, converting" ) { - d1 = d2; - EXPECT( !d1 ); - }} -} - -CASE( "optional: Allows to move-assign from/to engaged and disengaged optionals, converting (C++11, 6)" ) -{ -#if optional_CPP11_OR_GREATER - SETUP( "" ) { - optional d1; - optional d2; - optional e1( 123 ); - optional e2( '7' ); - - SECTION( "a disengaged optional assigned an engaged optional obtains its value, converting" ) { - d1 = std::move( e2 ); - EXPECT( d1 ); - EXPECT( *d1 == '7' ); - } - SECTION( "an engaged optional assigned an engaged optional obtains its value, converting" ) { - e1 = std::move( e2 ); - EXPECT( e1 ); - EXPECT( *e1 == '7' ); - } - SECTION( "an engaged optional assigned a disengaged optional becomes empty, converting" ) { - e1 = std::move( d2 ); - EXPECT( !e1 ); - } - SECTION( "a disengaged optional assigned a disengaged optional remains empty, converting" ) { - d1 = std::move( d2 ); - EXPECT( !d1 ); - }} -#else - EXPECT( !!"optional: move-assignment is not available (no C++11)" ); -#endif -} - -CASE( "optional: Allows to copy-assign from literal value (4)" ) -{ - optional a; - - a = 7; - - EXPECT( *a == 7 ); -} - -CASE( "optional: Allows to copy-assign from value (4)" ) -{ - const int i = 7; - optional a; - - a = i; - - EXPECT( *a == i ); -} - -CASE( "optional: Allows to move-assign from value (C++11, 4)" ) -{ -#if optional_CPP11_OR_GREATER - S s( 7 ); - optional a; - - a = std::move( s ); - - EXPECT( a->value == 7 ); - EXPECT( a->state == move_constructed ); - EXPECT( s.state == moved_from ); -#else - EXPECT( !!"optional: move-assign is not available (no C++11)" ); -#endif -} - -CASE( "optional: Allows to copy-emplace content from arguments (C++11, 7)" ) -{ -#if optional_CPP11_OR_GREATER - using pair_t = std::pair; - S s( 7 ); - optional a; - - a.emplace( 'a', s ); - - EXPECT( a->first == 'a' ); - EXPECT( a->second.value == 7 ); - EXPECT( a->second.state == copy_constructed ); - EXPECT( s.state != moved_from ); -#else - EXPECT( !!"optional: in-place construction is not available (no C++11)" ); -#endif -} - -CASE( "optional: Allows to move-emplace content from arguments (C++11, 7)" ) -{ -#if optional_CPP11_OR_GREATER - using pair_t = std::pair; - S s( 7 ); - optional a; - - a.emplace( 'a', std::move( s ) ); - - EXPECT( a->first == 'a' ); - EXPECT( a->second.value == 7 ); - EXPECT( a->second.state == move_constructed ); - EXPECT( s.state == moved_from ); -#else - EXPECT( !!"optional: in-place construction is not available (no C++11)" ); -#endif -} - -CASE( "optional: Allows to copy-emplace content from intializer-list and arguments (C++11, 8)" ) -{ -#if optional_CPP11_OR_GREATER - S s( 7 ); - optional a; - - a.emplace( { 7, 8, 9, }, 'a', s ); - - EXPECT( a->vec[0] == 7 ); - EXPECT( a->vec[1] == 8 ); - EXPECT( a->vec[2] == 9 ); - EXPECT( a->c == 'a' ); - EXPECT( a->s.value == 7 ); - EXPECT( a->s.state == copy_constructed ); - EXPECT( s.state != moved_from ); -#else - EXPECT( !!"optional: in-place construction is not available (no C++11)" ); -#endif -} - -CASE( "optional: Allows to move-emplace content from intializer-list and arguments (C++11, 8)" ) -{ -#if optional_CPP11_OR_GREATER - S s( 7 ); - optional a; - - a.emplace( { 7, 8, 9, }, 'a', std::move( s ) ); - - EXPECT( a->vec[0] == 7 ); - EXPECT( a->vec[1] == 8 ); - EXPECT( a->vec[2] == 9 ); - EXPECT( a->c == 'a' ); - EXPECT( a->s.value == 7 ); - EXPECT( a->s.state == move_constructed ); - EXPECT( s.state == moved_from ); -#else - EXPECT( !!"optional: in-place construction is not available (no C++11)" ); -#endif -} - -// swap: - -CASE( "optional: Allows to swap with other optional (member)" ) -{ - SETUP( "" ) { - optional d1; - optional d2; - optional e1( 42 ); - optional e2( 7 ); - - SECTION( "swap disengaged with disengaged optional" ) { - d1.swap( d2 ); - EXPECT( !d1 ); - } - SECTION( "swap engaged with engaged optional" ) { - e1.swap( e2 ); - EXPECT( e1 ); - EXPECT( e2 ); - EXPECT( *e1 == 7 ); - EXPECT( *e2 == 42 ); - } - SECTION( "swap disengaged with engaged optional" ) { - d1.swap( e1 ); - EXPECT( d1 ); - EXPECT( !e1 ); - EXPECT( *d1 == 42 ); - } - SECTION( "swap engaged with disengaged optional" ) { - e1.swap( d1 ); - EXPECT( d1 ); - EXPECT( !e1 ); - EXPECT( *d1 == 42 ); - }} -} - -// observers: - -CASE( "optional: Allows to obtain value via operator->()" ) -{ - SETUP( "" ) { - optional e( Implicit( 42 ) ); - optional const ce( Implicit( 42 ) ); - - SECTION( "operator->() yields pointer to value (const)" ) { - EXPECT( ce->x == 42 ); - } - SECTION( "operator->() yields pointer to value (non-const)" ) { - e->x = 7; - EXPECT( e->x == 7 ); - }} -} - -CASE( "optional: Allows to obtain moved-value via operator->() (C++11)" ) -{ -#if optional_CPP11_OR_GREATER - SETUP( "" ) { - optional e( Implicit( 42 ) ); - optional const ce( Implicit( 42 ) ); - - SECTION( "operator->() yields pointer to value (const)" ) { - EXPECT( std::move( ce )->x == 42 ); - } - SECTION( "operator->() yields pointer to value (non-const)" ) { - e->x = 7; - EXPECT( std::move( e )->x == 7 ); - }} -#else - EXPECT( !!"optional: move-semantics are not available (no C++11)" ); -#endif -} - -CASE( "optional: Allows to obtain value via operator*()" ) -{ - SETUP( "" ) { - optional e( 42 ); - optional const ce( 42 ); - - SECTION( "operator*() yields value (const)" ) { - EXPECT( *ce == 42 ); - } - SECTION( "operator*() yields value (non-const)" ) { - *e = 7; - EXPECT( *e == 7 ); - }} -} - -CASE( "optional: Allows to obtain moved-value via operator*() (C++11)" ) -{ -#if optional_CPP11_OR_GREATER - SETUP( "" ) { - optional e( 42 ); - optional const ce( 42 ); - - SECTION( "operator*() yields value (const)" ) { - EXPECT( *(std::move( ce )) == 42 ); - } - SECTION( "operator*() yields value (non-const)" ) { - *e = 7; - EXPECT( *(std::move( e )) == 7 ); - }} -#else - EXPECT( !!"optional: move-semantics are not available (no C++11)" ); -#endif -} - -CASE( "optional: Allows to obtain has_value() via operator bool()" ) -{ - optional a; - optional b( 7 ); - - EXPECT_NOT( a ); - EXPECT( b ); -} - -CASE( "optional: Allows to obtain value via value()" ) -{ - SETUP( "" ) { - optional e( 42 ); - optional const ce( 42 ); - - SECTION( "value() yields value (const)" ) { - EXPECT( opt_value( ce ) == 42 ); - } - SECTION( "value() yields value (non-const)" ) { - EXPECT( opt_value( e ) == 42 ); - }} -} - -CASE( "optional: Allows to obtain moved-value via value() (C++11)" ) -{ -#if optional_CPP11_OR_GREATER - SETUP( "" ) { - optional e( 42 ); - optional const ce( 42 ); - - SECTION( "value() yields value (const)" ) { - EXPECT( opt_value( std::move( ce ) ) == 42 ); - } - SECTION( "value() yields value (non-const)" ) { - EXPECT( opt_value( std::move( e ) ) == 42 ); - }} -#else - EXPECT( !!"optional: move-semantics are not available (no C++11)" ); -#endif -} - -CASE( "optional: Allows to obtain value or default via value_or()" ) -{ - SETUP( "" ) { - optional d; - optional e( 42 ); - - SECTION( "value_or( 7 ) yields value for non-empty optional" ) { - EXPECT( e.value_or( 7 ) == 42 ); - } - SECTION( "value_or( 7 ) yields default for empty optional" ) { - EXPECT( d.value_or( 7 ) == 7 ); - }} -} - -CASE( "optional: Allows to obtain moved-value or moved-default via value_or() (C++11)" ) -{ -#if optional_CPP11_OR_GREATER - SETUP( "" ) { - optional d; - optional e( 42 ); - optional ds; - optional es("77"); - - SECTION("for l-values") { - EXPECT( d.value_or( 7 ) == 7 ); - EXPECT( e.value_or( 7 ) == 42 ); - EXPECT( ds.value_or("7") == "7" ); - EXPECT( es.value_or("7") == "77" ); - EXPECT_NOT( es->empty() ); // see issue-60 - } - SECTION("for r-values") { - EXPECT( std::move( d ).value_or( 7 ) == 7 ); - EXPECT( std::move( e ).value_or( 7 ) == 42 ); - EXPECT( std::move( ds ).value_or("7") == "7" ); - EXPECT( std::move( es ).value_or("7") == "77" ); - }} -#else - EXPECT( !!"optional: move-semantics are not available (no C++11)" ); -#endif -} - -CASE( "optional: Throws bad_optional_access at disengaged access" ) -{ -#if optional_USES_STD_OPTIONAL && defined(__APPLE__) - EXPECT( true ); -#else - SETUP( "" ) { - optional d; - optional const cd; - - SECTION("for l-values") { - EXPECT_THROWS_AS( d.value(), bad_optional_access ); - EXPECT_THROWS_AS( cd.value(), bad_optional_access ); - } -# if optional_CPP11_OR_GREATER - SECTION("for r-values") { - EXPECT_THROWS_AS( std::move( d ).value(), bad_optional_access ); - EXPECT_THROWS_AS( std::move( cd ).value(), bad_optional_access ); - } -# endif - } -#endif -} - -CASE( "optional: Throws bad_optional_access with non-empty what()" ) -{ - try - { - optional d; - (void) d.value(); - } - catch( bad_optional_access const & e ) - { - EXPECT( ! std::string( e.what() ).empty() ); - } -} - -// modifiers: - -CASE( "optional: Allows to reset content" ) -{ - optional a = 7; - - a.reset(); - - EXPECT_NOT( a.has_value() ); -} - -// desctruction: - -namespace destruction { - -struct S -{ - static void reset() { ctor_count() = 0; dtor_count() = 0; } - static int & ctor_count() { static int i = 0; return i; } - static int & dtor_count() { static int i = 0; return i; } - - S( int /*i*/ ) { ++ctor_count(); } - S( char /*c*/, int /*i*/ ) { ++ctor_count(); } - S( S const & ) { ++ctor_count(); } -#if optional_CPP11_OR_GREATER - S( S&& ) {} -#endif - ~S() { ++dtor_count(); } -}; -} // namespace destruct - -CASE( "optional: Ensure object is destructed only once (C++11)" ) -{ -#if optional_CPP11_OR_GREATER - using destruction::S; - - SETUP( "- Reset ctor & dtor counts" ) { - - S::reset(); - - SECTION( "- Destruction with direct initialize (C++11)" ) - { - { - optional s( 7 ); - - EXPECT( s.has_value() ); - EXPECT( S::dtor_count() == 0 ); - } - EXPECT( S::dtor_count() == 1 ); - } - SECTION( "- Destruction with emplace (C++11)" ) - { - { - optional s; - - EXPECT( S::dtor_count() == 0 ); - - s.emplace( 'c', 42 ); - - EXPECT( S::dtor_count() == 0 ); - } - EXPECT( S::dtor_count() == 1 ); - }} -#else - EXPECT( !!"optional: in-place construction is not available (no C++11)" ); -#endif -} - -CASE( "optional: Ensure balanced construction-destruction (C++98)" ) -{ - using destruction::S; - - SETUP( "- Reset ctor & dtor counts" ) { - - S::reset(); - - SECTION( "- Destruction with direct initialize (C++98)" ) - { - { - optional s( 7 ); - - EXPECT( s.has_value() ); - EXPECT( S::ctor_count() == S::dtor_count() + 1 ); - } - EXPECT( S::ctor_count() == S::dtor_count() ); - }} -} - -// -// optional non-member functions: -// - -CASE( "optional: Allows to swaps engage state and values (non-member)" ) -{ - SETUP( "" ) { - optional d1; - optional d2; - optional e1( 42 ); - optional e2( 7 ); - - SECTION( "swap disengaged with disengaged optional" ) { - swap( d1, d2 ); - EXPECT( !d1 ); - } - SECTION( "swap engaged with engaged optional" ) { - swap( e1, e2 ); - EXPECT( e1 ); - EXPECT( e2 ); - EXPECT( *e1 == 7 ); - EXPECT( *e2 == 42 ); - } - SECTION( "swap disengaged with engaged optional" ) { - swap( d1, e1 ); - EXPECT( d1 ); - EXPECT( !e1 ); - EXPECT( *d1 == 42 ); - } - SECTION( "swap engaged with disengaged optional" ) { - swap( e1, d1 ); - EXPECT( d1 ); - EXPECT( !e1 ); - EXPECT( *d1 == 42 ); - }} -} - -template< typename R, typename S, typename T > -void relop( lest::env & lest_env ) -{ - SETUP( "" ) { - optional d; - optional e1( 6 ); - optional e2( 7 ); - - SECTION( "engaged == engaged" ) { EXPECT( e1 == e1 ); } - SECTION( "engaged == disengaged" ) { EXPECT( !(e1 == d ) ); } - SECTION( "disengaged == engaged" ) { EXPECT( !(d == e1) ); } - - SECTION( "engaged != engaged" ) { EXPECT( e1 != e2 ); } - SECTION( "engaged != disengaged" ) { EXPECT( e1 != d ); } - SECTION( "disengaged != engaged" ) { EXPECT( d != e2 ); } - - SECTION( "engaged < engaged" ) { EXPECT( e1 < e2 ); } - SECTION( "engaged < disengaged" ) { EXPECT( !(e1 < d ) ); } - SECTION( "disengaged < engaged" ) { EXPECT( d < e2 ); } - - SECTION( "engaged <= engaged" ) { EXPECT( e1 <= e1 ); } - SECTION( "engaged <= engaged" ) { EXPECT( e1 <= e2 ); } - SECTION( "engaged <= disengaged" ) { EXPECT( !(e1 <= d ) ); } - SECTION( "disengaged <= engaged" ) { EXPECT( d <= e2 ); } - - SECTION( "engaged > engaged" ) { EXPECT( e2 > e1 ); } - SECTION( "engaged > disengaged" ) { EXPECT( e2 > d ); } - SECTION( "disengaged > engaged" ) { EXPECT( !(d > e1) ); } - - SECTION( "engaged >= engaged" ) { EXPECT( e1 >= e1 ); } - SECTION( "engaged >= engaged" ) { EXPECT( e2 >= e1 ); } - SECTION( "engaged >= disengaged" ) { EXPECT( e2 >= d ); } - SECTION( "disengaged >= engaged" ) { EXPECT( !(d >= e1) ); } - - SECTION( "disengaged == nullopt" ) { EXPECT( (d == nullopt) ); } - SECTION( "nullopt == disengaged" ) { EXPECT( (nullopt == d ) ); } - SECTION( "engaged == nullopt" ) { EXPECT( (e1 != nullopt) ); } - SECTION( "nullopt == engaged" ) { EXPECT( (nullopt != e1 ) ); } - SECTION( "disengaged == nullopt" ) { EXPECT( !(d < nullopt) ); } - SECTION( "nullopt == disengaged" ) { EXPECT( !(nullopt < d ) ); } - SECTION( "disengaged == nullopt" ) { EXPECT( (d <= nullopt) ); } - SECTION( "nullopt == disengaged" ) { EXPECT( (nullopt <= d ) ); } - SECTION( "disengaged == nullopt" ) { EXPECT( !(d > nullopt) ); } - SECTION( "nullopt == disengaged" ) { EXPECT( !(nullopt > d ) ); } - SECTION( "disengaged == nullopt" ) { EXPECT( (d >= nullopt) ); } - SECTION( "nullopt == disengaged" ) { EXPECT( (nullopt >= d ) ); } - - SECTION( "engaged == value" ) { EXPECT( e1 == 6 ); } - SECTION( "value == engaged" ) { EXPECT( 6 == e1 ); } - SECTION( "engaged != value" ) { EXPECT( e1 != 7 ); } - SECTION( "value != engaged" ) { EXPECT( 6 != e2 ); } - SECTION( "engaged < value" ) { EXPECT( e1 < 7 ); } - SECTION( "value < engaged" ) { EXPECT( 6 < e2 ); } - SECTION( "engaged <= value" ) { EXPECT( e1 <= 7 ); } - SECTION( "value <= engaged" ) { EXPECT( 6 <= e2 ); } - SECTION( "engaged > value" ) { EXPECT( e2 > 6 ); } - SECTION( "value > engaged" ) { EXPECT( 7 > e1 ); } - SECTION( "engaged >= value" ) { EXPECT( e2 >= 6 ); } - SECTION( "value >= engaged" ) { EXPECT( 7 >= e1 ); } - } -} - -CASE( "optional: Provides relational operators (non-member)" ) -{ - relop( lest_env ); -} - -CASE( "optional: Provides mixed-type relational operators (non-member)" ) -{ - relop( lest_env ); -} - -CASE( "make_optional: Allows to copy-construct optional" ) -{ - S s( 7 ); - - EXPECT( make_optional( s )->value == 7 ); - EXPECT( s.state != moved_from ); -} - -CASE( "make_optional: Allows to move-construct optional (C++11)" ) -{ -#if optional_CPP11_OR_GREATER - S s( 7 ); - - EXPECT( make_optional( std::move( s ) )->value == 7 ); - EXPECT( s.state == moved_from ); -#else - EXPECT( !!"optional: move-construction is not available (no C++11)" ); -#endif -} - -CASE( "make_optional: Allows to in-place copy-construct optional from arguments (C++11)" ) -{ -#if optional_CPP11_OR_GREATER - using pair_t = std::pair; - - S s( 7); - auto a = make_optional( 'a', s ); - - EXPECT( a->first == 'a' ); - EXPECT( a->second.value == 7 ); -#if optional_USES_STD_OPTIONAL - EXPECT( a->second.state == copy_constructed ); -#else - EXPECT( a->second.state == move_constructed ); -#endif - EXPECT( s.state != moved_from ); -#else - EXPECT( !!"optional: in-place construction is not available (no C++11)" ); -#endif -} - -CASE( "make_optional: Allows to in-place move-construct optional from arguments (C++11)" ) -{ -#if optional_CPP11_OR_GREATER - using pair_t = std::pair; - - S s( 7 ); - auto a = make_optional( 'a', std::move( s ) ); - - EXPECT( a->first == 'a' ); - EXPECT( a->second.value == 7 ); - EXPECT( a->second.state == move_constructed ); - EXPECT( s.state == moved_from ); -#else - EXPECT( !!"optional: in-place construction is not available (no C++11)" ); -#endif -} - -CASE( "make_optional: Allows to in-place copy-construct optional from initializer-list and arguments (C++11)" ) -{ -#if optional_CPP11_OR_GREATER - S s( 7 ); - auto a = make_optional( { 7, 8, 9, }, 'a', s ); - - EXPECT( a->vec[0] == 7 ); - EXPECT( a->vec[1] == 8 ); - EXPECT( a->vec[2] == 9 ); - EXPECT( a->c == 'a' ); - EXPECT( a->s.value == 7 ); -#if optional_USES_STD_OPTIONAL - EXPECT( a->s.state == copy_constructed ); -#else - EXPECT( a->s.state == move_constructed ); -#endif - EXPECT( s.state != moved_from ); -#else - EXPECT( !!"optional: in-place construction is not available (no C++11)" ); -#endif -} - -CASE( "make_optional: Allows to in-place move-construct optional from initializer-list and arguments (C++11)" ) -{ -#if optional_CPP11_OR_GREATER - S s( 7 ); - auto a = make_optional( { 7, 8, 9, }, 'a', std::move( s ) ); - - EXPECT( a->vec[0] == 7 ); - EXPECT( a->vec[1] == 8 ); - EXPECT( a->vec[2] == 9 ); - EXPECT( a->c == 'a' ); - EXPECT( a->s.value == 7 ); - EXPECT( a->s.state == move_constructed ); - EXPECT( s.state == moved_from ); -#else - EXPECT( !!"optional: in-place construction is not available (no C++11)" ); -#endif -} - -CASE( "std::hash<>: Allows to obtain hash (C++11)" ) -{ -#if optional_CPP11_OR_GREATER - const auto a = optional( 7 ); - const auto b = optional( 7 ); - - EXPECT( std::hash>{}( a ) == std::hash>{}( b ) ); -#else - EXPECT( !!"std::hash<>: std::hash<> is not available (no C++11)" ); -#endif -} - -CASE( "tweak header: reads tweak header if supported " "[tweak]" ) -{ -#if optional_HAVE_TWEAK_HEADER - EXPECT( OPTIONAL_TWEAK_VALUE == 42 ); -#else - EXPECT( !!"Tweak header is not available (optional_HAVE_TWEAK_HEADER: 0)." ); -#endif -} - -// -// Negative tests: -// - -// -// Tests that print information: -// - -struct Struct{ Struct(){} }; - -#if !defined(optional_FEATURE_MAX_ALIGN_HACK) || !optional_FEATURE_MAX_ALIGN_HACK - -#define optional_OUTPUT_ALIGNMENT_OF( type ) \ - "alignment_of<" #type ">: " << \ - alignment_of::value << "\n" << - -CASE("alignment_of: Show alignment of various types" - "[.]" ) -{ -#if optional_CPP11_OR_GREATER - using std::alignment_of; -#else - using ::nonstd::optional_lite::detail::alignment_of; -#endif - - std::cout << - optional_OUTPUT_ALIGNMENT_OF( char ) - optional_OUTPUT_ALIGNMENT_OF( short ) - optional_OUTPUT_ALIGNMENT_OF( int ) - optional_OUTPUT_ALIGNMENT_OF( long ) - optional_OUTPUT_ALIGNMENT_OF( float ) - optional_OUTPUT_ALIGNMENT_OF( double ) - optional_OUTPUT_ALIGNMENT_OF( long double ) - optional_OUTPUT_ALIGNMENT_OF( Struct ) - ""; -} -#undef optional_OUTPUT_ALIGNMENT_OF -#endif - -#define optional_OUTPUT_SIZEOF( type ) \ - "sizeof( optional<" #type "> ): " << \ - sizeof( optional< type> ) << " (" << sizeof(type) << ")\n" << - -CASE("storage_t: Show sizeof various optionals" - "[.]" ) -{ - std::cout << -#if !optional_USES_STD_OPTIONAL - "sizeof( nonstd::optional_lite::detail::storage_t ): " << - sizeof( nonstd::optional_lite::detail::storage_t ) << "\n" << -#endif - optional_OUTPUT_SIZEOF( char ) - optional_OUTPUT_SIZEOF( short ) - optional_OUTPUT_SIZEOF( int ) - optional_OUTPUT_SIZEOF( long ) - optional_OUTPUT_SIZEOF( float ) - optional_OUTPUT_SIZEOF( double ) - optional_OUTPUT_SIZEOF( long double ) - optional_OUTPUT_SIZEOF( Struct ) - ""; -} -#undef optional_OUTPUT_SIZEOF - -// -// Issues: -// - -CASE( "optional: isocpp-lib: CH 3, p0032r2 -- let's not have too clever tags" "[.issue-1]" ) -{ - EXPECT( false ); -#if 0 - optional< optional< optional > > a ( - in_place, -#if 0 - in_place, -#else -// nonstd_lite_in_place_type_t(int), - static_cast< nonstd::in_place_t >( in_place ), -#endif - nullopt - ); - - EXPECT( a ); - EXPECT( *a ); - EXPECT_NOT( **a ); -#endif -} -// end of file diff --git a/include/icsneo/third-party/optional-lite/test/t.bat b/include/icsneo/third-party/optional-lite/test/t.bat deleted file mode 100644 index 89bb5d9..0000000 --- a/include/icsneo/third-party/optional-lite/test/t.bat +++ /dev/null @@ -1,56 +0,0 @@ -@echo off & setlocal enableextensions enabledelayedexpansion -:: -:: t.bat - compile & run tests (MSVC). -:: - -set unit=optional - -:: if no std is given, use compiler default - -set std=%1 -if not "%std%"=="" set std=-std:%std% - -call :CompilerVersion version -echo VC%version%: %args% - -set UCAP=%unit% -call :toupper UCAP - -set unit_select=-D%unit%_CONFIG_SELECT_%UCAP%=%unit%_%UCAP%_DEFAULT -::set unit_select=-D%unit%_CONFIG_SELECT_%UCAP%=%unit%_%UCAP%_NONSTD -::set unit_select=-D%unit%_CONFIG_SELECT_%UCAP%=%unit%_%UCAP%_STD - -set unit_config= - -set msvc_defines=^ - -D_CRT_SECURE_NO_WARNINGS ^ - -D_SCL_SECURE_NO_WARNINGS - -set CppCoreCheckInclude=%VCINSTALLDIR%\Auxiliary\VS\include - -cl -W3 -EHsc %std% %unit_select% %unit_config% %msvc_defines% -I../include -I. %unit%-main.t.cpp %unit%.t.cpp && %unit%-main.t.exe -endlocal & goto :EOF - -:: subroutines: - -:CompilerVersion version -@echo off & setlocal enableextensions -set tmpprogram=_getcompilerversion.tmp -set tmpsource=%tmpprogram%.c - -echo #include ^ >%tmpsource% -echo int main(){printf("%%d\n",_MSC_VER);} >>%tmpsource% - -cl /nologo %tmpsource% >nul -for /f %%x in ('%tmpprogram%') do set version=%%x -del %tmpprogram%.* >nul -set offset=0 -if %version% LSS 1900 set /a offset=1 -set /a version="version / 10 - 10 * ( 5 + offset )" -endlocal & set %1=%version%& goto :EOF - -:: toupper; makes use of the fact that string -:: replacement (via SET) is not case sensitive -:toupper -for %%L IN (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO SET %1=!%1:%%L=%%L! -goto :EOF diff --git a/include/icsneo/third-party/optional-lite/test/tc-cl.bat b/include/icsneo/third-party/optional-lite/test/tc-cl.bat deleted file mode 100644 index b453d1f..0000000 --- a/include/icsneo/third-party/optional-lite/test/tc-cl.bat +++ /dev/null @@ -1,6 +0,0 @@ -@setlocal -@set std=%1 -@if not "%std%"=="" set std=-std:%std% -clang-cl -m32 -W3 -EHsc %std% -Doptional_CONFIG_SELECT_OPTIONAL=optional_OPTIONAL_NONSTD -I../include -I. optional-main.t.cpp optional.t.cpp && optional-main.t.exe -@endlocal - diff --git a/include/icsneo/third-party/optional-lite/test/tc.bat b/include/icsneo/third-party/optional-lite/test/tc.bat deleted file mode 100644 index a86a8ac..0000000 --- a/include/icsneo/third-party/optional-lite/test/tc.bat +++ /dev/null @@ -1,53 +0,0 @@ -@echo off & setlocal enableextensions enabledelayedexpansion -:: -:: tc.bat - compile & run tests (clang). -:: - -set unit=optional - -:: if no std is given, use c++14 - -set std=%1 -if "%std%"=="" set std=c++14 - -set clang=clang - -call :CompilerVersion version -echo %clang% %version%: %std% - -set UCAP=%unit% -call :toupper UCAP - -set unit_select=-D%unit%_CONFIG_SELECT_%UCAP%=%unit%_%UCAP%_DEFAULT -::set unit_select=-D%unit%_CONFIG_SELECT_%UCAP%=%unit%_%UCAP%_NONSTD -::set unit_select=-D%unit%_CONFIG_SELECT_%UCAP%=%unit%_%UCAP%_STD - -set unit_config= - -rem -flto / -fwhole-program -set optflags=-O2 -set warnflags=-Wall -Wextra -Wpedantic -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Wno-missing-noreturn -Wno-documentation-unknown-command -Wno-documentation-deprecated-sync -Wno-documentation -Wno-weak-vtables -Wno-missing-prototypes -Wno-missing-variable-declarations -Wno-exit-time-destructors -Wno-global-constructors - -"%clang%" -m32 -std=%std% %optflags% %warnflags% %unit_select% %unit_config% -fms-compatibility-version=19.00 -isystem "%VCInstallDir%include" -isystem "%WindowsSdkDir_71A%include" -I../include -I. -o %unit%-main.t.exe %unit%-main.t.cpp %unit%.t.cpp && %unit%-main.t.exe -endlocal & goto :EOF - -:: subroutines: - -:CompilerVersion version -echo off & setlocal enableextensions -set tmpprogram=_getcompilerversion.tmp -set tmpsource=%tmpprogram%.c - -echo #include ^ > %tmpsource% -echo int main(){printf("%%d.%%d.%%d\n",__clang_major__,__clang_minor__,__clang_patchlevel__);} >> %tmpsource% - -"%clang%" -m32 -o %tmpprogram% %tmpsource% >nul -for /f %%x in ('%tmpprogram%') do set version=%%x -del %tmpprogram%.* >nul -endlocal & set %1=%version%& goto :EOF - -:: toupper; makes use of the fact that string -:: replacement (via SET) is not case sensitive -:toupper -for %%L IN (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO SET %1=!%1:%%L=%%L! -goto :EOF diff --git a/include/icsneo/third-party/optional-lite/test/tg-all.bat b/include/icsneo/third-party/optional-lite/test/tg-all.bat deleted file mode 100644 index 4b057da..0000000 --- a/include/icsneo/third-party/optional-lite/test/tg-all.bat +++ /dev/null @@ -1,3 +0,0 @@ -@for %%s in ( c++98 c++03 c++11 c++14 c++17 ) do ( - call tg.bat %%s -) diff --git a/include/icsneo/third-party/optional-lite/test/tg.bat b/include/icsneo/third-party/optional-lite/test/tg.bat deleted file mode 100644 index f05d34e..0000000 --- a/include/icsneo/third-party/optional-lite/test/tg.bat +++ /dev/null @@ -1,55 +0,0 @@ -@echo off & setlocal enableextensions enabledelayedexpansion -:: -:: tg.bat - compile & run tests (GNUC). -:: - -set unit=optional - -:: if no std is given, use c++11 - -set std=%1 -set args=%2 %3 %4 %5 %6 %7 %8 %9 -if "%1" == "" set std=c++11 - -set gpp=g++ - -call :CompilerVersion version -echo %gpp% %version%: %std% %args% - -set UCAP=%unit% -call :toupper UCAP - -set unit_select=-D%unit%_CONFIG_SELECT_%UCAP%=%unit%_%UCAP%_DEFAULT -::set unit_select=-D%unit%_CONFIG_SELECT_%UCAP%=%unit%_%UCAP%_NONSTD -::set unit_select=-D%unit%_CONFIG_SELECT_%UCAP%=%unit%_%UCAP%_STD - -set unit_config= - -rem -flto / -fwhole-program -set optflags=-O2 -set warnflags=-Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wno-padded -Wno-missing-noreturn - -%gpp% -std=%std% %optflags% %warnflags% %unit_select% %unit_config% -o %unit%-main.t.exe -I../include -I. %unit%-main.t.cpp %unit%.t.cpp && %unit%-main.t.exe - -endlocal & goto :EOF - -:: subroutines: - -:CompilerVersion version -echo off & setlocal enableextensions -set tmpprogram=_getcompilerversion.tmp -set tmpsource=%tmpprogram%.c - -echo #include ^ > %tmpsource% -echo int main(){printf("%%d.%%d.%%d\n",__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__);} >> %tmpsource% - -%gpp% -o %tmpprogram% %tmpsource% >nul -for /f %%x in ('%tmpprogram%') do set version=%%x -del %tmpprogram%.* >nul -endlocal & set %1=%version%& goto :EOF - -:: toupper; makes use of the fact that string -:: replacement (via SET) is not case sensitive -:toupper -for %%L IN (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO SET %1=!%1:%%L=%%L! -goto :EOF diff --git a/test/diskdrivertest.h b/test/diskdrivertest.h index 585f428..e0af4e0 100644 --- a/test/diskdrivertest.h +++ b/test/diskdrivertest.h @@ -3,10 +3,10 @@ #include "icsneo/disk/diskreaddriver.h" #include "icsneo/disk/diskwritedriver.h" -#include "icsneo/platform/optional.h" #include "gtest/gtest.h" #include #include +#include using namespace icsneo; @@ -17,7 +17,7 @@ class MockDiskDriver : public Disk::ReadDriver, public Disk::WriteDriver { public: std::pair getBlockSizeBounds() const override { return { 8, 256 }; } - optional readLogicalDiskAligned(Communication&, device_eventhandler_t, + std::optional readLogicalDiskAligned(Communication&, device_eventhandler_t, uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds) override { readCalls++; @@ -26,9 +26,9 @@ public: EXPECT_EQ(amount % getBlockSizeBounds().first, 0); if(pos > mockDisk.size()) // EOF - return nullopt; + return std::nullopt; - optional readAmount = std::min(amount, mockDisk.size() - pos); + std::optional readAmount = std::min(amount, mockDisk.size() - pos); if(readAmount > 0u) memcpy(into, mockDisk.data() + pos, static_cast(*readAmount)); @@ -39,7 +39,7 @@ public: return readAmount; } - optional writeLogicalDiskAligned(Communication&, device_eventhandler_t report, uint64_t pos, + std::optional writeLogicalDiskAligned(Communication&, device_eventhandler_t report, uint64_t pos, const uint8_t* atomicBuf, const uint8_t* from, uint64_t amount, std::chrono::milliseconds) override { writeCalls++; @@ -48,9 +48,9 @@ public: EXPECT_EQ(amount % getBlockSizeBounds().first, 0); if(pos > mockDisk.size()) // EOF - return nullopt; + return std::nullopt; - optional writeAmount = std::min(amount, mockDisk.size() - pos); + std::optional writeAmount = std::min(amount, mockDisk.size() - pos); if(writeAmount > 0u) { if(atomicBuf) { if(supportsAtomic) { @@ -107,15 +107,15 @@ protected: driver.reset(); } - optional readLogicalDisk(uint64_t pos, uint8_t* into, uint64_t amount) { + std::optional readLogicalDisk(uint64_t pos, uint8_t* into, uint64_t amount) { return driver->readLogicalDisk(*com, onError, pos, into, amount /* default timeout */); } - optional writeLogicalDisk(uint64_t pos, const uint8_t* from, uint64_t amount) { + std::optional writeLogicalDisk(uint64_t pos, const uint8_t* from, uint64_t amount) { return driver->writeLogicalDisk(*com, onError, *driver, pos, from, amount /* default timeout */); } - optional driver; + std::optional driver; std::queue< std::pair > expectedErrors; device_eventhandler_t onError; diff --git a/test/ethernetpacketizertest.cpp b/test/ethernetpacketizertest.cpp index 5e5a67b..364d76b 100644 --- a/test/ethernetpacketizertest.cpp +++ b/test/ethernetpacketizertest.cpp @@ -1,6 +1,6 @@ #include "icsneo/communication/ethernetpacketizer.h" -#include "icsneo/platform/optional.h" #include "gtest/gtest.h" +#include using namespace icsneo; @@ -27,7 +27,7 @@ protected: packetizer.reset(); } - optional packetizer; + std::optional packetizer; device_eventhandler_t onError; };