diff --git a/ChangeLog b/ChangeLog index 172e3cb2..100ca1f3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2021-05-01 Markus Gans + * Replace some std::bind with lambda functions + 2021-04-30 Markus Gans * Fixes Linux console bug from February 20, 2021 diff --git a/src/fapplication.cpp b/src/fapplication.cpp index ebfde71c..cbedeb89 100644 --- a/src/fapplication.cpp +++ b/src/fapplication.cpp @@ -397,10 +397,10 @@ void FApplication::init() // Initialize keyboard const auto& keyboard = FTerm::getFKeyboard(); - auto cmd1 = std::bind(&FApplication::keyPressed, this); - auto cmd2 = std::bind(&FApplication::keyReleased, this); - auto cmd3 = std::bind(&FApplication::escapeKeyPressed, this); - auto cmd4 = std::bind(&FApplication::mouseTracking, this); + auto cmd1 = [this] () { this->keyPressed(); }; + auto cmd2 = [this] () { this->keyReleased(); }; + auto cmd3 = [this] () { this->escapeKeyPressed(); }; + auto cmd4 = [this] () { this->mouseTracking(); }; FKeyboardCommand key_cmd1 (cmd1); FKeyboardCommand key_cmd2 (cmd2); FKeyboardCommand key_cmd3 (cmd3); @@ -414,8 +414,7 @@ void FApplication::init() // Initialize mouse control const auto& mouse = FTerm::getFMouseControl(); - using namespace std::placeholders; - auto cmd = std::bind(&FApplication::mouseEvent, this, _1); + auto cmd = [this] (const FMouseData& md) { this->mouseEvent(md); }; FMouseCommand mouse_cmd (cmd); mouse->setEventCommand (mouse_cmd); // Set stdin number for a gpm-mouse @@ -484,9 +483,8 @@ inline void FApplication::setLongOptions (std::vector& long_options) //---------------------------------------------------------------------- inline void FApplication::setCmdOptionsMap (CmdMap& cmd_map) { - using std::placeholders::_1; - auto enc = std::bind(&FApplication::setTerminalEncoding, _1); - auto log = std::bind(&FApplication::setLogFile, _1); + auto enc = [] (const FString& s) { FApplication::setTerminalEncoding(s); }; + auto log = [] (const FString& s) { FApplication::setLogFile(s); }; auto opt = &FApplication::getStartOptions; // --encoding diff --git a/src/flog.cpp b/src/flog.cpp index 003c906a..f8d5b252 100644 --- a/src/flog.cpp +++ b/src/flog.cpp @@ -48,19 +48,19 @@ FLog& FLog::operator << (LogLevel l) switch ( l ) { case LogLevel::Info: - current_log = std::bind(&FLog::info, this, _1); + current_log = [this] (const std::string& s) { info(s); }; break; case LogLevel::Warn: - current_log = std::bind(&FLog::warn, this, _1); + current_log = [this] (const std::string& s) { warn(s); }; break; case LogLevel::Error: - current_log = std::bind(&FLog::error, this, _1); + current_log = [this] (const std::string& s) { error(s); }; break; case LogLevel::Debug: - current_log = std::bind(&FLog::debug, this, _1); + current_log = [this] (const std::string& s) { debug(s); }; break; } diff --git a/src/include/final/flog.h b/src/include/final/flog.h index aa01f979..d1b8cd54 100644 --- a/src/include/final/flog.h +++ b/src/include/final/flog.h @@ -107,7 +107,7 @@ class FLog : public std::stringbuf // Data member LogLevel level{LogLevel::Info}; LineEnding end_of_line{LineEnding::CRLF}; - FLogPrint current_log{std::bind(&FLog::info, this, std::placeholders::_1)}; + FLogPrint current_log{ [this] (const std::string& s) { info(s); } }; std::mutex current_log_mutex{}; std::mutex stream_mutex{}; std::ostream stream{this}; diff --git a/test/fterm_functions-test.cpp b/test/fterm_functions-test.cpp index 69e2a646..8f98748e 100644 --- a/test/fterm_functions-test.cpp +++ b/test/fterm_functions-test.cpp @@ -43,7 +43,11 @@ class FTermFunctionsTest : public CPPUNIT_NS::TestFixture, test::ConEmu public: FTermFunctionsTest() { - std::setlocale (LC_CTYPE, "en_US.UTF-8"); + auto ret = std::setlocale (LC_CTYPE, "en_US.UTF-8"); + + if ( ! ret ) + ret = std::setlocale (LC_CTYPE, "C.UTF-8"); + fwide(stdout, 1); // Makes stream wide-character oriented } @@ -516,7 +520,12 @@ void FTermFunctionsTest::FullWidthHalfWidthTest() CPPUNIT_ASSERT ( finalcut::getColumnWidth(L'└') == 1 ); // wcwidth(L'└') == -1 (for LC_CTYPE = C) CPPUNIT_ASSERT ( finalcut::getColumnWidth(L'┌') == 1 ); // wcwidth(L'┌') == -1 (for LC_CTYPE = C) CPPUNIT_ASSERT ( finalcut::getColumnWidth(L'┘') == 1 ); // wcwidth(L'┘') == -1 (for LC_CTYPE = C) - std::setlocale (LC_CTYPE, "en_US.UTF-8"); + + auto ret = std::setlocale (LC_CTYPE, "en_US.UTF-8"); + + if ( ! ret ) + ret = std::setlocale (LC_CTYPE, "C.UTF-8"); + data->setTermEncoding (finalcut::Encoding::UTF8); // Column width (FString) diff --git a/test/ftermbuffer-test.cpp b/test/ftermbuffer-test.cpp index 8a57ad9b..477ddbc7 100644 --- a/test/ftermbuffer-test.cpp +++ b/test/ftermbuffer-test.cpp @@ -42,7 +42,11 @@ class FTermBufferTest : public CPPUNIT_NS::TestFixture public: FTermBufferTest() { - std::setlocale (LC_CTYPE, "en_US.UTF-8"); + auto ret = std::setlocale (LC_CTYPE, "en_US.UTF-8"); + + if ( ! ret ) + ret = std::setlocale (LC_CTYPE, "C.UTF-8"); + fwide(stdout, 1); // Makes stream wide-character oriented }