Passive data structure: Difference between revisions

Content deleted Content added
m m
m Fix Linter errors.
Line 6:
 
==In C++==
A PDS type in [[C++]], or [[Plain Old C++ Object]], is defined as either a scalar type or a PDS class.<ref>{{cite book |author= Information Technology Industry Council |publisher= ISO/IEC |___location= Geneva |title= Programming languages — C++ |id= 14882:2003(E) |edition= Second |date= 2003-10-15}}</ref> A PDS class has no user-defined copy assignment operator, no user-defined destructor, and no non-static data members that are not themselves PDS. Moreover, a PDS class must be an aggregate, meaning it has no user-declared constructors, no private nor protected non-static data, no virtual base classes{{efn|A PDS class can have a base class whose first non-static data members differs.<ref>{{cite book |author= Bjarne Stroustrup |publisher= Pearson Education, Inc |___location= United States of America |title= The C++ programming language |isbn= 978-0-321-56384-2 |edition= Fourth |date= June 2013}}</ref>}} and no virtual functions.<ref>{{cite web |url=http://www.fnal.gov/docs/working-groups/fpcltf/Pkg/ISOcxx/doc/POD.html |accessdate=6 December 2016 |title=C++ Language Note: POD Types |author=Walter E. Brown |publisher=[[Fermi National Accelerator Laboratory]] |date=September 29, 1999 |archive-url=https://web.archive.org/web/20161203130543/http://www.fnal.gov/docs/working-groups/fpcltf/Pkg/ISOcxx/doc/POD.html |archive-date=3 December 2016 |url-status=dead }}</ref> The standard includes statements about how PDS must behave in C++. The <ttcode>type_traits</ttcode> library in the [[C++ Standard Library]] provides a template named <ttcode>is_pod</ttcode> that can be used to determine whether a given type is a POD.<ref>{{cite web|url=http://www.cplusplus.com/reference/type_traits/is_pod/ |accessdate=6 December 2016 |title=is_pod C++ Reference |publisher=cplusplus.com}}</ref> In C++20 the notion of “plain old data” (POD) and by that <ttcode>is_pod</ttcode> is deprecated and replaced with the concept of “trivial” and “standard-layout” types.<ref>{{Cite web|url=http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0767r1.html|title=P0767R1: Deprecate POD|website=www.open-std.org|access-date=2020-01-20}}</ref>
 
In some contexts, C++ allows only PDS types to be used. For example, a <ttcode>union</ttcode> in C++98 cannot contain a class that has [[virtual function]]s or nontrivial constructors or destructors. This restriction is imposed because the compiler cannot determine which constructor or destructor should be called for a union. PDS types can also be used for interfacing with [[C (programming language)|C]], which supports only PDS.
 
==In Java==