In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "Why do not make unlimited non-member function calls in C++". Many people will encounter such a dilemma in the operation of actual cases. next, let the editor lead you to learn how to deal with these situations! I hope you can read it carefully and be able to achieve something!
T.69: within the template, do not make unrestricted non-member function calls unless you want it to be a customization point
Reason (reason)
Provide only intended flexibility.
Provide flexibility only as intended.
Avoid vulnerability to accidental environmental changes.
Avoid the vulnerability of accidental environmental changes.
Example (sample)
There are three major ways to let calling code customize a template.
There are three main ways for calling code to customize templates.
Template
/ / Call a member function
Void test1 (T t)
{
T.F (); / / require T to provide f ()
}
Template
Void test2 (T t)
/ / Call a non-member function without qualification
{
F (t); / / require f (/ * tasking /) be available in caller's scope or in T's namespace
}
Template
Void test3 (T t)
/ / Invoke a "trait"
{
Test_traits::f (t); / / require customizing test_traits
/ / to get non-default functions/types
}
A trait is usually a type alias to compute a type, a constexpr function to compute a value, or a traditional traits template to be specialized on the user's type.
A feature is usually a type alias for evaluating a type, a constant expression function for evaluation, or a traditional feature template that is specialized for a user type.
Note (Note)
If you intend to call your own helper function helper (t) with a value t that depends on a template type parameter, put it in a:: detail namespace and qualify the call as detail::helper (t) An unqualified call becomes a customization point where any function helper in the namespace of t's type can be invoked; this can cause problems like unintentionally invoking unconstrained function templates.
If you want to call your own helper function helper (t) with a value that depends on template type parameters, put it into:: detail namespace and use detail::helper (t) to qualify the call; if a helper function is in a namespace where the type of t can be triggered, unrestricted calls will become a customized point; this will cause unexpected calls to unconstrained function templates and other problems.
Enforcement (implementation recommendations)
In the same namespace of the template, if there is a non-member function with the same name, the unrestricted call in the tag template for the non-member function that passes variables of the affected type
This is the end of the content of "Why not to make unlimited non-member function calls in C++". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.