#include <charconv>
#include <iostream>
#include <optional>
#include <string_view>
#include <system_error>

std::optional<int> parse_integer(std::string_view text) {
    if (text.empty()) {
        return std::nullopt;
    }
    int value{};
    const auto [end, error] =
        std::from_chars(text.data(), text.data() + text.size(), value);
    if (error != std::errc{} || end != text.data() + text.size()) {
        return std::nullopt;
    }
    if (value < -1000000 || value > 1000000) {
        return std::nullopt;
    }
    return value;
}

void show(std::string_view text) {
    const auto result = parse_integer(text);
    if (result) {
        std::cout << "value " << *result << '\n';
    } else {
        std::cout << "invalid\n";
    }
}

int main() {
    show("0");
    show("12");
    show("12x");
    show("");
    show("-1000000");
    show("1000001");
    show("3x");
    show("9999999999999999999999999999999999999999");
}
