Make my C++ Class iterable via BOOST_FOREACH

前端 未结 3 437
失恋的感觉
失恋的感觉 2020-12-30 09:11

I have a class which I want to expose a list of structs (which just contain some integers). I don\'t want the outside to modify these data, just iterate over it and read the

3条回答
  •  误落风尘
    2020-12-30 09:59

    From the Boost FOR_EACH documentation page:

    BOOST_FOREACH iterates over sequences. But what qualifies as a sequence, exactly? Since BOOST_FOREACH is built on top of Boost.Range, it automatically supports those types which Boost.Range recognizes as sequences. Specifically, BOOST_FOREACH works with types that satisfy the Single Pass Range Concept. For example, we can use BOOST_FOREACH with:

提交回复
热议问题