Skip to content

Commit

Permalink
int: Allow TypeDesc to have all the right POD attributes (#4162)
Browse files Browse the repository at this point in the history
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 <scott@propersquid.com>
  • Loading branch information
scott-wilson authored Feb 20, 2024
1 parent 92a9b4d commit 43fea76
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/include/OpenImageIO/typedesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,7 @@ struct OIIO_UTIL_API TypeDesc {
TypeDesc (string_view typestring);

/// Copy constructor.
OIIO_HOSTDEVICE constexpr TypeDesc (const TypeDesc &t) noexcept
: basetype(t.basetype), aggregate(t.aggregate),
vecsemantics(t.vecsemantics), reserved(0), arraylen(t.arraylen)
{ }
OIIO_HOSTDEVICE constexpr TypeDesc (const TypeDesc &t) noexcept = default;


/// Return the name, for printing and whatnot. For example,
Expand Down Expand Up @@ -365,8 +362,13 @@ struct OIIO_UTIL_API TypeDesc {
#endif
};



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

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

0 comments on commit 43fea76

Please sign in to comment.