Repository: microsoft/terminal
File: src/cascadia/Remoting/Monarch.cpp (C++)

Code before:
                }
            }
            catch (...)
            {
                LOG_CAUGHT_EXCEPTION();
                // Normally, we'd just erase the peasant here. However, we can't
                // erase from the map while we're iterating over it like this.
                // Instead, pull a good ole Java and collect this id for removal
                // later.
                peasantsToErase.push_back(id);
            }
        }

        // Remove the dead peasants we came across while iterating.
        for (const auto& id : peasantsToErase)
        {
            // Remove the peasant from the list of peasants
            _peasants.erase(id);
            // Remove the peasant from the list of MRU windows. They're dead.
            // They can't be the MRU anymore.
            _clearOldMruEntries(id);
        }

        TraceLoggingWrite(g_hRemotingProvider,
                          "Monarch_lookupPeasantIdForName",
                          TraceLoggingWideString(winrt::hstring{ name }.c_str(), "name", "the name we're looking for"),
                          TraceLoggingUInt64(result, "peasantID", "the ID of the peasant with that name"),
                          TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE),
                          TraceLoggingKeyword(TIL_KEYWORD_TRACE));
        return result;
    }

    // Method Description:
    // - Handler for the `Peasant::WindowActivated` event. We'll make a in-proc
    //   copy of the WindowActivatedArgs from the peasant. That way, we won't
    //   need to worry about the origin process dying when working with the
    //   WindowActivatedArgs.
    // - If the peasant process dies while we're making this copy, then we'll
    //   just log it and do nothing. We certainly don't want to track a dead
    //   peasant.
    // - We'll pass that copy of the WindowActivatedArgs to
    //   _doHandleActivatePeasant, which will actually insert the
    //   WindowActivatedArgs into the list we're using to track the most recent
    //   peasants.
    // Arguments:
    // - args: the WindowActivatedArgs describing when and where the peasant was activated.
    // Return Value:
    // - <none>
    void Monarch::HandleActivatePeasant(const Remoting::WindowActivatedArgs& args)
    {
        // Start by making a local copy of these args. It's easier for us if our

Review comment (suggestion):
`std::wstring` would be a better fit and allow SSO.

Code after:
                }
            }
            catch (...)
            {
                LOG_CAUGHT_EXCEPTION();
                // Normally, we'd just erase the peasant here. However, we can't
                // erase from the map while we're iterating over it like this.
                // Instead, pull a good ole Java and collect this id for removal
                // later.
                peasantsToErase.push_back(id);
            }
        }

        // Remove the dead peasants we came across while iterating.
        for (const auto& id : peasantsToErase)
        {
            // Remove the peasant from the list of peasants
            _peasants.erase(id);
            // Remove the peasant from the list of MRU windows. They're dead.
            // They can't be the MRU anymore.
            _clearOldMruEntries(id);
        }

        TraceLoggingWrite(g_hRemotingProvider,
                          "Monarch_lookupPeasantIdForName",
                          TraceLoggingWideString(std::wstring{ name }.c_str(), "name", "the name we're looking for"),
                          TraceLoggingUInt64(result, "peasantID", "the ID of the peasant with that name"),
                          TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE),
                          TraceLoggingKeyword(TIL_KEYWORD_TRACE));
        return result;
    }

    // Method Description:
    // - Handler for the `Peasant::WindowActivated` event. We'll make a in-proc
    //   copy of the WindowActivatedArgs from the peasant. That way, we won't
    //   need to worry about the origin process dying when working with the
    //   WindowActivatedArgs.
    // - If the peasant process dies while we're making this copy, then we'll
    //   just log it and do nothing. We certainly don't want to track a dead
    //   peasant.
    // - We'll pass that copy of the WindowActivatedArgs to
    //   _doHandleActivatePeasant, which will actually insert the
    //   WindowActivatedArgs into the list we're using to track the most recent
    //   peasants.
    // Arguments:
    // - args: the WindowActivatedArgs describing when and where the peasant was activated.
    // Return Value:
    // - <none>
    void Monarch::HandleActivatePeasant(const Remoting::WindowActivatedArgs& args)
    {
        // Start by making a local copy of these args. It's easier for us if our