From fb052c13742deab981c7ba729dad36e33bdd7393 Mon Sep 17 00:00:00 2001 From: Jason Carey Date: Fri, 20 May 2016 11:35:47 -0400 Subject: 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. --- src/mongo/util/duration.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/mongo/util/duration.h') 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 + template < + typename Rep2, + stdx::enable_if_t::value && std::is_integral::value, + int> = 0> constexpr explicit Duration(const Rep2& r) : _count(r) { - static_assert(std::is_integral::value && - (std::is_signed::value || sizeof(Rep2) < sizeof(rep)), + static_assert(std::is_signed::value || sizeof(Rep2) < sizeof(rep), "Durations must be constructed from values of integral type that are " "representable as 64-bit signed integers"); } -- cgit v1.2.1