mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-07-03 15:15:53 +00:00
View: Add load() overload for arbitrary containers
We can utilize this to allow for transitions to other container types while retaining support for C-style arrays (e.g. We can seamlessly transition over to std::array).
This commit is contained in:
parent
b2e45e28fa
commit
eefcbb5340
@ -1,7 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <iterator>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include <type_traits>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include <boo/BooObject.hpp>
|
#include <boo/BooObject.hpp>
|
||||||
@ -115,11 +117,15 @@ public:
|
|||||||
std::copy(data, data + count, out);
|
std::copy(data, data + count, out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
template <typename VertArray>
|
template <typename ContiguousContainer>
|
||||||
void load(const VertArray data) {
|
void load(const ContiguousContainer& container) {
|
||||||
static_assert(std::is_same_v<std::remove_all_extents_t<VertArray>, VertStruct>, "mismatched type");
|
// All contiguous containers (even those that aren't containers like C arrays) are usable
|
||||||
constexpr size_t count = sizeof(VertArray) / sizeof(VertStruct);
|
// with std::begin(). Because of that, we can use it to deduce the contained type.
|
||||||
load(data, count);
|
static_assert(std::is_same_v<std::remove_reference_t<decltype(*std::begin(std::declval<ContiguousContainer&>()))>,
|
||||||
|
VertStruct>,
|
||||||
|
"Supplied container doesn't contain same type of vertex struct");
|
||||||
|
|
||||||
|
load(std::data(container), std::size(container));
|
||||||
}
|
}
|
||||||
|
|
||||||
operator const boo::ObjToken<boo::IShaderDataBinding>&() { return m_shaderBinding; }
|
operator const boo::ObjToken<boo::IShaderDataBinding>&() { return m_shaderBinding; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user