Replace some std::bind with lambda functions

This commit is contained in:
Markus Gans 2021-05-01 18:58:37 +02:00
parent 0fefcd81c2
commit 24553aa7d0
6 changed files with 31 additions and 17 deletions

View File

@ -1,3 +1,6 @@
2021-05-01 Markus Gans <guru.mail@muenster.de>
* Replace some std::bind with lambda functions
2021-04-30 Markus Gans <guru.mail@muenster.de> 2021-04-30 Markus Gans <guru.mail@muenster.de>
* Fixes Linux console bug from February 20, 2021 * Fixes Linux console bug from February 20, 2021

View File

@ -397,10 +397,10 @@ void FApplication::init()
// Initialize keyboard // Initialize keyboard
const auto& keyboard = FTerm::getFKeyboard(); const auto& keyboard = FTerm::getFKeyboard();
auto cmd1 = std::bind(&FApplication::keyPressed, this); auto cmd1 = [this] () { this->keyPressed(); };
auto cmd2 = std::bind(&FApplication::keyReleased, this); auto cmd2 = [this] () { this->keyReleased(); };
auto cmd3 = std::bind(&FApplication::escapeKeyPressed, this); auto cmd3 = [this] () { this->escapeKeyPressed(); };
auto cmd4 = std::bind(&FApplication::mouseTracking, this); auto cmd4 = [this] () { this->mouseTracking(); };
FKeyboardCommand key_cmd1 (cmd1); FKeyboardCommand key_cmd1 (cmd1);
FKeyboardCommand key_cmd2 (cmd2); FKeyboardCommand key_cmd2 (cmd2);
FKeyboardCommand key_cmd3 (cmd3); FKeyboardCommand key_cmd3 (cmd3);
@ -414,8 +414,7 @@ void FApplication::init()
// Initialize mouse control // Initialize mouse control
const auto& mouse = FTerm::getFMouseControl(); const auto& mouse = FTerm::getFMouseControl();
using namespace std::placeholders; auto cmd = [this] (const FMouseData& md) { this->mouseEvent(md); };
auto cmd = std::bind(&FApplication::mouseEvent, this, _1);
FMouseCommand mouse_cmd (cmd); FMouseCommand mouse_cmd (cmd);
mouse->setEventCommand (mouse_cmd); mouse->setEventCommand (mouse_cmd);
// Set stdin number for a gpm-mouse // Set stdin number for a gpm-mouse
@ -484,9 +483,8 @@ inline void FApplication::setLongOptions (std::vector<CmdOption>& long_options)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FApplication::setCmdOptionsMap (CmdMap& cmd_map) inline void FApplication::setCmdOptionsMap (CmdMap& cmd_map)
{ {
using std::placeholders::_1; auto enc = [] (const FString& s) { FApplication::setTerminalEncoding(s); };
auto enc = std::bind(&FApplication::setTerminalEncoding, _1); auto log = [] (const FString& s) { FApplication::setLogFile(s); };
auto log = std::bind(&FApplication::setLogFile, _1);
auto opt = &FApplication::getStartOptions; auto opt = &FApplication::getStartOptions;
// --encoding // --encoding

View File

@ -48,19 +48,19 @@ FLog& FLog::operator << (LogLevel l)
switch ( l ) switch ( l )
{ {
case LogLevel::Info: case LogLevel::Info:
current_log = std::bind(&FLog::info, this, _1); current_log = [this] (const std::string& s) { info(s); };
break; break;
case LogLevel::Warn: case LogLevel::Warn:
current_log = std::bind(&FLog::warn, this, _1); current_log = [this] (const std::string& s) { warn(s); };
break; break;
case LogLevel::Error: case LogLevel::Error:
current_log = std::bind(&FLog::error, this, _1); current_log = [this] (const std::string& s) { error(s); };
break; break;
case LogLevel::Debug: case LogLevel::Debug:
current_log = std::bind(&FLog::debug, this, _1); current_log = [this] (const std::string& s) { debug(s); };
break; break;
} }

View File

@ -107,7 +107,7 @@ class FLog : public std::stringbuf
// Data member // Data member
LogLevel level{LogLevel::Info}; LogLevel level{LogLevel::Info};
LineEnding end_of_line{LineEnding::CRLF}; 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 current_log_mutex{};
std::mutex stream_mutex{}; std::mutex stream_mutex{};
std::ostream stream{this}; std::ostream stream{this};

View File

@ -43,7 +43,11 @@ class FTermFunctionsTest : public CPPUNIT_NS::TestFixture, test::ConEmu
public: public:
FTermFunctionsTest() 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 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) 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); data->setTermEncoding (finalcut::Encoding::UTF8);
// Column width (FString) // Column width (FString)

View File

@ -42,7 +42,11 @@ class FTermBufferTest : public CPPUNIT_NS::TestFixture
public: public:
FTermBufferTest() 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 fwide(stdout, 1); // Makes stream wide-character oriented
} }