Re: [Boost-bugs] [Boost C++ Libraries] #11012: chrono_io v2 fail to compile with boost::chrono::duration< boost::rational<int> >

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #11012: chrono_io v2 fail to compile with boost::chrono::duration< boost::rational<int> >
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2015-02-16 14:55:36


#11012: chrono_io v2 fail to compile with boost::chrono::duration<
boost::rational<int> >
--------------------------------------------------+----------------------
  Reporter: Sébastien Barthélémy <barthelemy@…> | Owner: viboes
      Type: Bugs | Status: assigned
 Milestone: To Be Determined | Component: chrono
   Version: Boost 1.57.0 | Severity: Problem
Resolution: | Keywords:
--------------------------------------------------+----------------------

Comment (by viboes):

 My bad. You are right and std::chrono should support boost::rational.

 As you mention Boost.Chrono IO V2 doesn't supports it.

 V1 needed just that the Rep supports streaming

 {{{
     return os << d.count() << ' ' << f.template name<Period>(d.count());
 }}}


 V2 request num_put facet.



 {{{
         return std::use_facet<std::num_put<CharT, iter_type>
>(ios.getloc()).put(s, ios, fill,
             static_cast<long int> (d.count()));
             //d.count());
 }}}


 When I comment/uncomment the previous lines I got an ambiguous call to
 put. This was a bug, and when I replace your example by


 {{{
     typedef boost::chrono::duration< float > RationalSeconds;
     RationalSeconds d(0.5);
     std::cout << d << std::endl;
 }}}


 The decimal part is truncated. I get

 {{{
 0 seconds
 }}}


 instead of

 {{{
 0.5 seconds
 }}}

 I have added a trait that promotes int to long int


 {{{
     namespace detail
     {
       template <class T>
       struct propagate {
         typedef T type;
       };
       template <>
       struct propagate<boost::int_least32_t> {
         typedef boost::int_least64_t type;
       };
     }
 }}}

 and used it instead of the cast


 {{{
             static_cast<long int> (d.count()));
 }}}

 as follows


 {{{
             static_cast<typename detail::propagate<Rep>::type>
 (d.count()));
 }}}

 This will however not take in account boost::rational as a valid
 representation.

 There are other places where I have added more constraints to the
 representation.


 {{{
         return do_get_unit(style, rt_ratio(Period()),
 static_cast<intmax_t>(d.count()));
 }}}

 I 'll need to rethink how V2 can take care of IO of Rep not supported by
 the facets num_get/num_put and many other issues. :(

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/11012#comment:3>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:17 UTC