TVirtualPad Documentation (Drawing lines that stay in frame.)

The following worked for drawing lines that go from -inf to +inf that do not leave the frame as the axis is scaled and with no need to deal with gPad.

#include <limits>
#include <vector>

#include <TGraph.h>

void DrawLines(const std::vector< double > &axisValues, const bool &vertical) {
   std::vector< double > xValues(2), yValues(2);
   if (vertical) {
      yValues.at(0) = std::numeric_limits< double >::min();
      yValues.at(1) = std::numeric_limits< double >::max();
   }
   else {
      xValues.at(0) = std::numeric_limits< double >::min();
      xValues.at(1) = std::numeric_limits< double >::max();
   }

   TGraph *line = new TGraph();
   for (auto axisValue : axisValues) {
      if (vertical)  xValues.at(0) = xValues.at(1) = axisValue;
      else  yValues.at(0) = yValues.at(1) = axisValue;
      line->DrawGraph(2, xValues.data(), yValues.data(), "L");
   }
}

(Replacing TLine with TGraph inspired from Problem with TLine and resizing of x-axis)