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