Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:52

0001 /* Copyright 2006-2014 Joaquin M Lopez Munoz.
0002  * Distributed under the Boost Software License, Version 1.0.
0003  * (See accompanying file LICENSE_1_0.txt or copy at
0004  * http://www.boost.org/LICENSE_1_0.txt)
0005  *
0006  * See http://www.boost.org/libs/flyweight for library home page.
0007  */
0008 
0009 #ifndef BOOST_FLYWEIGHT_DETAIL_PERFECT_FWD_HPP
0010 #define BOOST_FLYWEIGHT_DETAIL_PERFECT_FWD_HPP
0011 
0012 #if defined(_MSC_VER)
0013 #pragma once
0014 #endif
0015 
0016 /* C++03-compatible implementation of perfect forwarding.
0017  * Usage:
0018  *
0019  *  # define NAME ...
0020  *  # define BODY(args) {...BOOST_FLYWEIGHT_FORWARD(args)...}
0021  *  BOOST_FLYWEIGHT_PERFECT_FWD(name,body)
0022  *
0023  * where NAME includes the return type and qualifiers (if any) and BODY(args)
0024  * is expected to fo the forwarding through BOOST_FLYWEIGHT_FORWARD(args).
0025  *
0026  * In compilers capable of perfect forwarding, the real thing is provided
0027  * (just one variadic args overload is generated). Otherwise the machinery
0028  * generates n+1 overloads, if rvalue refs are supported, or else 2^(n+1)-1
0029  * overloads accepting any combination of lvalue refs and const lvalue refs,
0030  * up to BOOST_FLYWEIGHT_LIMIT_PERFECT_FWD_ARGS args.
0031  *
0032  * BOOST_FLYWEIGHT_PERFECT_FWD_WITH_ARGS(name,body) is a variation omitting the
0033  * overloads with zero args --when perfect forwarding is available, this second
0034  * macro is exactly the same as the original. 
0035  */
0036 
0037 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
0038 #include <boost/preprocessor/cat.hpp>
0039 #include <boost/preprocessor/repetition/enum.hpp>
0040 #include <boost/preprocessor/repetition/enum_params.hpp>
0041 #include <boost/preprocessor/seq/seq.hpp>
0042 
0043 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
0044 #include <utility>
0045 #endif
0046 
0047 #define BOOST_FLYWEIGHT_FORWARD_FORWARD_AUX(z,n,_) \
0048 std::forward<BOOST_PP_CAT(T,n)>(BOOST_PP_CAT(t,n))
0049 
0050 #define BOOST_FLYWEIGHT_FORWARD_FORWARD(n) \
0051 BOOST_PP_ENUM(n,BOOST_FLYWEIGHT_FORWARD_FORWARD_AUX,~)
0052 
0053 #define BOOST_FLYWEIGHT_FORWARD_ENUM(n) BOOST_PP_ENUM_PARAMS(n,t)
0054 
0055 #define BOOST_FLYWEIGHT_FORWARD_PASS(arg) arg
0056 
0057 #define BOOST_FLYWEIGHT_FORWARD(args)\
0058 BOOST_PP_CAT(BOOST_FLYWEIGHT_FORWARD_,BOOST_PP_SEQ_HEAD(args))( \
0059 BOOST_PP_SEQ_HEAD(BOOST_PP_SEQ_TAIL(args)))
0060 
0061 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)||\
0062     defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
0063 
0064 #if !defined(BOOST_FLYWEIGHT_LIMIT_PERFECT_FWD_ARGS)
0065 #define BOOST_FLYWEIGHT_LIMIT_PERFECT_FWD_ARGS 5
0066 #endif
0067 
0068 #if BOOST_FLYWEIGHT_LIMIT_PERFECT_FWD_ARGS<0
0069 #error BOOST_FLYWEIGHT_LIMIT_PERFECT_FWD_ARGS must be >=0
0070 #endif
0071 
0072 #if BOOST_FLYWEIGHT_LIMIT_PERFECT_FWD_ARGS<=5
0073 #include <boost/flyweight/detail/pp_perfect_fwd.hpp>
0074 #else
0075 #include <boost/flyweight/detail/dyn_perfect_fwd.hpp>
0076 #endif
0077 
0078 #else
0079 
0080 /* real perfect forwarding */
0081 
0082 #define BOOST_FLYWEIGHT_PERFECT_FWD(name,body) \
0083 template<typename... Args>name(Args&&... args) \
0084 body((PASS)(std::forward<Args>(args)...))
0085 
0086 #define BOOST_FLYWEIGHT_PERFECT_FWD_WITH_ARGS  \
0087 BOOST_FLYWEIGHT_PERFECT_FWD
0088 
0089 #endif
0090 #endif