Jeff Garland wrote:
I'm not sure that this bug is related to boost::date_time as it occurs
in boost::lexical_cast but I encounter it using the last cvs 1.33
version of it.
Another question is about wide char support. As far as I
understand, wstring is supported only through stringstream and
facets?
Yes, but the new facets are much better than 1.32. They now support
'format string' based input and output. Here's how I'd implement your
parsing problem for narrow and wide streams:
using namespace boost::gregorian;
using namespace boost::posix_time;
using namespace std;
time_input_facet* tf = new time_input_facet();
//below sets: %Y%m%dT%H%M%S%F for format.
tf->set_iso_format();
stringstream ss;
ss.imbue(std::locale(std::locale::classic(), tf));
ss.str("20021017T231217.12345");
ptime pt3;
ss >> pt3;
cout << "pt3: " << pt3 << endl;
wstringstream wss; wss.str(L"20021017T231217.12345");
//this time we'll set the format
wtime_input_facet* wtif = new wtime_input_facet(L"%Y%m%dT%H%M%S%F");
// wtif->set_iso_format(); <-- this works too...
wss.imbue(std::locale(std::locale::classic(), wtif));
ptime pt4;
wss >> pt4;
wtime_facet* wtf = new wtime_facet(); wtf->set_iso_format();
wcout.imbue(std::locale(std::locale::classic(), wtf));
wcout << "pt4: " << pt4 << endl;
This code does not complie with MSVC++.NET 2003 with the following error:
c:\usr\include\boost-1_33\boost\lexical_cast.hpp(150) : error C2679:
binary '<<' : no operator found which takes a right-hand operand of type
'const NewSource' (or there is no acceptable conversion)
c:\usr\include\boost-1_33\boost\lexical_cast.hpp(149) : while
compiling class-template member function 'bool
boost::detail::lexical_stream::operator <<(const Source &)'
with
[
Target=boost::date_time::time_input_facetboost::posix_time::ptime,wchar_t::fracional_seconds_type,
Source=NewSource
]
c:\usr\include\boost-1_33\boost\lexical_cast.hpp(218) : see
reference to class template instantiation
'boost::detail::lexical_stream' being compiled
with
[
Target=boost::date_time::time_input_facetboost::posix_time::ptime,wchar_t::fracional_seconds_type,
Source=NewSource
]
c:\usr\include\boost-1_33\boost\date_time\time_facet.hpp(1172) :
see reference to function template instantiation 'Target
boost::lexical_cast::fracional_seconds_type,boost::date_time::time_input_facet::string_type>(const
Source &)' being compiled
with
[
Target=boost::date_time::time_input_facetboost::posix_time::ptime,wchar_t::fracional_seconds_type,
time_type=boost::posix_time::ptime,
CharT=wchar_t,
Source=boost::date_time::time_input_facetboost::posix_time::ptime,wchar_t::string_type
]
c:\usr\include\boost-1_33\boost\date_time\time_facet.hpp(1162) :
while compiling class-template member function 'void
boost::date_time::time_input_facet::parse_frac_type(InItrT
&,InItrT
&,boost::date_time::time_input_facet::fracional_seconds_type
&) const'
with
[
time_type=boost::posix_time::ptime,
CharT=wchar_t,
InItrT=std::istreambuf_iterator>
]
c:\Documents and Settings\suralis\My Documents\Visual Studio
Projects\boostdttest\dothings.cpp(24) : see reference to class template
instantiation 'boost::date_time::time_input_facet'
being compiled
with
[
time_type=boost::posix_time::ptime,
CharT=wchar_t
]
c:\usr\include\boost-1_33\boost\lexical_cast.hpp(150) : error C2228:
left of '.fail' must have class/struct/union type
The problem seems to be too deep in the library for me:(
TIA
--
Serge