Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use span or span_p

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how C++ uses span or span_p". In daily operation, I believe many people have doubts about how C++ uses span or span_p. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "how C++ uses span or span_p". Next, please follow the editor to study!

F.24: use span or span_p to represent semi-open sequences

Half-open is a mathematical concept, which means that when an array in C++ is represented by [p:p+n), p points to the first element, and pairn is outside the array.

Reason (reason)

Informal/non-explicit ranges are a source of errors.

Informal, unclear scope is the source of errors.

Example (sample)

X* find (span r, const X & v); / / find v in r

Vector vec;//... auto p = find ({vec.begin (), vec.end ()}, X {}); / / find X {} in veNote (Note)

The concept of scope is particularly common in C++ code. Typically, the scope is not explicit and it is difficult to confirm whether it is used properly. In particular, given a pair of representation parameters (p, n) to represent an array [n:p+n), it is usually impossible to know whether there are really n elements available after p. As a simple helper class, span is used to indicate the scope [ptrue Q), while the range used by span_p to represent begins with p and ends with the element whose first predicate is PRQ.

Translator's note: it is a pity that no examples of the use of span_p have been found.

Example (sample)

Span represents the scope of the element, but how do we manipulate the elements in the scope?

Void f (span s) {/ / range traversal (guaranteed correct) for (int x: s) cout

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report