From 9c129ec89ccad9ddea6904c97c6ceb77482d98de Mon Sep 17 00:00:00 2001 From: Eliyahu Ravuna Date: Mon, 5 Oct 2015 01:46:28 +0300 Subject: [PATCH] Feedback of Jared in #283 incorporated into I.4 --- CppCoreGuidelines.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index e9a39cd..75c2363 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -1108,9 +1108,24 @@ In the following example, it is not clear from the interface what time_to_blink std::chrono::duration types introduced in C++11 helps making the unit of time duration explicit. + void blink_led(milliseconds time_to_blink) //good - the unit is explicit + { + //... + //do something with time_to_blink + //... + } + + void use() + { + blink_led(1500ms); + } + +The function can also be written in such a way that it will accept any time duration unit. + template void blink_led(duration time_to_blink) //good - accepts any unit { + //assuming that millisecond is the smallest relevant unit auto milliseconds_to_blink = duration_cast(time_to_blink); //... //do something with milliseconds_to_blink