guideline-support-library

Ensures() - guideline support library

好久不见. 提交于 2019-12-08 17:28:18
问题 I am trying to understand how to use Ensures() in code. As given in the example, if I tried using Ensures() as follows... int main(void) { int result = 0; // Some calculation Ensures(result == 255); return 0; } If the result variable is not equal to 255 , the program crashes with the following output "terminate called without an active exception" . My question is how to use Ensures() properly? 回答1: Are you using the Microsoft GSL implementation? Then if you check the gsl_assert.h header file

gsl::not_null<T*> vs. std::reference_wrapper<T> vs. T&

[亡魂溺海] 提交于 2019-11-27 19:15:39
C++ Core Guidelines has been presented recently (congrats!) and I am concerned about gsl::not_null type. As stated in I.12: Declare a pointer that must not be null as not_null : To help avoid dereferencing nullptr errors. To improve performance by avoiding redundant checks for nullptr. ... By stating the intent in source, implementers and tools can provide better diagnostics, such as finding some classes of errors through static analysis, and perform optimizations, such as removing branches and null tests. The intent is clear. However, we already have a language feature for that. Pointers that

What's the difference between span and array_view in the gsl library?

杀马特。学长 韩版系。学妹 提交于 2019-11-27 11:37:40
In several recent conference presentation I've heard Bjarne Stroustrup and others mention new coding guidelines for C++ and some types supporting them. Specifically, I remember the example of span<T> instead of (T* p, int n) as a parameter to a function (at time about 32:00 into the talk); but I also remember the suggestion to use array_view<T> . Are they two alternatives but the same concept? Or am I confusing things and they're actually not so related? I can't seem to find any authoritative definition of what they're both supposed to be about. Bjarne Stroustrup We talked with people in the

gsl::not_null<T*> vs. std::reference_wrapper<T> vs. T&

旧巷老猫 提交于 2019-11-26 19:44:35
问题 C++ Core Guidelines has been presented recently (congrats!) and I am concerned about gsl::not_null type. As stated in I.12: Declare a pointer that must not be null as not_null: To help avoid dereferencing nullptr errors. To improve performance by avoiding redundant checks for nullptr. ... By stating the intent in source, implementers and tools can provide better diagnostics, such as finding some classes of errors through static analysis, and perform optimizations, such as removing branches

What&#39;s the difference between span and array_view in the gsl library?

为君一笑 提交于 2019-11-26 15:39:18
问题 In several recent conference presentation I've heard Bjarne Stroustrup and others mention new coding guidelines for C++ and some types supporting them. Specifically, I remember the example of span<T> instead of (T* p, int n) as a parameter to a function (at time about 32:00 into the talk); but I also remember the suggestion to use array_view<T> . Are they two alternatives but the same concept? Or am I confusing things and they're actually not so related? I can't seem to find any authoritative