From a786dfa2ca13c35e18268e57ea8b12f0aaf3e62e Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Tue, 21 Jul 2015 16:09:19 +0200 Subject: [PATCH] Add Array::FromVector() method fixes #9693 --- lib/base/array.hpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/base/array.hpp b/lib/base/array.hpp index f28d66b4b..b224fba31 100644 --- a/lib/base/array.hpp +++ b/lib/base/array.hpp @@ -21,6 +21,7 @@ #define ARRAY_H #include "base/i2-base.hpp" +#include "base/objectlock.hpp" #include "base/value.hpp" #include #include @@ -100,6 +101,15 @@ public: static Object::Ptr GetPrototype(void); + template + static Array::Ptr FromVector(const std::vector& v) + { + Array::Ptr result = new Array(); + ObjectLock olock(result); + std::copy(v.begin(), v.end(), std::back_inserter(result->m_Data)); + return result; + } + private: std::vector m_Data; /**< The data for the array. */ }; -- 2.40.0