`
luliangok
  • 浏览: 779550 次
文章分类
社区版块
存档分类
最新评论

修改Boost.date_time代码兼容VC6

 
阅读更多
修改Boost.date_time代码兼容VC6

Boost.date_time库明确不支持VC6。
实际上,只要稍作修改,就可兼容VC6。
而且只是代码风格上的调整,修改后比原来的代码更简洁。

在time_parsing.hpp文件的str_from_delimited_time_duration()模板函数中,有两个类型定义:

1 typedef boost::tokenizer<char_separator_type,
*2 typename std::basic_string<char_type>::const_iterator,
3 std::basic_string<char_type> > tokenizer;
4 typedef typename boost::tokenizer<char_separator_type,
*5 typename std::basic_string<char_type>::const_iterator,
*6 typename std::basic_string<char_type> >::iterator tokenizer_iterator;

对于打星号的2、5、6行,VC6报错:
error C2899: typename cannot be used outside a template declaration

这是VC6弱智的一点,明明在模板函数的声明中,却报告不能在模板声明之外使用typename。

还有我觉得在模板声明之外也应该可以使用typename,
虽然是多余,但可能会增加可读性,而编译器应该可以忽略它。
不知C++标准是不是禁止在模板声明之处使用typename?

如下更改就好了,多了个typedef,但代码变短了:

1. 提取2,5行的重复代码,定义const_iterator_type
2. 去除第6行中明显多余的typename

+ typedef typename std::basic_string<char_type>::const_iterator const_iterator_type;
typedef boost::tokenizer<char_separator_type,
+ const_iterator_type,
std::basic_string<char_type> > tokenizer;
typedef typename boost::tokenizer<char_separator_type,
+ const_iterator_type,
+ std::basic_string<char_type> >::iterator tokenizer_iterator;

题外话:VC6大势已去,Boost 1.35整个库已不考虑VC6的兼容性了,所以还是换工具为好。

(转载请注明来源于金庆的专栏)
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics