使用boost :: adapters :: indirected强制执行constness

时间:2013-10-01 00:45:31

标签: c++ boost const adaptor

我正在使用boost 1.52和Visual Studio 2010。

我想知道为什么我无法强制执行boost::adaptors::indirected返回的元素。

此示例代码显示了我正在尝试实现的目标:

#include <vector>
#include <string>
#include <boost/range/adaptor/indirected.hpp>
#include <boost/foreach.hpp>

int main() {
    using std::vector;
    using std::string;

    typedef vector<string*> type;
    type range;
    range.push_back(new string("42"));
    type const& const_range = range;

    // This is ok to compile
    BOOST_FOREACH(string const& foo, const_range | boost::adaptors::indirected) {
        //...
    }

    // I don't want this to compile
    BOOST_FOREACH(string& foo, const_range | boost::adaptors::indirected) {
        //...
    }
    return 0;
}

0 个答案:

没有答案