From 3c3d4d74f739b0d6535f1add2cebabea3f9279d0 Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Tue, 9 Apr 2019 16:20:33 +0200 Subject: [PATCH] Workaround lack of lvalue/rvalue operator overload on MSVC 2013. --- spirv_cross_containers.hpp | 11 ++++++++++- tests-other/small_vector.cpp | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/spirv_cross_containers.hpp b/spirv_cross_containers.hpp index bcc17aa9..11cb3719 100644 --- a/spirv_cross_containers.hpp +++ b/spirv_cross_containers.hpp @@ -156,16 +156,25 @@ public: } // Makes it easier to consume SmallVector. +#if defined(_MSC_VER) && _MSC_VER < 1900 + explicit operator std::vector() const + { + // Another MSVC 2013 workaround. It does not understand lvalue/rvalue qualified operations. + return std::vector(ptr, ptr + buffer_size); + } +#else + // Makes it easier to consume SmallVector. explicit operator std::vector() const & { return std::vector(ptr, ptr + buffer_size); } // If we are converting as an r-value, we can pilfer our elements. - explicit operator std::vector() const && + explicit operator std::vector() && { return std::vector(std::make_move_iterator(ptr), std::make_move_iterator(ptr + buffer_size)); } +#endif // Avoid sliced copies. Base class should only be read as a reference. VectorView(const VectorView &) = delete; diff --git a/tests-other/small_vector.cpp b/tests-other/small_vector.cpp index 42000809..7b03d85c 100644 --- a/tests-other/small_vector.cpp +++ b/tests-other/small_vector.cpp @@ -197,11 +197,14 @@ static void convert_to_std_vector() SPVC_ASSERT(ints[0].v == 1); SPVC_ASSERT(ints[1].v == 2); + // This doesn't work on MSVC 2013. Ignore it. +#if !(defined(_MSC_VER) && _MSC_VER < 1900) SmallVector> move_only_buffer; move_only_buffer.emplace_back(new RAIIInt(40)); std::vector> move_only_vector(std::move(move_only_buffer)); SPVC_ASSERT(move_only_vector.size() == 1); SPVC_ASSERT(move_only_vector[0]->v == 40); +#endif } int main()