Add Array::FromVector() method

fixes #9693
This commit is contained in:
Michael Friedrich 2015-07-21 16:09:19 +02:00
parent 59b81168ff
commit a786dfa2ca
1 changed files with 10 additions and 0 deletions

View File

@ -21,6 +21,7 @@
#define ARRAY_H
#include "base/i2-base.hpp"
#include "base/objectlock.hpp"
#include "base/value.hpp"
#include <boost/range/iterator.hpp>
#include <vector>
@ -100,6 +101,15 @@ public:
static Object::Ptr GetPrototype(void);
template<typename T>
static Array::Ptr FromVector(const std::vector<T>& 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<Value> m_Data; /**< The data for the array. */
};