Skip to content

Commit 0fe6c22

Browse files
committed
int: Allow TypeDesc to have all the right POD attributes (AcademySoftwareFoundation#4162)
This PR is for allowing the TypeDesc type to be used directly in a C API without indirection, and therefore also in a Rust API without indirection. --------- Signed-off-by: Scott Wilson <[email protected]>
1 parent 2303e67 commit 0fe6c22

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/include/OpenImageIO/typedesc.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,7 @@ struct OIIO_UTIL_API TypeDesc {
164164
TypeDesc (string_view typestring);
165165

166166
/// Copy constructor.
167-
OIIO_HOSTDEVICE constexpr TypeDesc (const TypeDesc &t) noexcept
168-
: basetype(t.basetype), aggregate(t.aggregate),
169-
vecsemantics(t.vecsemantics), reserved(0), arraylen(t.arraylen)
170-
{ }
167+
OIIO_HOSTDEVICE constexpr TypeDesc (const TypeDesc &t) noexcept = default;
171168

172169

173170
/// Return the name, for printing and whatnot. For example,
@@ -365,8 +362,13 @@ struct OIIO_UTIL_API TypeDesc {
365362
#endif
366363
};
367364

368-
369-
365+
// Validate that TypeDesc can be used directly as POD in a C interface.
366+
static_assert(std::is_default_constructible<TypeDesc>(), "TypeDesc is not default constructable.");
367+
static_assert(std::is_trivially_copyable<TypeDesc>(), "TypeDesc is not trivially copyable.");
368+
static_assert(std::is_trivially_destructible<TypeDesc>(), "TypeDesc is not trivially destructible.");
369+
static_assert(std::is_trivially_move_constructible<TypeDesc>(), "TypeDesc is not move constructible.");
370+
static_assert(std::is_trivially_copy_constructible<TypeDesc>(), "TypeDesc is not copy constructible.");
371+
static_assert(std::is_trivially_move_assignable<TypeDesc>(), "TypeDesc is not move assignable.");
370372

371373
// Static values for commonly used types. Because these are constexpr,
372374
// they should incur no runtime construction cost and should optimize nicely

0 commit comments

Comments
 (0)