Advertisement
Ilya_Bykonya

Untitled

Jan 27th, 2023 (edited)
760
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | Source Code | 0 0
  1. template<typename Callable>
  2. constexpr auto invert(Callable&& callable) noexcept {
  3.     return[func = std::move(callable)] <typename...Args> (Args&&... args) ->std::invoke_result_t<Callable, Args...> {
  4.         return not std::invoke(func, std::forward<Args>(args)...);
  5.     };
  6. }
  7.  
  8.  
  9. //Версия от Георгия Яковлева
  10. //upd -- убрал [[nodiscard]] после requires, потому что с ним не всюду работает
  11. template<typename Callable>
  12. [[nodiscard]] constexpr auto invert(Callable&& callable)
  13.     noexcept(std::is_nothrow_move_assignable_v<Callable>)
  14. {
  15.     return [func = std::move(callable)]<typename...Args> requires std::invocable<Callable, Args...>
  16.         (Args&&...args) noexcept(std::is_nothrow_invocable_v<Callable, Args...>) -> std::invoke_result_t<Callable, Args...> {
  17.         return not std::invoke(func, std::forward<Args>(args)...);
  18.     };
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement