const TOpt* TOpts::FindCharOption(char c) const {
    for (TOptsVector::const_iterator it = Opts_.begin(); it != Opts_.end(); ++it) {
        const TOpt* opt = it->Get();
        if (IsIn(opt->GetShortNames(), c))
            return opt;
    }
    return 0;
}
bool TOpts::HasAnyLongOption() const {
    for (TOptsVector::const_iterator it = Opts_.begin(); it != Opts_.end(); ++it) {
        TOpt* opt = it->Get();
        if (!opt->GetLongNames().empty())
            return true;
    }
    return false;
}
const TOpt* TOpts::FindLongOption(const TStringBuf& name) const {
    for (TOptsVector::const_iterator it = Opts_.begin(); it != Opts_.end(); ++it) {
        const TOpt* opt = it->Get();
        if (IsIn(opt->GetLongNames(), name))
            return opt;
    }
    return 0;
}
void TOpts::Validate() const {
    for (TOptsVector::const_iterator i = Opts_.begin(); i != Opts_.end(); ++i) {
        TOpt* opt = i->Get();
        const TOpt::TShortNames& shortNames = opt->GetShortNames();
        for (auto c : shortNames) {
            for (TOptsVector::const_iterator j = i + 1; j != Opts_.end(); ++j) {
                TOpt* nextOpt = j->Get();
                if (nextOpt->CharIs(c))
                    ythrow TConfException() << "option "
                    << NPrivate::OptToString(c)
                    << " is defined more than once";
            }
        }
        const TOpt::TLongNames& longNames = opt->GetLongNames();
        for (const auto& longName : longNames) {
            for (TOptsVector::const_iterator j = i + 1; j != Opts_.end(); ++j) {
                TOpt* nextOpt = j->Get();
                if (nextOpt->NameIs(longName))
                    ythrow TConfException() << "option "
                    << NPrivate::OptToString(longName)
                    << " is defined more than once";
            }
        }
    }
    if (FreeArgsMax_ < FreeArgsMin_) {
        ythrow TConfException() << "FreeArgsMax must be >= FreeArgsMin";
    }
    if (!FreeArgSpecs_.empty() && FreeArgSpecs_.rbegin()->first >= FreeArgsMax_) {
        ythrow TConfException() << "Described args count is greater than FreeArgsMax. Either increase FreeArgsMax or remove unreachable descriptions";
    }
}