修改Boost.date_time代码兼容VC6

本文介绍如何通过简单修改使Boost.date_time库兼容Visual C++ 6.0。主要涉及对time_parsing.hpp文件中特定模板函数的类型定义进行调整,解决了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的兼容性了,所以还是换工具为好。

(转载请注明来源于金庆的专栏)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值