I’m pretty new to C++ and kinda got thrown into it this semester. I really like understanding code rather than copying and praying, and my professor is hard to reach so I thought I’d ask here. This code is a temmplate was provided as an example to use Lambdas to index strings. ie. string “123” becomes unsigned int 123.
My issue is the main for loop, the line starting with ‘lIndex’. I understand the second half of this line where the number character ‘aKey[i]’ is subtracted by ‘0’s ASCII code to produce the ASCII code of the decimal version of the number. However, I can’t wrap my head around why lIndex keeps accumulating and multiplying by ten. This is probably silly and I’ve been programming too long today, but thank you if you answer!

template<typename T, size_t N = 20>
class StringIndexerLambda
{

private:
    BasicIndexer<T, N> fElements;
public:

    T& operator[](const std::string& aKey) { return item(aKey); }

    T& item(const std::string& aKey,
        std::function<size_t(const std::string&)> aMap = [](const std::string& aKey)
        {
            size_t lIndex = 0;

            for (size_t i = 0; i < aKey.size(); i++) {
                lIndex = lIndex * 10 + (static_cast<size_t>(aKey[i]) - '0'); }

                    return lIndex;
            })
                {
                    size_t lIndex = aMap(aKey);

                    assert(lIndex < fElements.size());

                    return fElements[lIndex];
                }
        };