Repository: microsoft/terminal
File: src/cascadia/TerminalApp/TerminalPage.cpp (C++)

Code before:
                this->_SplitPane(SplitDirection::Automatic,
                                 0.5f,
                                 newPane);
            }
            else
            {
                _CreateNewTabFromPane(newPane);
            }
        }
    }

    winrt::fire_and_forget TerminalPage::_RemoveOnCloseRoutine(Microsoft::UI::Xaml::Controls::TabViewItem tabViewItem, winrt::com_ptr<TerminalPage> page)
    {
        co_await wil::resume_foreground(page->_tabView.Dispatcher());

        if (auto tab{ _GetTabByTabViewItem(tabViewItem) })
        {
            _RemoveTab(tab);
        }
    }

    // Method Description:
    // - Creates a new connection based on the profile settings
    // Arguments:
    // - the profile we want the settings from
    // - the terminal settings
    // Return value:
    // - the desired connection
    TerminalConnection::ITerminalConnection TerminalPage::_CreateConnectionFromSettings(Profile profile,
                                                                                        TerminalSettings settings,
                                                                                        const bool inheritCursor)
    {
        TerminalConnection::ITerminalConnection connection{ nullptr };

        auto connectionType = profile.ConnectionType();
        winrt::guid sessionGuid{};

        if (connectionType == TerminalConnection::AzureConnection::ConnectionType() &&
            TerminalConnection::AzureConnection::IsAzureConnectionAvailable())
        {
            std::filesystem::path azBridgePath{ wil::GetModuleFileNameW<std::wstring>(nullptr) };
            azBridgePath.replace_filename(L"TerminalAzBridge.exe");
            if constexpr (Feature_AzureConnectionInProc::IsEnabled())
            {
                connection = TerminalConnection::AzureConnection{};
            }
            else
            {
                connection = TerminalConnection::ConptyConnection{};
            }


Review comment (suggestion):
`winrt::hstring` is implicitly convertible to `std::wstring_view`, so there's no need for explicit casts like this most of the time. It just doesn't work for something like `std::filesystem::path::operator/=`, because C++ wouldn't know which of the 31 overloads to call, given a `hstring`.

Also, when cppwinrt generates `String` parameters for functions, it'll not use `winrt::hstring` but `winrt::param::hstring` which binds to almost any string type, include `std::wstring`, without making any extra copies on the heap. We can thus just return a `std::wstring` from this function and it'll work without any additional modifications.

Code after:
            {
                this->_SplitPane(SplitDirection::Automatic,
                                 0.5f,
                                 newPane);
            }
            else
            {
                _CreateNewTabFromPane(newPane);
            }
        }
    }

    winrt::fire_and_forget TerminalPage::_RemoveOnCloseRoutine(Microsoft::UI::Xaml::Controls::TabViewItem tabViewItem, winrt::com_ptr<TerminalPage> page)
    {
        co_await wil::resume_foreground(page->_tabView.Dispatcher());

        if (auto tab{ _GetTabByTabViewItem(tabViewItem) })
        {
            _RemoveTab(tab);
        }
    }

    std::wstring TerminalPage::_evaluatePathForCwd(const std::wstring_view path)
    {
        return Utils::EvaluateStartingDirectory(_WindowProperties.VirtualWorkingDirectory(), path);
    }

    // Method Description:
    // - Creates a new connection based on the profile settings
    // Arguments:
    // - the profile we want the settings from
    // - the terminal settings
    // Return value:
    // - the desired connection
    TerminalConnection::ITerminalConnection TerminalPage::_CreateConnectionFromSettings(Profile profile,
                                                                                        TerminalSettings settings,
                                                                                        const bool inheritCursor)
    {
        TerminalConnection::ITerminalConnection connection{ nullptr };

        auto connectionType = profile.ConnectionType();
        winrt::guid sessionGuid{};

        if (connectionType == TerminalConnection::AzureConnection::ConnectionType() &&
            TerminalConnection::AzureConnection::IsAzureConnectionAvailable())
        {
            std::filesystem::path azBridgePath{ wil::GetModuleFileNameW<std::wstring>(nullptr) };
            azBridgePath.replace_filename(L"TerminalAzBridge.exe");
            if constexpr (Feature_AzureConnectionInProc::IsEnabled())
            {
                connection = TerminalConnection::AzureConnection{};