小编Mar*_*pel的帖子

constexpr 组合评估失败

我尝试constexpr将 ipv4 地址解析为四位数字,但它不起作用。所以我将代码精简到失败的地方:

#include <cstdint>
#include <stdexcept>
#include <string_view>

#define WORKS 1

static constexpr uint8_t
getIpVal(const std::string_view &sv) noexcept {

    size_t pos = 0;
    auto len = sv.size();
    unsigned long val = 0;

    while (sv[pos] >= '0' && sv[pos] <= '9' && pos < len) {
        int digit = sv[pos] - '0';
        val *= 10;
        val += digit;
        if (val > UINT8_MAX) {
            return 0;
            // throw std::invalid_argument(sv.data());
        }
        ++pos;
    }

    if (pos < len) {
            return 0; …
Run Code Online (Sandbox Code Playgroud)

c++ constexpr c++17

0
推荐指数
1
解决办法
94
查看次数

标签 统计

c++ ×1

c++17 ×1

constexpr ×1