cpp-core-guidelines

What is gsl::multi_span to be used for?

ぃ、小莉子 提交于 2019-11-30 05:40:56
问题 The C++ core guidelines mention spans, not "multi-spans". But - I see that Microsoft's GSL implementation has a multi_span class template < typename ValueType, std::ptrdiff_t FirstDimension, std::ptrdiff_t... RestDimensions > class multi_span { ... }; So, obviously this is some sort of a multi-dimensional version of gsl::span . But what is that supposed to mean? Why do we need this multi-dimensional span, or rather - when would we use it? I can't seem to find any documentation on this. 回答1:

Is CppCoreGuidelines C.21 correct?

无人久伴 提交于 2019-11-28 21:30:55
While reading the Bjarne Stroustrup's CoreCppGuidelines, I have found a guideline which contradicts my experience. The C.21 requires the following: If you define or =delete any default operation, define or =delete them all With the following reason: The semantics of the special functions are closely related, so if one needs to be non-default, the odds are that others need modification too. From my experience, the two most common situations of redefinition of default operations are the following: #1: Definition of virtual destructor with default body to allow inheritance: class C1 { ... virtual

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

Is CppCoreGuidelines C.21 correct?

走远了吗. 提交于 2019-11-27 13:54:43
问题 While reading the Bjarne Stroustrup's CoreCppGuidelines, I have found a guideline which contradicts my experience. The C.21 requires the following: If you define or =delete any default operation, define or =delete them all With the following reason: The semantics of the special functions are closely related, so if one needs to be non-default, the odds are that others need modification too. From my experience, the two most common situations of redefinition of default operations are the

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

What is a “span” and when should I use one?

喜夏-厌秋 提交于 2019-11-26 03:15:36
问题 Recently I\'ve gotten suggestions to use span<T> \'s in my code, or have seen some answers here on the site which use span \'s - supposedly some kind of container. But - I can\'t find anything like that in the C++ standard library. So what is this mysterious span<T> , and why (or when) is it a good idea to use it if it\'s non-standard? 回答1: What is it? A span<T> is: A very lightweight abstraction of a contiguous sequence of values of type T somewhere in memory. Basically a struct { T * ptr;