#include <iostream>
#include <future>
#include <functional>
#include <type_traits>
namespace std
{
template<class T>
static constexpr bool is_member_pointer_v = std::is_member_pointer<T>::value;
template<class T>
static constexpr bool is_function_v = std::is_function<T>::value;
template<class B, class T>
static constexpr bool is_base_of_v = std::is_base_of<B, T>::value;
namespace detail {
template <class T>
struct is_reference_wrapper : std::false_type {};
template <class U>
struct is_reference_wrapper<std::reference_wrapper<U>> : std::true_type {};
template <class T>
constexpr bool is_reference_wrapper_v = is_reference_wrapper<T>::value;
template <class Base, class T, class Derived, class... Args>
auto INVOKE(T Base::*pmf, Derived&& ref, Args&&... args)
noexcept(noexcept((std::forward<Derived>(ref).*pmf)(std::forward<Args>(args)...)))
-> std::enable_if_t<std::is_function_v<T> &&
std::is_base_of_v<Base, std::decay_t<Derived>>,
decltype((std::forward<Derived>(ref).*pmf)(std::forward<Args>(args)...))>
{
return (std::forward<Derived>(ref).*pmf)(std::forward<Args>(args)...);
}
template <class Base, class T, class RefWrap, class... Args>
auto INVOKE(T Base::*pmf, RefWrap&& ref, Args&&... args)
noexcept(noexcept((ref.get().*pmf)(std::forward<Args>(args)...)))
-> std::enable_if_t<std::is_function_v<T> &&
is_reference_wrapper_v<std::decay_t<RefWrap>>,
decltype((ref.get().*pmf)(std::forward<Args>(args)...))>
{
return (ref.get().*pmf)(std::forward<Args>(args)...);
}
template <class Base, class T, class Pointer, class... Args>
auto INVOKE(T Base::*pmf, Pointer&& ptr, Args&&... args)
noexcept(noexcept(((*std::forward<Pointer>(ptr)).*pmf)(std::forward<Args>(args)...)))
-> std::enable_if_t<std::is_function_v<T> &&
!is_reference_wrapper_v<std::decay_t<Pointer>> &&
!std::is_base_of_v<Base, std::decay_t<Pointer>>,
decltype(((*std::forward<Pointer>(ptr)).*pmf)(std::forward<Args>(args)...))>
{
return ((*std::forward<Pointer>(ptr)).*pmf)(std::forward<Args>(args)...);
}
template <class Base, class T, class Derived>
auto INVOKE(T Base::*pmd, Derived&& ref)
noexcept(noexcept(std::forward<Derived>(ref).*pmd))
-> std::enable_if_t<!std::is_function_v<T> &&
std::is_base_of_v<Base, std::decay_t<Derived>>,
decltype(std::forward<Derived>(ref).*pmd)>
{
return std::forward<Derived>(ref).*pmd;
}
template <class Base, class T, class RefWrap>
auto INVOKE(T Base::*pmd, RefWrap&& ref)
noexcept(noexcept(ref.get().*pmd))
-> std::enable_if_t<!std::is_function_v<T> &&
is_reference_wrapper_v<std::decay_t<RefWrap>>,
decltype(ref.get().*pmd)>
{
return ref.get().*pmd;
}
template <class Base, class T, class Pointer>
auto INVOKE(T Base::*pmd, Pointer&& ptr)
noexcept(noexcept((*std::forward<Pointer>(ptr)).*pmd))
-> std::enable_if_t<!std::is_function_v<T> &&
!is_reference_wrapper_v<std::decay_t<Pointer>> &&
!std::is_base_of_v<Base, std::decay_t<Pointer>>,
decltype((*std::forward<Pointer>(ptr)).*pmd)>
{
return (*std::forward<Pointer>(ptr)).*pmd;
}
template <class F, class... Args>
auto INVOKE(F&& f, Args&&... args)
noexcept(noexcept(std::forward<F>(f)(std::forward<Args>(args)...)))
-> std::enable_if_t<!std::is_member_pointer_v<std::decay_t<F>>,
decltype(std::forward<F>(f)(std::forward<Args>(args)...))>
{
return std::forward<F>(f)(std::forward<Args>(args)...);
}
} // namespace detail
template< class F, class... ArgTypes >
auto invoke(F&& f, ArgTypes&&... args)
// exception specification for QoI
noexcept(noexcept(detail::INVOKE(std::forward<F>(f), std::forward<ArgTypes>(args)...)))
-> decltype(detail::INVOKE(std::forward<F>(f), std::forward<ArgTypes>(args)...))
{
return detail::INVOKE(std::forward<F>(f), std::forward<ArgTypes>(args)...);
}
}
template<class Fn, class... Args>
inline auto runAsyncTerminateOnException(Fn&& fn, Args&&... args) {
return std::async(std::launch::async, [=]() -> decltype(auto) {
try {
return std::invoke(fn, args...);
} catch (...) {
std::cout << "Terminate Called!" << std::endl;
std::terminate();
}
});
}
struct Foo {
template<class... Args>
void print(Args&&... args) {
printf("Foo::print(%d)\n", std::forward<Args>(args)...);
}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IHN0ZDo6Zm9yd2FyZDxBcmdUeXBlcz4oYXJncykuLi4pOwp9Cn0KCnRlbXBsYXRlPGNsYXNzIEZuLCBjbGFzcy4uLiBBcmdzPgppbmxpbmUgYXV0byBydW5Bc3luY1Rlcm1pbmF0ZU9uRXhjZXB0aW9uKEZuJiYgZm4sIEFyZ3MmJi4uLiBhcmdzKSB7CgogICAgcmV0dXJuIHN0ZDo6YXN5bmMoc3RkOjpsYXVuY2g6OmFzeW5jLCBbPV0oKSAtPiBkZWNsdHlwZShhdXRvKSB7CiAgICAgICAgdHJ5IHsKICAgICAgICAgICAgcmV0dXJuIHN0ZDo6aW52b2tlKGZuLCBhcmdzLi4uKTsKICAgICAgICB9IGNhdGNoICguLi4pIHsKICAgICAgICAgICAgc3RkOjpjb3V0IDw8ICJUZXJtaW5hdGUgQ2FsbGVkISIgPDwgc3RkOjplbmRsOwogICAgICAgICAgICBzdGQ6OnRlcm1pbmF0ZSgpOwogICAgICAgIH0KICAgIH0pOwp9CgpzdHJ1Y3QgRm9vIHsKCXRlbXBsYXRlPGNsYXNzLi4uIEFyZ3M+CiAgICB2b2lkIHByaW50KEFyZ3MmJi4uLiBhcmdzKSB7CiAgICAgICAgcHJpbnRmKCJGb286OnByaW50KCVkKVxuIiwgc3RkOjpmb3J3YXJkPEFyZ3M+KGFyZ3MpLi4uKTsKICAgIH0KfTsKCmludCBtYWluKCkgewogICAgRm9vIGZvbzsKICAgIHN0ZDo6ZnV0dXJlPHZvaWQ+IGZ1dHVyZSA9IHJ1bkFzeW5jVGVybWluYXRlT25FeGNlcHRpb24oJkZvbzo6cHJpbnQ8aW50PiwgJmZvbywgMik7CiAgICAvLyB5b3VyIGNvZGUgZ29lcyBoZXJlCiAgICByZXR1cm4gMDsKfQ==
prog.cpp: In instantiation of 'runAsyncTerminateOnException(Fn&&, Args&& ...)::<lambda()> [with Fn = void (Foo::*)(int&&); Args = {Foo*, int}]':
prog.cpp:110:36: required from 'struct runAsyncTerminateOnException(Fn&&, Args&& ...) [with Fn = void (Foo::*)(int&&); Args = {Foo*, int}]::<lambda()>'
prog.cpp:108:22: required from 'auto runAsyncTerminateOnException(Fn&&, Args&& ...) [with Fn = void (Foo::*)(int&&); Args = {Foo*, int}]'
prog.cpp:127:86: required from here
prog.cpp:110:31: error: no matching function for call to 'invoke(void (Foo::* const&)(int&&), Foo* const&, const int&)'
return std::invoke(fn, args...);
^
prog.cpp:96:6: note: candidate: template<class F, class ... ArgTypes> decltype (std::detail::INVOKE(forward<F>(f), (forward<ArgTypes>)(std::invoke::args)...)) std::invoke(F&&, ArgTypes&& ...)
auto invoke(F&& f, ArgTypes&&... args)
^
prog.cpp:96:6: note: template argument deduction/substitution failed:
prog.cpp: In substitution of 'template<class F, class ... ArgTypes> decltype (std::detail::INVOKE(forward<F>(f), (forward<ArgTypes>)(std::invoke::args)...)) std::invoke(F&&, ArgTypes&& ...) [with F = void (Foo::* const&)(int&&); ArgTypes = {Foo* const&, const int&}]':
prog.cpp:110:31: required from 'runAsyncTerminateOnException(Fn&&, Args&& ...)::<lambda()> [with Fn = void (Foo::*)(int&&); Args = {Foo*, int}]'
prog.cpp:110:36: required from 'struct runAsyncTerminateOnException(Fn&&, Args&& ...) [with Fn = void (Foo::*)(int&&); Args = {Foo*, int}]::<lambda()>'
prog.cpp:108:22: required from 'auto runAsyncTerminateOnException(Fn&&, Args&& ...) [with Fn = void (Foo::*)(int&&); Args = {Foo*, int}]'
prog.cpp:127:86: required from here
prog.cpp:99:28: error: no matching function for call to 'INVOKE(void (Foo::* const&)(int&&), Foo* const&, const int&)'
-> decltype(detail::INVOKE(std::forward<F>(f), std::forward<ArgTypes>(args)...))
^
prog.cpp:23:6: note: candidate: template<class Base, class T, class Derived, class ... Args> std::enable_if_t<(std::is_function_v<T> && std::is_base_of_v<Base, typename std::decay<Derived>::type>), decltype ((forward<Derived>)(*std::detail::INVOKE::ref).*std::detail::INVOKE::pmf((forward<Args>)(std::detail::INVOKE::args)...))> std::detail::INVOKE(T Base::*, Derived&&, Args&& ...)
auto INVOKE(T Base::*pmf, Derived&& ref, Args&&... args)
^
prog.cpp:23:6: note: template argument deduction/substitution failed:
prog.cpp: In substitution of 'template<class Base, class T, class Derived, class ... Args> std::enable_if_t<(std::is_function_v<T> && std::is_base_of_v<Base, typename std::decay<Derived>::type>), decltype ((forward<Derived>)(*std::detail::INVOKE::ref).*std::detail::INVOKE::pmf((forward<Args>)(std::detail::INVOKE::args)...))> std::detail::INVOKE(T Base::*, Derived&&, Args&& ...) [with Base = Foo; T = void(int&&); Derived = Foo* const&; Args = {const int&}]':
prog.cpp:99:28: required by substitution of 'template<class F, class ... ArgTypes> decltype (std::detail::INVOKE(forward<F>(f), (forward<ArgTypes>)(std::invoke::args)...)) std::invoke(F&&, ArgTypes&& ...) [with F = void (Foo::* const&)(int&&); ArgTypes = {Foo* const&, const int&}]'
prog.cpp:110:31: required from 'runAsyncTerminateOnException(Fn&&, Args&& ...)::<lambda()> [with Fn = void (Foo::*)(int&&); Args = {Foo*, int}]'
prog.cpp:110:36: required from 'struct runAsyncTerminateOnException(Fn&&, Args&& ...) [with Fn = void (Foo::*)(int&&); Args = {Foo*, int}]::<lambda()>'
prog.cpp:108:22: required from 'auto runAsyncTerminateOnException(Fn&&, Args&& ...) [with Fn = void (Foo::*)(int&&); Args = {Foo*, int}]'
prog.cpp:127:86: required from here
prog.cpp:27:41: error: cannot apply member pointer 'pmf' to 'std::forward<Foo* const&>((* & ref))', which is of non-class type 'Foo*'
decltype((std::forward<Derived>(ref).*pmf)(std::forward<Args>(args)...))>
^
prog.cpp: In substitution of 'template<class F, class ... ArgTypes> decltype (std::detail::INVOKE(forward<F>(f), (forward<ArgTypes>)(std::invoke::args)...)) std::invoke(F&&, ArgTypes&& ...) [with F = void (Foo::* const&)(int&&); ArgTypes = {Foo* const&, const int&}]':
prog.cpp:110:31: required from 'runAsyncTerminateOnException(Fn&&, Args&& ...)::<lambda()> [with Fn = void (Foo::*)(int&&); Args = {Foo*, int}]'
prog.cpp:110:36: required from 'struct runAsyncTerminateOnException(Fn&&, Args&& ...) [with Fn = void (Foo::*)(int&&); Args = {Foo*, int}]::<lambda()>'
prog.cpp:108:22: required from 'auto runAsyncTerminateOnException(Fn&&, Args&& ...) [with Fn = void (Foo::*)(int&&); Args = {Foo*, int}]'
prog.cpp:127:86: required from here
prog.cpp:33:6: note: candidate: template<class Base, class T, class RefWrap, class ... Args> std::enable_if_t<(std::is_function_v<T> && std::detail::is_reference_wrapper_v<typename std::decay<Derived>::type>), decltype (std::detail::INVOKE::ref->get().*std::detail::INVOKE::pmf((forward<Args>)(std::detail::INVOKE::args)...))> std::detail::INVOKE(T Base::*, RefWrap&&, Args&& ...)
auto INVOKE(T Base::*pmf, RefWrap&& ref, Args&&... args)
^
prog.cpp:33:6: note: template argument deduction/substitution failed:
prog.cpp: In substitution of 'template<class Base, class T, class RefWrap, class ... Args> std::enable_if_t<(std::is_function_v<T> && std::detail::is_reference_wrapper_v<typename std::decay<Derived>::type>), decltype (std::detail::INVOKE::ref->get().*std::detail::INVOKE::pmf((forward<Args>)(std::detail::INVOKE::args)...))> std::detail::INVOKE(T Base::*, RefWrap&&, Args&& ...) [with Base = Foo; T = void(int&&); RefWrap = Foo* const&; Args = {const int&}]':
prog.cpp:99:28: required by substitution of 'template<class F, class ... ArgTypes> decltype (std::detail::INVOKE(forward<F>(f), (forward<ArgTypes>)(std::invoke::args)...)) std::invoke(F&&, ArgTypes&& ...) [with F = void (Foo::* const&)(int&&); ArgTypes = {Foo* const&, const int&}]'
prog.cpp:110:31: required from 'runAsyncTerminateOnException(Fn&&, Args&& ...)::<lambda()> [with Fn = void (Foo::*)(int&&); Args = {Foo*, int}]'
prog.cpp:110:36: required from 'struct runAsyncTerminateOnException(Fn&&, Args&& ...) [with Fn = void (Foo::*)(int&&); Args = {Foo*, int}]::<lambda()>'
prog.cpp:108:22: required from 'auto runAsyncTerminateOnException(Fn&&, Args&& ...) [with Fn = void (Foo::*)(int&&); Args = {Foo*, int}]'
prog.cpp:127:86: required from here
prog.cpp:37:24: error: request for member 'get' in 'ref', which is of pointer type 'Foo* const' (maybe you meant to use '->' ?)
decltype((ref.get().*pmf)(std::forward<Args>(args)...))>
^
prog.cpp: In substitution of 'template<class F, class ... ArgTypes> decltype (std::detail::INVOKE(forward<F>(f), (forward<ArgTypes>)(std::invoke::args)...)) std::invoke(F&&, ArgTypes&& ...) [with F = void (Foo::* const&)(int&&); ArgTypes = {Foo* const&, const int&}]':
prog.cpp:110:31: required from 'runAsyncTerminateOnException(Fn&&, Args&& ...)::<lambda()> [with Fn = void (Foo::*)(int&&); Args = {Foo*, int}]'
prog.cpp:110:36: required from 'struct runAsyncTerminateOnException(Fn&&, Args&& ...) [with Fn = void (Foo::*)(int&&); Args = {Foo*, int}]::<lambda()>'
prog.cpp:108:22: required from 'auto runAsyncTerminateOnException(Fn&&, Args&& ...) [with Fn = void (Foo::*)(int&&); Args = {Foo*, int}]'
prog.cpp:127:86: required from here
prog.cpp:44:6: note: candidate: template<class Base, class T, class Pointer, class ... Args> std::enable_if_t<((std::is_function_v<T> && (! std::detail::is_reference_wrapper_v<typename std::decay<Derived>::type>)) && (! std::is_base_of_v<Base, typename std::decay<Derived>::type>)), decltype (*(forward<Pointer>)(*std::detail::INVOKE::ptr).*std::detail::INVOKE::pmf((forward<Args>)(std::detail::INVOKE::args)...))> std::detail::INVOKE(T Base::*, Pointer&&, Args&& ...)
auto INVOKE(T Base::*pmf, Pointer&& ptr, Args&&... args)
^
prog.cpp:44:6: note: template argument deduction/substitution failed:
prog.cpp: In substitution of 'template<class Base, class T, class Pointer, class ... Args> std::enable_if_t<((std::is_function_v<T> && (! std::detail::is_reference_wrapper_v<typename std::decay<Derived>::type>)) && (! std::is_base_of_v<Base, typename std::decay<Derived>::type>)), decltype (*(forward<Pointer>)(*std::detail::INVOKE::ptr).*std::detail::INVOKE::pmf((forward<Args>)(std::detail::INVOKE::args)...))> std::detail::INVOKE(T Base::*, Pointer&&, Args&& ...) [with Base = Foo; T = void(int&&); Pointer = Foo* const&; Args = {const int&}]':
prog.cpp:99:28: required by substitution of 'template<class F, class ... ArgTypes> decltype (std::detail::INVOKE(forward<F>(f), (forward<ArgTypes>)(std::invoke::args)...)) std::invoke(F&&, ArgTypes&& ...) [with F = void (Foo::* const&)(int&&); ArgTypes = {Foo* const&, const int&}]'
prog.cpp:110:31: required from 'runAsyncTerminateOnException(Fn&&, Args&& ...)::<lambda()> [with Fn = void (Foo::*)(int&&); Args = {Foo*, int}]'
prog.cpp:110:36: required from 'struct runAsyncTerminateOnException(Fn&&, Args&& ...) [with Fn = void (Foo::*)(int&&); Args = {Foo*, int}]::<lambda()>'
prog.cpp:108:22: required from 'auto runAsyncTerminateOnException(Fn&&, Args&& ...) [with Fn = void (Foo::*)(int&&); Args = {Foo*, int}]'
prog.cpp:127:86: required from here
prog.cpp:49:50: error: cannot bind 'const int' lvalue to 'int&&'
decltype(((*std::forward<Pointer>(ptr)).*pmf)(std::forward<Args>(args)...))>
^
prog.cpp: In substitution of 'template<class F, class ... ArgTypes> decltype (std::detail::INVOKE(forward<F>(f), (forward<ArgTypes>)(std::invoke::args)...)) std::invoke(F&&, ArgTypes&& ...) [with F = void (Foo::* const&)(int&&); ArgTypes = {Foo* const&, const int&}]':
prog.cpp:110:31: required from 'runAsyncTerminateOnException(Fn&&, Args&& ...)::<lambda()> [with Fn = void (Foo::*)(int&&); Args = {Foo*, int}]'
prog.cpp:110:36: required from 'struct runAsyncTerminateOnException(Fn&&, Args&& ...) [with Fn = void (Foo::*)(int&&); Args = {Foo*, int}]::<lambda()>'
prog.cpp:108:22: required from 'auto runAsyncTerminateOnException(Fn&&, Args&& ...) [with Fn = void (Foo::*)(int&&); Args = {Foo*, int}]'
prog.cpp:127:86: required from here
prog.cpp:55:6: note: candidate: template<class Base, class T, class Derived> std::enable_if_t<((! std::is_function_v<T>) && std::is_base_of_v<Base, typename std::decay<Derived>::type>), decltype ((forward<Derived>)(*std::detail::INVOKE::ref).*std::detail::INVOKE::pmd)> std::detail::INVOKE(T Base::*, Derived&&)
auto INVOKE(T Base::*pmd, Derived&& ref)
^
prog.cpp:55:6: note: template argument deduction/substitution failed:
prog.cpp:99:28: note: candidate expects 2 arguments, 3 provided
-> decltype(detail::INVOKE(std::forward<F>(f), std::forward<ArgTypes>(args)...))
^
prog.cpp:65:6: note: candidate: template<class Base, class T, class RefWrap> std::enable_if_t<((! std::is_function_v<T>) && std::detail::is_reference_wrapper_v<typename std::decay<Derived>::type>), decltype (std::detail::INVOKE::ref->get().*std::detail::INVOKE::pmd)> std::detail::INVOKE(T Base::*, RefWrap&&)
auto INVOKE(T Base::*pmd, RefWrap&& ref)
^
prog.cpp:65:6: note: template argument deduction/substitution failed:
prog.cpp:99:28: note: candidate expects 2 arguments, 3 provided
-> decltype(detail::INVOKE(std::forward<F>(f), std::forward<ArgTypes>(args)...))
^
prog.cpp:75:6: note: candidate: template<class Base, class T, class Pointer> std::enable_if_t<(((! std::is_function_v<T>) && (! std::detail::is_reference_wrapper_v<typename std::decay<Derived>::type>)) && (! std::is_base_of_v<Base, typename std::decay<Derived>::type>)), decltype (*(forward<Pointer>)(*std::detail::INVOKE::ptr).*std::detail::INVOKE::pmd)> std::detail::INVOKE(T Base::*, Pointer&&)
auto INVOKE(T Base::*pmd, Pointer&& ptr)
^
prog.cpp:75:6: note: template argument deduction/substitution failed:
prog.cpp:99:28: note: candidate expects 2 arguments, 3 provided
-> decltype(detail::INVOKE(std::forward<F>(f), std::forward<ArgTypes>(args)...))
^
prog.cpp:86:6: note: candidate: template<class F, class ... Args> std::enable_if_t<(! std::is_member_pointer_v<typename std::decay<_Tp>::type>), decltype (forward<F>(f)((forward<Args>)(std::detail::INVOKE::args)...))> std::detail::INVOKE(F&&, Args&& ...)
auto INVOKE(F&& f, Args&&... args)
^
prog.cpp:86:6: note: template argument deduction/substitution failed:
prog.cpp: In substitution of 'template<class F, class ... Args> std::enable_if_t<(! std::is_member_pointer_v<typename std::decay<_Tp>::type>), decltype (forward<F>(f)((forward<Args>)(std::detail::INVOKE::args)...))> std::detail::INVOKE(F&&, Args&& ...) [with F = void (Foo::* const&)(int&&); Args = {Foo* const&, const int&}]':
prog.cpp:99:28: required by substitution of 'template<class F, class ... ArgTypes> decltype (std::detail::INVOKE(forward<F>(f), (forward<ArgTypes>)(std::invoke::args)...)) std::invoke(F&&, ArgTypes&& ...) [with F = void (Foo::* const&)(int&&); ArgTypes = {Foo* const&, const int&}]'
prog.cpp:110:31: required from 'runAsyncTerminateOnException(Fn&&, Args&& ...)::<lambda()> [with Fn = void (Foo::*)(int&&); Args = {Foo*, int}]'
prog.cpp:110:36: required from 'struct runAsyncTerminateOnException(Fn&&, Args&& ...) [with Fn = void (Foo::*)(int&&); Args = {Foo*, int}]::<lambda()>'
prog.cpp:108:22: required from 'auto runAsyncTerminateOnException(Fn&&, Args&& ...) [with Fn = void (Foo::*)(int&&); Args = {Foo*, int}]'
prog.cpp:127:86: required from here
prog.cpp:89:32: error: must use '.*' or '->*' to call pointer-to-member function in 'std::forward<void (Foo::* const&)(int&&)>((* & f)) (...)', e.g. '(... ->* std::forward<void (Foo::* const&)(int&&)>((* & f))) (...)'
decltype(std::forward<F>(f)(std::forward<Args>(args)...))>
^
In file included from prog.cpp:2:0:
/usr/include/c++/5/future:1703:5: error: 'std::future<typename std::result_of<_Functor(_ArgTypes ...)>::type> std::async(std::launch, _Fn&&, _Args&& ...) [with _Fn = runAsyncTerminateOnException(Fn&&, Args&& ...) [with Fn = void (Foo::*)(int&&); Args = {Foo*, int}]::<lambda()>; _Args = {}; typename std::result_of<_Functor(_ArgTypes ...)>::type = void]', declared using local type 'runAsyncTerminateOnException(Fn&&, Args&& ...) [with Fn = void (Foo::*)(int&&); Args = {Foo*, int}]::<lambda()>', is used but never defined [-fpermissive]
async(launch __policy, _Fn&& __fn, _Args&&... __args)
^