Make my C++ Class iterable via BOOST_FOREACH

前端 未结 3 429
失恋的感觉
失恋的感觉 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:49

    If your collection type presents a standard container interface, you don't need to do anything to make BOOST_FOREACH work with your type. In other words, if your type has iterator and const_iterator nested typedefs, and begin() and end() member functions, BOOST_FOREACH already knows how to iterate over your type. No further action is required.

    http://boost-sandbox.sourceforge.net/libs/foreach/doc/html/boost_foreach/extending_boost_foreach.html

提交回复
热议问题