diff --git a/autotest/autotest.bat b/autotest/autotest.bat index 09bf143..2097a32 100644 --- a/autotest/autotest.bat +++ b/autotest/autotest.bat @@ -15,6 +15,9 @@ rem @echo off @call :testh opp_vector.cpp @if %errorlevel% neq 0 goto :error +@call :testh opp_static_vector.cpp +@if %errorlevel% neq 0 goto :error + @call :testh opp_vector_string.cpp @if %errorlevel% neq 0 goto :error diff --git a/autotest/opp_static_vector.cpp b/autotest/opp_static_vector.cpp new file mode 100644 index 0000000..4038eb6 --- /dev/null +++ b/autotest/opp_static_vector.cpp @@ -0,0 +1,78 @@ +#include +#include +#include +#include + +int main(void) +{ + opp::static_vector a; + + for(int i=0; i<10; i++) + a.push_back(i); + + int s = 0; + for(int i=0; i v; + + for(int i=0; i<10; i++) + v.push_back(i); + + assert(v.size() == 10); + v.insert(0, 20); + assert(v.size() == 11); + v.insert(6, 21); + assert(v.size() == 12); + v.insert(12, 22); + + int * fi = opp::find(v.begin(), v.end(), 21); + + fi = v.insert(fi, 30); + fi = v.insert(fi, 31); + fi = v.insert(fi, 32); + + assert(v.size() == 16); + assert(v[0] == 20); + assert(v[15] == 22); + assert(v[8] == 32); + + fi = opp::find(v.begin(), v.end(), 32); + + for(int i=0; i<30; i++) + { + fi = v.insert(fi, i + 40); + } + + assert(v.size() == 46); + assert(v[28] == 60); + + v.erase(10, 10); + + for(int i : v) + opp::cout << i << ", "; + opp::cout << "\n"; + + assert(v.size() == 36); + assert(v[18] == 60); + + v.assign(42, 11); + + assert(v.size() == 42); + assert(v[0] == 11); + assert(v[15] == 11); + assert(v[41] == 11); + + return 0; +} diff --git a/autotest/opp_vector.cpp b/autotest/opp_vector.cpp index f2d56a1..cfe14e7 100644 --- a/autotest/opp_vector.cpp +++ b/autotest/opp_vector.cpp @@ -64,5 +64,15 @@ int main(void) opp::cout << i << ", "; opp::cout << "\n"; + assert(v.size() == 36); + assert(v[18] == 60); + + v.assign(42, 11); + + assert(v.size() == 42); + assert(v[0] == 11); + assert(v[15] == 11); + assert(v[41] == 11); + return 0; } diff --git a/include/opp/static_vector.h b/include/opp/static_vector.h index 237160c..be9693b 100644 --- a/include/opp/static_vector.h +++ b/include/opp/static_vector.h @@ -173,6 +173,8 @@ public: ((T*)_space)[_size].~T(); } + void assign(size_t count, const T & t); + void insert(size_t at, const T & t); void erase(size_t at, size_t n = 1); @@ -229,6 +231,17 @@ void static_vector::emplace_back(const P&... p) new ((T*)_space + _size++)T(p...); } +template +void static_vector::assign(size_t count, const T & t) +{ + T * data = (T*)_space; + for(size_t i=0; i<_size; i++) + data[i].~T(); + for(size_t i=0; i void static_vector::insert(size_t at, const T & t) { diff --git a/include/opp/vector.h b/include/opp/vector.h index 7503abc..b8dc1bb 100644 --- a/include/opp/vector.h +++ b/include/opp/vector.h @@ -192,6 +192,8 @@ public: _data[_size].~T(); } + void assign(size_t count, const T & t); + void insert(size_t at, const T & t); void erase(size_t at, size_t n = 1); @@ -296,6 +298,21 @@ void vector::emplace_back(const P&... p) new (add_back())T(p...); } +template +void vector::assign(size_t count, const T & t) +{ + for(size_t i=0; i<_size; i++) + _data[i].~T(); + if (count > _capacity) + { + _size = 0; + reserve(count); + } + for(size_t i=0; i void vector::insert(size_t at, const T & t) { diff --git a/oscar64/Parser.cpp b/oscar64/Parser.cpp index cc0b57d..3b2dbfe 100644 --- a/oscar64/Parser.cpp +++ b/oscar64/Parser.cpp @@ -11271,7 +11271,10 @@ Declaration* Parser::ParseTemplateExpansion(Declaration* tmpld, Declaration* exp if (mindist == 0) return etdec->mBase; else if (mindist == NOOVERLOAD) - mErrors->Error(tdec->mLocation, EERR_TEMPLATE_PARAMS, "No matching template parameters"); + { + mErrors->Error(FullLocation(tmpld->mLocation), EERR_TEMPLATE_PARAMS, "No matching template parameters", tmpld->mQualIdent); + return tdec; + } else tmpld = etdec;