金庆的专栏

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  423 随笔 :: 0 文章 :: 454 评论 :: 0 Trackbacks
修改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的兼容性了,所以还是换工具为好。

(转载请注明来源于金庆的专栏)
posted on 2008-06-12 09:59 金庆 阅读(2039) 评论(3)  编辑 收藏 引用 所属分类: 1. C/C++

评论

# re: 修改Boost.date_time代码兼容VC6 2008-06-12 14:02 赖勇浩
金庆兄最近也是搞C++比较多了?  回复  更多评论
  

# re: 修改Boost.date_time代码兼容VC6 2008-06-12 19:01 陈梓瀚(vczh)
以前用VC6的时候,偶尔写个operator overloading都能神奇的让编译器卡死。  回复  更多评论
  

# re: 修改Boost.date_time代码兼容VC6 2008-06-13 10:13 金庆
@赖勇浩
C++一直是我的主兵器。“精通一个,学习另一个,关注下一个”,我一直在打磨我的C++之剑,努力精通C++技艺。  回复  更多评论
  


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理