[typeof] preprocessor reentrancy

I think you may want to use (BOOST_PP_)REPEAT in conjunction with SEQ_ELEM and SEQ_SIZE instead of SEQ_FOR_EACH. Since REPEAT is automatically re-entrant, it may be less
Reposting under a new subject. --- Arkadiy Vertleyb wrote: trouble to
use it, and you don't depend on what typeof has inside.
I'm also studying file iteration so I can see if that helps me out.
(OTOH, I am thinking of adopting the same strategy, so that people don't have re-entrancy problems when using typeof.)
Please do adopt this strategy. Currently this kind of code doesn't work: BOOST_TYPEOF_REGISTER_TYPE( boost::mpl::math::string_c_to_double , BOOST_MPL_PP_ARG_SEQ(unsigned char, 40) ) BOOST_MPL_PP_ARG_SEQ uses BOOST_PP_REPEAT to create a sequence of N elements containing the specified primitive integral type.
Added in CVS:
BOOST_TYPEOF_REGISTER_TYPE_EXPLICIT_ID(Name, Id) BOOST_TYPEOF_REGISTER_TEMPLATE_EXPLICIT_ID(Name, Params, Id)
I'll make use of them when I get the chance. Cromwell D. Enage __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com

"Cromwell Enage" <sponage@yahoo.com> wrote
I'm also studying file iteration so I can see if that helps me out.
File iteration works good with typeof, and you don't have to explicitly specify IDs. The only problem -- you can't use the file iteration in a macro.
(OTOH, I am thinking of adopting the same strategy, so that people don't have re-entrancy problems when using typeof.)
Please do adopt this strategy. Currently this kind of code doesn't work:
BOOST_TYPEOF_REGISTER_TYPE( ^^^^^ boost::mpl::math::string_c_to_double , BOOST_MPL_PP_ARG_SEQ(unsigned char, 40) )
BOOST_MPL_PP_ARG_SEQ uses BOOST_PP_REPEAT to create a sequence of N elements containing the specified primitive integral type.
Do you mean BOOST_TYPEOF_REGISTER_TEMPLATE? I am not sure REPEAT is a problem here. The following example works (vc71): ---------------- #define BOOST_TYPEOF_COMPLIANT #include <boost/typeof/typeof.hpp> template<int n, short m> class x {}; #define seq (int)(short) #define MACRO(z, n, text) (BOOST_PP_SEQ_ELEM(n, text)) BOOST_TYPEOF_REGISTER_TEMPLATE(x, BOOST_PP_REPEAT(BOOST_PP_SEQ_SIZE(seq), MACRO, seq)) typedef BOOST_TYPEOF((x<1, 2>())) type; type y; int main() {} ----------------- Regards, Arkadiy

--- Arkadiy Vertleyb wrote:
"Cromwell Enage" wrote
I'm also studying file iteration so I can see if that helps me out.
File iteration works good with typeof, and you don't have to explicitly specify IDs. The only problem -- you can't use the file iteration in a macro.
Understood.
The following example works (vc71):
---------------- #define BOOST_TYPEOF_COMPLIANT #include <boost/typeof/typeof.hpp>
template<int n, short m> class x {};
#define seq (int)(short) #define MACRO(z, n, text) (BOOST_PP_SEQ_ELEM(n, text)) BOOST_TYPEOF_REGISTER_TEMPLATE(x, BOOST_PP_REPEAT(BOOST_PP_SEQ_SIZE(seq), MACRO, seq))
typedef BOOST_TYPEOF((x<1, 2>())) type; type y;
int main() {}
Okay, I'll give it a roll. Cromwell D. Enage __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com

Arkadiy Vertleyb wrote:
"Cromwell Enage" <sponage@yahoo.com> wrote
File iteration works good with typeof,
and you don't have to explicitly ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ specify IDs. ^^^^^^^^^^^^^^
Curious question: does it work like this if IS_ITERATING then id <- 0 for i <- 0, i < ITERATION_DEPTH id <- id * ITERATION_FINISH(i) + FRAME_ITERATION(i) id <- encode_full_id(BOOST_PP_COUNTER, id) ?
Please do adopt this strategy. Currently this kind of code doesn't work:
BOOST_TYPEOF_REGISTER_TYPE(
^^^^^
boost::mpl::math::string_c_to_double , BOOST_MPL_PP_ARG_SEQ(unsigned char, 40) )
Are you sure the output of BOOST_MPL_PP_ARG_SEQ is a sequence? (unsigned char)(unsigned char)(unsigned char)(unsigned char) [... x10 ]
BOOST_MPL_PP_ARG_SEQ uses BOOST_PP_REPEAT to create a sequence of N elements containing the specified primitive integral type.
Do you mean BOOST_TYPEOF_REGISTER_TEMPLATE? I am not sure REPEAT is a problem here.
Because BOOST_PP_REPEAT should really not be a problem here. Rescanning happens /after/ argument substitution [ 16.3.4.-1 ] and the replacement restrictions for rescanning [ 16.3.4-2 ] do not apply for argument substitution [ 16.3.1 "A parameter in the replacement list [...] is replaced by the corresponding argument after /all/ macros contained therein have been expanded" ]. Simple example: #include <boost/preprocessor/cat.hpp> BOOST_PP_CAT(f,BOOST_PP_CAT(o,o)) // expands to foo, no tricks necessary The proof for BOOST_PP_REPEAT (note that I use BOOST_PP_REPEAT_1ST to ensure they are nonreentrant): #include <boost/preprocessor/cat.hpp> #include <boost/preprocessor/seq/size.hpp> #include <boost/preprocessor/seq/elem.hpp> #include <boost/preprocessor/repetition/repeat.hpp> #define make_seq_elem(z,i,d) (foo) #define make_seq(n) BOOST_PP_REPEAT_1ST(n,make_seq_elem,-) #define for_each(seq,m) BOOST_PP_REPEAT_1ST(BOOST_PP_SEQ_SIZE(seq),m,seq) #define seq_suffix_elem_idx(z,i,seq) (BOOST_PP_CAT(BOOST_PP_SEQ_ELEM(i,seq),i)) for_each(make_seq(10),seq_suffix_elem_idx) // (foo0) (foo1) (foo2) (foo3) (foo4) (foo5) (foo6) (foo7) (foo8) (foo9) Regards, Tobias

"Tobias Schwinger" <tschwinger@neoscientists.org> wrote
Arkadiy Vertleyb wrote:
File iteration works good with typeof,
and you don't have to explicitly ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ specify IDs. ^^^^^^^^^^^^^^
Curious question: does it work like this
if IS_ITERATING then id <- 0 for i <- 0, i < ITERATION_DEPTH id <- id * ITERATION_FINISH(i) + FRAME_ITERATION(i) id <- encode_full_id(BOOST_PP_COUNTER, id)
?
Not really... There is nothing specific in typeof to handle this case. All you have to do is to increment the registration group inside the iterated file, so that each iteration uses its own registration group (and the same line numbers). Regards, Arkadiy
participants (3)
-
Arkadiy Vertleyb
-
Cromwell Enage
-
Tobias Schwinger