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_DYN_PERFECT_FWD_HPP
10 #define BOOST_FLYWEIGHT_DETAIL_DYN_PERFECT_FWD_HPP
16 #include <boost/config.hpp>
18 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
20 #include <boost/preprocessor/arithmetic/add.hpp>
21 #include <boost/preprocessor/cat.hpp>
22 #include <boost/preprocessor/repetition/enum.hpp>
23 #include <boost/preprocessor/repetition/enum_params.hpp>
24 #include <boost/preprocessor/repetition/repeat_from_to.hpp>
25 #include <boost/preprocessor/seq/seq.hpp>
27 #define BOOST_FLYWEIGHT_PERFECT_FWD_ARG(z,n,_) \
28 BOOST_PP_CAT(T,n)&& BOOST_PP_CAT(t,n)
30 #define BOOST_FLYWEIGHT_PERFECT_FWD_N_AUX(n,name,body) \
31 template<BOOST_PP_ENUM_PARAMS(n,typename T)> \
32 name(BOOST_PP_ENUM(n,BOOST_FLYWEIGHT_PERFECT_FWD_ARG,~)) \
35 #define BOOST_FLYWEIGHT_PERFECT_FWD_N(z,n,data) \
36 BOOST_FLYWEIGHT_PERFECT_FWD_N_AUX( \
37 n,BOOST_PP_SEQ_HEAD(data), \
38 BOOST_PP_SEQ_HEAD(BOOST_PP_SEQ_TAIL(data)))
40 #define BOOST_FLYWEIGHT_PERFECT_FWD_WITH_ARGS(name,body) \
41 BOOST_PP_REPEAT_FROM_TO( \
42 1,BOOST_PP_ADD(BOOST_FLYWEIGHT_LIMIT_PERFECT_FWD_ARGS,1), \
43 BOOST_FLYWEIGHT_PERFECT_FWD_N,(name)(body))
45 #define BOOST_FLYWEIGHT_PERFECT_FWD(name,body) \
46 name()body((ENUM)(0)) \
47 BOOST_FLYWEIGHT_PERFECT_FWD_WITH_ARGS(name,body)
51 /* no rvalue refs -> [const] Tn& overloads */
53 #include <boost/preprocessor/arithmetic/add.hpp>
54 #include <boost/preprocessor/cat.hpp>
55 #include <boost/preprocessor/repetition/enum.hpp>
56 #include <boost/preprocessor/repetition/enum_params.hpp>
57 #include <boost/preprocessor/repetition/repeat.hpp>
58 #include <boost/preprocessor/repetition/repeat_from_to.hpp>
59 #include <boost/preprocessor/seq/elem.hpp>
60 #include <boost/preprocessor/seq/for_each_product.hpp>
61 #include <boost/preprocessor/seq/seq.hpp>
62 #include <boost/preprocessor/seq/size.hpp>
64 #define BOOST_FLYWEIGHT_CONST(b) BOOST_PP_CAT(BOOST_FLYWEIGHT_CONST,b)
65 #define BOOST_FLYWEIGHT_CONST0
66 #define BOOST_FLYWEIGHT_CONST1 const
68 /* if mask[n]==0 --> Tn& tn
69 * if mask[n]==1 --> const Tn& tn
72 #define BOOST_FLYWEIGHT_PERFECT_FWD_ARG(z,n,mask) \
73 BOOST_FLYWEIGHT_CONST(BOOST_PP_SEQ_ELEM(n,mask)) \
74 BOOST_PP_CAT(T,n)& BOOST_PP_CAT(t,n)
76 /* overload accepting size(mask) args, where the template args are
77 * marked const or not according to the given mask (a seq of 0 or 1)
80 #define BOOST_FLYWEIGHT_PERFECT_FWD_MASK_AUX(r,name,body,mask) \
81 template<BOOST_PP_ENUM_PARAMS(BOOST_PP_SEQ_SIZE(mask),typename T)> \
84 BOOST_PP_SEQ_SIZE(mask),BOOST_FLYWEIGHT_PERFECT_FWD_ARG,mask)) \
85 body((ENUM)(BOOST_PP_SEQ_SIZE(mask)))
87 #define BOOST_FLYWEIGHT_PERFECT_FWD_MASK(r,data) \
88 BOOST_FLYWEIGHT_PERFECT_FWD_MASK_AUX( \
90 BOOST_PP_SEQ_ELEM(0,BOOST_PP_SEQ_HEAD(data)), \
91 BOOST_PP_SEQ_ELEM(1,BOOST_PP_SEQ_HEAD(data)), \
92 BOOST_PP_SEQ_TAIL(data))
94 #define BOOST_FLYWEIGHT_01(z,n,_) ((0)(1))
96 /* Perfect forwarding overloads accepting 1 to n args */
98 #define BOOST_FLYWEIGHT_PERFECT_FWD_N(z,n,data) \
99 BOOST_PP_SEQ_FOR_EACH_PRODUCT( \
100 BOOST_FLYWEIGHT_PERFECT_FWD_MASK, \
102 BOOST_PP_REPEAT(n,BOOST_FLYWEIGHT_01,~))
104 #define BOOST_FLYWEIGHT_PERFECT_FWD_WITH_ARGS(name,body) \
105 BOOST_PP_REPEAT_FROM_TO( \
106 1,BOOST_PP_ADD(BOOST_FLYWEIGHT_LIMIT_PERFECT_FWD_ARGS,1), \
107 BOOST_FLYWEIGHT_PERFECT_FWD_N,(name)(body))
109 #define BOOST_FLYWEIGHT_PERFECT_FWD(name,body) \
110 name()body((ENUM)(0)) \
111 BOOST_FLYWEIGHT_PERFECT_FWD_WITH_ARGS(name,body)