我正在尝试删除Mach7内的goto语句,因为goto is not allowed in constexpr function:
#define MatchQ(s) { \
XTL_MATCH_PREAMBULA(s) \
enum { __base_counter = XTL_COUNTER }; \
typedef mch::unified_switch<source_type> switch_traits; \
XTL_PRELOADABLE_LOCAL_STATIC(XTL_CPP0X_TYPENAME switch_traits::static_data_type,static_data,match_uid_type,XTL_EMPTY()); \
XTL_CPP0X_TYPENAME switch_traits::local_data_type local_data; \
bool processed = false; \
size_t jump_target = switch_traits::choose(subject_ptr,static_data,local_data); \
XTL_CONCAT(ReMatch,__LINE__): \
switch (jump_target) \
{ \
XTL_NON_REDUNDANCY_ONLY(default:) \
{ XTL_REDUNDANCY_ONLY(try){{ \
if (switch_traits::on_default(jump_target,local_data,static_data)) \
goto XTL_CONCAT(ReMatch,__LINE__); \
XTL_SUBCLAUSE_FIRST
以上代码在此处使用goto:goto XTL_CONCAT(ReMatch,__LINE__);
,可以跳到switch语句的上方。
如何用其他东西代替goto?
答案 0 :(得分:0)
在@ozlsn和gcc -E
的帮助下,替换完成。
说服代码:
while(true)
{
bool continue_flag = false;
switch(var)
{
default:
if(something)
continue_flag = true;
break;
// do something
OtherCases:
// do something
}
if (!contine_flag)
break;
}
此处完全提交:https://github.com/FirstLoveLife/Mach7/commit/3db24a337a7643018ed9e12ac95f53f9a036251c
以下是相关的质量检查:Using continue in a switch statement