Chris@101
|
1 /* Copyright 2006-2014 Joaquin M Lopez Munoz.
|
Chris@16
|
2 * Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
3 * (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
4 * http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
5 *
|
Chris@16
|
6 * See http://www.boost.org/libs/flyweight for library home page.
|
Chris@16
|
7 */
|
Chris@16
|
8
|
Chris@101
|
9 #ifndef BOOST_FLYWEIGHT_DETAIL_PERFECT_FWD_HPP
|
Chris@101
|
10 #define BOOST_FLYWEIGHT_DETAIL_PERFECT_FWD_HPP
|
Chris@101
|
11
|
Chris@101
|
12 #if defined(_MSC_VER)
|
Chris@101
|
13 #pragma once
|
Chris@101
|
14 #endif
|
Chris@101
|
15
|
Chris@101
|
16 /* C++03-compatible implementation of perfect forwarding.
|
Chris@101
|
17 * Usage:
|
Chris@101
|
18 *
|
Chris@101
|
19 * # define NAME ...
|
Chris@101
|
20 * # define BODY(args) {...BOOST_FLYWEIGHT_FORWARD(args)...}
|
Chris@101
|
21 * BOOST_FLYWEIGHT_PERFECT_FWD(name,body)
|
Chris@101
|
22 *
|
Chris@101
|
23 * where NAME includes the return type and qualifiers (if any) and BODY(args)
|
Chris@101
|
24 * is expected to fo the forwarding through BOOST_FLYWEIGHT_FORWARD(args).
|
Chris@101
|
25 *
|
Chris@101
|
26 * In compilers capable of perfect forwarding, the real thing is provided
|
Chris@101
|
27 * (just one variadic args overload is generated). Otherwise the machinery
|
Chris@101
|
28 * generates n+1 overloads, if rvalue refs are supported, or else 2^(n+1)-1
|
Chris@101
|
29 * overloads accepting any combination of lvalue refs and const lvalue refs,
|
Chris@101
|
30 * up to BOOST_FLYWEIGHT_LIMIT_PERFECT_FWD_ARGS args.
|
Chris@101
|
31 *
|
Chris@101
|
32 * BOOST_FLYWEIGHT_PERFECT_FWD_WITH_ARGS(name,body) is a variation omitting the
|
Chris@101
|
33 * overloads with zero args --when perfect forwarding is available, this second
|
Chris@101
|
34 * macro is exactly the same as the original.
|
Chris@16
|
35 */
|
Chris@16
|
36
|
Chris@101
|
37 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
|
Chris@101
|
38 #include <boost/preprocessor/cat.hpp>
|
Chris@101
|
39 #include <boost/preprocessor/repetition/enum.hpp>
|
Chris@101
|
40 #include <boost/preprocessor/repetition/enum_params.hpp>
|
Chris@101
|
41 #include <boost/preprocessor/seq/seq.hpp>
|
Chris@101
|
42
|
Chris@101
|
43 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
Chris@101
|
44 #include <utility>
|
Chris@101
|
45 #endif
|
Chris@101
|
46
|
Chris@101
|
47 #define BOOST_FLYWEIGHT_FORWARD_FORWARD_AUX(z,n,_) \
|
Chris@101
|
48 std::forward<BOOST_PP_CAT(T,n)>(BOOST_PP_CAT(t,n))
|
Chris@101
|
49
|
Chris@101
|
50 #define BOOST_FLYWEIGHT_FORWARD_FORWARD(n) \
|
Chris@101
|
51 BOOST_PP_ENUM(n,BOOST_FLYWEIGHT_FORWARD_FORWARD_AUX,~)
|
Chris@101
|
52
|
Chris@101
|
53 #define BOOST_FLYWEIGHT_FORWARD_ENUM(n) BOOST_PP_ENUM_PARAMS(n,t)
|
Chris@101
|
54
|
Chris@101
|
55 #define BOOST_FLYWEIGHT_FORWARD_PASS(arg) arg
|
Chris@101
|
56
|
Chris@101
|
57 #define BOOST_FLYWEIGHT_FORWARD(args)\
|
Chris@101
|
58 BOOST_PP_CAT(BOOST_FLYWEIGHT_FORWARD_,BOOST_PP_SEQ_HEAD(args))( \
|
Chris@101
|
59 BOOST_PP_SEQ_HEAD(BOOST_PP_SEQ_TAIL(args)))
|
Chris@101
|
60
|
Chris@101
|
61 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)||\
|
Chris@101
|
62 defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
Chris@16
|
63
|
Chris@16
|
64 #if !defined(BOOST_FLYWEIGHT_LIMIT_PERFECT_FWD_ARGS)
|
Chris@16
|
65 #define BOOST_FLYWEIGHT_LIMIT_PERFECT_FWD_ARGS 5
|
Chris@16
|
66 #endif
|
Chris@16
|
67
|
Chris@101
|
68 #if BOOST_FLYWEIGHT_LIMIT_PERFECT_FWD_ARGS<0
|
Chris@101
|
69 #error BOOST_FLYWEIGHT_LIMIT_PERFECT_FWD_ARGS must be >=0
|
Chris@101
|
70 #endif
|
Chris@101
|
71
|
Chris@16
|
72 #if BOOST_FLYWEIGHT_LIMIT_PERFECT_FWD_ARGS<=5
|
Chris@16
|
73 #include <boost/flyweight/detail/pp_perfect_fwd.hpp>
|
Chris@16
|
74 #else
|
Chris@16
|
75 #include <boost/flyweight/detail/dyn_perfect_fwd.hpp>
|
Chris@16
|
76 #endif
|
Chris@101
|
77
|
Chris@101
|
78 #else
|
Chris@101
|
79
|
Chris@101
|
80 /* real perfect forwarding */
|
Chris@101
|
81
|
Chris@101
|
82 #define BOOST_FLYWEIGHT_PERFECT_FWD(name,body) \
|
Chris@101
|
83 template<typename... Args>name(Args&&... args) \
|
Chris@101
|
84 body((PASS)(std::forward<Args>(args)...))
|
Chris@101
|
85
|
Chris@101
|
86 #define BOOST_FLYWEIGHT_PERFECT_FWD_WITH_ARGS \
|
Chris@101
|
87 BOOST_FLYWEIGHT_PERFECT_FWD
|
Chris@101
|
88
|
Chris@101
|
89 #endif
|
Chris@101
|
90 #endif
|