diff options
author | Hans-Kristian Arntzen <post@arntzen-software.no> | 2019-04-09 16:47:19 +0300 |
---|---|---|
committer | Hans-Kristian Arntzen <post@arntzen-software.no> | 2019-04-09 16:47:59 +0300 |
commit | bbac2e8d8da823198e2abc0072a3b4aceb57b8ee (patch) | |
tree | 7e89004aa59eca695ae5fc9a65d55f5800dfa7a6 /tests-other | |
parent | 0262f601c3bbaea730844e1fc14d2faf2ffdf8a9 (diff) |
Support direct conversions to std::vector from SmallVector.
Makes it a bit nicer to consume SmallVector.
Diffstat (limited to 'tests-other')
-rw-r--r-- | tests-other/small_vector.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/tests-other/small_vector.cpp b/tests-other/small_vector.cpp index 0674a297..42000809 100644 --- a/tests-other/small_vector.cpp +++ b/tests-other/small_vector.cpp @@ -15,6 +15,7 @@ */ #include "spirv_cross.hpp" +#include <memory> using namespace spirv_cross; @@ -185,6 +186,24 @@ static void erase_start() SPVC_ASSERT(ints[1].v == 4); } +static void convert_to_std_vector() +{ + SmallVector<RAIIInt, 4> foo; + foo.push_back(1); + foo.push_back(2); + std::vector<RAIIInt> ints(foo); + SPVC_ASSERT(ints.size() == 2); + SPVC_ASSERT(foo.size() == 2); + SPVC_ASSERT(ints[0].v == 1); + SPVC_ASSERT(ints[1].v == 2); + + SmallVector<std::unique_ptr<RAIIInt>> move_only_buffer; + move_only_buffer.emplace_back(new RAIIInt(40)); + std::vector<std::unique_ptr<RAIIInt>> move_only_vector(std::move(move_only_buffer)); + SPVC_ASSERT(move_only_vector.size() == 1); + SPVC_ASSERT(move_only_vector[0]->v == 40); +} + int main() { propagate_stack_to_heap(); @@ -197,5 +216,8 @@ int main() erase_middle(); erase_start(); + convert_to_std_vector(); + SPVC_ASSERT(allocations > 0 && deallocations > 0 && deallocations == allocations); -}
\ No newline at end of file +} + |