From 7b8f62e45063ea0e06864eaf8f39b0963215357a Mon Sep 17 00:00:00 2001 From: HOHOHO Date: Thu, 29 Nov 2018 17:31:38 +0100 Subject: [PATCH 01/17] small beautifies --- src/SPI/mcp2210_hal.cpp | 70 ++++++++++++++++++++------------------- src/SPI/mcp2210_hal.h | 73 ++++++++++++++++++++++++++--------------- 2 files changed, 82 insertions(+), 61 deletions(-) diff --git a/src/SPI/mcp2210_hal.cpp b/src/SPI/mcp2210_hal.cpp index 96ebddc..f662ba7 100644 --- a/src/SPI/mcp2210_hal.cpp +++ b/src/SPI/mcp2210_hal.cpp @@ -3,11 +3,9 @@ MCP2210::MCP2210() { try { logger = spdlog::basic_logger_mt("mcplogger", "mcp_log.txt"); - } catch(const spdlog::spdlog_ex &ex) { + } catch (const spdlog::spdlog_ex &ex) { std::cerr << "could not create logger: " << ex.what() << std::endl; } - - //tut: http://www.signal11.us/oss/udev/ connect(); } @@ -19,18 +17,20 @@ MCP2210::~MCP2210() { std::unique_ptr MCP2210::transfer(const spi::Data &input) { auto tmp = input.create(); if (*connection) { + uint16_t i = 0; - for(auto data : input) { - txdata[i] = data; - i++; - } + + for (auto data : input) { + txdata[i] = data; + i++; + } + int32_t error = send(static_cast(i)); - for(i = 0; i < input.bytesUsed();i++){ - (*tmp)[i] = rxdata[i]; - } - if (error != ERR_NOERR) { - exceptionHandling(error); + + for (i = 0; i < input.bytesUsed(); i++) { + (*tmp)[i] = rxdata[i]; } + exceptionHandling(error); } return tmp; } @@ -51,50 +51,51 @@ void MCP2210::setGPIODirection(const gpio::gpioDirection &direction, const gpio: } } -void MCP2210::slaveSelect(const std::shared_ptr& slave) { - auto& pin = slave->getSlavePin(); - if((bool)pin) +void MCP2210::slaveSelect(const std::shared_ptr &slave) { + auto &pin = slave->getSlavePin(); + if ((bool) pin) writeGPIO(gpio::gpioState::off, pin); else { } } -void MCP2210::slaveDeselect(const std::shared_ptr& slave) { +void MCP2210::slaveDeselect(const std::shared_ptr &slave) { writeGPIO(gpio::gpioState::on, slave->getSlavePin()); } -void MCP2210::slaveRegister(const std::shared_ptr& device, const gpio::GPIOPin &pin) { +void MCP2210::slaveRegister(const std::shared_ptr &device, const gpio::GPIOPin &pin) { device->selectPin(pin); } gpio::gpioState MCP2210::readGPIO(const gpio::GPIOPin &pin) const { int val = 0; exceptionHandling(gpio_read(fd, &val, static_cast(pin))); - auto erg = val == static_cast(pin) ? gpio::gpioState::on : gpio::gpioState::off; // cannot be null it would cause an exception + auto erg = val == static_cast(pin) ? gpio::gpioState::on + : gpio::gpioState::off; // cannot be null it would cause an exception return erg; } -int32_t MCP2210::send(const uint16_t &dataCount) { - return spi_data_xfer(fd, txdata.data() , rxdata.data() , dataCount, - static_cast(settings.mode), settings.speed, settings.actcsval, settings.idlecsval, settings.gpcsmask, +int32_t MCP2210::send(const uint16_t byteCount) { + return spi_data_xfer(fd, txdata.data(), rxdata.data(), byteCount, + static_cast(settings.mode), settings.speed, settings.actcsval, settings.idlecsval, + settings.gpcsmask, settings.cs2datadly, settings.data2datadly, settings.data2csdly); } std::vector> -MCP2210::transfer(const std::initializer_list>& spiData) { +MCP2210::transfer(const std::initializer_list> &spiData) { if (*connection) { uint16_t i = 0; - for (const auto& elem: spiData) { + for (const auto &elem: spiData) { if (i >= SPI_BUF_LEN) break; auto spicontainer = elem.get(); - for(uint8_t data : *spicontainer) { + for (uint8_t data : *spicontainer) { txdata[i] = data; i++; } } - int32_t error = send(static_cast(i)); - if (error != ERR_NOERR) exceptionHandling(error); + exceptionHandling(send(static_cast(i))); std::vector> dataOut = std::vector>(i); for (i = 0; i < spiData.size(); i++) { if (i >= SPI_BUF_LEN) throw MCPIOException{}; @@ -138,8 +139,9 @@ void MCP2210::connect() { } if (std::string(udev_device_get_sysattr_value(dev, "idVendor")) == - std::string(deviceinformations::vendor_ID) && - std::string(udev_device_get_sysattr_value(dev, "idProduct")) == std::string(deviceinformations::device_ID)){ + std::string(deviceinformations::vendor_ID) && + std::string(udev_device_get_sysattr_value(dev, "idProduct")) == + std::string(deviceinformations::device_ID)) { fd = open_device(npath); std::cout << "device found: " << std::endl; printf(" VID/PID: %s %s\n", @@ -165,7 +167,7 @@ void MCP2210::connect() { *connection = true; } } else { - std::wcerr << "device is already connected" << std::endl; + std::cerr << "device is already connected" << std::endl; } } @@ -174,7 +176,7 @@ MCP2210::operator bool() { return *connection; } -void MCP2210::exceptionHandling(int32_t errorCode) const{ +void MCP2210::exceptionHandling(int32_t errorCode) const { switch (-errorCode) { case (ERR_NOERR) : return; @@ -210,12 +212,12 @@ void MCP2210::exceptionHandling(int32_t errorCode) const{ } case (130): { std::cout << " Get SPI Settings Error " << std::endl; - logger->log(spdlog::level::err, ( " Get SPI Settings Error " )); + logger->log(spdlog::level::err, (" Get SPI Settings Error ")); break; } case (140): { std::cout << " set SPI Settings Error " << std::endl; - logger->log(spdlog::level::err, ( " set SPI Settings Error " )); + logger->log(spdlog::level::err, (" set SPI Settings Error ")); break; } case (150): { @@ -247,7 +249,7 @@ void MCP2210::exceptionHandling(int32_t errorCode) const{ return; } } - *connection=false; + *connection = false; close_device(fd); std::cerr << "device disconnected" << std::endl; } @@ -256,6 +258,6 @@ MCP2210::spiSettings MCP2210::getSettings() const { return settings; } -void MCP2210::setSettings(const MCP2210::spiSettings& settings) { +void MCP2210::setSettings(const MCP2210::spiSettings &settings) { MCP2210::settings = settings; } \ No newline at end of file diff --git a/src/SPI/mcp2210_hal.h b/src/SPI/mcp2210_hal.h index 9956d6f..1849150 100644 --- a/src/SPI/mcp2210_hal.h +++ b/src/SPI/mcp2210_hal.h @@ -1,4 +1,5 @@ #pragma once + #include #include #include @@ -13,11 +14,12 @@ //#include "USB/LibUSBDevices.h" struct MCPIOException : public std::exception { - const char* what() const noexcept override { + const char *what() const noexcept override { return "MCPIOException"; }; }; -using error_pair = std::pair; + +using error_pair = std::pair; namespace deviceinformations { @@ -25,23 +27,23 @@ namespace deviceinformations { inline static constexpr const char *device_ID = "00de"; } -class MCP2210 final : public spi::SPIBridge, public gpio::GPIOBridge{ +class MCP2210 final : public spi::SPIBridge, public gpio::GPIOBridge { public: - enum class spiMode : uint16_t{ + enum class spiMode : uint16_t { mode0 = 0, //clock polarity = 0 clock phase = 0 mode1 = 1, //clock polarity = 0 clock phase = 1 mode2 = 2, //clock polarity = 1 clock phase = 0 mode3 = 3 //clock polarity = 1 clock phase = 1 }; - struct spiSettings { - spiMode mode = spiMode::mode0; - uint16_t speed = 20000, //bits per second - actcsval = 0xFFEF, //active chip select value - idlecsval = 0xFFFF, //idle chip select value - gpcsmask = 0x0010, //general purpose chip select? - cs2datadly = 0, //chip select to data delay - data2datadly = 0, // delay between subsequent data bytes - data2csdly = 0; // last data byte to chip select delay + struct spiSettings { + spiMode mode = spiMode::mode0; + uint16_t speed = 20000, //bits per second + actcsval = 0xFFEF, //active chip select value + idlecsval = 0xFFFF, //idle chip select value + gpcsmask = 0x0010, //general purpose chip select? + cs2datadly = 0, //chip select to data delay + data2datadly = 0, // delay between subsequent data bytes + data2csdly = 0; // last data byte to chip select delay }; private: const char *npath = nullptr; @@ -49,34 +51,51 @@ class MCP2210 final : public spi::SPIBridge, public gpio::GPIOBridge{ struct udev *udev; struct udev_enumerate *enumerate; struct udev_list_entry *devices, *dev_list_entry; - struct udev_device* dev; + struct udev_device *dev; spiSettings settings; std::unique_ptr connection = std::make_unique(false); static constexpr int SPI_BUF_LEN = 1024; - std::array txdata{}, rxdata{}; + std::array txdata{}, rxdata{}; int fd = -1; - int32_t send(const uint16_t& dataCount); + int32_t send(const uint16_t dataCount); public: static constexpr gpio::GPIOPin - pin0 = gpio::GPIOPin(1<<0), pin1 = gpio::GPIOPin(1<<1), pin2 = gpio::GPIOPin(1<<2), pin3 = gpio::GPIOPin(1<<3), - pin4 = gpio::GPIOPin(1<<4), pin5 = gpio::GPIOPin(1<<6), pin6 = gpio::GPIOPin(1<<6), pin7 = gpio::GPIOPin(1<<7); + pin0 = gpio::GPIOPin(1 << 0), pin1 = gpio::GPIOPin(1 << 1), pin2 = gpio::GPIOPin( + 1 << 2), pin3 = gpio::GPIOPin(1 << 3), + pin4 = gpio::GPIOPin(1 << 4), pin5 = gpio::GPIOPin(1 << 6), pin6 = gpio::GPIOPin( + 1 << 6), pin7 = gpio::GPIOPin(1 << 7); spiSettings getSettings() const; - void setSettings(const spiSettings& settings); + + void setSettings(const spiSettings &settings); + explicit MCP2210(); + ~MCP2210() override; - std::unique_ptr transfer(const spi::Data& input) override; - std::vector> transfer(const std::initializer_list>& spiData) override; - void setGPIODirection(const gpio::gpioDirection& direction, const gpio::GPIOPin& pin) override; - void writeGPIO(const gpio::gpioState& state, const gpio::GPIOPin& pin) override; - gpio::gpioState readGPIO(const gpio::GPIOPin& pin) const override; - void slaveSelect(const std::shared_ptr& slave) override; - void slaveDeselect(const std::shared_ptr& slave) override; - void slaveRegister(const std::shared_ptr& device, const gpio::GPIOPin& pin) override; + + std::unique_ptr transfer(const spi::Data &input) override; + + std::vector> + transfer(const std::initializer_list> &spiData) override; + + void setGPIODirection(const gpio::gpioDirection &direction, const gpio::GPIOPin &pin) override; + + void writeGPIO(const gpio::gpioState &state, const gpio::GPIOPin &pin) override; + + gpio::gpioState readGPIO(const gpio::GPIOPin &pin) const override; + + void slaveSelect(const std::shared_ptr &slave) override; + + void slaveDeselect(const std::shared_ptr &slave) override; + + void slaveRegister(const std::shared_ptr &device, const gpio::GPIOPin &pin) override; + void exceptionHandling(int32_t errorCode) const; + operator bool(); + void connect(); }; \ No newline at end of file From f757147c59043eb51b04ea1b664ade19c7f9518a Mon Sep 17 00:00:00 2001 From: HOHOHO Date: Tue, 11 Dec 2018 14:37:57 +0100 Subject: [PATCH 02/17] removed compiler warning unused parameter --- src/Devices/A4963/A4963.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Devices/A4963/A4963.h b/src/Devices/A4963/A4963.h index 144cf32..3bb2b7c 100644 --- a/src/Devices/A4963/A4963.h +++ b/src/Devices/A4963/A4963.h @@ -149,7 +149,8 @@ namespace NS_A4963 { template<> inline uint16_t A4963::getRuntime(A4963RegisterNames name){ - return A4963::getRegisterEntry(RegisterValues::code,RegisterValues::mask); + if(static_cast(name) > 0){}; + return A4963::getRegisterEntry(RegisterValues::code,RegisterValues::mask); } template< A4963RegisterNames toSet> From 0976a21bb81e7df977cfecbe97bf0de927e64b43 Mon Sep 17 00:00:00 2001 From: HOHOHO Date: Tue, 11 Dec 2018 14:45:13 +0100 Subject: [PATCH 03/17] . --- src/Devices/A4963/A4963.h | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Devices/A4963/A4963.h b/src/Devices/A4963/A4963.h index 3bb2b7c..de3079d 100644 --- a/src/Devices/A4963/A4963.h +++ b/src/Devices/A4963/A4963.h @@ -140,19 +140,17 @@ namespace NS_A4963 { template(0)> uint16_t A4963::getRuntime(A4963RegisterNames name){ - if (toGet == name){ - return getRegisterEntry(RegisterValues::code,RegisterValues::mask); + if constexpr(static_cast(toGet) >= static_cast(A4963RegisterNames::Run)){ + return A4963::getRegisterEntry(RegisterValues::code,RegisterValues::mask); } else { - return getRuntime(static_cast(toGet)+1)>(name); + if (toGet == name) { + return getRegisterEntry(RegisterValues::code, RegisterValues::mask); + } else { + return getRuntime(static_cast(toGet) + 1)>(name); + } } } - template<> - inline uint16_t A4963::getRuntime(A4963RegisterNames name){ - if(static_cast(name) > 0){}; - return A4963::getRegisterEntry(RegisterValues::code,RegisterValues::mask); - } - template< A4963RegisterNames toSet> struct possibleValues { static_assert(!RegisterValues::isRanged, "here is no checked type allowed"); From c60e1a37294ae34e17a8afd9b9a8326e60bb4002 Mon Sep 17 00:00:00 2001 From: Unknown <19Sebastian95@gmx.de> Date: Mon, 24 Dec 2018 22:44:30 +0100 Subject: [PATCH 04/17] more [[nodiscard]] constexpr ... noexcept --- src/CustomDataTypes/SIUnit.h | 2 +- src/SPI/SPIDevice.cpp | 7 ------- src/SPI/SPIDevice.h | 8 ++++++-- src/SPI/mcp2210_hal.cpp | 2 +- src/USB/HIDevice.h | 30 +++++++++++++++--------------- src/USB/LibUSBDevices.cpp | 4 ++-- src/USB/LibUSBDevices.h | 2 +- src/USB/USBUtils.cpp | 4 ---- src/USB/USBUtils.h | 5 ++++- src/utils/RatioLookup.h | 2 +- src/utils/scales/UnitScale.h | 8 ++++---- src/utils/utils.h | 28 ++++++++++++++-------------- 12 files changed, 49 insertions(+), 53 deletions(-) diff --git a/src/CustomDataTypes/SIUnit.h b/src/CustomDataTypes/SIUnit.h index 8c57ed3..07a550c 100644 --- a/src/CustomDataTypes/SIUnit.h +++ b/src/CustomDataTypes/SIUnit.h @@ -40,7 +40,7 @@ namespace CustomDataTypes { return derived_this(); } - constexpr Rep count() const { return internalRepresentation; } + [[nodiscard]] constexpr Rep count() const noexcept { return internalRepresentation; } constexpr Derived operator+() const { return derived_this(); diff --git a/src/SPI/SPIDevice.cpp b/src/SPI/SPIDevice.cpp index c9ca6f9..9415932 100644 --- a/src/SPI/SPIDevice.cpp +++ b/src/SPI/SPIDevice.cpp @@ -4,10 +4,3 @@ #include "SPIDevice.h" -const gpio::GPIOPin &SPIDevice::getSlavePin() const{ - return slavePin; -} - -void SPIDevice::selectPin(const gpio::GPIOPin &pin){ - slavePin = pin; -} diff --git a/src/SPI/SPIDevice.h b/src/SPI/SPIDevice.h index ed91612..98bb624 100644 --- a/src/SPI/SPIDevice.h +++ b/src/SPI/SPIDevice.h @@ -11,7 +11,11 @@ class SPIDevice : public std::enable_shared_from_this { private: gpio::GPIOPin slavePin; public: - void selectPin(const gpio::GPIOPin& pin); - const gpio::GPIOPin& getSlavePin() const; + constexpr void selectPin(const gpio::GPIOPin& pin) noexcept { + slavePin = pin; + } + [[nodiscard]] constexpr gpio::GPIOPin getSlavePin() const noexcept { + return slavePin; + } }; diff --git a/src/SPI/mcp2210_hal.cpp b/src/SPI/mcp2210_hal.cpp index 96ebddc..3baccaa 100644 --- a/src/SPI/mcp2210_hal.cpp +++ b/src/SPI/mcp2210_hal.cpp @@ -52,7 +52,7 @@ void MCP2210::setGPIODirection(const gpio::gpioDirection &direction, const gpio: } void MCP2210::slaveSelect(const std::shared_ptr& slave) { - auto& pin = slave->getSlavePin(); + auto pin = slave->getSlavePin(); if((bool)pin) writeGPIO(gpio::gpioState::off, pin); else { diff --git a/src/USB/HIDevice.h b/src/USB/HIDevice.h index 8c3589e..088b6a1 100644 --- a/src/USB/HIDevice.h +++ b/src/USB/HIDevice.h @@ -15,31 +15,31 @@ namespace usb { private: //(source: http://janaxelson.com/code/generic_hid.c) - static const int CONTROL_REQUEST_TYPE_IN = + static constexpr int CONTROL_REQUEST_TYPE_IN = LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE; - static const int CONTROL_REQUEST_TYPE_OUT = + static constexpr int CONTROL_REQUEST_TYPE_OUT = LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE; - static const int INTERRUPT_IN_ENDPOINT = 0x81; - static const int INTERRUPT_OUT_ENDPOINT = 0x01; + static constexpr int INTERRUPT_IN_ENDPOINT = 0x81; + static constexpr int INTERRUPT_OUT_ENDPOINT = 0x01; - static const int MAX_INTERRUPT_IN_TRANSFER_SIZE = 8; - static const int MAX_INTERRUPT_OUT_TRANSFER_SIZE = 8; + static constexpr int MAX_INTERRUPT_IN_TRANSFER_SIZE = 8; + static constexpr int MAX_INTERRUPT_OUT_TRANSFER_SIZE = 8; // From the HID spec: - static const int HID_GET_REPORT = 0x01; - static const int HID_SET_REPORT = 0x09; - static const int HID_REPORT_TYPE_INPUT = 0x01; - static const int HID_REPORT_TYPE_OUTPUT = 0x02; - static const int HID_REPORT_TYPE_FEATURE = 0x03; + static constexpr int HID_GET_REPORT = 0x01; + static constexpr int HID_SET_REPORT = 0x09; + static constexpr int HID_REPORT_TYPE_INPUT = 0x01; + static constexpr int HID_REPORT_TYPE_OUTPUT = 0x02; + static constexpr int HID_REPORT_TYPE_FEATURE = 0x03; // With firmware support, transfers can be > the endpoint's max packet size. - static const int MAX_CONTROL_IN_TRANSFER_SIZE = 8; - static const int MAX_CONTROL_OUT_TRANSFER_SIZE = 8; + static constexpr int MAX_CONTROL_IN_TRANSFER_SIZE = 8; + static constexpr int MAX_CONTROL_OUT_TRANSFER_SIZE = 8; - static const int INTERFACE_NUMBER = 0; - static const int TIMEOUT_MS = 5000; + static constexpr int INTERFACE_NUMBER = 0; + static constexpr int TIMEOUT_MS = 5000; }; } diff --git a/src/USB/LibUSBDevices.cpp b/src/USB/LibUSBDevices.cpp index 057c51a..1af32a4 100644 --- a/src/USB/LibUSBDevices.cpp +++ b/src/USB/LibUSBDevices.cpp @@ -44,8 +44,8 @@ namespace usb { return mDevices; }*/ - const std::optional> - LibUSBDeviceList::findDevice(const VendorID& vendorID, const DeviceID& deviceID) { + [[nodiscard]] const std::optional> + LibUSBDeviceList::findDevice(const VendorID& vendorID, const DeviceID& deviceID) noexcept { for (std::pair> &device : mDevices) { if (device.second->getDeviceID() == deviceID && device.second->getVendorID() == vendorID) { return device.second; diff --git a/src/USB/LibUSBDevices.h b/src/USB/LibUSBDevices.h index 6760c51..45b3dd9 100644 --- a/src/USB/LibUSBDevices.h +++ b/src/USB/LibUSBDevices.h @@ -20,7 +20,7 @@ namespace usb { virtual ~LibUSBDeviceList(); size_t size(); - const std::optional> findDevice(const VendorID& vendorID, const DeviceID& deviceID); + [[nodiscard]] const std::optional> findDevice(const VendorID& vendorID, const DeviceID& deviceID) noexcept; private: libusb_context *context = nullptr; diff --git a/src/USB/USBUtils.cpp b/src/USB/USBUtils.cpp index 545255e..b5e920c 100644 --- a/src/USB/USBUtils.cpp +++ b/src/USB/USBUtils.cpp @@ -20,10 +20,6 @@ namespace usb { VendorID::VendorID(uint16_t vendorID) noexcept : vendorID(vendorID) {} - uint16_t VendorID::getVendorID() const { - return vendorID; - } - bool VendorID::operator==(const VendorID &rhs) const { return vendorID == rhs.vendorID; } diff --git a/src/USB/USBUtils.h b/src/USB/USBUtils.h index a6b726a..8e2cad6 100644 --- a/src/USB/USBUtils.h +++ b/src/USB/USBUtils.h @@ -26,10 +26,13 @@ namespace usb { class VendorID { public: explicit VendorID(uint16_t vendorID) noexcept; - uint16_t getVendorID() const; bool operator==(const VendorID &rhs) const; bool operator!=(const VendorID &rhs) const; + [[nodiscard]] constexpr uint16_t getVendorID() const noexcept { + return vendorID; + } + private: uint16_t vendorID; }; diff --git a/src/utils/RatioLookup.h b/src/utils/RatioLookup.h index 25f9ec9..d63cc75 100644 --- a/src/utils/RatioLookup.h +++ b/src/utils/RatioLookup.h @@ -114,7 +114,7 @@ namespace utils { static constexpr std::string_view value = "exa"; }; - constexpr std::pair getRatio(const char prefix) { + [[nodiscard]] constexpr std::pair getRatio(const char prefix) { switch (prefix) { case 'a': return {1, 1000000000000000000}; diff --git a/src/utils/scales/UnitScale.h b/src/utils/scales/UnitScale.h index 90ced33..2525560 100644 --- a/src/utils/scales/UnitScale.h +++ b/src/utils/scales/UnitScale.h @@ -43,7 +43,7 @@ class NewUnitScale { const const_iterator end() const { return const_iterator(inverse_functor(max)+stepsize); } template - constexpr std::optional convertValue(const T& value) const { + [[nodiscard]] constexpr std::optional convertValue(const T& value) const noexcept { using namespace utils::printable; //TODO: round value up/down if(utils::approximately_greater_or_equal(value, min) && @@ -69,16 +69,16 @@ class NewUnitScale { } } - constexpr non_ref_type getActualValue(TValueType value) const { + [[nodiscard]] constexpr non_ref_type getActualValue(TValueType value) const noexcept { return non_ref_type{functor(value)}; } - constexpr non_ref_type getMaxValue() const { + [[nodiscard]] constexpr non_ref_type getMaxValue() const noexcept { return max; } - constexpr non_ref_type getMinValue() const { + [[nodiscard]] constexpr non_ref_type getMinValue() const noexcept { return min; } }; diff --git a/src/utils/utils.h b/src/utils/utils.h index 3da1539..d1dadea 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -13,7 +13,7 @@ namespace utils { template - constexpr typename std::make_unsigned::type getFirstSetBitPos(T n) { + [[nodiscard]] constexpr typename std::make_unsigned::type getFirstSetBitPos(T n) noexcept { static_assert(std::numeric_limits::is_integer); return std::log2(n&-n); } @@ -247,7 +247,7 @@ namespace utils { }; template - constexpr bool sameTypes() { + [[nodiscard]] constexpr bool sameTypes() noexcept { if constexpr(sizeof...(T) == 0) return true; else { @@ -301,7 +301,7 @@ namespace utils { struct is_template_same, T> : std::true_type {}; template - inline constexpr bool is_template_same_v = is_template_same::value; + constexpr bool is_template_same_v = is_template_same::value; template struct periodic_printable; @@ -321,19 +321,19 @@ namespace utils { typedef std::remove_cv_t> type; }; - constexpr bool approximately_same(long a, long b) + [[nodiscard]] constexpr auto approximately_same(long a, long b) noexcept { return a == b; } template>> - bool approximately_same(T a, T b) + [[nodiscard]] constexpr bool approximately_same(T a, T b) noexcept { return std::fabs(a - b) <= 1E-13; } template