Boost logo

Boost Users :

From: Serge Skorokhodov (serge.skorokhodov_at_[hidden])
Date: 2005-07-17 14:42:56


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<Target,Source>::operator <<(const Source &)'
        with
        [
           
Target=boost::date_time::time_input_facet<boost::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<Target,Source>' being compiled
        with
        [
           
Target=boost::date_time::time_input_facet<boost::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<boost::date_time::time_input_facet<time_type,CharT>::fracional_seconds_type,boost::date_time::time_input_facet<time_type,CharT>::string_type>(const
Source &)' being compiled
        with
        [
           
Target=boost::date_time::time_input_facet<boost::posix_time::ptime,wchar_t>::fracional_seconds_type,
            time_type=boost::posix_time::ptime,
            CharT=wchar_t,
           
Source=boost::date_time::time_input_facet<boost::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<time_type,CharT>::parse_frac_type(InItrT
&,InItrT
&,boost::date_time::time_input_facet<time_type,CharT>::fracional_seconds_type
&) const'
        with
        [
            time_type=boost::posix_time::ptime,
            CharT=wchar_t,
           
InItrT=std::istreambuf_iterator<wchar_t,std::char_traits<wchar_t>>
        ]
        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<time_type,CharT>'
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

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net