{"id":3967,"date":"2020-08-10T13:31:08","date_gmt":"2020-08-10T11:31:08","guid":{"rendered":"https:\/\/mariusbancila.ro\/blog\/?p=3967"},"modified":"2021-03-30T21:15:05","modified_gmt":"2021-03-30T19:15:05","slug":"no-more-plain-old-data","status":"publish","type":"post","link":"https:\/\/mariusbancila.ro\/blog\/2020\/08\/10\/no-more-plain-old-data\/","title":{"rendered":"No more plain old data"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">When working in C++, you often hear about <em>POD types<\/em> (which stands for <em>Plain Old Data<\/em>). PODs are useful for communicating with code written in other programming languages (such as C or .NET languages). They can also be copied using <code>memcpy<\/code> (which is important because this is a fast, low-level function that provides performance benefits), and have other characteristics that are key for some scenarios. However, the new C++20 standard has deprecated the concept of POD types in favor of two more refined categories, which are <em>trivial<\/em> and <em>standard-layout<\/em> types. In this post, I will discuss what these categories are and when to use instead of POD.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s start with a simple example:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">struct A\n{\n   int    a;\n   double b;\n};\n\nstruct B\n{\nprivate:\n   int a;\npublic:\n   double b;\n};\n\nstruct C\n{\n   int    a;\n   double b;\n   C(int const x, double const y) :a{ x }, b{ y }\n   {}\n};<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The question is, which of these is a POD type? To answer the question, we can use the type traits available in the standard library since C++11:<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table class=\"has-fixed-layout\"><thead><tr><th>Type trait (since C++11)<\/th><th>Variable template (since C++17)<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>std::is_pod&lt;T><\/code><\/td><td><code>std::is_pod_v&lt;T><\/code><\/td><td>If\u00a0<code>T<\/code>\u00a0is a POD type, then the constant member\u00a0<code>value<\/code>\u00a0is true; otherwise it is false<\/td><\/tr><tr><td><code>std::is_trivial&lt;T><\/code><\/td><td><code>std::is_trivial_v&lt;T><\/code><\/td><td>If\u00a0<code>T<\/code>\u00a0is a trivial type, then the constant member\u00a0<code>value<\/code>\u00a0is true; otherwise it is false<\/td><\/tr><tr><td><code>std::is_standard_layout&lt;T><\/code><\/td><td><code>std::is_standard_layout_v&lt;T><\/code><\/td><td>If\u00a0<code>T<\/code>\u00a0is a standard type, then the constant member\u00a0<code>value<\/code>\u00a0is true; otherwise it is false<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Using these type traits, provides the following answer:<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table class=\"has-fixed-layout\"><thead><tr><th>Type<\/th><th>Trivial<\/th><th>Standard layout<\/th><th>POD<\/th><\/tr><\/thead><tbody><tr><td><code>A<\/code><\/td><td><img decoding=\"async\" alt=\"\u2714\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/13.0.1\/svg\/2714.svg\" style=\"width: 16px;\"><\/td><td><img decoding=\"async\" alt=\"\u2714\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/13.0.1\/svg\/2714.svg\" style=\"width: 16px;\"><\/td><td><img decoding=\"async\" alt=\"\u2714\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/13.0.1\/svg\/2714.svg\" style=\"width: 16px;\"><\/td><\/tr><tr><td><code>B<\/code><\/td><td><img decoding=\"async\" alt=\"\u2714\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/13.0.1\/svg\/2714.svg\" style=\"width: 16px;\"><\/td><td>\u274c<\/td><td>\u274c<\/td><\/tr><tr><td><code>C<\/code><\/td><td>\u274c<\/td><td><img decoding=\"async\" alt=\"\u2714\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/13.0.1\/svg\/2714.svg\" style=\"width: 16px;\"><\/td><td>\u274c<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">We can see from this table that <code>B<\/code> is trivial, <code>C<\/code> is standard-layout, and <code>A<\/code> is trivial, standard-layout, and POD. And this leads us to the definition of a POD type:<\/p>\n\n\n\n<p class=\"has-vivid-green-cyan-background-color has-background wp-block-paragraph\">A POD type is a type that is both trivial and standard-layout. This definition must hold recursively for all its non-static data members.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Or, in standardese:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>A POD class is a class that is both a trivial class and a standard-layout class, and has no non-static data members of type non-POD class (or array thereof). A POD type is a scalar type, a POD class, an array of such a type, or a cv-qualified version of one of these types.<\/p><\/blockquote>\n\n\n\n<div class=\"wp-block-group has-background\" style=\"background-color:#dcf5ff\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<p class=\"wp-block-paragraph\">This definition refers to scalar types, so for completeness, a scalar type is any of the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>an arithmetic type<\/li><li>an enumeration type<\/li><li>a pointer type<\/li><li>a pointer-to-member type<\/li><li>the <code>std::nullptr_t<\/code> type<\/li><li>cv-qualified versions of the above types<\/li><\/ul>\n<\/div><\/div>\n<\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">POD types cannot have non-static member data that are not themselves POD types. However, it has no requirements on static members or functions. Therefore, the type <code>A1<\/code> shown here, is still a POD type, although it has member functions and non-POD static members.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">struct A1\n{\n   int    a;\n   double b;\n   static std::string s;\n   int get() const { return a; }\n};<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If a POD type is a trivial type with standard layout, the question is what is trivial and what is standard-layout? Let&#8217;s answer one at a time.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Trivial types<\/h2>\n\n\n\n<p class=\"has-vivid-green-cyan-background-color has-background wp-block-paragraph\">A trivial type is a type that is trivially copyable and has one or more default constructors, all of which are either trivial or deleted, and at least one of which is not deleted.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Keep in mind that a class can have multiple default constructors (for instance a constructor with no parameters, and a constructor that supplies default arguments for all its parameters) as long as it is possible to create, without any ambiguity, an instance of the type without explicitly invoking the constructor (can be default-initialized).<\/p>\n\n\n\n<div class=\"wp-block-group has-background\" style=\"background-color:#dcf5ff\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<p class=\"wp-block-paragraph\">A trivially-copyable type is a type that has:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>only copy-constructors and copy-assignment operators that are either trivial or deleted<\/li><li>only move-constructors and move-assignment operators that are either trivial or deleted<\/li><li>at least one of these four special member functions is not deleted<\/li><li>a trivial non-deleted destructor<\/li><li>no virtual functions or virtual base classes<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">In this definition, trivial means that the special member function belongs to a class that:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>it is not user-provided<\/li><li>has no virtual functions or virtual base classes<\/li><li>has no base classes with a non-trivial constructor\/operator\/destructor<\/li><li>has no data members of a type that has non-trivial constructor\/operator\/destructor<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The specifications for trivial types are available <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/named_req\/TrivialType\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>.<\/p>\n<\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Trivial types have some properties:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>They occupy a contiguous memory area.<\/li><li>There can be padding bytes between members due to alignment requirements.<\/li><li>Can use <code>memcpy<\/code> with objects of trivial types.<\/li><li>Can be copied to an array of <code>char<\/code> or <code>unsigned char<\/code> and then back.<\/li><li>They can have members with different access specifiers. However, in this situation the compiler can decide how to order the members.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">However, trivial types cannot be safely used to interop with code written in other programming languages. This is due to the fact that the order of the members is compiler-specific.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The following snippet shows more examples of trivial types (<code>B1<\/code>, <code>B2<\/code>, <code>B3<\/code>, and <code>B4<\/code> are all trivial types):<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">struct B1\n{\n};\n\nstruct B2\n{\nprivate:\n   int a;\npublic:\n   double b;\n   void foo() {} \n};\n\nstruct B3\n{\nprivate:\n   int a;\npublic:\n   double b;\n\n   B3(int const x, double const y) :\n      a(x), b(y) {}\n   B3() = default;\n};\n\nstruct B4Base\n{\n   int    a;\n   double b;\n};\n\nstruct B4 : public B4Base\n{\nprivate:\n   int a;\n};<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Standard-layout types<\/h2>\n\n\n\n<p class=\"has-vivid-green-cyan-background-color has-background wp-block-paragraph\">In simple words, a standard-layout type is a type that has members with the same access control and does not have virtual functions or virtual base classes, or other features not present in the C language.<\/p>\n\n\n\n<div class=\"wp-block-group has-background\" style=\"background-color:#dcf5ff\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<p class=\"wp-block-paragraph\">Formally defined, a standard-layout type is a type that:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>has the same access control for all the non-static data members<\/li><li>has no non-static data members of reference types<\/li><li>has no virtual functions or virtual base classes<\/li><li>all the non-static data members and base classes are standard-layout types<\/li><li>has no two base class sub-objects of the same type (no diamond problem due to multiple inheritance)<\/li><li>has all non-static data members and bit-fields declared in the same class<\/li><li>has no base classes of the same type as the first non-static data member<\/li><\/ul>\n<\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">The specifications for standard layout types are available <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/named_req\/StandardLayoutType\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Standard-layout types have some properties, including the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>The memory layout of a standard-layout type is well defined so that it can be used to interop with other programming languages, such as C.<\/li><li>Objects of standard-layout types can be <code>memcpy<\/code>-ed.<\/li><li>Facilitates empty base class optimization. This is an optimization that ensures base classes with no data members take up no space and, therefore, have the size zero. Also, such a base sub-object has the same address as the first data member of the derived class (therefore, the last limitation in the preceding list).<\/li><li>Can use the <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/types\/offsetof\" target=\"_blank\" rel=\"noopener noreferrer\"><code>offsetof<\/code><\/a> macro to determine the offset of a data member, in bytes, from the beginning of the object.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s look at some more examples of standard-layout types. In the snippet below, the classes <code>C1<\/code>, <code>C2<\/code>, and <code>C3<\/code> are all standard-layout.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">struct C1\n{\n};\n\nstruct C2\n{\n   A      a;\n   double b;\n};\n\nstruct C3Base\n{\n   void foo() {}\n};\n\nstruct C3 : public C3Base\n{\n   int    a;\n   double b;\n};<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">On the other hand, none of the following classes, <code>C4<\/code> to <code>C8<\/code>, are standard-layout.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">struct C4Base\n{\n   int    a;\n};\n\nstruct C4 : public C4Base\n{\n   double b;\n};\n\nstruct C5\n{\n   int    a;\nprivate:\n   virtual void foo() {};\n};\n\nstruct C6Base {};\nstruct X : public C6Base {};\nstruct Y : public C6Base {};\nstruct C6 : public X, Y {};\n\nstruct C7\n{\n   int    a;\nprivate:\n   double b;\n};\n\nstruct C8 : public C6Base\n{\n   C6Base b;\n   int    a;\n};<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The reason for this is that:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>C4<\/code> does not have all the non-static data members defined in the same class<\/li><li><code>C5<\/code> has virtual functions<\/li><li><code>C6<\/code> has two base class sub-objects of the same type (diamond problem)<\/li><li><code>C7<\/code> has members with different access control<\/li><li><code>C8<\/code> has the first non-static data member of the same type as the base class<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Although it has a non-static data member of the base class such in the case of the <code>C8<\/code> class, the <code>C9<\/code> class shown below is standard-layout, because this member is not the first.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">struct C9 : public C6Base\n{\n   int    a;\n   C6Base b;\n};<\/pre>\n\n\n\n<p class=\"has-background wp-block-paragraph\" style=\"background-color:#ffcfd0\">This <code>C9<\/code> class is reported as non standard-type by the VC++ compiler, although Clang and GCC correctly identify it as standard-layout.<br><br>A demo is available\u00a0<a href=\"https:\/\/wandbox.org\/permlink\/gPs6l9j2ijtnPYTL\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Deprecated POD<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The C++20 standard has deprecated the concept of POD and the type trait <code>std::is_pod&lt;T&gt;<\/code> (and the variable template <code>std::is_pod_v&lt;T&gt;<\/code>) because, one one hand, POD is equivalent to trivial <em>and<\/em> standard-layout, and, on the other hand, in most scenarios, using just trivial <em>or<\/em> standard-layout types is enough or desired. The following comment is taken from the ISO committee notes:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>The term POD no longer serves a purpose in the standard, it is merely defined, and restrictions apply for when a few other types preserve this vestigial property. The is_pod trait should be deprecated, moving the definition of a POD type alongside the trait in Annex D, and any remaining wording referring to POD should be struck, or revised to clearly state intent (usually triviality) without mentioning PODs.<\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">You can check the following papers:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"http:\/\/www.open-std.org\/jtc1\/sc22\/wg21\/docs\/papers\/2017\/p0767r1.html\" target=\"_blank\" rel=\"noopener noreferrer\">P0767R1: Deprecate POD<\/a><\/li><li><a href=\"http:\/\/www.open-std.org\/jtc1\/sc22\/wg21\/docs\/papers\/2016\/p0488r0.pdf\" target=\"_blank\" rel=\"noopener noreferrer\">WG21 Working Paper, NB Comments, ISO\/IEC CD 14882<\/a><\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The key question that arises from this is what should be used instead of POD? The answer is the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>for scenarios where initialization is concerned, use triviality<\/li><li>for scenarios where layout and interoping with other programming languages is concerned, use the standard layout requirement<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/media1.tenor.com\/images\/66ea2a9ceb4101aa2cd6d249c5780e74\/tenor.gif\" alt=\"Okay?\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">See also<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/botondballo.wordpress.com\/2017\/11\/20\/trip-report-c-standards-meeting-in-albuquerque-november-2017\/\" target=\"_blank\" rel=\"noopener noreferrer\">Trip Report: C++ Standards Meeting in Albuquerque, November 2017<\/a><\/li><li><a href=\"https:\/\/docs.microsoft.com\/en-us\/cpp\/cpp\/trivial-standard-layout-and-pod-types?view=vs-2019\" target=\"_blank\" rel=\"noopener noreferrer\">Trivial, standard-layout, POD, and literal types<\/a><\/li><li><a href=\"https:\/\/pabloariasal.github.io\/2020\/01\/02\/static-variable-initialization\/\" target=\"_blank\" rel=\"noopener noreferrer\">C++ &#8211; Initialization of Static Variables<\/a><\/li><li><a href=\"https:\/\/en.cppreference.com\/w\/cpp\/language\/initialization\" target=\"_blank\" rel=\"noopener noreferrer\">C++ Initialization<\/a><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>When working in C++, you often hear about <em>POD types<\/em> (which stands for <em>Plain Old Data<\/em>). PODs are useful for communicating with code written in other programming languages (such as C or .NET languages). They can also be copied using <tt>memcpy<\/tt> (which is important because this is a fast, low-level function that provides performance benefits), and have other characteristics that are key for some scenarios. However, the new C++20 standard has deprecated the concept of POD types in favor of two more refined categories, which are <em>trivial<\/em> and <em>standard-layout<\/em> types. In this post, I will discuss what these categories are and when to use instead of POD.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","advgb_blocks_editor_width":"","advgb_blocks_columns_visual_guide":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[7],"tags":[451,543,628,629],"class_list":["post-3967","post","type-post","status-publish","format-standard","hentry","category-c","tag-c","tag-c20","tag-pod","tag-traits"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.1.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"This article discusses the deprecated concept of plain old data (POD) C++ types and the new trivial and standard-layout types.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Marius Bancila\"\/>\n\t<meta name=\"keywords\" content=\"c++,c++20,pod,traits\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/mariusbancila.ro\/blog\/2020\/08\/10\/no-more-plain-old-data\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.1.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Marius Bancila&#039;s Blog | About code. Mostly on C++\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"No more plain old data\" \/>\n\t\t<meta property=\"og:description\" content=\"This article discusses the deprecated concept of plain old data (POD) C++ types and the new trivial and standard-layout types.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/mariusbancila.ro\/blog\/2020\/08\/10\/no-more-plain-old-data\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2020-08-10T11:31:08+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2021-03-30T19:15:05+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"No more plain old data\" \/>\n\t\t<meta name=\"twitter:description\" content=\"This article discusses the deprecated concept of plain old data (POD) C++ types and the new trivial and standard-layout types.\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2020\\\/08\\\/10\\\/no-more-plain-old-data\\\/#article\",\"name\":\"No more plain old data\",\"headline\":\"No more plain old data\",\"author\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/s.w.org\\\/images\\\/core\\\/emoji\\\/13.0.1\\\/svg\\\/2714.svg\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2020\\\/08\\\/10\\\/no-more-plain-old-data\\\/#articleImage\"},\"datePublished\":\"2020-08-10T13:31:08+02:00\",\"dateModified\":\"2021-03-30T21:15:05+02:00\",\"inLanguage\":\"en-US\",\"commentCount\":4,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2020\\\/08\\\/10\\\/no-more-plain-old-data\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2020\\\/08\\\/10\\\/no-more-plain-old-data\\\/#webpage\"},\"articleSection\":\"C++, C++, c++20, POD, traits\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2020\\\/08\\\/10\\\/no-more-plain-old-data\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"name\":\"IT\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"position\":2,\"name\":\"IT\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"name\":\"Software\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"position\":3,\"name\":\"Software\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/#listItem\",\"name\":\"C++\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"name\":\"IT\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/#listItem\",\"position\":4,\"name\":\"C++\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2020\\\/08\\\/10\\\/no-more-plain-old-data\\\/#listItem\",\"name\":\"No more plain old data\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"name\":\"Software\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2020\\\/08\\\/10\\\/no-more-plain-old-data\\\/#listItem\",\"position\":5,\"name\":\"No more plain old data\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/#listItem\",\"name\":\"C++\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\",\"name\":\"Marius Bancila's Blog\",\"description\":\"About code. Mostly on C++\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/\",\"name\":\"Marius Bancila\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2020\\\/08\\\/10\\\/no-more-plain-old-data\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a84dd2831d955c38355ddea55df4df260809b88f36408bc14fd4eab8f7f131c9?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Marius Bancila\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2020\\\/08\\\/10\\\/no-more-plain-old-data\\\/#webpage\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2020\\\/08\\\/10\\\/no-more-plain-old-data\\\/\",\"name\":\"No more plain old data\",\"description\":\"This article discusses the deprecated concept of plain old data (POD) C++ types and the new trivial and standard-layout types.\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2020\\\/08\\\/10\\\/no-more-plain-old-data\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"datePublished\":\"2020-08-10T13:31:08+02:00\",\"dateModified\":\"2021-03-30T21:15:05+02:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\",\"name\":\"Marius Bancila's Blog\",\"description\":\"About code. Mostly on C++\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"No more plain old data","description":"This article discusses the deprecated concept of plain old data (POD) C++ types and the new trivial and standard-layout types.","canonical_url":"https:\/\/mariusbancila.ro\/blog\/2020\/08\/10\/no-more-plain-old-data\/","robots":"max-image-preview:large","keywords":"c++,c++20,pod,traits","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/mariusbancila.ro\/blog\/2020\/08\/10\/no-more-plain-old-data\/#article","name":"No more plain old data","headline":"No more plain old data","author":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"publisher":{"@id":"https:\/\/mariusbancila.ro\/blog\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/s.w.org\/images\/core\/emoji\/13.0.1\/svg\/2714.svg","@id":"https:\/\/mariusbancila.ro\/blog\/2020\/08\/10\/no-more-plain-old-data\/#articleImage"},"datePublished":"2020-08-10T13:31:08+02:00","dateModified":"2021-03-30T21:15:05+02:00","inLanguage":"en-US","commentCount":4,"mainEntityOfPage":{"@id":"https:\/\/mariusbancila.ro\/blog\/2020\/08\/10\/no-more-plain-old-data\/#webpage"},"isPartOf":{"@id":"https:\/\/mariusbancila.ro\/blog\/2020\/08\/10\/no-more-plain-old-data\/#webpage"},"articleSection":"C++, C++, c++20, POD, traits"},{"@type":"BreadcrumbList","@id":"https:\/\/mariusbancila.ro\/blog\/2020\/08\/10\/no-more-plain-old-data\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog#listItem","position":1,"name":"Home","item":"https:\/\/mariusbancila.ro\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","name":"IT"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","position":2,"name":"IT","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","name":"Software"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","position":3,"name":"Software","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/#listItem","name":"C++"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","name":"IT"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/#listItem","position":4,"name":"C++","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/2020\/08\/10\/no-more-plain-old-data\/#listItem","name":"No more plain old data"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","name":"Software"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/2020\/08\/10\/no-more-plain-old-data\/#listItem","position":5,"name":"No more plain old data","previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/#listItem","name":"C++"}}]},{"@type":"Organization","@id":"https:\/\/mariusbancila.ro\/blog\/#organization","name":"Marius Bancila's Blog","description":"About code. Mostly on C++","url":"https:\/\/mariusbancila.ro\/blog\/"},{"@type":"Person","@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author","url":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/","name":"Marius Bancila","image":{"@type":"ImageObject","@id":"https:\/\/mariusbancila.ro\/blog\/2020\/08\/10\/no-more-plain-old-data\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/a84dd2831d955c38355ddea55df4df260809b88f36408bc14fd4eab8f7f131c9?s=96&d=mm&r=g","width":96,"height":96,"caption":"Marius Bancila"}},{"@type":"WebPage","@id":"https:\/\/mariusbancila.ro\/blog\/2020\/08\/10\/no-more-plain-old-data\/#webpage","url":"https:\/\/mariusbancila.ro\/blog\/2020\/08\/10\/no-more-plain-old-data\/","name":"No more plain old data","description":"This article discusses the deprecated concept of plain old data (POD) C++ types and the new trivial and standard-layout types.","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/mariusbancila.ro\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/mariusbancila.ro\/blog\/2020\/08\/10\/no-more-plain-old-data\/#breadcrumblist"},"author":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"creator":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"datePublished":"2020-08-10T13:31:08+02:00","dateModified":"2021-03-30T21:15:05+02:00"},{"@type":"WebSite","@id":"https:\/\/mariusbancila.ro\/blog\/#website","url":"https:\/\/mariusbancila.ro\/blog\/","name":"Marius Bancila's Blog","description":"About code. Mostly on C++","inLanguage":"en-US","publisher":{"@id":"https:\/\/mariusbancila.ro\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"Marius Bancila's Blog | About code. Mostly on C++","og:type":"article","og:title":"No more plain old data","og:description":"This article discusses the deprecated concept of plain old data (POD) C++ types and the new trivial and standard-layout types.","og:url":"https:\/\/mariusbancila.ro\/blog\/2020\/08\/10\/no-more-plain-old-data\/","article:published_time":"2020-08-10T11:31:08+00:00","article:modified_time":"2021-03-30T19:15:05+00:00","twitter:card":"summary","twitter:title":"No more plain old data","twitter:description":"This article discusses the deprecated concept of plain old data (POD) C++ types and the new trivial and standard-layout types."},"aioseo_meta_data":{"post_id":"3967","title":null,"description":"This article discusses the deprecated concept of plain old data (POD) C++ types and the new trivial and standard-layout types.","keywords":[],"keyphrases":{"focus":[],"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":[],"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":{"id":"aioseo-article-6369652214b7b","slug":"article","graphName":"Article","label":"Article","properties":{"type":"BlogPosting","name":"#post_title","headline":"#post_title","description":"#post_excerpt","image":"","keywords":"","author":{"name":"#author_name","url":"#author_url"},"dates":{"include":true,"datePublished":"","dateModified":""}}},"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":"{\"article\":{\"articleType\":\"BlogPosting\"},\"course\":{\"name\":\"\",\"description\":\"\",\"provider\":\"\"},\"faq\":{\"pages\":[]},\"product\":{\"reviews\":[]},\"recipe\":{\"ingredients\":[],\"instructions\":[],\"keywords\":[]},\"software\":{\"reviews\":[],\"operatingSystems\":[]},\"webPage\":{\"webPageType\":\"WebPage\"}}","pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","location":null,"local_seo":{"businessInfo":{"name":"","urls":{"website":"","aboutPage":"","contactPage":""},"address":{"line1":"","line2":"","zip":"","city":"","state":"","country":""},"contact":{"email":"","phone":"","fax":""},"ids":{"vatID":"","taxID":"","chamberID":""},"payment":{"priceIndication":"","currenciesAccepted":"","methodsAccepted":""},"areaServed":""},"openingHours":{"show":false,"closedLabel":"","open24h":false,"open24hLabel":"","open247":false,"use24hFormat":false,"twoSets":false,"timezone":"","hours":[]}},"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2021-03-18 21:02:54","updated":"2025-12-12 07:55:32","seo_analyzer_scan_date":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"author_meta":{"display_name":"Marius Bancila","author_link":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/"},"featured_img":null,"jetpack_publicize_connections":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Marius Bancila","author_link":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/"},"uagb_comment_info":4,"uagb_excerpt":"When working in C++, you often hear about POD types (which stands for Plain Old Data). PODs are useful for communicating with code written in other programming languages (such as C or .NET languages). They can also be copied using memcpy (which is important because this is a fast, low-level function that provides performance benefits),&hellip;","coauthors":[],"tax_additional":{"categories":{"linked":["<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/\" class=\"advgb-post-tax-term\">C++<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">C++<\/span>"]},"tags":{"linked":["<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/\" class=\"advgb-post-tax-term\">C++<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/\" class=\"advgb-post-tax-term\">c++20<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/\" class=\"advgb-post-tax-term\">POD<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/\" class=\"advgb-post-tax-term\">traits<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">C++<\/span>","<span class=\"advgb-post-tax-term\">c++20<\/span>","<span class=\"advgb-post-tax-term\">POD<\/span>","<span class=\"advgb-post-tax-term\">traits<\/span>"]}},"comment_count":"4","relative_dates":{"created":"Posted 6 years ago","modified":"Updated 6 years ago"},"absolute_dates":{"created":"Posted on August 10, 2020","modified":"Updated on March 30, 2021"},"absolute_dates_time":{"created":"Posted on August 10, 2020 1:31 pm","modified":"Updated on March 30, 2021 9:15 pm"},"featured_img_caption":"","series_order":"","jetpack_shortlink":"https:\/\/wp.me\/pYNdv-11Z","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/3967","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/comments?post=3967"}],"version-history":[{"count":44,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/3967\/revisions"}],"predecessor-version":[{"id":4272,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/3967\/revisions\/4272"}],"wp:attachment":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/media?parent=3967"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/categories?post=3967"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/tags?post=3967"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}