#include "arg.ih"

bool Arg__::fillLongMap(LongOption const *begin, 
                      LongOption const *const end)
{
    for (; begin != end; ++begin)
    {
        d_longOpt = begin->d_name;

        // pair<iterator, bool> emplace(
            // first: an iterator to its element: first: key
            //                                   second: value
            // second: bool (true: OK)
        auto pair = d_longMap.emplace("--" + d_longOpt, begin);

        if (not pair.second)                     // element already defined
        {
            d_optionType = MULTI_LONG;
            return false;
        }

        if (                                    // optionChar not in d_optStr
            typeOf(pair.first) == AsCharOption 
            and
            d_optStr.find(d_nextChar = charOf(pair.first)) == string::npos
        )
        {
            
            d_optionType = NO_SHORTOPT;
            return false;
        }
    }

    return true;
}

