From 418acb052f3ff415069b66f9a67df550c5977c47 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 5 Aug 2016 01:51:10 -0400 Subject: [PATCH] #256: compatibility with gcc 4.8 --- daemon/main/Scheduler.cpp | 2 +- daemon/main/nzbget.h | 15 +++++++++++++++ daemon/queue/QueueEditor.cpp | 6 +++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/daemon/main/Scheduler.cpp b/daemon/main/Scheduler.cpp index 4cdcc714..aebfc086 100644 --- a/daemon/main/Scheduler.cpp +++ b/daemon/main/Scheduler.cpp @@ -40,7 +40,7 @@ void Scheduler::FirstCheck() Guard guard(m_taskListMutex); std::sort(m_taskList.begin(), m_taskList.end(), - [](std::unique_ptr& task1, std::unique_ptr& task2) + [](const std::unique_ptr& task1, const std::unique_ptr& task2) { return (task1->m_hours < task2->m_hours) || ((task1->m_hours == task2->m_hours) && (task1->m_minutes < task2->m_minutes)); diff --git a/daemon/main/nzbget.h b/daemon/main/nzbget.h index 1344fbe4..ed627b5f 100644 --- a/daemon/main/nzbget.h +++ b/daemon/main/nzbget.h @@ -340,4 +340,19 @@ typedef unsigned char uchar; #define SCANF_SYNTAX(strindex) #endif +// providing "std::make_unique" for GCC 4.8.x (only 4.8.x) +#if __GNUC__ && __cplusplus < 201402L && __cpp_generic_lambdas < 201304 +namespace std { +template struct _Unique_if { typedef unique_ptr _Single_object; }; +template struct _Unique_if { typedef unique_ptr _Unknown_bound; }; +template typename _Unique_if::_Single_object make_unique(Args&&... args) { + return unique_ptr(new T(std::forward(args)...)); +} +template typename _Unique_if::_Unknown_bound make_unique(size_t n) { + typedef typename remove_extent::type U; + return unique_ptr(new U[n]()); +} +} +#endif + #endif /* NZBGET_H */ diff --git a/daemon/queue/QueueEditor.cpp b/daemon/queue/QueueEditor.cpp index 95d403a4..b8a3ab8b 100644 --- a/daemon/queue/QueueEditor.cpp +++ b/daemon/queue/QueueEditor.cpp @@ -38,7 +38,7 @@ public: GroupSorter(NzbList* nzbList, QueueEditor::ItemList* sortItemList) : m_nzbList(nzbList), m_sortItemList(sortItemList) {} bool Execute(const char* sort); - bool operator()(std::unique_ptr& refNzbInfo1, std::unique_ptr& refNzbInfo2) const; + bool operator()(const std::unique_ptr& refNzbInfo1, const std::unique_ptr& refNzbInfo2) const; private: enum ESortCriteria @@ -129,7 +129,7 @@ bool GroupSorter::Execute(const char* sort) std::sort(m_nzbList->begin(), m_nzbList->end(), *this); if (origSortOrder == soAuto && - std::equal(tempList.begin(), tempList.end(), m_nzbList->begin(), m_nzbList->end(), + std::equal(tempList.begin(), tempList.end(), m_nzbList->begin(), [](NzbInfo* nzbInfo1, std::unique_ptr& nzbInfo2) { return nzbInfo1 == nzbInfo2.get(); @@ -142,7 +142,7 @@ bool GroupSorter::Execute(const char* sort) return true; } -bool GroupSorter::operator()(std::unique_ptr& refNzbInfo1, std::unique_ptr& refNzbInfo2) const +bool GroupSorter::operator()(const std::unique_ptr& refNzbInfo1, const std::unique_ptr& refNzbInfo2) const { NzbInfo* nzbInfo1 = refNzbInfo1.get(); NzbInfo* nzbInfo2 = refNzbInfo2.get();