From 01176efbdf71da67a6e9868e7b5a538d32425920 Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Mon, 29 Jul 2019 12:57:21 -0600 Subject: [PATCH] Provide implementation of aligned_union Although it is mostly C++11 compliant, GCC 4.8 does not have an implementation of std::aligned_union. We cannot drop this compiler, so provide our own implementation in that case. --- vtkm/internal/Variant.h | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/vtkm/internal/Variant.h b/vtkm/internal/Variant.h index a73e20d27..67813863e 100644 --- a/vtkm/internal/Variant.h +++ b/vtkm/internal/Variant.h @@ -14,6 +14,45 @@ #include + +// It would make sense to put this in its own header file, but it is hard to imagine needing +// aligned_union anywhere else. +#if (defined(VTKM_GCC) && (__GNUC__ == 4)) || (defined(VTKM_ICC) && (__INTEL_COMPILER < 1800)) +#include +namespace vtkmstd +{ +template +struct max_size; +template +struct max_size +{ + static constexpr std::size_t value = X; +}; +template +struct max_size +{ + static constexpr std::size_t other_value = max_size::value; + static constexpr std::size_t value = (other_value > X0) ? other_value : X0; +}; +// This implementation comes from https://en.cppreference.com/w/cpp/types/aligned_union +template +struct aligned_union +{ + static constexpr std::size_t alignment_value = vtkmstd::max_size::value; + + struct type + { + alignas(alignment_value) char _s[vtkmstd::max_size::value]; + }; +}; +} // namespace vtkmstd +#else +namespace vtkmstd +{ +using std::aligned_union; +} // namespace vtkmstd +#endif + namespace vtkm { namespace internal @@ -51,7 +90,7 @@ class Variant { }; - typename std::aligned_union<0, Ts...>::type Storage; + typename vtkmstd::aligned_union<0, Ts...>::type Storage; VTKM_EXEC_CONT void* GetPointer() { return reinterpret_cast(&this->Storage); } VTKM_EXEC_CONT const void* GetPointer() const