diff options
author | Jason Carey <jcarey@argv.me> | 2016-05-20 11:35:47 -0400 |
---|---|---|
committer | Jason Carey <jcarey@argv.me> | 2016-05-20 17:46:36 -0400 |
commit | fb052c13742deab981c7ba729dad36e33bdd7393 (patch) | |
tree | 6ac9f7f1127f55ef7e2daaf80984fbb1e081c316 /src/mongo/util/duration.h | |
parent | e43573eea1fafa5a31d9e47440abc1f26d6cba17 (diff) | |
download | mongo-fb052c13742deab981c7ba729dad36e33bdd7393.tar.gz |
SERVER-24104 sfinae duration ctor overloads
We can't just static_assert in the duration constructors, because we need overload resolution to
continue and find things like implicit conversions that then dispatch to default copy constructors.
This adds standard required sfinae to those ctors. In other cases where the standard uses sfinae,
it's either not needed for us (because we don't require extension of duration types and we only have
integral duration reps) or appears not necessary now (several arithmetic overloads could
theoretically have other targets, but for the moment I think it's unlikely that we'd expect
Milliseconds{} / MySpecialNonRepType{} to actually work). We'll have to revisit sfinae in those cases
if we ever do.
Diffstat (limited to 'src/mongo/util/duration.h')
-rw-r--r-- | src/mongo/util/duration.h | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/mongo/util/duration.h b/src/mongo/util/duration.h index 6cf26b06421..97c67ba04e4 100644 --- a/src/mongo/util/duration.h +++ b/src/mongo/util/duration.h @@ -215,11 +215,13 @@ public: /** * Constructs a duration representing "r" periods. */ - template <typename Rep2> + template < + typename Rep2, + stdx::enable_if_t<std::is_convertible<Rep2, rep>::value && std::is_integral<Rep2>::value, + int> = 0> constexpr explicit Duration(const Rep2& r) : _count(r) { - static_assert(std::is_integral<Rep2>::value && - (std::is_signed<Rep2>::value || sizeof(Rep2) < sizeof(rep)), + static_assert(std::is_signed<Rep2>::value || sizeof(Rep2) < sizeof(rep), "Durations must be constructed from values of integral type that are " "representable as 64-bit signed integers"); } |