#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 parsed =
        std::from_chars(text.data(), text.data() + text.size(), value);
    if (parsed.ec != std::errc{}) {
        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("12x");
    show("12");
}
