Boost C++ Libraries: Ticket #11631: boost chrono io v2 does not let you support custom clocks https://svn.boost.org/trac10/ticket/11631 <p> v1 lets you specialize struct clock_string in order to add support for a custom clock. </p> <p> I could not find a way to do the equivalent with v2. If confirmed, that would also mean that boost chrono io canot support std::chrono clocks. </p> <p> Attached is a minimalistic example showing a custom clock with chrono io v1 support. The code does not compile under v2. </p> <p> Compilation result with boost 1.58 </p> <pre class="wiki">$ make clean &amp;&amp; make test rm -f src/*.o src/chrono_io clang++ -std=c++11 -c -g -fPIC -Iinclude -I/usr/include -o src/chrono_io.o src/chrono_io.cc clang++ -std=c++11 -rdynamic -Lsrc -o src/chrono_io src/chrono_io.o -lboost_chrono -lboost_system -L/usr/lib/x86_64-linux-gnu LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu ./src/chrono_io 1402372272646902866 nanoseconds since year 2k </pre><p> idem with #define BOOST_CHRONO_DONT_PROVIDES_DEPRECATED_IO_SINCE_V2_0_0 </p> <pre class="wiki">$ make clean &amp;&amp; make test rm -f src/*.o src/chrono_io clang++ -std=c++11 -c -g -fPIC -Iinclude -I/usr/include -o src/chrono_io.o src/chrono_io.cc In file included from src/chrono_io.cc:4: In file included from /usr/include/boost/chrono/chrono_io.hpp:26: In file included from /usr/include/boost/chrono/io/time_point_io.hpp:22: In file included from /usr/include/boost/chrono/io/time_point_put.hpp:15: /usr/include/boost/chrono/io/time_point_units.hpp:77:16: error: no matching member function for call to 'do_get_epoch' return do_get_epoch(Clock()); ^~~~~~~~~~~~ /usr/include/boost/chrono/io/time_point_put.hpp:236:42: note: in instantiation of function template specialization 'boost::chrono::time_point_units&lt;char&gt;::get_epoch&lt;MyMillenniumClock&gt;' requested here string_type str = facet.template get_epoch&lt;Clock&gt;(); ^ /usr/include/boost/chrono/io/time_point_put.hpp:134:19: note: in instantiation of function template specialization 'boost::chrono::time_point_put&lt;char, std::ostreambuf_iterator&lt;char, std::char_traits&lt;char&gt; &gt; &gt;::put_epoch&lt;MyMillenniumClock&gt;' requested here s = put_epoch&lt;Clock&gt; (units_facet, s, ios); ^ /usr/include/boost/chrono/io/time_point_put.hpp:170:18: note: in instantiation of function template specialization 'boost::chrono::time_point_put&lt;char, std::ostreambuf_iterator&lt;char, std::char_traits&lt;char&gt; &gt; &gt;::put&lt;MyMillenniumClock, boost::chrono::duration&lt;long, boost::ratio&lt;1, 1000000000&gt; &gt; &gt;' requested here return put(facet, i, ios, fill, tp, str.data(), str.data() + str.size()); ^ /usr/include/boost/chrono/io/time_point_io.hpp:662:44: note: in instantiation of function template specialization 'boost::chrono::time_point_put&lt;char, std::ostreambuf_iterator&lt;char, std::char_traits&lt;char&gt; &gt; &gt;::put&lt;MyMillenniumClock, boost::chrono::duration&lt;long, boost::ratio&lt;1, 1000000000&gt; &gt; &gt;' requested here if (time_point_put&lt;CharT&gt; ().put(os, os, os.fill(), tp) .failed()) ^ src/chrono_io.cc:45:15: note: in instantiation of function template specialization 'boost::chrono::operator&lt;&lt;&lt;char, std::char_traits&lt;char&gt;, MyMillenniumClock, boost::chrono::duration&lt;long, boost::ratio&lt;1, 1000000000&gt; &gt; &gt;' requested here std::cout &lt;&lt; MyMillenniumClock::now() &lt;&lt; std::endl; ^ /usr/include/boost/chrono/io/time_point_units.hpp:92:27: note: candidate function not viable: no known conversion from 'MyMillenniumClock' to 'boost::chrono::system_clock' for 1st argument virtual string_type do_get_epoch(system_clock) const=0; ^ /usr/include/boost/chrono/io/time_point_units.hpp:99:27: note: candidate function not viable: no known conversion from 'MyMillenniumClock' to 'boost::chrono::steady_clock' for 1st argument virtual string_type do_get_epoch(steady_clock) const=0; ^ /usr/include/boost/chrono/io/time_point_units.hpp:107:27: note: candidate function not viable: no known conversion from 'MyMillenniumClock' to 'boost::chrono::process_real_cpu_clock' for 1st argument virtual string_type do_get_epoch(process_real_cpu_clock) const=0; ^ /usr/include/boost/chrono/io/time_point_units.hpp:114:27: note: candidate function not viable: no known conversion from 'MyMillenniumClock' to 'boost::chrono::process_user_cpu_clock' for 1st argument virtual string_type do_get_epoch(process_user_cpu_clock) const=0; ^ /usr/include/boost/chrono/io/time_point_units.hpp:120:27: note: candidate function not viable: no known conversion from 'MyMillenniumClock' to 'boost::chrono::process_system_cpu_clock' for 1st argument virtual string_type do_get_epoch(process_system_cpu_clock) const=0; ^ /usr/include/boost/chrono/io/time_point_units.hpp:126:27: note: candidate function not viable: no known conversion from 'MyMillenniumClock' to 'boost::chrono::process_cpu_clock' for 1st argument virtual string_type do_get_epoch(process_cpu_clock) const=0; ^ /usr/include/boost/chrono/io/time_point_units.hpp:135:27: note: candidate function not viable: no known conversion from 'MyMillenniumClock' to 'boost::chrono::thread_clock' for 1st argument virtual string_type do_get_epoch(thread_clock) const=0; ^ 1 error generated. Makefile:7: recipe for target 'src/chrono_io.o' failed make: *** [src/chrono_io.o] Error 1 </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11631 Trac 1.4.3 Sébastien Barthélémy <barthelemy@…> Wed, 09 Sep 2015 10:00:53 GMT attachment set https://svn.boost.org/trac10/ticket/11631 https://svn.boost.org/trac10/ticket/11631 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">chrono_io_custom.tgz</span> </li> </ul> Ticket viboes Thu, 10 Sep 2015 06:05:16 GMT status changed https://svn.boost.org/trac10/ticket/11631#comment:1 https://svn.boost.org/trac10/ticket/11631#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> My bad. maybe the documentation is not explicit enough that this is not supported. </p> <p> The reference states the possible customization points </p> <pre class="wiki"> protected: virtual ~time_point_units(); virtual string_type do_get_epoch(system_clock) const=0; virtual string_type do_get_epoch(steady_clock) const=0; #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS) virtual string_type do_get_epoch(process_real_cpu_clock) const=0; virtual string_type do_get_epoch(process_user_cpu_clock) const=0; virtual string_type do_get_epoch(process_system_cpu_clock) const=0; virtual string_type do_get_epoch(process_cpu_clock) const=0; #endif #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK) virtual string_type do_get_epoch(thread_clock) const=0; #endif}}} I would need to type erase the clock in someway, but I don't know how the user could identify its clock. </pre> Ticket viboes Thu, 10 Sep 2015 17:47:11 GMT milestone changed https://svn.boost.org/trac10/ticket/11631#comment:2 https://svn.boost.org/trac10/ticket/11631#comment:2 <ul> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.60.0</span> </li> </ul> <p> I think that I have found a way the user can customize the Clock string. I don't know however how it can customize it depending on a specific locale. </p> <p> The trick is to use an indirection </p> <pre class="wiki"> template &lt;typename Clock&gt; string_type get_epoch() const { return get_epoch_custom&lt;CharT&gt;(Clock(), *this); } </pre><p> </p> <p> where get_epoch_custom just forwards again to the facet. </p> <pre class="wiki"> template &lt;typename CharT, typename Clock, typename TPUFacet&gt; std::basic_string&lt;CharT&gt; get_epoch_custom(Clock, TPUFacet&amp; f) { return f.do_get_epoch(Clock()); } </pre><p> The user can specialize its onw Clock by overloading this customization function. </p> <pre class="wiki">template &lt;typename CharT, typename TPUFacet&gt; std::basic_string&lt;CharT&gt; get_epoch_custom(MyMillenniumClock, TPUFacet&amp;) { return boost::chrono::clock_string&lt;MyMillenniumClock,CharT&gt;::since(); } </pre><p> Committed in master branch <a class="ext-link" href="https://github.com/boostorg/chrono/commit/533851116fa2c3870e05d878a9cc9c82c4b93fa1"><span class="icon">​</span>https://github.com/boostorg/chrono/commit/533851116fa2c3870e05d878a9cc9c82c4b93fa1</a> </p> Ticket viboes Sun, 25 Oct 2015 23:52:37 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/11631#comment:3 https://svn.boost.org/trac10/ticket/11631#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> <a class="ext-link" href="https://github.com/boostorg/chrono/commit/621b6faaf19d5c0b5ffd0a313e696b81495316a4"><span class="icon">​</span>https://github.com/boostorg/chrono/commit/621b6faaf19d5c0b5ffd0a313e696b81495316a4</a> </p> Ticket