andy-thomason / Vookoo

A set of utilities for taking the pain out of Vulkan in header only modern C++
MIT License
524 stars 52 forks source link

Remove `std::aligned_union` #54

Open Cons-Cat opened 1 year ago

Cons-Cat commented 1 year ago

std::aligned_union is an obsolete standard library feature, and its use causes Vookoo to not compile with a nightly libc++18 in C++2c mode.

/home/conscat/foo/Vookoo/include/vku/vku.hpp:1162:10: error: no template named 'aligned_union' in namespace 'std'
 1162 |     std::aligned_union<4, VkBool32, uint32_t, int32_t, float, double>::type
      |     ~~~~~^

Simply changing the compiler flag down to 20 makes this compile again. It was deprecated in 23 and removed in 2c. https://en.cppreference.com/w/cpp/types/aligned_union https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1413r2.pdf

I think these definitions could be used to substitute the std identifiers, also.

namespace foo {
template <std::size_t S, typename... Ts>
struct aligned_union {
    static constexpr std::size_t alignment_value =
        std::max({alignof(Ts)...});

    struct type {
        alignas(alignment_value) char bytes[std::max({S, sizeof(Ts)...})];
    };
};

template <typename T>
using aligned_storage [[gnu::aligned(alignof(T))]] = std::byte[sizeof(T)];
}