__STL_TRY和__STL_UNWIND这两个宏的意思

转载地址:http://bbs.csdn.net/topics/350153434

void fill_initialize(size_type n, const T& value) {
    empty_initialize();
    __STL_TRY {
      insert(begin(), n, value);
    }
    __STL_UNWIND(clear(); put_node(node));
  }
这是stl中fill_initialize的源代码,其中__STL_TRY和__STL_UNWIND是不是和try、catch的功能类似,为什么__STL_TRY后面的代码用花括号括起来,而__STL_UNWIND后面的代码则用小括号括起来呢


#define __STL_TRY  
 
   
Definition at line 230 of file stl_config.h. 

Referenced by rb_tree::__copy, __uninitialized_copy_copy, __uninitialized_copy_fill, __uninitialized_copy_n, __uninitialized_fill_copy, vector< node *, Alloc >::allocate_and_copy, vector< node *, Alloc >::allocate_and_fill, hashtable::copy_from, rb_tree< key_type, value_type, select1st< value_type >, key_compare, Alloc >::create_node, slist::create_node, list::create_node, deque::deque, slist::fill_initialize, list::fill_initialize, vector::insert, vector::insert_aux, hashtable< Value, Value, HashFcn, identity< Value >, EqualKey, Alloc >::new_node, priority_queue::pop, priority_queue::push, rope::push_front, slist::range_initialize, list::range_initialize, rb_tree< key_type, value_type, select1st< value_type >, key_compare, Alloc >::rb_tree, hashtable::resize, rope::rope, rope::RopeLeaf_from_unowned_char_ptr, temporary_buffer::temporary_buffer, and deque::~deque. 


#define __STL_UNWIND (  action     )   
 
   
Definition at line 234 of file stl_config.h. 

Referenced by rb_tree::__copy, __uninitialized_copy_copy, __uninitialized_copy_fill, __uninitialized_copy_n, __uninitialized_fill_copy, vector< node *, Alloc >::allocate_and_copy, vector< node *, Alloc >::allocate_and_fill, hashtable::copy_from, rb_tree< key_type, value_type, select1st< value_type >, key_compare, Alloc >::create_node, slist::create_node, list::create_node, deque::deque, slist::fill_initialize, list::fill_initialize, hashtable< Value, Value, HashFcn, identity< Value >, EqualKey, Alloc >::new_node, priority_queue::pop, priority_queue::push, rope::push_front, slist::range_initialize, list::range_initialize, rb_tree< key_type, value_type, select1st< value_type >, key_compare, Alloc >::rb_tree, rope::rope, rope::RopeLeaf_from_unowned_char_ptr, and temporary_buffer::temporary_buffer. 
 


通过宏定义,控制是否使用C++的异常机制,实现起来可能是这样:

C/C++ code
?
1
2
3
4
5
6
7
#ifdef __STL_USE_EXCEPTIONS
#define __STL_TRY   try
#define __STL_UNWIND(action)   catch(...) { action; throw; }
#else
#define __STL_TRY
#define __STL_UNWIND(action)
#endif


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值