Commit dc91b004 authored by Adam Simpkins's avatar Adam Simpkins Committed by Facebook Github Bot

implement to() conversions for std::chrono to timespec/timeval

Summary:
Add folly::to() conversions to convert between std::chrono::duration or
std::chrono::time_point types and struct timespec or struct timeval types.

To conform to the behavior of the existing arithmetic-to-arithmetic
conversions, this code performs proper overflow checking and throws a
`ConversionError` on overflow.  This unfortunately does make the code rather
complicated compared to a non-checking implementation.

Conversions between some unusual duration types is not implemented yet, and
will fail at compile time if someone tries to use it.  This happens for
durations where neither the numerator nor the denominator of the ratio is 1.
For instance, 7/13ths of a second.

Reviewed By: yfeldblum

Differential Revision: D6356700

fbshipit-source-id: 9dce8ab8f32d8c18089f32c7176a8abf3c3f11f7
parent aa7f8dcd
......@@ -327,6 +327,9 @@ if (BUILD_TESTS)
apply_folly_compile_options_to_target(folly_test_support)
folly_define_tests(
DIRECTORY chrono/test/
TEST chrono_conv_test SOURCES ConvTest.cpp
DIRECTORY compression/test/
TEST compression_test SOURCES CompressionTest.cpp
......
......@@ -5,7 +5,7 @@ endif
# Note that the order of SUBDIRS matters.
# Many subdirectories depend on libfollytest from the test directory,
# so it must appear before other directories
SUBDIRS = . test experimental $(MAYBE_INIT) io/test stats/test
SUBDIRS = . test experimental $(MAYBE_INIT) chrono/test io/test stats/test
ACLOCAL_AMFLAGS = -I m4
......@@ -42,6 +42,7 @@ nobase_follyinclude_HEADERS = \
Bits.h \
CachelinePadded.h \
Chrono.h \
chrono/Conv.h \
ClockGettimeWrappers.h \
ConcurrentSkipList.h \
ConcurrentSkipList-inl.h \
......
This diff is collapsed.
This diff is collapsed.
ACLOCAL_AMFLAGS = -I m4
CPPFLAGS = -I$(top_srcdir)/test/gtest/googletest/include
ldadd = $(top_builddir)/test/libfollytestmain.la
check_PROGRAMS = \
conv_test
TESTS = $(check_PROGRAMS)
conv_test_SOURCES = ConvTest.cpp
conv_test_LDADD = $(ldadd)
......@@ -632,6 +632,7 @@ FB_FILTER_PKG_LIBS([$AM_LDFLAGS $LIBS])
# Output
AC_CONFIG_FILES([Makefile
chrono/test/Makefile
io/test/Makefile
libfolly.pc
test/Makefile
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment