Permalink
Browse files

Assignment to an empty vector should resize it

  • Loading branch information...
dlevin256 committed Dec 4, 2018
1 parent 0ad7506 commit a229a6dcabfb83dde41b5c0cb764a1f4d777084d
Showing with 18 additions and 1 deletion.
  1. +8 −1 include/kfr/base/univector.hpp
  2. +10 −0 tests/expression_test.cpp
@@ -332,7 +332,14 @@ struct univector<T, tag_dynamic_vector> : std::vector<T, allocator<T>>,
{
return index < this->size() ? this->operator[](index) : fallback_value;
}
using univector_base<T, univector>::operator=;
template <typename Input, KFR_ENABLE_IF(is_input_expression<Input>::value)>
CMT_INLINE univector& operator=(Input&& input)
{
if (this->empty())
this->resize(input.size());
this->assign_expr(std::forward<Input>(input));
return *this;
}
};
template <typename T>
@@ -85,6 +85,16 @@ TEST(placeholders_pointer)
CHECK_EXPRESSION(expr, infinite_size, [](size_t i) { return 10.f * i; });
}
TEST(univector_assignment)
{
univector<int> x = truncate(counter(), 10);
CHECK(x.size() == 10);
univector<int> y;
y = truncate(counter(), 10);
CHECK(y.size() == 10);
}
TEST(size_calc)
{
auto a = counter();

0 comments on commit a229a6d

Please sign in to comment.