piranha  0.10
forwarding.hpp
Go to the documentation of this file.
1 /* Copyright 2009-2017 Francesco Biscani (bluescarni@gmail.com)
2 
3 This file is part of the Piranha library.
4 
5 The Piranha library is free software; you can redistribute it and/or modify
6 it under the terms of either:
7 
8  * the GNU Lesser General Public License as published by the Free
9  Software Foundation; either version 3 of the License, or (at your
10  option) any later version.
11 
12 or
13 
14  * the GNU General Public License as published by the Free Software
15  Foundation; either version 3 of the License, or (at your option) any
16  later version.
17 
18 or both in parallel, as here.
19 
20 The Piranha library is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 for more details.
24 
25 You should have received copies of the GNU General Public License and the
26 GNU Lesser General Public License along with the Piranha library. If not,
27 see https://www.gnu.org/licenses/. */
28 
35 #ifndef PIRANHA_FORWARDING_HPP
36 #define PIRANHA_FORWARDING_HPP
37 
38 #include <type_traits>
39 #include <utility>
40 
42 
50 #define PIRANHA_FORWARDING_CTOR(Derived, Base) \
51  template < \
52  typename T_, typename... Args_, \
53  typename = typename std:: \
54  enable_if<std::is_constructible<Base, T_ &&, Args_ &&...>::value \
55  && (sizeof...(Args_) || !std::is_base_of<Derived, typename std::decay<T_>::type>::value)>::type> \
56  explicit Derived(T_ &&arg0, Args_ &&... args) : Base(std::forward<T_>(arg0), std::forward<Args_>(args)...) \
57  { \
58  }
59 
61 
68 #define PIRANHA_FORWARDING_ASSIGNMENT(Derived, Base) \
69  template <typename T_> \
70  typename std::enable_if<std::is_assignable<Base &, T_ &&>::value \
71  && !std::is_base_of<Derived, typename std::decay<T_>::type>::value, \
72  Derived &>::type \
73  operator=(T_ &&arg) \
74  { \
75  Base::operator=(std::forward<T_>(arg)); \
76  return *this; \
77  }
78 
79 #endif