Chris@101: /* Copyright 2006-2014 Joaquin M Lopez Munoz. Chris@16: * Distributed under the Boost Software License, Version 1.0. Chris@16: * (See accompanying file LICENSE_1_0.txt or copy at Chris@16: * http://www.boost.org/LICENSE_1_0.txt) Chris@16: * Chris@16: * See http://www.boost.org/libs/flyweight for library home page. Chris@16: */ Chris@16: Chris@101: #ifndef BOOST_FLYWEIGHT_DETAIL_PERFECT_FWD_HPP Chris@101: #define BOOST_FLYWEIGHT_DETAIL_PERFECT_FWD_HPP Chris@101: Chris@101: #if defined(_MSC_VER) Chris@101: #pragma once Chris@101: #endif Chris@101: Chris@101: /* C++03-compatible implementation of perfect forwarding. Chris@101: * Usage: Chris@101: * Chris@101: * # define NAME ... Chris@101: * # define BODY(args) {...BOOST_FLYWEIGHT_FORWARD(args)...} Chris@101: * BOOST_FLYWEIGHT_PERFECT_FWD(name,body) Chris@101: * Chris@101: * where NAME includes the return type and qualifiers (if any) and BODY(args) Chris@101: * is expected to fo the forwarding through BOOST_FLYWEIGHT_FORWARD(args). Chris@101: * Chris@101: * In compilers capable of perfect forwarding, the real thing is provided Chris@101: * (just one variadic args overload is generated). Otherwise the machinery Chris@101: * generates n+1 overloads, if rvalue refs are supported, or else 2^(n+1)-1 Chris@101: * overloads accepting any combination of lvalue refs and const lvalue refs, Chris@101: * up to BOOST_FLYWEIGHT_LIMIT_PERFECT_FWD_ARGS args. Chris@101: * Chris@101: * BOOST_FLYWEIGHT_PERFECT_FWD_WITH_ARGS(name,body) is a variation omitting the Chris@101: * overloads with zero args --when perfect forwarding is available, this second Chris@101: * macro is exactly the same as the original. Chris@16: */ Chris@16: Chris@101: #include /* keep it first to prevent nasty warns in MSVC */ Chris@101: #include Chris@101: #include Chris@101: #include Chris@101: #include Chris@101: Chris@101: #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) Chris@101: #include Chris@101: #endif Chris@101: Chris@101: #define BOOST_FLYWEIGHT_FORWARD_FORWARD_AUX(z,n,_) \ Chris@101: std::forward(BOOST_PP_CAT(t,n)) Chris@101: Chris@101: #define BOOST_FLYWEIGHT_FORWARD_FORWARD(n) \ Chris@101: BOOST_PP_ENUM(n,BOOST_FLYWEIGHT_FORWARD_FORWARD_AUX,~) Chris@101: Chris@101: #define BOOST_FLYWEIGHT_FORWARD_ENUM(n) BOOST_PP_ENUM_PARAMS(n,t) Chris@101: Chris@101: #define BOOST_FLYWEIGHT_FORWARD_PASS(arg) arg Chris@101: Chris@101: #define BOOST_FLYWEIGHT_FORWARD(args)\ Chris@101: BOOST_PP_CAT(BOOST_FLYWEIGHT_FORWARD_,BOOST_PP_SEQ_HEAD(args))( \ Chris@101: BOOST_PP_SEQ_HEAD(BOOST_PP_SEQ_TAIL(args))) Chris@101: Chris@101: #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)||\ Chris@101: defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) Chris@16: Chris@16: #if !defined(BOOST_FLYWEIGHT_LIMIT_PERFECT_FWD_ARGS) Chris@16: #define BOOST_FLYWEIGHT_LIMIT_PERFECT_FWD_ARGS 5 Chris@16: #endif Chris@16: Chris@101: #if BOOST_FLYWEIGHT_LIMIT_PERFECT_FWD_ARGS<0 Chris@101: #error BOOST_FLYWEIGHT_LIMIT_PERFECT_FWD_ARGS must be >=0 Chris@101: #endif Chris@101: Chris@16: #if BOOST_FLYWEIGHT_LIMIT_PERFECT_FWD_ARGS<=5 Chris@16: #include Chris@16: #else Chris@16: #include Chris@16: #endif Chris@101: Chris@101: #else Chris@101: Chris@101: /* real perfect forwarding */ Chris@101: Chris@101: #define BOOST_FLYWEIGHT_PERFECT_FWD(name,body) \ Chris@101: templatename(Args&&... args) \ Chris@101: body((PASS)(std::forward(args)...)) Chris@101: Chris@101: #define BOOST_FLYWEIGHT_PERFECT_FWD_WITH_ARGS \ Chris@101: BOOST_FLYWEIGHT_PERFECT_FWD Chris@101: Chris@101: #endif Chris@101: #endif