summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2016-09-22 19:27:56 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2016-09-22 19:27:56 -0300
commit88419e5e87152cf28d64c9e7d35993785e68fbe2 (patch)
tree80602b6f7b5c72822c895e5b79554934f5aec442
parentaf82abb57a77a0f64ef5a691b9da9457257c5577 (diff)
eina-cxx: Implement aligned_union for GCC 4.9
-rw-r--r--src/bindings/cxx/eina_cxx/eina_aligned_union.hh31
-rw-r--r--src/bindings/cxx/eina_cxx/eina_variant.hh4
2 files changed, 34 insertions, 1 deletions
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 @@
1#ifndef EFL_EINA_EINA_ALIGNED_UNION_HH_
2#define EFL_EINA_EINA_ALIGNED_UNION_HH_
3
4namespace efl { namespace eina { namespace _mpl {
5
6template <std::size_t...Numbers>
7struct max;
8
9template <std::size_t A0>
10struct max<A0> : std::integral_constant<std::size_t, A0> {};
11
12template <std::size_t A0, std::size_t A1, std::size_t...Args>
13struct max<A0, A1, Args...> : max<(A0 > A1 ? A0 : A1), Args...> {};
14
15}
16
17// Workaround needed for GCC before 5.1
18template <std::size_t Min, typename...Args>
19struct aligned_union
20{
21 static constexpr std::size_t alignment_value = _mpl::max<alignof(Args)...>::value;
22
23 typedef typename std::aligned_storage
24 < _mpl::max<Min, sizeof(Args)...>::value
25 , alignment_value >::type type;
26};
27
28} }
29
30#endif
31
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 @@
7#include <type_traits> 7#include <type_traits>
8#include <tuple> 8#include <tuple>
9 9
10#include <eina_aligned_union.hh>
11
10namespace efl { namespace eina { 12namespace efl { namespace eina {
11 13
12namespace _impl { 14namespace _impl {
@@ -236,7 +238,7 @@ private:
236 new (&buffer) T(std::move(object)); 238 new (&buffer) T(std::move(object));
237 } 239 }
238 240
239 typedef typename std::aligned_union<1, Args...>::type buffer_type; 241 typedef typename eina::aligned_union<1, Args...>::type buffer_type;
240 242
241 friend bool operator==(variant<Args...> const& lhs, variant<Args...> const& rhs) 243 friend bool operator==(variant<Args...> const& lhs, variant<Args...> const& rhs)
242 { 244 {