Repository: microsoft/terminal
File: src/cascadia/TerminalSettingsEditor/LaunchViewModel.cpp (C++)

Code before:
    }

    winrt::hstring LaunchViewModel::LaunchParametersCurrentValue()
    {
        // todo: get all the current values and combine them into a string
        const auto launchModeString = CurrentLaunchMode().as<EnumEntry>()->EnumName();
        const auto centerOnLaunchString = CenterOnLaunch() ? RS_(L"Globals_CenterOnLaunchOn") : RS_(L"Globals_CenterOnLaunchOff");

        winrt::hstring result;

        if (UseDefaultLaunchPosition())
        {
            result = fmt::format(L"{}, {}, {}", launchModeString, RS_(L"Globals_LaunchModeDefault/Content"), centerOnLaunchString);
        }
        else
        {
            std::wstring xPosString;
            std::wstring yPosString;
            if (!isnan(InitialPosX()))
            {
                xPosString = std::to_wstring(gsl::narrow_cast<int>(InitialPosX()));
            }
            else
            {
                xPosString = RS_(L"Globals_LaunchModeDefault/Content");
            }
            if (!isnan(InitialPosY()))
            {
                yPosString = std::to_wstring(gsl::narrow_cast<int>(InitialPosY()));
            }
            else
            {
                yPosString = RS_(L"Globals_LaunchModeDefault/Content");
            }
            result = fmt::format(L"{}, ({},{}), {}", launchModeString, xPosString, yPosString, centerOnLaunchString);
        }
        return result;
    }

    double LaunchViewModel::InitialPosX()
    {
        const auto x = _Settings.GlobalSettings().InitialPosition().X;
        // If there's no value here, return NAN - XAML will ignore it and
        // put the placeholder text in the box instead
        auto xCoord = x.try_as<int64_t>();
        return xCoord.has_value() ? gsl::narrow_cast<double>(xCoord.value()) : NAN;
    }

    double LaunchViewModel::InitialPosY()
    {
        const auto y = _Settings.GlobalSettings().InitialPosition().Y;

Review comment (suggestion):
```suggestion
                xPosString = isnan(InitialPosX()) ? RS_(L"Globals_LaunchModeDefault/Content") : std::to_wstring(gsl::narrow_cast<int>(InitialPosX()));
```
You can really cut down on code if you use the ternary operator here (and similarly with `InitialPosY`)

Code after:
    }

    winrt::hstring LaunchViewModel::LaunchParametersCurrentValue()
    {
        const auto launchModeString = CurrentLaunchMode().as<EnumEntry>()->EnumName();
        const auto centerOnLaunchString = CenterOnLaunch() ? RS_(L"Globals_CenterOnLaunchOn") : RS_(L"Globals_CenterOnLaunchOff");

        winrt::hstring result;

        if (UseDefaultLaunchPosition())
        {
            result = fmt::format(L"{}, {}, {}", launchModeString, RS_(L"Globals_LaunchModeDefault/Content"), centerOnLaunchString);
        }
        else
        {
            const std::wstring xPosString = isnan(InitialPosX()) ? RS_(L"Globals_LaunchModeDefault/Content").c_str() : std::to_wstring(gsl::narrow_cast<int>(InitialPosX()));
            const std::wstring yPosString = isnan(InitialPosY()) ? RS_(L"Globals_LaunchModeDefault/Content").c_str() : std::to_wstring(gsl::narrow_cast<int>(InitialPosY()));
            result = fmt::format(L"{}, ({},{}), {}", launchModeString, xPosString, yPosString, centerOnLaunchString);
        }
        return result;
    }

    double LaunchViewModel::InitialPosX()
    {
        const auto x = _Settings.GlobalSettings().InitialPosition().X;
        // If there's no value here, return NAN - XAML will ignore it and
        // put the placeholder text in the box instead
        const auto xCoord = x.try_as<int64_t>();
        return xCoord.has_value() ? gsl::narrow_cast<double>(xCoord.value()) : NAN;
    }

    double LaunchViewModel::InitialPosY()
    {
        const auto y = _Settings.GlobalSettings().InitialPosition().Y;
        // If there's no value here, return NAN - XAML will ignore it and
        // put the placeholder text in the box instead
        const auto yCoord = y.try_as<int64_t>();
        return yCoord.has_value() ? gsl::narrow_cast<double>(yCoord.value()) : NAN;
    }

    void LaunchViewModel::InitialPosX(double xCoord)
    {
        winrt::Windows::Foundation::IReference<int64_t> xCoordRef;
        // If the value was cleared, xCoord will be NAN, so check for that
        if (!isnan(xCoord))
        {
            xCoordRef = gsl::narrow_cast<int64_t>(xCoord);
        }
        const LaunchPosition newPos{ xCoordRef, _Settings.GlobalSettings().InitialPosition().Y };
        _Settings.GlobalSettings().InitialPosition(newPos);
        _NotifyChanges(L"LaunchParametersCurrentValue");