You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
788 B

1 year ago
  1. #pragma once
  2. #include "core.h"
  3. namespace vlc
  4. {
  5. #ifndef VLC_HAS_STD_ALIGNED_UNION
  6. namespace detail
  7. {
  8. template<size_t...> struct Max;
  9. template<> struct Max<>
  10. {
  11. static constexpr size_t value = 0;
  12. };
  13. template<size_t val> struct Max<val>
  14. {
  15. static constexpr size_t value = val;
  16. };
  17. template<size_t A, size_t B, size_t... Rest> struct Max<A, B, Rest...> :
  18. public Max<A < B ? B : A, Rest...>
  19. {
  20. };
  21. }
  22. template<size_t minSize, typename... Types> struct aligned_union
  23. {
  24. static constexpr size_t len = detail::Max<minSize, sizeof(Types)...>::value;
  25. static constexpr size_t alignment = detail::Max<std::alignment_of<Types>::value...>::value;
  26. using type = typename std::aligned_storage<len, alignment>::type;
  27. };
  28. #else
  29. using std::aligned_union;
  30. #endif
  31. }