Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What are the advantages of using the standard concept in C++

Shulou Source: shulou.com Published: 2022-06-01 20:48:47 09月22日 Update

This article mainly explains "what are the advantages of using the standard concept of C++", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what are the advantages of using the standard concept of C++"?

T.11: use standard concepts whenever possible

Reason (reason)

"Standard" concepts (as provided by the GSL and the Ranges TS, and hopefully soon the ISO standard itself) save us the work of thinking up our own concepts, are better thought out than we can manage to do in a hurry, and improve interoperability.

The concept of "standards" (provided by GSL or Range technical specifications, and most likely ISO standards soon) can save us the work of designing concepts for our own use, and standard concepts will be better and more interchangeable than those we hastily designed.

Note (Note)

Unless you are creating a new generic library, most of the concepts you need will already be defined by the standard library

Unless you are developing a new generic library, most of the concepts you need should already be defined in the standard library and do not require additional design.

Example (using TS concepts) (instance (using TS concept))

Template

/ / don't define this: Sortable is in the GSL

Concept Ordered_container = Sequence & & Random_access & & Ordered

Void sort (Ordered_container& s)

This Ordered_container is quite plausible, but it is very similar to the Sortable concept in the GSL (and the Range TS). Is it better? Is it right? Does it accurately reflect the standard's requirements for sort? It is better and simpler just to use Sortable:

Ordered_container is quite reasonable, but it is very similar to the concept of Sortable in GSL (and RangeTS). Is it better to do this? Is this the right thing to do? Does it accurately reflect the standard requirements for sorting? It is simpler and better to use Sortable directly.

Void sort (Sortable& s); / / betterNote (note)

The set of "standard" concepts is evolving as we approach an ISO standard including concepts.

In the process of introducing the concept into the ISO standard, this set of "standard" concepts are also gradually developing.

Note (Note)

Designing a useful concept is challenging.

Designing a useful concept is a challenge.

Enforcement (implementation recommendations)

Hard.

It's hard

Look for unconstrained arguments, templates that use "unusual" / non-standard concepts, templates that use "homebrew" concepts without axioms.

Look for templates that use unconstrained parameters, templates that use "unusual" / non-standard concepts, and templates that use self-defined concepts that have not been well demonstrated.

Develop a concept-discovery tool (e.g.see an early experiment).

Design a tool for discovering concepts

At this point, I believe you have a deeper understanding of "what are the advantages of the standard concept of the use of C++?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Concepts standards design advantages Clearing content templates learning rigor practicality deeper similarity haste interchangeability interchangeability interests reasons parameters most examples Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Apple Linux macOS Microsoft