From 88419e5e87152cf28d64c9e7d35993785e68fbe2 Mon Sep 17 00:00:00 2001 From: Felipe Magno de Almeida Date: Thu, 22 Sep 2016 19:27:56 -0300 Subject: [PATCH] eina-cxx: Implement aligned_union for GCC 4.9 --- .../cxx/eina_cxx/eina_aligned_union.hh | 31 +++++++++++++++++++ src/bindings/cxx/eina_cxx/eina_variant.hh | 4 ++- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/bindings/cxx/eina_cxx/eina_aligned_union.hh diff --git a/src/bindings/cxx/eina_cxx/eina_aligned_union.hh b/src/bindings/cxx/eina_cxx/eina_aligned_union.hh new file mode 100644 index 0000000000..eabe878408 --- /dev/null +++ b/src/bindings/cxx/eina_cxx/eina_aligned_union.hh @@ -0,0 +1,31 @@ +#ifndef EFL_EINA_EINA_ALIGNED_UNION_HH_ +#define EFL_EINA_EINA_ALIGNED_UNION_HH_ + +namespace efl { namespace eina { namespace _mpl { + +template +struct max; + +template +struct max : std::integral_constant {}; + +template +struct max : max<(A0 > A1 ? A0 : A1), Args...> {}; + +} + +// Workaround needed for GCC before 5.1 +template +struct aligned_union +{ + static constexpr std::size_t alignment_value = _mpl::max::value; + + typedef typename std::aligned_storage + < _mpl::max::value + , alignment_value >::type type; +}; + +} } + +#endif + diff --git a/src/bindings/cxx/eina_cxx/eina_variant.hh b/src/bindings/cxx/eina_cxx/eina_variant.hh index 6bdd1a9d8e..fb92954c65 100644 --- a/src/bindings/cxx/eina_cxx/eina_variant.hh +++ b/src/bindings/cxx/eina_cxx/eina_variant.hh @@ -7,6 +7,8 @@ #include #include +#include + namespace efl { namespace eina { namespace _impl { @@ -236,7 +238,7 @@ private: new (&buffer) T(std::move(object)); } - typedef typename std::aligned_union<1, Args...>::type buffer_type; + typedef typename eina::aligned_union<1, Args...>::type buffer_type; friend bool operator==(variant const& lhs, variant const& rhs) {