#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;
}

bool update(int& current, std::string_view text) {
    const auto candidate = parse_integer(text);
    if (!candidate) {
        return false;
    }
    current = *candidate;
    return true;
}

void show(std::string_view text) {
    int current{7};
    const bool accepted = update(current, text);
    std::cout << accepted << ' ' << current << '\n';
}

int main() {
    show("0");
    show("12x");
    show("1000001");
}
