mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-06 19:41:51 +00:00
add dv::value.add(...)
This commit is contained in:
parent
464eb9989c
commit
371d714774
2 changed files with 24 additions and 1 deletions
|
|
@ -214,6 +214,13 @@ namespace dv {
|
|||
return *this;
|
||||
}
|
||||
|
||||
value& add(value v);
|
||||
|
||||
template<class T>
|
||||
value& add(T v) {
|
||||
return add(value(v));
|
||||
}
|
||||
|
||||
value& operator[](const key_t& key);
|
||||
|
||||
const value& operator[](const key_t& key) const;
|
||||
|
|
@ -280,6 +287,11 @@ namespace dv::objects {
|
|||
const_reference operator[](std::size_t index) const {
|
||||
return list.at(index);
|
||||
}
|
||||
|
||||
reference add(value v) {
|
||||
list.push_back(std::move(v));
|
||||
return list[list.size()-1];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -336,4 +348,11 @@ namespace dv {
|
|||
value list(std::initializer_list<value> values) {
|
||||
return std::make_shared<objects::List>(values);
|
||||
}
|
||||
|
||||
value& value::add(value v) {
|
||||
if (type == value_type::list) {
|
||||
return val.list->add(std::move(v));
|
||||
}
|
||||
throw std::runtime_error("value is not a list");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue