修改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的兼容性了,所以還是換工具為好。
(轉載請注明來源于金慶的專欄)
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的兼容性了,所以還是換工具為好。
(轉載請注明來源于金慶的專欄)