Apache Mesos
cpp17.hpp
Go to the documentation of this file.
1 // Licensed under the Apache License, Version 2.0 (the "License");
2 // you may not use this file except in compliance with the License.
3 // You may obtain a copy of the License at
4 //
5 // http://www.apache.org/licenses/LICENSE-2.0
6 //
7 // Unless required by applicable law or agreed to in writing, software
8 // distributed under the License is distributed on an "AS IS" BASIS,
9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 // limitations under the License.
11 
12 #ifndef __STOUT_CPP17_HPP__
13 #define __STOUT_CPP17_HPP__
14 
15 #include <utility>
16 
17 // This file contains implementation of C++17 standard library features.
18 // Once we adopt C++17, this file should be removed and usages of its
19 // functionality should be replaced with the standard library equivalents
20 // by replacing `cpp17` with `std` and including the appropriate headers.
21 
22 // Note that code in this file may not follow stout conventions strictly
23 // as it uses names as defined in C++ standard.
24 
25 namespace cpp17 {
26 
27 // <functional>
28 
29 // `std::invoke`
30 
31 #ifdef __WINDOWS__
32 using std::invoke;
33 #else
34 #define RETURN(...) -> decltype(__VA_ARGS__) { return __VA_ARGS__; }
35 
36 // NOTE: This implementation is not strictly conforming currently
37 // as attempting to use it with `std::reference_wrapper` will result
38 // in compilation failure.
39 
40 template <typename F, typename... As>
41 auto invoke(F&& f, As&&... as)
42  RETURN(std::forward<F>(f)(std::forward<As>(as)...))
43 
44 template <typename B, typename T, typename D>
45 auto invoke(T B::*pmv, D&& d)
46  RETURN(std::forward<D>(d).*pmv)
47 
48 template <typename Pmv, typename Ptr>
49 auto invoke(Pmv pmv, Ptr&& ptr)
50  RETURN((*std::forward<Ptr>(ptr)).*pmv)
51 
52 template <typename B, typename T, typename D, typename... As>
53 auto invoke(T B::*pmf, D&& d, As&&... as)
54  RETURN((std::forward<D>(d).*pmf)(std::forward<As>(as)...))
55 
56 template <typename Pmf, typename Ptr, typename... As>
57 auto invoke(Pmf pmf, Ptr&& ptr, As&&... as)
58  RETURN(((*std::forward<Ptr>(ptr)).*pmf)(std::forward<As>(as)...))
59 
60 #undef RETURN
61 #endif
62 
63 } // namespace cpp17 {
64 
65 #endif // __STOUT_CPP17_HPP__
F && f
Definition: defer.hpp:270
#define RETURN(...)
Definition: cpp17.hpp:34
Definition: type_utils.hpp:619
Definition: cpp17.hpp:25