Hi there, I convert a std::vector<std::vector<float>> to a JSON string. Basically it works, but the format is scientific: "[[1.017E3,1.017E3,1.017E3 ... ]]" My method looks now like this: std::string Class::convertFieldAsJSON(std::vector<std::vector<float>> field) { return boost::json::serialize(boost::json::value_from(field)); } It works, but my colleagues want to see a 1017 and not 1.017E3 in the output. Is there a way to format the string? Thanks in advance, Markus
Hi there, Looking at the source code of boost::json this behavior doesn't seem customizable because it calls - detail::format_double in serializer::write_number and the former further calls ryu::d2s_buffered_n. I could be missing something here, though. So it's probably better to wait for more opinions on the subject. On the other hand, you can always serialize the json::value manually in a way similar to the one shown in this example - https://www.boost.org/doc/libs/1_81_0/libs/json/doc/html/json/examples.html#... . This way you'll have control how exactly you want to display the float values. HTH, Pavel. On Fri, Feb 24, 2023 at 11:25 AM Markus Pieper via Boost-users < boost-users@lists.boost.org> wrote:
Hi there,
I convert a std::vector<std::vector<float>> to a JSON string. Basically it works, but the format is scientific: "[[1.017E3,1.017E3,1.017E3 ... ]]"
My method looks now like this:
std::string Class::convertFieldAsJSON(std::vector<std::vector<float>> field) { return boost::json::serialize(boost::json::value_from(field)); }
It works, but my colleagues want to see a 1017 and not 1.017E3 in the output. Is there a way to format the string?
Thanks in advance, Markus
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org https://lists.boost.org/mailman/listinfo.cgi/boost-users
For the quickest response from the maintainers, consider using the slack channel: #boost-json https://cppalliance.org/slack/ I have also raised this issue. On Fri, 24 Feb 2023 at 10:48, Pavel Vazharov via Boost-users < boost-users@lists.boost.org> wrote:
Hi there,
Looking at the source code of boost::json this behavior doesn't seem customizable because it calls - detail::format_double in serializer::write_number and the former further calls ryu::d2s_buffered_n. I could be missing something here, though. So it's probably better to wait for more opinions on the subject. On the other hand, you can always serialize the json::value manually in a way similar to the one shown in this example - https://www.boost.org/doc/libs/1_81_0/libs/json/doc/html/json/examples.html#... . This way you'll have control how exactly you want to display the float values.
HTH, Pavel.
On Fri, Feb 24, 2023 at 11:25 AM Markus Pieper via Boost-users < boost-users@lists.boost.org> wrote:
Hi there,
I convert a std::vector<std::vector<float>> to a JSON string. Basically it works, but the format is scientific: "[[1.017E3,1.017E3,1.017E3 ... ]]"
My method looks now like this:
std::string Class::convertFieldAsJSON(std::vector<std::vector<float>> field) { return boost::json::serialize(boost::json::value_from(field)); }
It works, but my colleagues want to see a 1017 and not 1.017E3 in the output. Is there a way to format the string?
Thanks in advance, Markus
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org https://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org https://lists.boost.org/mailman/listinfo.cgi/boost-users
Hello Is this a known problem or am I just too stupid? Since we switched to c++20 in VS2022 with toolset v143, the timers no longer compile. We have tested it with VS 17.5.0 and 17.5.4. Test code: asio::io_service io; asio::steady_timer t(io, 1s); Compiler: 1>\boost\boost_1_81_0\include\boost/asio/detail/io_object_impl.hpp(59,16): error C2665: 'boost::asio::any_io_executor::any_io_executor': no overloaded function could convert all the argument types 1>\boost\boost_1_81_0\include\boost/asio/impl/any_io_executor.ipp(34,18): message : could be 'boost::asio::any_io_executor::any_io_executor(std::nullptr_t) noexcept' 1>\boost\boost_1_81_0\include\boost/asio/detail/io_object_impl.hpp(59,16): message : 'boost::asio::any_io_executor::any_io_executor(std::nullptr_t) noexcept': cannot convert argument 1 from 'boost::asio::io_context::executor_type' to 'std::nullptr_t' 1>\boost\boost_1_81_0\include\boost/asio/detail/io_object_impl.hpp(59,37): message : No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called 1>E:\DitecLibs\Packages\boost\boost_1_81_0\include\boost/asio/any_io_executor.hpp(189,3): message : or 'boost::asio::any_io_executor::any_io_executor(std::nothrow_t,Executor,constraint<std::conditional<!std::is_same<OtherAnyExecutor,boost::asio::any_io_executor>::value&&!std::is_base_of<boost::asio::execution::detail::any_executor_base,Executor>::value,boost::asio::execution::detail::is_valid_target_executor<Executor,boost::asio::any_io_executor::supportable_properties_type>,std::false_type>::type::value,int>::type) noexcept' 1>\boost\boost_1_81_0\include\boost/asio/detail/io_object_impl.hpp(59,16): message : 'boost::asio::any_io_executor::any_io_executor(std::nothrow_t,Executor,constraint<std::conditional<!std::is_same<OtherAnyExecutor,boost::asio::any_io_executor>::value&&!std::is_base_of<boost::asio::execution::detail::any_executor_base,Executor>::value,boost::asio::execution::detail::is_valid_target_executor<Executor,boost::asio::any_io_executor::supportable_properties_type>,std::false_type>::type::value,int>::type) noexcept': expects 3 arguments - 1 provided 1>\boost\boost_1_81_0\include\boost/asio/any_io_executor.hpp(167,3): message : or 'boost::asio::any_io_executor::any_io_executor(Executor,constraint<std::conditional<!std::is_same<OtherAnyExecutor,boost::asio::any_io_executor>::value&&!std::is_base_of<boost::asio::execution::detail::any_executor_base,Executor>::value,boost::asio::execution::detail::is_valid_target_executor<Executor,boost::asio::any_io_executor::supportable_properties_type>,std::false_type>::type::value,int>::type)' 1>\boost\boost_1_81_0\include\boost/asio/detail/io_object_impl.hpp(59,16): message : Failed to specialize function template 'boost::asio::any_io_executor::any_io_executor(Executor,constraint<std::conditional<!std::is_same<OtherAnyExecutor,boost::asio::any_io_executor>::value&&!std::is_base_of<boost::asio::execution::detail::any_executor_base,Executor>::value,boost::asio::execution::detail::is_valid_target_executor<Executor,boost::asio::any_io_executor::supportable_properties_type>,std::false_type>::type::value,int>::type)' 1>\boost\boost_1_81_0\include\boost/asio/detail/io_object_impl.hpp(59,16): message : With the following template arguments: 1>\boost\boost_1_81_0\include\boost/asio/detail/io_object_impl.hpp(59,16): message : 'Executor=boost::asio::io_context::executor_type' 1>\boost\boost_1_81_0\include\boost/asio/any_io_executor.hpp(134,3): message : or 'boost::asio::any_io_executor::any_io_executor(std::nothrow_t,OtherAnyExecutor,constraint<std::conditional<!std::is_same<OtherAnyExecutor,boost::asio::any_io_executor>::value&&std::is_base_of<boost::asio::execution::detail::any_executor_base,Executor>::value,boost::asio::execution::detail::supportable_properties<0,void (boost::asio::execution::context_as_t<boost::asio::execution_context &>,boost::asio::execution::detail::blocking::never_t<0>,boost::asio::execution::prefer_only<boost::asio::execution::detail::blocking::possibly_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::tracked_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::untracked_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::fork_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::continuation_t<0>>)>::is_valid_target<OtherAnyExecutor>,std::false_type>::type::value,int>::type) noexcept' 1>\boost\boost_1_81_0\include\boost/asio/detail/io_object_impl.hpp(59,16): message : 'boost::asio::any_io_executor::any_io_executor(std::nothrow_t,OtherAnyExecutor,constraint<std::conditional<!std::is_same<OtherAnyExecutor,boost::asio::any_io_executor>::value&&std::is_base_of<boost::asio::execution::detail::any_executor_base,Executor>::value,boost::asio::execution::detail::supportable_properties<0,void (boost::asio::execution::context_as_t<boost::asio::execution_context &>,boost::asio::execution::detail::blocking::never_t<0>,boost::asio::execution::prefer_only<boost::asio::execution::detail::blocking::possibly_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::tracked_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::untracked_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::fork_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::continuation_t<0>>)>::is_valid_target<OtherAnyExecutor>,std::false_type>::type::value,int>::type) noexcept': expects 3 arguments - 1 provided 1>\boost\boost_1_81_0\include\boost/asio/any_io_executor.hpp(110,3): message : or 'boost::asio::any_io_executor::any_io_executor(OtherAnyExecutor,constraint<std::conditional<!std::is_same<OtherAnyExecutor,boost::asio::any_io_executor>::value&&std::is_base_of<boost::asio::execution::detail::any_executor_base,Executor>::value,boost::asio::execution::detail::supportable_properties<0,void (boost::asio::execution::context_as_t<boost::asio::execution_context &>,boost::asio::execution::detail::blocking::never_t<0>,boost::asio::execution::prefer_only<boost::asio::execution::detail::blocking::possibly_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::tracked_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::untracked_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::fork_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::continuation_t<0>>)>::is_valid_target<OtherAnyExecutor>,std::false_type>::type::value,int>::type)' 1>\boost\boost_1_81_0\include\boost/asio/detail/io_object_impl.hpp(59,16): message : Failed to specialize function template 'boost::asio::any_io_executor::any_io_executor(OtherAnyExecutor,constraint<std::conditional<!std::is_same<OtherAnyExecutor,boost::asio::any_io_executor>::value&&std::is_base_of<boost::asio::execution::detail::any_executor_base,Executor>::value,boost::asio::execution::detail::supportable_properties<0,void (boost::asio::execution::context_as_t<boost::asio::execution_context &>,boost::asio::execution::detail::blocking::never_t<0>,boost::asio::execution::prefer_only<boost::asio::execution::detail::blocking::possibly_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::tracked_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::untracked_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::fork_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::continuation_t<0>>)>::is_valid_target<OtherAnyExecutor>,std::false_type>::type::value,int>::type)' 1>\boost\boost_1_81_0\include\boost/asio/detail/io_object_impl.hpp(59,16): message : With the following template arguments: 1>\boost\boost_1_81_0\include\boost/asio/detail/io_object_impl.hpp(59,16): message : 'OtherAnyExecutor=boost::asio::io_context::executor_type' 1>\boost\boost_1_81_0\include\boost/asio/detail/io_object_impl.hpp(59,16): message : while trying to match the argument list '(boost::asio::io_context::executor_type)' 1>\boost\boost_1_81_0\include\boost/asio/basic_waitable_timer.hpp(284,1): message : see reference to function template instantiation 'boost::asio::detail::io_object_impl<boost::asio::detail::deadline_timer_service<boost::asio::detail::chrono_time_traits<Clock,WaitTraits>>,boost::asio::any_io_executor>::io_object_impl<ExecutionContext>(int,int,ExecutionContext &)' being compiled 1> with 1> [ 1> Clock=std::chrono::steady_clock, 1> WaitTraits=boost::asio::wait_traits<std::chrono::steady_clock>, 1> ExecutionContext=boost::asio::io_service 1> ] 1>\boost\boost_1_81_0\include\boost/asio/basic_waitable_timer.hpp(283,12): message : see reference to function template instantiation 'boost::asio::detail::io_object_impl<boost::asio::detail::deadline_timer_service<boost::asio::detail::chrono_time_traits<Clock,WaitTraits>>,boost::asio::any_io_executor>::io_object_impl<ExecutionContext>(int,int,ExecutionContext &)' being compiled 1> with 1> [ 1> Clock=std::chrono::steady_clock, 1> WaitTraits=boost::asio::wait_traits<std::chrono::steady_clock>, 1> ExecutionContext=boost::asio::io_service 1> ] 1>main.cpp(27,29): message : see reference to function template instantiation 'boost::asio::basic_waitable_timer<std::chrono::steady_clock,boost::asio::wait_traits<Clock>,boost::asio::any_io_executor>::basic_waitable_timer<boost::asio::io_service>(ExecutionContext &,const std::chrono::duration<__int64,std::nano> &,int)' being compiled 1> with 1> [ 1> Clock=std::chrono::steady_clock, 1> ExecutionContext=boost::asio::io_service 1> ] 1>main.cpp(27,22): message : see reference to function template instantiation 'boost::asio::basic_waitable_timer<std::chrono::steady_clock,boost::asio::wait_traits<Clock>,boost::asio::any_io_executor>::basic_waitable_timer<boost::asio::io_service>(ExecutionContext &,const std::chrono::duration<__int64,std::nano> &,int)' being compiled 1> with 1> [ 1> Clock=std::chrono::steady_clock, 1> ExecutionContext=boost::asio::io_service 1> ] What could be the reason for this? Best regards Sören
participants (4)
-
Dr. Sören Textor
-
Markus Pieper
-
Pavel Vazharov
-
Richard Hodges