120

std::is_pod will be probably deprecated in C++20.
What's the reason for this choice? What should I use in place of std::is_pod to know if a type is actually a POD?

skypjack
  • 49,335
  • 19
  • 95
  • 187
  • 1
    See also http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0767r1.html and US 101 in http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0488r0.pdf – Baum mit Augen Jan 12 '18 at 12:01
  • 3
    Why do you want to know if a type is POD? – Marc Glisse Jan 12 '18 at 16:35
  • 14
    @MarcGlisse A question about changes in the standard or a trait like this doesn't necessarily mean that I want to use that feature. I found the _deprecated_ note while googling and I was just curious to know why it was deprecated. – skypjack Jan 12 '18 at 16:38
  • My question was actually an indirect answer: it was removed because (roughly) there is no reason to ask if a type is POD. – Marc Glisse Jan 12 '18 at 20:46
  • 10
    I would use it for a `static_assert` to ensure no one touches structs that should be shared with C code. – Mirko Apr 09 '19 at 05:48
  • @Mirko I find myself using it for that quite a lot as well, so this change is fairly disappointing. – Οurous May 07 '19 at 02:57

1 Answers1

96

POD is being replaced with two categories that give more nuances. The c++ standard meeting in november 2017 had this to say about it:

Deprecating the notion of “plain old data” (POD). It has been replaced with two more nuanced categories of types, “trivial” and “standard-layout”. “POD” is equivalent to “trivial and standard layout”, but for many code patterns, a narrower restriction to just “trivial” or just “standard layout” is appropriate; to encourage such precision, the notion of “POD” was therefore deprecated. The library trait is_pod has also been deprecated correspondingly.

For simple data types use the is_standard_layout function, for trivial data types (such as simple structs) use the is_trivial function.

Baum mit Augen
  • 49,044
  • 25
  • 144
  • 182
D.J. Klomp
  • 2,429
  • 1
  • 15
  • 30
  • 6
    So, they add `remove_cvref` on one side, that is a composed trait, while on the other side they remove other composed traits? It seems insane. :-) – skypjack Jan 12 '18 at 12:20
  • 2
    @skypjack One could argue pod is a misleading or often misused term – Passer By Jan 12 '18 at 13:10
  • 11
    It seems to be trivial AND standard layout AND a clause involving being recursively POD. Is the recursive clause redundant? Ie, is it guaranteed that `std::is_pod{} == (std::is_trivial{} && std::is_standard_layout{})`? – Yakk - Adam Nevraumont Jan 12 '18 at 15:29
  • 6
    @skypjack: The point of removing POD is that it no longer serves a purpose. The composition of "trivial" and "standard layout" doesn't actually mean anything in C++, and there's no reason why you would restrict an interface to POD rather than "trivial" or "standard layout" based on what you're actually doing with it. By contrast, removing "cvref" means something; the resulting type is an object type with no qualifiers. – Nicol Bolas Jan 12 '18 at 17:37
  • @skypjack: "*Granted, but it's part of a library that contains an std::move utility that doesn't move anything.*" It shouldn't have been using `is_pod`; it should have used `is_trivially_copyable`. – Nicol Bolas Jan 12 '18 at 17:40
  • 11
    I for one really appreciate this change. As a systems software programmer, "standard layout" was really what I cared about all along, and the requirement for PODs not having constructors made them not properly describe my common "structs with constructors" idiom. Previously I was forced to call those "pseudo-PODs". Cute, but it makes certain anime fans look funny at you when you talk about having pseudopods in your code. – T.E.D. Jan 12 '18 at 20:07
  • 2
    Are `std::is_pod`, `std::is_trivia` and `std::is_standard_layout` compile-time? Because in algorithms, you might wish for a faster algorithm using memcpy() etc if C-layout compatible. – SJHowe Sep 06 '18 at 18:32
  • 5
    @SJHowe type_traits are all compile time just by the virtue of them being the traits of the __type__ (which only really exist at compile time). – Dan M. Oct 24 '18 at 14:03
  • MSVC claims `class S { S() = default; };` is POD but not trivial. I assume that's wrong? – user541686 Sep 01 '23 at 02:27