Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How can C++ avoid using highly unrestricted templates with common names

Shulou Source: shulou.com Published: 2022-06-01 20:49:20 11月12日 Update

This article mainly explains "how C++ avoids using a highly unrestricted template for common names". 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 how C++ can avoid using a highly unrestricted template for common names.

T.47: avoid using highly unrestricted templates with common names

Reason (reason)

An unconstrained template argument is a perfect match for anything so such a template can be preferred over more specific types that require minor conversions. This is particularly annoying/dangerous when ADL is used. Common names make this problem more likely.

Unrestricted template parameters perfectly match anything, so such templates can cover specific types that require slight conversion. This situation can be troublesome / dangerous when using ADL. A common name will make this problem more likely to occur.

Example (sample)

Namespace Bad {

Struct S {int m;}

Template

Bool operator== (T1, T2) {cout

Tags: Templates names heights questions types categories codes actual space content situations standards examples rules learning practical deeper same slight dangerous Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple OPPO Reno Shulou Tech Info macOS NVidia