Boost foreach 绝非小事。与海湾合作委员会4.6:
int main()
{
std::string hello( "Hello, world!" );
BOOST_FOREACH( char ch, hello )
{
std::cout << ch;
}
return 0;
}
产生大量调查案件A?B:C
.
int main()
{
std::string hello( "Hello, world!" );
if (
boost::foreach_detail_::auto_any_t _foreach_col9 =
boost::foreach_detail_::contain( (hello) , (true ? 0 :
boost::foreach_detail_::or_(
boost::foreach_detail_::and_(
boost::foreach_detail_::not_(
boost::foreach_detail_::is_array_(hello)) , (true ? 0 :
boost::foreach_detail_::is_rvalue_( (true ?
boost::foreach_detail_::make_probe(hello) : (hello)), 0))) ,
boost::foreach_detail_::and_(
boost::foreach_detail_::not_(boost_foreach_is_noncopyable(
boost::foreach_detail_::to_ptr(hello) , boost_foreach_argument_dependent_lookup_hack_value)) , boost_foreach_is_lightweight_proxy(
boost::foreach_detail_::to_ptr(hello) , boost_foreach_argument_dependent_lookup_hack_value)))))) {} else if (
boost::foreach_detail_::auto_any_t _foreach_cur9 =
boost::foreach_detail_::begin( _foreach_col9 , (true ? 0 :
boost::foreach_detail_::encode_type(hello,
boost::foreach_detail_::is_const_(hello))) , (true ? 0 :
boost::foreach_detail_::or_(
boost::foreach_detail_::and_(
boost::foreach_detail_::not_(
boost::foreach_detail_::is_array_(hello)) , (true ? 0 :
boost::foreach_detail_::is_rvalue_( (true ?
boost::foreach_detail_::make_probe(hello) : (hello)), 0))) ,
boost::foreach_detail_::and_(
boost::foreach_detail_::not_(boost_foreach_is_noncopyable(
boost::foreach_detail_::to_ptr(hello) , boost_foreach_argument_dependent_lookup_hack_value)) , boost_foreach_is_lightweight_proxy(
boost::foreach_detail_::to_ptr(hello) , boost_foreach_argument_dependent_lookup_hack_value)))))) {} else if (
boost::foreach_detail_::auto_any_t _foreach_end9 =
boost::foreach_detail_::end( _foreach_col9 , (true ? 0 :
boost::foreach_detail_::encode_type(hello,
boost::foreach_detail_::is_const_(hello))) , (true ? 0 :
boost::foreach_detail_::or_(
boost::foreach_detail_::and_(
boost::foreach_detail_::not_(
boost::foreach_detail_::is_array_(hello)) , (true ? 0 :
boost::foreach_detail_::is_rvalue_( (true ?
boost::foreach_detail_::make_probe(hello) : (hello)), 0))) ,
boost::foreach_detail_::and_(
boost::foreach_detail_::not_(boost_foreach_is_noncopyable(
boost::foreach_detail_::to_ptr(hello) , boost_foreach_argument_dependent_lookup_hack_value)) , boost_foreach_is_lightweight_proxy(
boost::foreach_detail_::to_ptr(hello) , boost_foreach_argument_dependent_lookup_hack_value)))))) {} else for (bool _foreach_continue9 = true; _foreach_continue9 && !
boost::foreach_detail_::done( _foreach_cur9 , _foreach_end9 , (true ? 0 :
boost::foreach_detail_::encode_type(hello,
boost::foreach_detail_::is_const_(hello)))); _foreach_continue9 ?
boost::foreach_detail_::next( _foreach_cur9 , (true ? 0 :
boost::foreach_detail_::encode_type(hello,
boost::foreach_detail_::is_const_(hello)))) : (void)0) if (
boost::foreach_detail_::set_false(_foreach_continue9)) {} else for (char ch =
boost::foreach_detail_::deref( _foreach_cur9 , (true ? 0 :
boost::foreach_detail_::encode_type(hello,
boost::foreach_detail_::is_const_(hello)))); !_foreach_continue9; _foreach_continue9 = true)
{
std::cout << ch;
}
return 0;
}
您可能想要循环的事物类型有很多。使用 c++11 不再需要所有这些技巧,因为您可以使用以下命令循环几乎所有内容
for(auto const &a: something){ .. }
or
for(auto a=begin(something);a!=end(something);++i){ .. }