diff options
| author | Jordan Maples <jomaples@microsoft.com> | 2020-08-10 16:45:47 -0700 |
|---|---|---|
| committer | Jordan Maples <jomaples@microsoft.com> | 2020-08-10 16:45:47 -0700 |
| commit | 01eaf5bef131ff51274ca57f5ade2d10851aa00b (patch) | |
| tree | a4cba6363389a9be24cd451861245eb0a9fc8c5e | |
| parent | 63379b7935e41b19a006227910d03dd037a7aa6c (diff) | |
| download | platform_external_Microsoft-GSL-01eaf5bef131ff51274ca57f5ade2d10851aa00b.tar.gz platform_external_Microsoft-GSL-01eaf5bef131ff51274ca57f5ade2d10851aa00b.tar.bz2 platform_external_Microsoft-GSL-01eaf5bef131ff51274ca57f5ade2d10851aa00b.zip | |
macro version
| -rw-r--r-- | include/gsl/gsl_util | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/include/gsl/gsl_util b/include/gsl/gsl_util index 89fb2ee..2e79605 100644 --- a/include/gsl/gsl_util +++ b/include/gsl/gsl_util @@ -32,6 +32,12 @@ #endif // _MSC_VER +#if __has_cpp_attribute(nodiscard) >= 201603L +#define GSL_NODISCARD [[nodiscard]] +#else +#define GSL_NODISCARD +#endif + namespace gsl { // @@ -67,13 +73,13 @@ private: // finally() - convenience function to generate a final_action template <class F> -final_action<F> finally(const F& f) noexcept +GSL_NODISCARD final_action<F> finally(const F& f) noexcept { return final_action<F>(f); } template <class F> -final_action<F> finally(F&& f) noexcept +GSL_NODISCARD final_action<F> finally(F&& f) noexcept { return final_action<F>(std::forward<F>(f)); } @@ -98,16 +104,16 @@ constexpr T narrow(U u) noexcept(false) { constexpr const bool is_different_signedness = (std::is_signed<T>::value != std::is_signed<U>::value); - + const T t = narrow_cast<T>(u); - + if (static_cast<U>(t) != u || (is_different_signedness && ((t < T{}) != (u < U{})))) { throw narrowing_error{}; } - + return t; } |
