HowardHinnant.github.io
kandi X-RAY | HowardHinnant.github.io Summary
kandi X-RAY | HowardHinnant.github.io Summary
HowardHinnant.github.io
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of HowardHinnant.github.io
HowardHinnant.github.io Key Features
HowardHinnant.github.io Examples and Code Snippets
Community Discussions
Trending Discussions on HowardHinnant.github.io
QUESTION
I'd like to serialize a std::chrono::local_time
by sending it's time_since_epoch().count()
value. My question is how is a non-C++ receiver supposed to interpret that value? Is it the actual number of ticks since the epoch at local midnight (1970-01-01T00:00:00)? What about daylight saving time changes? Is the time_since_epoch()
bijective with the wall clock time? That is, can there be two values of std::chrono::local_time::time_since_spoch()
that represent the same wall clock/calendar time?
I cannot find detailed information about the interpretation of std::chrono::local_time::time_since_spoch()
at the usual places: cppreference, the latest C++ standard draft, or Howard Hinnant's date library documentation.
'Why even serialize a std::chrono::local_time
?', you may ask. Well, a use case would be a building automation system that must perform a certain task at a given local time on a special day, regardless of timezones or daylight saving time. For example, "turn off the lights at 20:00 local time on Earth Day, 2021 (April 22).
EDIT: 'Why not serialize it as an ISO8601 date/time (without any offset), you may ask?'. I want to serialize it as a compact number using a binary protocol, such as CBOR.
...ANSWER
Answered 2021-Jun-03 at 23:01The value in a local_time
is the exact same value it would have in a sys_time
. For example:
QUESTION
I have the following toy code:
...ANSWER
Answered 2021-Feb-15 at 01:26That operator<<
is inside the date
namespace. Since neither of the operand types are from this namespace, argument-dependent lookup won't find it.
To use it you need either using namespace date
or using date::operator<<
.
Another issue in your code is that microseconds
can only be constructed from an integer type, not floating point.
QUESTION
TL;DR: I am implementing custom formatter for fmt and Howard Hinnant's date library. With date::year_month_day d{};
, why does fmt::to_string(d)
return "{}"
while fmt::format("{}", d)
works fine, returning "0000-00-00"
? Example on godbolt.
I'm using date library and trying to switch from iostreams to fmt. I need to format date::year_month_day
in YYYY-MM-DD format so I wrote a custom formatter (template specialization of fmt::formatter for date::year_month_day
):
ANSWER
Answered 2020-Jun-21 at 16:50This is an unfortunate effect of the argument-dependent lookup: fmt::to_string
calls format
which ends up being resolved to date::format
instead of fmt::format
. The fix is to fully qualify the call to format
in fmt::to_string
since it depends on a user-defined type.
Update: this has been fixed in https://github.com/fmtlib/fmt/commit/2cac8a9d2e36cd920a9a60ec5b776c187e843fbb.
QUESTION
In this code that uses the date library, is it safe to store this type sys_time
in binary format?
sys_time
is non-POD but here it looks like int64
.
ANSWER
Answered 2020-Mar-24 at 18:50I would say yes, except for endian issues. I.e. if you save it on a big endian machine and read it with a little endian machine, you'll get the wrong answer.
Since sys_time
is not a POD, you could also just extract its integral POD value and save that as binary:
QUESTION
I would like to create a custom allocator for basic_string
that allows me to take ownership of the allocated internal array of the string. My specific use case is a .NET interop scenario, where marshaling back strings to managed code is expensive as it requires strings to be allocated in a specific pool (at least in Windows) and more important the ownership of the array in the heap must be transferred. I was able to code such custom allocator for std::vector
and verified compatibility in major compilers (MSVC, gcc, clang) successfully. I am now trying to use the same allocator for basic_string
and I'm observing strange behavior, as all the major STL implementations seems to not use the provided allocator for the first allocation, tipically the first 16 bytes. It follows the code I am using:
ANSWER
Answered 2019-Dec-02 at 22:33What you are seeing is Short String Optimization (SSO). The standard allows for std::string
to be built with a small internal buffer that the string can use to avoid doing any dynamic memory allocation. This is very advantageous since most strings are small so you can save a lot of allocations.
Unfortunately there is no restriction on the size of this buffer in the standard. MSVC uses 16 characters, libc++ uses 22.
This means that you'll either need to make sure you allocate a string that is big enough to use your allocator, or you'll just need to implement your own string class. A trick to allocate enough memory is to use
QUESTION
I am using C++ 14 and am trying to get the current day of week. After some reading I am using date.h by Howard E. Hinnant.
However I am struggling to get a day of the week (encoded as 0 thru 6).
Something like this prints out Thu
:
ANSWER
Answered 2019-Aug-20 at 10:20This would give the index of the day using date.h:
QUESTION
I am trying to use Howard Hinnant's stack_alloc
with boost rtrees, as in the following example:
ANSWER
Answered 2019-Aug-06 at 19:25The heart of the issue is essentially a circular dependency.
Constructing the RTree
causes the rtree<...>
template instantiation which includes a typedef node_pointer = allocators_type::node_pointer
, which triggers the instantiation of allocators_type
, i.e. detail::rtree::allocators<...>
, which has a base class of detail::rtree::node_alloc<...>
, which in its definition rebinds the allocator to the node type. The node type is a variant of detail::rtree::variant_leaf<...>
and detail::rtree::variant_internal_node<...>
.
But stack_alloc
needs the sizeof(T)
, so both templates included in the variant
types get instantiated, and when instantiating variant_internal_node
, it needs Allocators::node_pointer
, so Allocators
must be instantiated, but isn't that what we're in the middle of instantiating!
I suggest trying short_alloc
and passing the allocator to the container. Because it separates the storage from the allocator type, it should not require completeness of the template type, breaking the circle.
QUESTION
I am using iso_week.h
from howardhinnant.github.io/iso_week.html to calculate the week number for a given date. However, it looks that it updates the week number on Monday at 3 a.m., instead of midnight.
For example code like this:
...ANSWER
Answered 2019-Aug-01 at 22:48Could this have something to do with your time zone? I know a lot of businesses are located on the east coast and "iso_week.h" could be based on that time, meaning it could be running at midnight and it just tells you that it is running at 3am. If this is not the case would it be wrong to just run the program at 9pm?
QUESTION
This example uses the date library without any using namespace
:
ANSWER
Answered 2019-Mar-11 at 08:53Numeric literal operator 'operator""_y' is declared inside of namespace 'date'.
You can use 'using namespace date' or 'using namespace date::literals'
More information: How to refer to user defined literal operator inside a namespace?
QUESTION
I have a date string like so YYYYMMDD HHMMSSFFF
. I am trying to use Howard Hinnats date library. Snippet of code is like so,
ANSWER
Answered 2019-Jan-05 at 02:55Use %T, it seems to work. Here is an example:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install HowardHinnant.github.io
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page