Skip to content

Commit 5d1e674

Browse files
committed
return std pair instead
1 parent 1f0b948 commit 5d1e674

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

cmake/generate_spvrc_source.cmake

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,18 @@ constexpr uint32_t hash(std::string_view data) noexcept {
2525
}
2626
2727
namespace spvrc {
28-
auto load(std::string_view path) -> std::vector<uint32_t> {
29-
std::vector<uint32_t> data;
28+
auto load(std::string_view path) -> std::pair<const uint32_t*, std::size_t> {
3029
switch (hash(path)) {"
3130
)
3231
# insert shader data
3332
foreach(SPIRV_FILE SPIRV_SYMBOL IN ZIP_LISTS SPVRC_SPIRV_FILES SPVRC_SPIRV_SYMBOLS)
3433
file(APPEND "${SPVRC_SRC}" "
35-
case hash(\"${SPIRV_FILE}\"): data = { ${SPIRV_SYMBOL}, ${SPIRV_SYMBOL} + std::size(${SPIRV_SYMBOL})}; break;"
34+
case hash(\"${SPIRV_FILE}\"): return std::make_pair(${SPIRV_SYMBOL}, std::size(${SPIRV_SYMBOL}));"
3635
)
3736
endforeach(SPIRV_FILE SPIRV_SYMBOL)
3837
# end namespace
3938
file(APPEND "${SPVRC_SRC}" "
40-
default: assert(false && \"Shader not found\");
39+
default: assert(false && \"Shader not found\"); return { nullptr, 0 };
4140
}
42-
return data;
4341
}
4442
}")

include/spvrc/spvrc.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#include <vector>
55

66
namespace spvrc {
7-
auto load(std::string_view path) -> std::vector<uint32_t>;
8-
auto inline load(const char* path) -> std::vector<uint32_t> {
7+
auto load(std::string_view path) -> std::pair<const uint32_t*, std::size_t>;
8+
auto inline load(const char* path) -> std::pair<const uint32_t*, std::size_t> {
99
return load(std::string_view(path));
1010
}
1111
}

src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <string_view>
44

55
int main() {
6-
auto data = spvrc::load("example.comp");
7-
std::cout << "data.size() = " << data.size() << std::endl;
6+
auto [arr, size] = spvrc::load("example.comp");
7+
std::cout << "data size: " << size << std::endl;
88
return 0;
99
}

0 commit comments

Comments
 (0)