Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / msg / async / dpdk / capture.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 /*
3  * Ceph - scalable distributed file system
4  *
5  * Copyright (C) 2015 XSky <haomai@xsky.com>
6  *
7  * Author: Haomai Wang <haomaiwang@gmail.com>
8  *
9  * This is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License version 2.1, as published by the Free Software
12  * Foundation.  See file COPYING.
13  *
14  */
15
16 #ifndef CEPH_MSG_DPDK_CAPTURE_H
17 #define CEPH_MSG_DPDK_CAPTURE_H
18
19 #include <utility>
20
21 template <typename T, typename F>
22 class capture_impl {
23   T x;
24   F f;
25  public:
26   capture_impl(capture_impl &) = delete;
27   capture_impl( T && x, F && f )
28       : x{std::forward<T>(x)}, f{std::forward<F>(f)}
29   {}
30
31   template <typename ...Ts> auto operator()( Ts&&...args )
32   -> decltype(f( x, std::forward<Ts>(args)... ))
33   {
34     return f( x, std::forward<Ts>(args)... );
35   }
36
37   template <typename ...Ts> auto operator()( Ts&&...args ) const
38   -> decltype(f( x, std::forward<Ts>(args)... ))
39   {
40     return f( x, std::forward<Ts>(args)... );
41   }
42 };
43
44 template <typename T, typename F>
45 capture_impl<T,F> capture( T && x, F && f ) {
46   return capture_impl<T,F>(
47       std::forward<T>(x), std::forward<F>(f) );
48 }
49
50 #endif //CEPH_MSG_DPDK_CAPTURE_H