__STL_TRY和__STL_UNWIND这两个宏的意思

hualibinbin 2010-11-10 09:50:50
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后面的代码则用小括号括起来呢
...全文
307 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
hualibinbin 2010-11-24
  • 打赏
  • 举报
回复
那么如果construct失败,调用put_node后是不是仍然返回p,此时p所指的内存都已经释放掉了,那p是不是NULL啊
daidodo 2010-11-24
  • 打赏
  • 举报
回复
通过宏定义,控制是否使用C++的异常机制,实现起来可能是这样:

#ifdef __STL_USE_EXCEPTIONS
#define __STL_TRY try
#define __STL_UNWIND(action) catch(...) { action; throw; }
#else
#define __STL_TRY
#define __STL_UNWIND(action)
#endif
赵4老师 2010-11-24
  • 打赏
  • 举报
回复
gules 2010-11-10
  • 打赏
  • 举报
回复
就是异常处理。
wokonglinglude 2010-11-10
  • 打赏
  • 举报
回复
#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.



龙哥依旧 2010-11-10
  • 打赏
  • 举报
回复
这是大师级别研究的东西!

64,701

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧