vulkan-renderer
vulkan-renderer copied to clipboard
Use or don't use const consistently for function parameters
Const or not const - that is the question?
MeshBuffer(const wrapper::Device &device, const VkQueue data_transfer_queue,
const std::uint32_t data_transfer_queue_family_index, const VmaAllocator vma_allocator,
const std::string &name, const VkDeviceSize size_of_vertex_structure,
const std::size_t number_of_vertices, void *vertices, const VkDeviceSize size_of_index_structure,
const std::size_t number_of_indices, void *indices);
- When to use const in function declarations in header files?
- When to use const in function definitions in cpp files?
- Which types should be const? Should Vulkan handles be const or not?
When creating a PR for this, we could also resolve the following issue:
ImGUIOverlay(const ImGUIOverlay &) = delete;
ImGUIOverlay(ImGUIOverlay &&) noexcept;
ImGUIOverlay &operator=(const ImGUIOverlay &) = delete;
ImGUIOverlay &operator=(ImGUIOverlay &&) noexcept;
or
ImGUIOverlay(const ImGUIOverlay &) = delete;
ImGUIOverlay(ImGUIOverlay &&other) noexcept;
ImGUIOverlay &operator=(const ImGUIOverlay &other) = delete;
ImGUIOverlay &operator=(ImGUIOverlay &&other) noexcept;
Use const for every pointee-type if possible. But for values (including the pointer type), don't use const, at least in the header (declaration), whether you use it in the source file (definition) is up to you.
Should get methods return a const type? Does it even matter?
Not for values or pointer types. E.g. putting const here:
const Foo *bar();
is ok, but putting const here is useless:
Foo *const bar();
const Foo baz();
Also const for references?
[[nodiscard]] const std::string &name() const {
return m_name;
}
I introduced a lot of stuff which is unnecessary, like const VkPhysicalDevice &graphics_card.
Vulkan pointers don't need to be const references.
TODO:
- [ ] Don't use const in header files at all, only in source files.
- [ ] Don't const Vulkan resource pointers like
VkDevice, - [ ] Don't use references for Vulkan resource pointers.
- [ ] Don't use const for get methods unless it's a get method for a const reference.