From 7ef5d0b10ae214f7c58aa77fb84547be1388f2d6 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Mon, 25 Dec 2017 17:20:27 +0900 Subject: Now really switching to the new toolchain: C++14, GCC/Clang 5, Qt 5.6 Also a bit of code tightening with some C++14 (but not only) things. --- CMakeLists.txt | 35 ++++++++++------------------------- room.cpp | 13 ++++++------- room.h | 14 +++++++------- 3 files changed, 23 insertions(+), 39 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e33c4e0e..7750b7ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,6 @@ -cmake_minimum_required(VERSION 2.8.11) # Maybe works with even older versions +cmake_minimum_required(VERSION 3.1) -project(qmatrixclient) -enable_language(CXX) +project(qmatrixclient CXX) include(CheckCXXCompilerFlag) @@ -19,30 +18,16 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) "MinSizeRel" "RelWithDebInfo") endif() -# Setup command line parameters for the compiler and linker -CHECK_CXX_COMPILER_FLAG("-Wall" WALL_FLAG_SUPPORTED) -if ( WALL_FLAG_SUPPORTED AND NOT CMAKE_CXX_FLAGS MATCHES "(^| )-Wall($| )") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") -endif ( ) -CHECK_CXX_COMPILER_FLAG("-Wpedantic" PEDANTIC_FLAG_SUPPORTED) -if ( PEDANTIC_FLAG_SUPPORTED AND NOT CMAKE_CXX_FLAGS MATCHES "(^| )pedantic($| )") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpedantic") -endif ( ) -CHECK_CXX_COMPILER_FLAG("-Werror=return-type" WERROR_FLAG_SUPPORTED) -if ( WERROR_FLAG_SUPPORTED ) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=return-type") -endif ( ) +foreach (FLAG all pedantic error=return-type) + CHECK_CXX_COMPILER_FLAG("-W${FLAG}" WARN_${FLAG}_SUPPORTED) + if ( WARN_${FLAG}_SUPPORTED AND NOT CMAKE_CXX_FLAGS MATCHES "(^| )-W?${FLAG}($| )") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W${FLAG}") + endif () +endforeach () -if ( CMAKE_VERSION VERSION_LESS "3.1" ) - CHECK_CXX_COMPILER_FLAG("-std=c++11" STD_FLAG_SUPPORTED) - if ( STD_FLAG_SUPPORTED ) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") - endif ( STD_FLAG_SUPPORTED ) -else ( CMAKE_VERSION VERSION_LESS "3.1" ) - set(CMAKE_CXX_STANDARD 11) -endif ( CMAKE_VERSION VERSION_LESS "3.1" ) +set(CMAKE_CXX_STANDARD 14) -find_package(Qt5 5.2.1 REQUIRED Network Gui) +find_package(Qt5 5.6 REQUIRED Network Gui) get_filename_component(Qt5_Prefix "${Qt5_DIR}/../../../.." ABSOLUTE) message( STATUS ) diff --git a/room.cpp b/room.cpp index d39e6d32..45521a73 100644 --- a/room.cpp +++ b/room.cpp @@ -457,7 +457,7 @@ void Room::Private::removeMemberFromMap(const QString& username, User* u) emit q->memberRenamed(formerNamesakes[0]); } -inline QByteArray makeErrorStr(const Event& e, QByteArray msg) +inline auto makeErrorStr(const Event& e, QByteArray msg) { return msg.append("; event dump follows:\n").append(e.originalJson()); } @@ -499,7 +499,7 @@ void Room::Private::addMember(User *u) { insertMemberIntoMap(u); connect(u, &User::nameChanged, q, - [=] (User* u, const QString& newName) { renameMember(u, newName); }); + bind(&Private::renameMember, this, _1, _2)); emit q->userAdded(u); } } @@ -660,7 +660,7 @@ void Room::Private::getPreviousContent(int limit) { roomMessagesJob = connection->callApi(id, prevBatch, limit); - connect( roomMessagesJob, &RoomMessagesJob::result, [=]() { + connect( roomMessagesJob, &RoomMessagesJob::result, [=] { if( !roomMessagesJob->error() ) { addHistoricalMessageEvents(roomMessagesJob->releaseEvents()); @@ -780,8 +780,7 @@ void Room::Private::processRedaction(RoomEventPtr redactionEvent) } auto keepContentKeys = find_if(keepContentKeysMap.begin(), keepContentKeysMap.end(), - [&](const std::pair& t) - { return ti->type() == t.first; } ); + [&ti](const auto& t) { return ti->type() == t.first; } ); if (keepContentKeys == keepContentKeysMap.end()) { originalJson.remove("content"); @@ -1226,9 +1225,9 @@ bool MemberSorter::operator()(User *u1, User *u2) const { auto n1 = room->roomMembername(u1); auto n2 = room->roomMembername(u2); - if (n1[0] == '@') + if (n1.startsWith('@')) n1.remove(0, 1); - if (n2[0] == '@') + if (n2.startsWith('@')) n2.remove(0, 1); return n1.localeAwareCompare(n2) < 0; } diff --git a/room.h b/room.h index 08327917..77d56377 100644 --- a/room.h +++ b/room.h @@ -18,8 +18,9 @@ #pragma once -#include -#include +#include "jobs/syncjob.h" +#include "events/roommessageevent.h" +#include "joinstate.h" #include #include @@ -27,9 +28,9 @@ #include #include -#include "jobs/syncjob.h" -#include "events/roommessageevent.h" -#include "joinstate.h" +#include +#include +#include namespace QMatrixClient { @@ -58,8 +59,7 @@ namespace QMatrixClient // Used for event redaction RoomEventPtr replaceEvent(RoomEventPtr&& other) { - evt.swap(other); - return move(other); + return std::exchange(evt, std::move(other)); } private: -- cgit v1.2.3