mirror of
https://github.com/KjellKod/g3log.git
synced 2024-12-12 10:23:50 +01:00
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
This commit is contained in:
parent
2fca06ff6d
commit
e28f559d32
@ -43,7 +43,7 @@ cmake_minimum_required(VERSION 3.2)
|
|||||||
|
|
||||||
project(g3log CXX)
|
project(g3log CXX)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 14)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
if(NOT CMAKE_BUILD_TYPE AND NOT (MSVC_IDE OR XCODE))
|
if(NOT CMAKE_BUILD_TYPE AND NOT (MSVC_IDE OR XCODE))
|
||||||
|
@ -2,7 +2,7 @@ environment:
|
|||||||
P: "c:/projects/libs"
|
P: "c:/projects/libs"
|
||||||
|
|
||||||
# Operating system (build VM template)
|
# Operating system (build VM template)
|
||||||
os: Visual Studio 2015
|
os: Visual Studio 2017
|
||||||
|
|
||||||
# scripts that are called at very beginning, before repo cloning
|
# scripts that are called at very beginning, before repo cloning
|
||||||
#init:
|
#init:
|
||||||
@ -24,7 +24,7 @@ before_build:
|
|||||||
- cd build
|
- cd build
|
||||||
|
|
||||||
build_script:
|
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
|
- cmake --build . --config Release --target install
|
||||||
|
|
||||||
# scripts to run after build
|
# scripts to run after build
|
||||||
|
@ -8,7 +8,7 @@ apt-get install -y apt-utils | true
|
|||||||
apt-get install -y software-properties-common | true
|
apt-get install -y software-properties-common | true
|
||||||
apt-get install -y python-software-properties
|
apt-get install -y python-software-properties
|
||||||
apt-get update -y
|
apt-get update -y
|
||||||
add-apt-repository -y ppa:jonathonf/gcc-7.1
|
add-apt-repository -y ppa:jonathonf/gcc
|
||||||
apt-get update -y
|
apt-get update -y
|
||||||
apt-get install -y cmake software-properties-common git make
|
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
|
||||||
|
@ -42,9 +42,9 @@ namespace g3 {
|
|||||||
// auto msg_call=[=](){return ("Hello from the Background");};
|
// auto msg_call=[=](){return ("Hello from the Background");};
|
||||||
// auto future_msg = g3::spawn_task(msg_lambda, bgWorker.get());
|
// auto future_msg = g3::spawn_task(msg_lambda, bgWorker.get());
|
||||||
template <typename Func, class BgWorker>
|
template <typename Func, class BgWorker>
|
||||||
std::future<typename std::result_of<Func()>::type> spawn_task(Func func, BgWorker *worker)
|
std::future<std::invoke_result_t<Func>> spawn_task(Func func, BgWorker *worker)
|
||||||
{
|
{
|
||||||
typedef typename std::result_of<Func()>::type result_type;
|
typedef std::invoke_result_t<Func> result_type;
|
||||||
typedef std::packaged_task<result_type()> task_type;
|
typedef std::packaged_task<result_type()> task_type;
|
||||||
|
|
||||||
if (nullptr == worker) {
|
if (nullptr == worker) {
|
||||||
|
@ -70,7 +70,7 @@ namespace g3 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename Call, typename... Args>
|
template<typename Call, typename... Args>
|
||||||
auto async(Call call, Args &&... args)-> std::future< typename std::result_of<decltype(call)(T, Args...)>::type> {
|
auto async(Call call, Args &&... args)-> std::future<std::invoke_result_t<decltype(call), T, Args...>> {
|
||||||
return g3::spawn_task(std::bind(call, _real_sink.get(), std::forward<Args>(args)...), _bg.get());
|
return g3::spawn_task(std::bind(call, _real_sink.get(), std::forward<Args>(args)...), _bg.get());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -37,12 +37,12 @@ namespace g3 {
|
|||||||
// the returned future will contain a bad_weak_ptr exception instead of the
|
// the returned future will contain a bad_weak_ptr exception instead of the
|
||||||
// call result.
|
// call result.
|
||||||
template<typename AsyncCall, typename... Args>
|
template<typename AsyncCall, typename... Args>
|
||||||
auto call(AsyncCall func , Args&& ... args) -> std::future<typename std::result_of<decltype(func)(T, Args...)>::type> {
|
auto call(AsyncCall func , Args&& ... args) -> std::future<std::invoke_result_t<decltype(func), T, Args...>> {
|
||||||
try {
|
try {
|
||||||
std::shared_ptr<internal::Sink<T>> sink(_sink);
|
std::shared_ptr<internal::Sink<T>> sink(_sink);
|
||||||
return sink->async(func, std::forward<Args>(args)...);
|
return sink->async(func, std::forward<Args>(args)...);
|
||||||
} catch (const std::bad_weak_ptr& e) {
|
} catch (const std::bad_weak_ptr& e) {
|
||||||
typedef typename std::result_of<decltype(func)(T, Args...)>::type PromiseType;
|
typedef std::invoke_result_t<decltype(func), T, Args...> PromiseType;
|
||||||
std::promise<PromiseType> promise;
|
std::promise<PromiseType> promise;
|
||||||
promise.set_exception(std::make_exception_ptr(e));
|
promise.set_exception(std::make_exception_ptr(e));
|
||||||
return std::move(promise.get_future());
|
return std::move(promise.get_future());
|
||||||
|
@ -75,9 +75,9 @@ TEST(TestOf_CopyableLambdaCall, Expecting_AllFine)
|
|||||||
|
|
||||||
|
|
||||||
template<typename F>
|
template<typename F>
|
||||||
std::future<typename std::result_of<F()>::type> ObsoleteSpawnTask(F f)
|
std::future<std::invoke_result_t<F>> ObsoleteSpawnTask(F f)
|
||||||
{
|
{
|
||||||
typedef typename std::result_of<F()>::type result_type;
|
typedef std::invoke_result_t<F> result_type;
|
||||||
typedef std::packaged_task<result_type()> task_type;
|
typedef std::packaged_task<result_type()> task_type;
|
||||||
|
|
||||||
task_type task(std::move(f));
|
task_type task(std::move(f));
|
||||||
@ -119,9 +119,9 @@ namespace WORKING
|
|||||||
std::vector<std::function<void()>> vec;
|
std::vector<std::function<void()>> vec;
|
||||||
|
|
||||||
template<typename F>
|
template<typename F>
|
||||||
std::future<typename std::result_of<F()>::type> spawn_task(F f)
|
std::future<std::invoke_result_t<F>> spawn_task(F f)
|
||||||
{
|
{
|
||||||
typedef typename std::result_of<F()>::type result_type;
|
typedef std::invoke_result_t<F> result_type;
|
||||||
typedef std::packaged_task<result_type()> task_type;
|
typedef std::packaged_task<result_type()> task_type;
|
||||||
|
|
||||||
task_type task(std::move(f));
|
task_type task(std::move(f));
|
||||||
|
@ -86,7 +86,7 @@ namespace testing_helpers {
|
|||||||
|
|
||||||
|
|
||||||
template<typename Call, typename ... Args >
|
template<typename Call, typename ... Args >
|
||||||
typename std::result_of<Call(Args...)>::type callToLogger(Call call, Args&& ... args) {
|
std::invoke_result_t<Call(Args...)> callToLogger(Call call, Args&& ... args) {
|
||||||
auto func = std::bind(call, _scope->get(), std::forward<Args>(args)...);
|
auto func = std::bind(call, _scope->get(), std::forward<Args>(args)...);
|
||||||
return func();
|
return func();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user