Logo ROOT  
Reference Guide
RNotFn.hxx
Go to the documentation of this file.
1/// \file ROOT/RNotFn.hxx
2/// \ingroup Base StdExt
3/// \author Danilo Piparo, Enrico Guiraud
4/// \date 2018-01-19
5
6/*************************************************************************
7 * Copyright (C) 1995-2018, Rene Brun and Fons Rademakers. *
8 * All rights reserved. *
9 * *
10 * For the licensing terms see $ROOTSYS/LICENSE. *
11 * For the list of contributors see $ROOTSYS/README/CREDITS. *
12 *************************************************************************/
13
14#ifndef ROOT_RNotFn
15#define ROOT_RNotFn
16
17#include <functional>
18
19// Backport if not_fn is not available.
20// libc++ does not define __cpp_lib_not_fn.
21// Assume we have not_fn if libc++ is compiled with C++14 and up.
22#if !defined(__cpp_lib_not_fn) && !(defined(_LIBCPP_VERSION) && __cplusplus > 201103L)
23
24#define R__NOTFN_BACKPORT
25
26#include "ROOT/TypeTraits.hxx" // InvokeInvokeResult_t
27 //
28#include <type_traits> // std::decay
29#include <utility> // std::forward, std::declval
30
31namespace std {
32
33namespace __ROOT_noinline {
34template <typename F>
35class not_fn_t {
36 std::decay_t<F> fFun;
37
38public:
39 explicit not_fn_t(F &&f) : fFun(std::forward<F>(f)) {}
40 not_fn_t(not_fn_t &&h) = default;
41 not_fn_t(const not_fn_t &f) = default;
42
43 template <class... Args>
44 auto
45 operator()(Args &&...args) & -> decltype(!std::declval<ROOT::TypeTraits::InvokeResult_t<std::decay_t<F>, Args...>>())
46 {
47 return !fFun(std::forward<Args>(args)...);
48 }
49 template <class... Args>
50 auto operator()(Args &&...args)
51 const & -> decltype(!std::declval<ROOT::TypeTraits::InvokeResult_t<std::decay_t<F> const, Args...>>())
52 {
53 return !fFun(std::forward<Args>(args)...);
54 }
55};
56}
57
58
59template <typename F>
60__ROOT_noinline::not_fn_t<F> not_fn(F &&f)
61{
62 return __ROOT_noinline::not_fn_t<F>(std::forward<F>(f));
63}
64}
65
66#endif
67
68#endif
#define f(i)
Definition: RSha256.hxx:104
#define h(i)
Definition: RSha256.hxx:106
TRObject operator()(const T1 &t1) const
#define F(x, y, z)