eina-cxx: Implement aligned_union for GCC 4.9
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>
Thu, 22 Sep 2016 22:27:56 +0000 (19:27 -0300)
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>
Thu, 22 Sep 2016 22:27:56 +0000 (19:27 -0300)
src/bindings/cxx/eina_cxx/eina_aligned_union.hh [new file with mode: 0644]
src/bindings/cxx/eina_cxx/eina_variant.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 (file)
index 0000000..eabe878
--- /dev/null
@@ -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 <std::size_t...Numbers>
+struct max;
+
+template <std::size_t A0>
+struct max<A0> : std::integral_constant<std::size_t, A0> {};
+
+template <std::size_t A0, std::size_t A1, std::size_t...Args>
+struct max<A0, A1, Args...> : max<(A0 > A1 ? A0 : A1), Args...> {};
+
+}
+
+// Workaround needed for GCC before 5.1
+template <std::size_t Min, typename...Args>
+struct aligned_union
+{
+   static constexpr std::size_t alignment_value = _mpl::max<alignof(Args)...>::value;
+
+   typedef typename std::aligned_storage
+   < _mpl::max<Min, sizeof(Args)...>::value
+     , alignment_value >::type type;
+};
+
+} }
+
+#endif
+
index 6bdd1a9..fb92954 100644 (file)
@@ -7,6 +7,8 @@
 #include <type_traits>
 #include <tuple>
 
+#include <eina_aligned_union.hh>
+
 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<Args...> const& lhs, variant<Args...> const& rhs)
    {