Add utility for converting std::vector types
This commit is contained in:
@@ -575,6 +575,25 @@ namespace chaiscript
|
|||||||
return chaiscript::make_shared<detail::Type_Conversion_Base, detail::Type_Conversion_Impl<decltype(func)>>(user_type<From>(), user_type<To>(), func);
|
return chaiscript::make_shared<detail::Type_Conversion_Base, detail::Type_Conversion_Impl<decltype(func)>>(user_type<From>(), user_type<To>(), func);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename To>
|
||||||
|
Type_Conversion vector_conversion()
|
||||||
|
{
|
||||||
|
auto func = [](const Boxed_Value &t_bv) -> Boxed_Value {
|
||||||
|
const std::vector<Boxed_Value> &from_vec = detail::Cast_Helper<const std::vector<Boxed_Value> &>::cast(t_bv, nullptr);
|
||||||
|
|
||||||
|
|
||||||
|
To vec;
|
||||||
|
|
||||||
|
for (const Boxed_Value &bv : from_vec) {
|
||||||
|
vec.push_back(detail::Cast_Helper<typename To::value_type>::cast(bv, nullptr));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Boxed_Value(std::move(vec));
|
||||||
|
};
|
||||||
|
|
||||||
|
return chaiscript::make_shared<detail::Type_Conversion_Base, detail::Type_Conversion_Impl<decltype(func)>>(user_type<std::vector<Boxed_Value>>(), user_type<To>(), func);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user