CLI: untieStdIO() to avoid unwanted implicit flush() calls on std::cout → less write() calls
--- a/include/relpipe/cli/CLI.h Thu Nov 29 22:30:11 2018 +0100
+++ b/include/relpipe/cli/CLI.h Mon Dec 03 16:11:40 2018 +0100
@@ -23,6 +23,7 @@
#include <sstream>
#include <locale>
#include <codecvt>
+#include <iostream>
using namespace std;
@@ -69,6 +70,14 @@
static const int EXIT_CODE_UNKNOWN_COMMAND = 4;
static const int EXIT_CODE_DATA_ERROR = 5;
+ /**
+ * std::cin and std::cout are "tied" by default i.e. reading from std::cin causes flush of the std::cout.
+ * Call this to "untie" them and have less write() calls (better buffering).
+ */
+ static void untieStdIO() {
+ std::cin.tie(nullptr);
+ }
+
private:
int* argc;
char*** argv;