In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to use non-template core implementation in C++ to provide stable ABI interface". In daily operation, I believe many people have doubts about how to use non-template core implementation in C++ to provide stable ABI interface. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the question of "how to use non-template core implementation to provide a stable ABI interface in C++"! Next, please follow the editor to study!
T.84: provide a stable ABI interface using a non-template core implementation
Reason (reason)
Improve stability of code. Avoid code bloat.
Improve the stability of the code. Avoid code ballooning.
Example (sample)
It could be a base class:
It can exist as a base class:
Struct Link_base {/ / stable
Link_base* suc
Link_base* pre
}
Template / / templated wrapper to add type safety
Struct Link: Link_base {
T val
}
Struct List_base {
Link_base* first; / / first element (if any)
Int sz; / / number of elements
Void add_front (Link_base* p)
/ /...
}
Template
Class List: List_base {
Public:
Void put_front (const Te) {add_front (new Link {e});} / / implicit cast to Link_base
T & front () {static_cast (first) .val;} / / explicit cast back to Link
/ /...
}
List li
List ls
Now there is only one copy of the operations linking and unlinking elements of a List. The Link and List classes do nothing but type manipulation.
(although two List classes are illustrated) there is only one copy of the set of operations (functions) for the associated and non-associative elements of the List. Link and List do nothing but type operations.
Instead of using a separate "base" type, another common technique is to specialize for void or void* and have the general template for T be just the safely-encapsulated casts to and from the core void implementation.
In addition to using independent "base" types, another common technique is to define core implementations based on void and void* types and prepare a generic template class that is limited to safely encapsulating conversions from or to void core implementations.
Alternative: Use a Pimpl implementation.
Other options: use the pointer technology that points to the implementation.
At this point, the study on "how to use non-template core implementations in C++ to provide a stable ABI interface" is over. I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.