From f6e670ecbd3a6990dabc4c1da496e8409a5dda04 Mon Sep 17 00:00:00 2001
From: Tobias Frisch <tfrisch@uni-koblenz.de>
Date: Mon, 26 Apr 2021 15:54:16 +0200
Subject: [PATCH] Changed copy-by-value to copy-by-reference and made getters
 const

Signed-off-by: Tobias Frisch <tfrisch@uni-koblenz.de>
---
 projects/first_triangle/src/main.cpp |  6 +++---
 src/vkcv/Context.cpp                 |  6 +++---
 src/vkcv/Context.hpp                 | 11 ++++++++---
 3 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/projects/first_triangle/src/main.cpp b/projects/first_triangle/src/main.cpp
index 6b99b0e2..542bec6b 100644
--- a/projects/first_triangle/src/main.cpp
+++ b/projects/first_triangle/src/main.cpp
@@ -8,9 +8,9 @@ int main(int argc, const char** argv) {
 			VK_MAKE_VERSION(0, 0, 1)
 	);
 
-	const vk::Instance instance = context.getInstance();
-	const vk::PhysicalDevice physicalDevice = context.getPhysicalDevice();
-	const vk::Device device = context.getDevice();
+	const vk::Instance& instance = context.getInstance();
+	const vk::PhysicalDevice& physicalDevice = context.getPhysicalDevice();
+	const vk::Device& device = context.getDevice();
 
 	std::cout << "Physical device: " << physicalDevice.getProperties().deviceName << std::endl;
 
diff --git a/src/vkcv/Context.cpp b/src/vkcv/Context.cpp
index e77bae20..a1c54c08 100644
--- a/src/vkcv/Context.cpp
+++ b/src/vkcv/Context.cpp
@@ -53,15 +53,15 @@ namespace vkcv {
 		return Context(instance, physicalDevice, device);
 	}
 
-	vk::Instance Context::getInstance() {
+	const vk::Instance& Context::getInstance() const {
 		return m_instance;
 	}
 
-	vk::PhysicalDevice Context::getPhysicalDevice() {
+	const vk::PhysicalDevice& Context::getPhysicalDevice() const {
 		return m_physicalDevice;
 	}
 
-	vk::Device Context::getDevice() {
+	const vk::Device& Context::getDevice() const {
 		return m_device;
 	}
 }
diff --git a/src/vkcv/Context.hpp b/src/vkcv/Context.hpp
index 116d5f5a..c6b365a4 100644
--- a/src/vkcv/Context.hpp
+++ b/src/vkcv/Context.hpp
@@ -16,9 +16,14 @@ namespace vkcv {
 		Context(const Context &other) = delete;
 		Context(Context &&other) = default;
 
-		vk::Instance getInstance();
-		vk::PhysicalDevice getPhysicalDevice();
-		vk::Device getDevice();
+		[[nodiscard]]
+		const vk::Instance& getInstance() const;
+		
+		[[nodiscard]]
+		const vk::PhysicalDevice& getPhysicalDevice() const;
+		
+		[[nodiscard]]
+		const vk::Device& getDevice() const;
 
 		virtual ~Context();
 
-- 
GitLab