Карта сайта Kansoftware
НОВОСТИУСЛУГИРЕШЕНИЯКОНТАКТЫ
Разработка программного обеспечения

BOOST_PP_FOR

Boost , ,

The BOOST_PP_FOR macro represents a generalized horizontal repetition construct.

Usage

BOOST_PP_FOR(state, pred, op, macro)

Arguments

state
The initial state.
pred
A binary predicate of the form pred(r, state).  This macro must expand to an integer in the range of 0 to BOOST_PP_LIMIT_MAGBOOST_PP_FOR repeatedly expands macro while this predicate returns non-zero.  This macro is called with the next available BOOST_PP_FOR repetition and the current state.
op
A binary operation of the form op(r, state).  This operation is expanded by BOOST_PP_FOR with the next available BOOST_PP_FOR repetition and the current state.  This macro is repeatedly applied to the state, each time producing a new state, until pred returns 0.
macro
A binary macro of the form macro(r, state).  This macro is expanded by BOOST_PP_FOR with the next available BOOST_PP_FOR repetition and the current state.  This macro is is repeated by BOOST_PP_FOR until pred returns 0.

Remarks

This macro expands to the sequence:
macro(r, state) macro(r, op(r, state)) ... macro(r, op(r, ... op(r, state) ... ))
The r value that is passed to pred, op, and macro represents the next available BOOST_PP_FOR repetition.  Other macros that have _R suffix variants internally use BOOST_PP_FOR--for example, BOOST_PP_LIST_FOR_EACH and BOOST_PP_LIST_FOR_EACH_R.  Using these _R versions is not strictly necessary, but passing the r value (that is passed to pred, op, and macro) to these macros allows them to reenter BOOST_PP_FOR with maximum efficiency.
To directly use this r value, rather than simply passing it to another macro, see BOOST_PP_FOR_r.
Previously, this macro could not be used recursively inside BOOST_PP_FOR.  This limitation no longer exists, as the library can automatically detect the next available BOOST_PP_FOR repetition.

See Also

Requirements

Header:  <boost/preprocessor/repetition/for.hpp>

Sample Code

#include <boost/preprocessor/arithmetic/inc.hpp>
#include <boost/preprocessor/comparison/not_equal.hpp>
#include <boost/preprocessor/repetition/for.hpp>
#include <boost/preprocessor/tuple/elem.hpp>
#define PRED(r, state) \
   BOOST_PP_NOT_EQUAL( \
      BOOST_PP_TUPLE_ELEM(2, 0, state), \
      BOOST_PP_INC(BOOST_PP_TUPLE_ELEM(2, 1, state)) \
   ) \
   /**/
#define OP(r, state) \
   ( \
      BOOST_PP_INC(BOOST_PP_TUPLE_ELEM(2, 0, state)), \
      BOOST_PP_TUPLE_ELEM(2, 1, state) \
   ) \
   /**/
#define MACRO(r, state) BOOST_PP_TUPLE_ELEM(2, 0, state)
BOOST_PP_FOR((5, 10), PRED, OP, MACRO) // expands to 5 6 7 8 9 10

© Copyright Housemarque Oy 2002
© Copyright Paul Mensonides 2002

Распространяется в соответствии с лицензией Boost Software License, Version 1.0. (См. сопроводительный файл)LICENSE_1_0.txtили копия наwww.boost.org/LICENSE_1_0.txt

Статья BOOST_PP_FOR раздела может быть полезна для разработчиков на c++ и boost.




Материалы статей собраны из открытых источников, владелец сайта не претендует на авторство. Там где авторство установить не удалось, материал подаётся без имени автора. В случае если Вы считаете, что Ваши права нарушены, пожалуйста, свяжитесь с владельцем сайта.



:: Главная :: ::


реклама


©KANSoftWare (разработка программного обеспечения, создание программ, создание интерактивных сайтов), 2007
Top.Mail.Ru

Время компиляции файла: 2024-08-30 11:47:00
2025-05-21 09:05:03/0.0033819675445557/0