ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
T_SizeInPlaceholder< TMappedPlain > Struct Template Reference

Description:

template<typename TMappedPlain>
struct alib::boxing::T_SizeInPlaceholder< TMappedPlain >

This specializable TMP struct must be set for custom types, if the following applies:

  • A custom boxing implements T_Boxer::Write in a way that a different number of bytes are used in union Placeholder than the sizeof() operator reports on the mapped type's size.
  • if the standard copy constructor (used with default boxing) writes a different size.
  • One of the above and no specialized version of both box-functions FHashcode or FEquals are set.

Background:
The default implementations of FHashcode and FEquals must use the first N "relevant" bytes of the placeholder only. The non-relevant bytes are not written and therefore must not be taken into account.
To receive the number of relevant bytes, they invoke Box::GetPlaceholderUsageLength (at run-time). This value is set at compile-time with the creation of a mapped type's vtable. While for array types, the value is set to the overall size of union Placeholder , for non-array types, the value of this TMP struct is used.

It might be surprising, but a built-in specialization exists for even a C++ fundamental type long double, which is dependent on the compiler/platform. For example, on GNU/Linux 64-bit, GCC reports 16 with sizeof(long double). However, if a long double value is copied, e.g with:

 *pointerToLongDouble= 3.14L;

then only 10 bytes are written. The reason for this is that sizeof reports the size needed for alignment when placed in an array of that type. In the case of ALib Boxing , 6 bytes of the placeholder remain random and therefore must not be used for hashing or testing values on equality.

Template Parameters
TMappedPlainThe mapped type to modify relevant placeholder length for FHashcode and FEquals implementation.

Definition at line 367 of file typetraits.inl.

Public Static Field Index:

static constexpr unsigned int value = sizeof(TMappedPlain)
 

Field Details:

◆ value

template<typename TMappedPlain >
constexpr unsigned int value = sizeof(TMappedPlain)
staticconstexpr

The size used with the placeholder

Definition at line 370 of file typetraits.inl.


The documentation for this struct was generated from the following file: