From e28f559d32591e982af6441adc5fc4b8a9fefa3e Mon Sep 17 00:00:00 2001 From: FriendlyFire Date: Wed, 16 Dec 2020 08:51:26 -0500 Subject: [PATCH] C++20 compatability -- std::result_of with std::invoke_result (#392) * Replaced result_of with invoke_result_t. * Fixed a few compile errors and updated CMakeLists. * Updated Cloud CI --- CMakeLists.txt | 2 +- appveyor.yml | 8 ++++---- scripts/.travis-bootstrap-ubuntu.sh | 8 ++++---- src/g3log/future.hpp | 4 ++-- src/g3log/sink.hpp | 2 +- src/g3log/sinkhandle.hpp | 4 ++-- test_unit/test_cpp_future_concepts.cpp | 10 +++++----- test_unit/testing_helpers.h | 2 +- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1492005..2eeaf84 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,7 +43,7 @@ cmake_minimum_required(VERSION 3.2) project(g3log CXX) -set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) if(NOT CMAKE_BUILD_TYPE AND NOT (MSVC_IDE OR XCODE)) diff --git a/appveyor.yml b/appveyor.yml index a9014aa..8421b59 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,7 +2,7 @@ environment: P: "c:/projects/libs" # Operating system (build VM template) -os: Visual Studio 2015 +os: Visual Studio 2017 # scripts that are called at very beginning, before repo cloning #init: @@ -21,12 +21,12 @@ install: before_build: - cd c:\projects\g3log\ - mkdir build - - cd build + - cd build build_script: - - cmake -G "Visual Studio 14 2015 Win64" -DADD_G3LOG_UNIT_TEST=ON -DUSE_DYNAMIC_LOGGING_LEVELS=ON -DCHANGE_G3LOG_DEBUG_TO_DBUG=ON -DCMAKE_INSTALL_PREFIX=c:\g3log .. + - cmake -G "Visual Studio 15 2017 Win64" -DADD_G3LOG_UNIT_TEST=ON -DUSE_DYNAMIC_LOGGING_LEVELS=ON -DCHANGE_G3LOG_DEBUG_TO_DBUG=ON -DCMAKE_INSTALL_PREFIX=c:\g3log .. - cmake --build . --config Release --target install - + # scripts to run after build after_build: - cmd /c Release\g3log-FATAL-contract.exe || exit /B 0 diff --git a/scripts/.travis-bootstrap-ubuntu.sh b/scripts/.travis-bootstrap-ubuntu.sh index 89ddd7e..2ba45d6 100644 --- a/scripts/.travis-bootstrap-ubuntu.sh +++ b/scripts/.travis-bootstrap-ubuntu.sh @@ -8,11 +8,11 @@ apt-get install -y apt-utils | true apt-get install -y software-properties-common | true apt-get install -y python-software-properties apt-get update -y -add-apt-repository -y ppa:jonathonf/gcc-7.1 -apt-get update -y +add-apt-repository -y ppa:jonathonf/gcc +apt-get update -y apt-get install -y cmake software-properties-common git make -apt-get install -y gcc-7 g++-7 +apt-get install -y gcc-7 g++-7 update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 90 -update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 90 +update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 90 apt-get install -y unzip zlib1g-dev apt-get install -y libboost-all-dev \ No newline at end of file diff --git a/src/g3log/future.hpp b/src/g3log/future.hpp index 370f377..3bec01f 100644 --- a/src/g3log/future.hpp +++ b/src/g3log/future.hpp @@ -42,9 +42,9 @@ namespace g3 { // auto msg_call=[=](){return ("Hello from the Background");}; // auto future_msg = g3::spawn_task(msg_lambda, bgWorker.get()); template - std::future::type> spawn_task(Func func, BgWorker *worker) + std::future> spawn_task(Func func, BgWorker *worker) { - typedef typename std::result_of::type result_type; + typedef std::invoke_result_t result_type; typedef std::packaged_task task_type; if (nullptr == worker) { diff --git a/src/g3log/sink.hpp b/src/g3log/sink.hpp index 70543b5..14c0ea6 100644 --- a/src/g3log/sink.hpp +++ b/src/g3log/sink.hpp @@ -70,7 +70,7 @@ namespace g3 { } template - auto async(Call call, Args &&... args)-> std::future< typename std::result_of::type> { + auto async(Call call, Args &&... args)-> std::future> { return g3::spawn_task(std::bind(call, _real_sink.get(), std::forward(args)...), _bg.get()); } }; diff --git a/src/g3log/sinkhandle.hpp b/src/g3log/sinkhandle.hpp index d0128a5..414d74e 100644 --- a/src/g3log/sinkhandle.hpp +++ b/src/g3log/sinkhandle.hpp @@ -37,12 +37,12 @@ namespace g3 { // the returned future will contain a bad_weak_ptr exception instead of the // call result. template - auto call(AsyncCall func , Args&& ... args) -> std::future::type> { + auto call(AsyncCall func , Args&& ... args) -> std::future> { try { std::shared_ptr> sink(_sink); return sink->async(func, std::forward(args)...); } catch (const std::bad_weak_ptr& e) { - typedef typename std::result_of::type PromiseType; + typedef std::invoke_result_t PromiseType; std::promise promise; promise.set_exception(std::make_exception_ptr(e)); return std::move(promise.get_future()); diff --git a/test_unit/test_cpp_future_concepts.cpp b/test_unit/test_cpp_future_concepts.cpp index 2993247..9a4aae1 100644 --- a/test_unit/test_cpp_future_concepts.cpp +++ b/test_unit/test_cpp_future_concepts.cpp @@ -2,7 +2,7 @@ * 2012 by KjellKod.cc. This is PUBLIC DOMAIN to use at your own risk and comes * with no warranties. This code is yours to share, use and modify with no * strings attached and no restrictions or obligations. - * + * * For more information see g3log/LICENSE or refer refer to http://unlicense.org * ============================================================================*/ @@ -75,9 +75,9 @@ TEST(TestOf_CopyableLambdaCall, Expecting_AllFine) template -std::future::type> ObsoleteSpawnTask(F f) +std::future> ObsoleteSpawnTask(F f) { - typedef typename std::result_of::type result_type; + typedef std::invoke_result_t result_type; typedef std::packaged_task task_type; task_type task(std::move(f)); @@ -119,9 +119,9 @@ namespace WORKING std::vector> vec; template - std::future::type> spawn_task(F f) + std::future> spawn_task(F f) { - typedef typename std::result_of::type result_type; + typedef std::invoke_result_t result_type; typedef std::packaged_task task_type; task_type task(std::move(f)); diff --git a/test_unit/testing_helpers.h b/test_unit/testing_helpers.h index 59c492b..c410140 100644 --- a/test_unit/testing_helpers.h +++ b/test_unit/testing_helpers.h @@ -86,7 +86,7 @@ namespace testing_helpers { template - typename std::result_of::type callToLogger(Call call, Args&& ... args) { + std::invoke_result_t callToLogger(Call call, Args&& ... args) { auto func = std::bind(call, _scope->get(), std::forward(args)...); return func(); }