diff --git a/largest.h b/largest.h index a949b252..25765d7a 100644 --- a/largest.h +++ b/largest.h @@ -32,6 +32,8 @@ SOFTWARE. ///\defgroup largest largest ///\ingroup utilities +#include "type_traits.h" + namespace etl { //*************************************************************************** @@ -39,13 +41,13 @@ namespace etl /// Supports up to 16 types. /// Defines 'value_type' which is the type of the largest parameter. /// Defines 'size' which is the size of the largest parameter. - ///\ingroup numeric + ///\ingroup largest //*************************************************************************** template - struct largest + struct largest_type { private: @@ -71,8 +73,8 @@ namespace etl public: - // Define 'largest_other' as 'largest' with all but the first parameter. - typedef typename largest::type largest_other; + // Define 'largest_other' as 'largest_type' with all but the first parameter. + typedef typename largest_type::type largest_other; // Set 'type' to be the largest of the first parameter and any of the others. // This is recursive. @@ -92,10 +94,10 @@ namespace etl // Specialisation for one template parameter. //*************************************************************************** template - struct largest + struct largest_type { typedef T1 type; @@ -104,6 +106,61 @@ namespace etl size = sizeof(type) }; }; + + //*************************************************************************** + /// Template to determine the largest alignment. + /// Supports up to 16 types. + /// Defines 'value' which is the largest alignment of all the parameters. + ///\ingroup largest + //*************************************************************************** + template + struct largest_alignment + { + // Determine the largest size. + template + struct max_size + { + enum + { + value = (size1 > size2) ? size1 : size2 + }; + }; + + // All of the alignments. + enum + { + t1 = alignment_of::value, + t2 = alignment_of::value, + t3 = alignment_of::value, + t4 = alignment_of::value, + t5 = alignment_of::value, + t6 = alignment_of::value, + t7 = alignment_of::value, + t8 = alignment_of::value, + t9 = alignment_of::value, + t10 = alignment_of::value, + t11 = alignment_of::value, + t12 = alignment_of::value, + t13 = alignment_of::value, + t14 = alignment_of::value, + t15 = alignment_of::value, + t16 = alignment_of::value, + }; + + public: + + // The largest of all of them. + enum + { + value = max_size + ::value>::value>::value>::value>::value>::value>::value>::value> + ::value>::value>::value>::value>::value>::value>::value + }; + }; } #endif