Template specialization using typedefs

While studying Vulcan, I came across some code in the VulkanCookbook. in VulkanCookbook, the author writes code to import Vulkan functions and classes manually. Well, I slowly converted it to the LunarG SDK for Vulkan, and I ran into a problem in the less than 64-bit VkFence, which was typedef'd for VkFence_T *, which is good and everything except 32-bit is typedef'd like uint64_t , which causes a problem for VkDestroyer, which uses code similar to below

#include <iostream>
#include <stdint.h>

typedef uint64_t A;
typedef uint64_t B;

template<typename T>
class Handler
{
    void DestroyObject( T parent );
};

template<>
inline void Handler<A>::DestroyObject(A object) {
  std::cout << "destroy type A" << std::endl;
}

template<>
inline void Handler<B>::DestroyObject(B object) {
  std::cout << "destroy type B!" << std::endl;
}

int main()
{}

Is there a good way to deal with this problem, or do I need to go and recycle all the sample code to delete the objects manually? I would like to compile up to 32 bits if possible.

, , , google . , _A _B, uint64_t, , -, , DestroyObject , .

: , .

+4
3

++ typedef. - , , .

A B , , uint64_t. , .

- .

#include <type_traits>

template<typename E>
using argument_t = std::conditional_t<std::is_enum<E>::value,
                                      std::underlying_type_t<E>,
                                      E>; 

template<typename T>
class Handler
{
    void DestroyObject( argument_t<T> parent );
};

enum A : uint64_t {};
enum B : uint64_t {}; 

template<>
inline void Handler<A>::DestroyObject(uint64_t object) {
  std::cout << "destroy type A" << std::endl;
}

template<>
inline void Handler<B>::DestroyObject(uint64_t object) {
  std::cout << "destroy type B!" << std::endl;
}

:

  • argument_t , E , . E.

  • T .

  • A B , . .

+4

... , Handler<_A>::DestroyObject(_A object) Handler<_B>::DestroyObject(_B object) -. , uint32_t. template<> void Handler<uint32_t>::DestroyObject(uint32_t o). .

0

There is no way for the template to distinguish between pasded Aand Bas a type parameter.

There may be alternatives to manually cleaning objects, but your question is too vague and focused on finding a way to get a non-viable solution to determine what your problem is.

You probably need to blur between types using something other than the types themselves.

0
source

Source: https://habr.com/ru/post/1688356/


All Articles