diff options
-rw-r--r-- | CHANGELOG.txt | 4 | ||||
-rw-r--r-- | test.cc | 204 | ||||
-rw-r--r-- | zp/include/zp/det/mem.ii | 47 | ||||
-rw-r--r-- | zp/include/zp/det/zp.ii | 42 | ||||
-rw-r--r-- | zp/include/zp/mem | 37 | ||||
-rw-r--r-- | zp/include/zp/zp | 44 |
6 files changed, 288 insertions, 90 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt index e49b752..cbc7aec 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -3,6 +3,10 @@ * Bump extension version; * Add type for storing either errors or return values: res; +* Add type for dynamic arrays: arr; +* Make cpy, equ, fil, and srh run-time and throwable; +* Bring back opt; + # 1.0.0 * Update API-BREAK file; @@ -4,6 +4,7 @@ #include <exception> #include <iostream> #include <limits> +#include <memory> #include <typeinfo> #include <zp/mem> #include <zp/mth> @@ -158,11 +159,11 @@ static_assert(::zp::maxval<int long unsigned>::val == ::std::numeric_limits static_assert(::zp::maxval<int long long unsigned>::val == ::std::numeric_limits<int long long unsigned>::max()); static_assert(::zp::maxval<wchar_t>::val == ::std::numeric_limits<wchar_t>::max()); -template<typename ltyp,typename rtyp> static auto cmp(int unsigned & numerr,int long const ln,ltyp const & lvalref,rtyp const & rvalref) noexcept { +template<typename ltyp,typename rtyp> static auto cmp(int unsigned & numerr,int long const ln,::zp::i8 const mth,ltyp const& lvalref,rtyp const& rvalref) noexcept { char const* const ltypnm = typeid (ltyp).name(); char const* const rtypnm = typeid (rtyp).name(); - auto const getval = [](auto const & valref) { + auto const getval = [](auto const& valref) { using typ = typename ::zp::remqual<typename ::zp::remref<decltype (valref)>::typ>::typ; if constexpr (::zp::ischrtyp<typ>::val) {return static_cast<::zp::i02>(valref);} @@ -173,20 +174,63 @@ template<typename ltyp,typename rtyp> static auto cmp(int unsigned & numerr,int auto const lval = getval(lvalref); auto const rval = getval(rvalref); - ::std::cout << " " << ln << ". comparing " << ltypnm << " (" << lval << ") vs. " << rtypnm << " (" << rval << ")... "; + auto const cmp = [&mth](auto const& lval,auto const& rval) -> bool { + switch (mth) { + default: + ::zp::unrch(); + case 0x0u: + return lval == rval; + case 0x1u: + return lval >= rval; + case 0x2u: + return lval > rval; + case 0x3u: + return lval <= rval; + case 0x4u: + return lval < rval; + case 0x5u: + return lval != rval; + } + }; - if (lval != rval) { - ::std::cout << "\x1B[38;5;161munequal\x1B[0m\n"; + auto const mthstr = [&mth]() -> char const * { + switch (mth) { + default: + ::zp::unrch(); + case 0x0u: + return "=="; + case 0x1u: + return ">="; + case 0x2u: + return ">"; + case 0x3u: + return "<="; + case 0x4u: + return "<"; + case 0x5u: + return "!="; + } + }(); + + ::std::cout << " " << ln << ". " << ltypnm << " (" << lval << ") " << mthstr << " " << rtypnm << " (" << rval << ")... "; + + if (!cmp(lval,rval)) { + ::std::cout << "\x1B[38;5;161merror\x1B[0m\n"; //throw ::std::exception {}; ++numerr; return; } - ::std::cout <<"\x1B[38;5;77mequal\x1B[0m\n"; + ::std::cout <<"\x1B[38;5;77mokay\x1B[0m\n"; } -#define cmp(lval,rval) (::cmp(numerr,__LINE__,(lval),(rval))) +#define chkeq(lval,rval) (::cmp(numerr,__LINE__,0x0u,(lval),(rval))) +#define chkge(lval,rval) (::cmp(numerr,__LINE__,0x1u,(lval),(rval))) +#define chkgt(lval,rval) (::cmp(numerr,__LINE__,0x2u,(lval),(rval))) +#define chkle(lval,rval) (::cmp(numerr,__LINE__,0x3u,(lval),(rval))) +#define chklt(lval,rval) (::cmp(numerr,__LINE__,0x4u,(lval),(rval))) +#define chkne(lval,rval) (::cmp(numerr,__LINE__,0x5u,(lval),(rval))) int main() { int unsigned numerr = 0x0u; @@ -199,12 +243,31 @@ int main() { try { [&] { + tst("optionals"); + + ::zp::opt<::zp::i8s> opt = ::zp::nulopt; + + chkeq(opt.chk(),false); + + auto const fun = [](char const* msg) -> void { + ::std::cout << msg << ::std::endl; + + ::std::abort(); + }; + + opt = -0x45; + + chkeq(opt.chk(),true); + chkeq(opt.exp(fun,"expectation failed"),-0x45); + }(); + + [&] { tst("results"); ::zp::res<::zp::i8s,::zp::i8s> res = ::zp::err<::zp::i8s>(0x45); - cmp(res.chk(),false); - cmp(res.err(),0x45); + chkeq(res.chk(),false); + chkeq(res.err(),0x45); res = -0x45; @@ -214,8 +277,8 @@ int main() { ::std::abort(); }; - cmp(res.chk(),true); - cmp(res.exp(fun,"expectation failed"),-0x45); + chkeq(res.chk(),true); + chkeq(res.exp(fun,"expectation failed"),-0x45); }(); [&] { @@ -224,20 +287,20 @@ int main() { ::zp::f02 f02; ::zp::f04 f04; - cmp(sizeof (f02),0x4u); - cmp(sizeof (f04),0x8u); + chkeq(sizeof (f02),0x4u); + chkeq(sizeof (f04),0x8u); f02 = ::zp::nan<::zp::f02>::val; f04 = ::zp::nan<::zp::f04>::val; - cmp(::zp::isnan(f02),true); - cmp(::zp::isnan(f04),true); + chkeq(::zp::isnan(f02),true); + chkeq(::zp::isnan(f04),true); f02 = ::zp::inf<::zp::f02>::val; f04 = ::zp::inf<::zp::f04>::val; - cmp(f02 > ::zp::maxval<::zp::f02>::val,true); - cmp(f04 > ::zp::maxval<::zp::f04>::val,true); + chkeq(f02 > ::zp::maxval<::zp::f02>::val,true); + chkeq(f04 > ::zp::maxval<::zp::f04>::val,true); }(); [&] { @@ -255,7 +318,7 @@ int main() { .x = +0x2, .y = -0x4, }; - cmp(::zp::dot(lvec2,rvec2),0xE); + chkeq(::zp::dot(lvec2,rvec2),0xE); ::zp::vec3<int> const lvec3 = { .x = +0x1, @@ -267,7 +330,7 @@ int main() { .y = -0x4, .z = +0x6, }; - cmp(::zp::dot(lvec3,rvec3),0x2C); + chkeq(::zp::dot(lvec3,rvec3),0x2C); ::zp::vec4<int> const lvec4 = { .x = +0x1, @@ -281,14 +344,14 @@ int main() { .z = +0x6, .w = -0x8, }; - cmp(::zp::dot(lvec4,rvec4),0x64); + chkeq(::zp::dot(lvec4,rvec4),0x64); auto const avec2 = ::zp::vadd(lvec2,rvec2); auto const svec2 = ::zp::vsub(lvec2,rvec2); - cmp(avec2.x,+0x3); - cmp(avec2.y,-0x7); - cmp(svec2.x,-0x1); - cmp(svec2.y,+0x1); + chkeq(avec2.x,+0x3); + chkeq(avec2.y,-0x7); + chkeq(svec2.x,-0x1); + chkeq(svec2.y,+0x1); }();*/ [&] { @@ -296,19 +359,19 @@ int main() { ::zp::i04 filbuf; - cmp(::zp::memfil(&filbuf,0xFFu,0x8u),reinterpret_cast<char unsigned *>(&filbuf)+0x8u); - cmp(::zp::memfil(&filbuf,0x7Fu,0x4u),reinterpret_cast<char unsigned *>(&filbuf)+0x4u); - cmp(::zp::memfil(&filbuf,0x3Fu,0x2u),reinterpret_cast<char unsigned *>(&filbuf)+0x2u); - cmp(::zp::memfil(&filbuf,0x1Fu,0x1u),reinterpret_cast<char unsigned *>(&filbuf)+0x1u); + chkeq(::zp::memfil(&filbuf,0xFFu,0x8u),reinterpret_cast<char unsigned *>(&filbuf)+0x8u); + chkeq(::zp::memfil(&filbuf,0x7Fu,0x4u),reinterpret_cast<char unsigned *>(&filbuf)+0x4u); + chkeq(::zp::memfil(&filbuf,0x3Fu,0x2u),reinterpret_cast<char unsigned *>(&filbuf)+0x2u); + chkeq(::zp::memfil(&filbuf,0x1Fu,0x1u),reinterpret_cast<char unsigned *>(&filbuf)+0x1u); - cmp(filbuf,0xFFFFFFFF7F7F3F1Fu); + chkeq(filbuf,0xFFFFFFFF7F7F3F1Fu); ::zp::i04 cpybuf; ::zp::memcpy(&cpybuf,&filbuf,0x8u); - cmp(cpybuf,filbuf); + chkeq(cpybuf,filbuf); - cmp(::zp::memsrh(&cpybuf,0x1Fu,0x8u),reinterpret_cast<char unsigned *>(&cpybuf)); + chkeq(::zp::memsrh(&cpybuf,0x1Fu,0x8u),reinterpret_cast<char unsigned *>(&cpybuf)); }(); [&] { @@ -322,17 +385,17 @@ int main() { ::zp::siz const wlen = ::zp_wstrlen( wstr); ::zp::siz const len02 = ::zp_utf32len(str02); - cmp(len, 0xCu); - cmp(wlen, 0xCu); - cmp(len02,0xCu); + chkeq(len, 0xCu); + chkeq(wlen, 0xCu); + chkeq(len02,0xCu); auto const buf = new char[ len]; auto const wbuf = new wchar_t[ wlen]; auto const buf02 = new char32_t[len02]; - cmp(::zp_strcpy( buf, str), len); - cmp(::zp_wstrcpy( wbuf, wstr), wlen); - cmp(::zp_utf32cpy(buf02,str02),len02); + chkeq(::zp_strcpy( buf, str), len); + chkeq(::zp_wstrcpy( wbuf, wstr), wlen); + chkeq(::zp_utf32cpy(buf02,str02),len02); delete[] buf; delete[] wbuf; @@ -345,27 +408,27 @@ int main() { char32_t const src[] = U"\U0001F480"; ::zp::siz const buf8len = ::zp_utf8enclen(src); - cmp(buf8len,0x4u); + chkeq(buf8len,0x4u); ::zp::c8 * buf8 = new ::zp::c8[buf8len+0x1]; ::zp_utf8enc(buf8,src); - cmp(buf8[0x0],0xF0u); - cmp(buf8[0x1],0x9Fu); - cmp(buf8[0x2],0x92u); - cmp(buf8[0x3],0x80u); - cmp(buf8[0x4],0x00u); + chkeq(buf8[0x0],0xF0u); + chkeq(buf8[0x1],0x9Fu); + chkeq(buf8[0x2],0x92u); + chkeq(buf8[0x3],0x80u); + chkeq(buf8[0x4],0x00u); ::zp::siz const buf02len = ::zp_utf8declen(buf8); - cmp(buf02len,0x1u); + chkeq(buf02len,0x1u); char32_t * buf02 = new char32_t[buf02len+0x1]; ::zp_utf8dec(buf02,buf8); - cmp(buf02[0x0],0x1F480u); - cmp(buf02[0x1],0x0u); + chkeq(buf02[0x0],0x1F480u); + chkeq(buf02[0x1],0x0u); delete[] buf8; delete[] buf02; @@ -377,33 +440,62 @@ int main() { char32_t const src[] = U"\U0001F480\u00F0"; ::zp::siz const buf01len = ::zp_utf16enclen(src); - cmp(buf01len,0x3u); + chkeq(buf01len,0x3u); char16_t * buf01 = new char16_t[buf01len+0x1]; ::zp_utf16enc(buf01,src); - cmp(buf01[0x0],0xD83Du); - cmp(buf01[0x1],0xDC80u); - cmp(buf01[0x2],0x00F0u); - cmp(buf01[0x3],0x0000u); + chkeq(buf01[0x0],0xD83Du); + chkeq(buf01[0x1],0xDC80u); + chkeq(buf01[0x2],0x00F0u); + chkeq(buf01[0x3],0x0000u); ::zp::siz const buf02len = ::zp_utf16declen(buf01); - cmp(buf02len,0x2u); + chkeq(buf02len,0x2u); char32_t * buf02 = new char32_t[buf02len+0x1]; ::zp_utf16dec(buf02,buf01); - cmp(buf02[0x0],0x1F480u); - cmp(buf02[0x1],0xF0u); - cmp(buf02[0x2],0x0u); + chkeq(buf02[0x0],0x1F480u); + chkeq(buf02[0x1],0xF0u); + chkeq(buf02[0x2],0x0u); delete[] buf01; delete[] buf02; }(); + + [&] { + tst("arrays"); + + ::zp::arr<::zp::i8,::std::allocator<::zp::i8>> arr(0x8u); + + chkeq(arr.len(),0x8u); + + arr[0x0] = 0x7Fu; + arr[0x1] = 0x3Fu; + arr[0x2] = 0x1Fu; + arr[0x3] = 0x0Fu; + arr[0x4] = 0x07u; + arr[0x5] = 0x03u; + arr[0x6] = 0x01u; + arr[0x7] = 0x00u; + + ::zp::i8 prv = 0xFFu; + for (::zp::i8 const val : arr) { + chkeq(val,static_cast<::zp::i8>(prv>>0x1u)); + prv = val; + } + + arr.fil(0xFFu); + + for (::zp::i8 const val : arr) { + chkeq(val,0xFFu); + } + }(); } - catch (::std::exception const &) { + catch (::std::exception const&) { return EXIT_FAILURE; } diff --git a/zp/include/zp/det/mem.ii b/zp/include/zp/det/mem.ii index 11c6aab..ce1a522 100644 --- a/zp/include/zp/det/mem.ii +++ b/zp/include/zp/det/mem.ii @@ -4,6 +4,35 @@ If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>. */ +template<typename typ,typename alctyp> zp::arr<typ,alctyp>::arr() : _alc(alctyp()) {} + +template<typename typ,typename alctyp> zp::arr<typ,alctyp>::arr(::zp::siz const len) : _alc(alctyp()),_buf(this->_alc.allocate(len)),_len(len) {} + +template<typename typ,typename alctyp> zp_nothw zp::arr<typ,alctyp>::~arr() { + zp_unlik (this->_buf == zp_nulptr) {return;} + this->_alc.deallocate(this->_buf,this->_len); +} + +template<typename typ,typename alctyp> zp_nothw ::zp::siz zp::arr<typ,alctyp>::len() const {return this->_len;} + +template<typename typ,typename alctyp> bool zp::arr<typ,alctyp>::alc(::zp::siz const len) { + this->_len = len; + this->_buf = this->_alc(len); + + zp_unlik (this->_buf == zp_nulptr) {return true;} // If the allocator does NOT throw exceptions. + return false; +} + +template<typename typ,typename alctyp> template<typename valtyp> ::zp::siz zp::arr<typ,alctyp>::fil(valtyp const& val) {return static_cast<::zp::siz>(::zp::fil(this->_buf,val,this->_len)-this->_buf);} + +template<typename typ,typename alctyp> typ * zp::arr<typ,alctyp>::begin() {return this->_buf;} +template<typename typ,typename alctyp> typ const* zp::arr<typ,alctyp>::begin() const {return this->_buf;} +template<typename typ,typename alctyp> typ * zp::arr<typ,alctyp>::end() {return this->_buf+this->_len;} +template<typename typ,typename alctyp> typ const* zp::arr<typ,alctyp>::end() const {return this->_buf+this->_len;} + +template<typename typ,typename alctyp> typ & zp::arr<typ,alctyp>::operator [](::zp::ptrdif const off) {return this->_buf[off];} +template<typename typ,typename alctyp> typ const& zp::arr<typ,alctyp>::operator [](::zp::ptrdif const off) const {return this->_buf[off];} + template<typename dsttyp,typename srctyp> zp_nothw inline ::zp::cpyres<dsttyp,srctyp> zp::memcpy(dsttyp * dst,srctyp const* src,::zp::siz const num) { ::zp_cpyres const cpyres = ::zp_memcpy(dst,src,num); @@ -15,15 +44,18 @@ template<typename dsttyp,typename srctyp> zp_nothw inline ::zp::cpyres<dsttyp,sr return res; } -#if zp_std_cxx11 -template<typename ltyp,typename rtyp> constexpr auto zp::cpy(ltyp * dst,rtyp * src,::zp::siz const num) noexcept -> ::zp::cpyres<ltyp,rtyp> { +template<typename ltyp,typename rtyp> ::zp::cpyres<ltyp,rtyp> zp::cpy(ltyp * dst,rtyp * src,::zp::siz const num) { ltyp * const stp = dst+num; while (dst != stp) {*dst++ = *src++;} - return ::zp::cpyres<ltyp,rtyp> {dst,src,}; + ::zp::cpyres<ltyp,rtyp> res; + res.dst = dst; + res.src = src; + + return res; } -template<typename ltyp,typename rtyp> constexpr auto zp::equ(ltyp * lbuf,rtyp * rbuf,::zp::siz const num) noexcept -> bool { +template<typename ltyp,typename rtyp> bool zp::equ(ltyp * lbuf,rtyp * rbuf,::zp::siz const num) { ltyp const* const stp = lbuf+num; while (lbuf != stp) { @@ -33,14 +65,14 @@ template<typename ltyp,typename rtyp> constexpr auto zp::equ(ltyp * lbuf,rtyp * return true; } -template<typename buftyp,typename valtyp> constexpr auto zp::fil(buftyp * buf,valtyp & val,::zp::siz const num) noexcept -> buftyp * { +template<typename buftyp,typename valtyp> buftyp * zp::fil(buftyp * buf,valtyp & val,::zp::siz const num) { buftyp * const stp = buf+num; while (buf != stp) {*buf++ = val;} return stp; } -template<typename buftyp,typename valtyp> constexpr auto zp::srh(buftyp * buf,valtyp & val,::zp::siz const num) noexcept -> buftyp * { +template<typename buftyp,typename valtyp> buftyp * zp::srh(buftyp * buf,valtyp & val,::zp::siz const num) { buftyp * const stp = buf+num; while (buf != stp) { @@ -48,6 +80,5 @@ template<typename buftyp,typename valtyp> constexpr auto zp::srh(buftyp * buf,va zp_unlik (*addr == val) {return addr;} } - return nullptr; + return zp_nulptr; } -#endif diff --git a/zp/include/zp/det/zp.ii b/zp/include/zp/det/zp.ii index f93e2c1..c4a23bf 100644 --- a/zp/include/zp/det/zp.ii +++ b/zp/include/zp/det/zp.ii @@ -17,27 +17,49 @@ constexpr auto ::zp::iscstevl() noexcept -> bool { } #endif +template<typename typ> zp_nothw zp::opt<typ>::opt(::zp::det::nulopt) : _hasval(false) {} +template<typename typ> zp::opt<typ>::opt(typ const& val) : _hasval(true),_val(val) {} + +template<typename typ> zp_nothw bool zp::opt<typ>::chk() const {return this->_hasval;} + +template<typename typ> zp_nothw typ const& zp::opt<typ>::val() const {return this->_val;} + +template<typename typ> template<typename funtyp,typename msgtyp> zp_nothw typ const& zp::opt<typ>::exp(funtyp const& fun,msgtyp const& msg) const { + zp_unlik (!this->_hasval) { + fun(msg); + ::zp::unrch(); + } + return this->_val; +} + +template<typename typ> ::zp::opt<typ> zp::opt<typ>::operator =(typ const& val) { + this->_hasval = true; + this->_val = val; + + return *this; +} + template<typename typ> zp_nothw typ zp::errtyp<typ>::val() const {return this->errval;} -template<typename typ> template<typename valtyp> zp_nothw ::zp::errtyp<typ> zp::errtyp<typ>::operator =(valtyp const & val) { - this->errval = static_cast<typ>(val); +template<typename typ> template<typename valtyp> zp_nothw ::zp::errtyp<typ> zp::errtyp<typ>::operator =(valtyp const& val) { + this->errval = val; return *this; } -template<typename typ,typename valtyp> zp_nothw ::zp::errtyp<typ> zp::err(valtyp const & val) { +template<typename typ,typename valtyp> zp_nothw ::zp::errtyp<typ> zp::err(valtyp const& val) { ::zp::errtyp<typ> err; return err = val; } -template<typename okytyp,typename errtyp> zp_nothw zp::res<okytyp,errtyp>::res(okytyp const & oky) : hasoky(true), okyval(oky) {} -template<typename okytyp,typename errtyp> zp_nothw zp::res<okytyp,errtyp>::res(::zp::errtyp<errtyp> const & err) : hasoky(false),errval(err.val()) {} +template<typename okytyp,typename errtyp> zp_nothw zp::res<okytyp,errtyp>::res(okytyp const& oky) : hasoky(true), okyval(oky) {} +template<typename okytyp,typename errtyp> zp_nothw zp::res<okytyp,errtyp>::res(::zp::errtyp<errtyp> const& err) : hasoky(false),errval(err.val()) {} template<typename okytyp,typename errtyp> zp_nothw bool zp::res<okytyp,errtyp>::chk() const {return this->hasoky;} -template<typename okytyp,typename errtyp> zp_nothw okytyp const & zp::res<okytyp,errtyp>::oky() const {return this->okyval;} -template<typename okytyp,typename errtyp> zp_nothw errtyp const & zp::res<okytyp,errtyp>::err() const {return this->errval;} +template<typename okytyp,typename errtyp> zp_nothw okytyp const& zp::res<okytyp,errtyp>::oky() const {return this->okyval;} +template<typename okytyp,typename errtyp> zp_nothw errtyp const& zp::res<okytyp,errtyp>::err() const {return this->errval;} -template<typename okytyp,typename errtyp> template<typename funtyp,typename msgtyp> zp_nothw okytyp const & zp::res<okytyp,errtyp>::exp(funtyp const & fun,msgtyp const & msg) const { +template<typename okytyp,typename errtyp> template<typename funtyp,typename msgtyp> zp_nothw okytyp const& zp::res<okytyp,errtyp>::exp(funtyp const& fun,msgtyp const& msg) const { zp_unlik (!this->hasoky) { fun(msg); ::zp::unrch(); @@ -46,14 +68,14 @@ template<typename okytyp,typename errtyp> template<typename funtyp,typename msgt return this->okyval; } -template<typename okytyp,typename errtyp> zp_nothw ::zp::res<okytyp,errtyp> zp::res<okytyp,errtyp>::operator =(okytyp const & oky) { +template<typename okytyp,typename errtyp> zp_nothw ::zp::res<okytyp,errtyp> zp::res<okytyp,errtyp>::operator =(okytyp const& oky) { this->hasoky = true; this->okyval = oky; return *this; } -template<typename okytyp,typename errtyp> zp_nothw ::zp::res<okytyp,errtyp> zp::res<okytyp,errtyp>::operator =(::zp::errtyp<errtyp> const & err) { +template<typename okytyp,typename errtyp> zp_nothw ::zp::res<okytyp,errtyp> zp::res<okytyp,errtyp>::operator =(::zp::errtyp<errtyp> const& err) { this->hasoky = false; this->errval = err.val(); diff --git a/zp/include/zp/mem b/zp/include/zp/mem index de841f7..da45e84 100644 --- a/zp/include/zp/mem +++ b/zp/include/zp/mem @@ -16,18 +16,43 @@ namespace zp { srctyp * src; }; + template<typename typ,typename alctyp> class arr { + public: + arr(); + explicit arr(::zp::siz len); + + zp_nothw ~arr(); + + zp_nothw ::zp::siz len() const; + + bool alc(::zp::siz len); + + template<typename valtyp> ::zp::siz fil(valtyp const& val); + + zp_nothw typ * begin(); + zp_nothw typ const* begin() const; + zp_nothw typ * end(); + zp_nothw typ const* end() const; + + zp_nothw typ & operator [](::zp::ptrdif off); + zp_nothw typ const& operator [](::zp::ptrdif off) const; + + private: + alctyp _alc; + typ * _buf; + ::zp::siz _len; + }; + template<typename dsttyp,typename srctyp> zp_iln zp_nothw inline ::zp::cpyres<dsttyp,srctyp> memcpy(dsttyp * zp_prv_rsr dst, srctyp const* zp_prv_rsr src, ::zp::siz const num); // Implement in seperate file. template<typename ltyp, typename rtyp> zp_useres zp_iln zp_nothw inline bool memequ(ltyp const* zp_prv_rsr lbuf,rtyp const* zp_prv_rsr rbuf,::zp::siz const num) {return ::zp_memequ(lbuf,rbuf,num);} template<typename typ> zp_iln zp_nothw inline typ * memfil(typ * zp_prv_rsr dst, char unsigned val, ::zp::siz const num) {return static_cast<typ *>(::zp_memfil(dst,val,num));} template<typename typ> zp_useres zp_nothw zp_iln inline typ * memsrh(typ * zp_prv_rsr buf, char unsigned val, ::zp::siz const num) {return static_cast<typ *>(::zp_memsrh(buf,val,num));} template<typename typ> zp_useres zp_nothw zp_iln inline typ const* memsrh(typ const* zp_prv_rsr buf, char unsigned val, ::zp::siz const num) {return const_cast<typ const*>(static_cast<typ *>(::zp_memsrh(buf,val,num)));} -#if zp_std_cxx11 - template<typename ltyp, typename rtyp> constexpr auto cpy(ltyp * dst, rtyp * src, ::zp::siz num) noexcept -> ::zp::cpyres<ltyp,rtyp>; - template<typename ltyp, typename rtyp> constexpr auto equ(ltyp * lbuf,rtyp * rbuf,::zp::siz num) noexcept -> bool; - template<typename buftyp,typename valtyp> constexpr auto fil(buftyp * buf, valtyp & val, ::zp::siz num) noexcept -> buftyp *; - template<typename buftyp,typename valtyp> constexpr auto srh(buftyp * buf, valtyp & val, ::zp::siz num) noexcept -> buftyp *; -#endif + template<typename ltyp, typename rtyp> zp_nothw ::zp::cpyres<ltyp,rtyp> cpy(ltyp * dst, rtyp * src, ::zp::siz num); + template<typename ltyp, typename rtyp> zp_nothw bool equ(ltyp * lbuf,rtyp * rbuf,::zp::siz num); + template<typename buftyp,typename valtyp> zp_nothw buftyp * fil(buftyp * buf, valtyp & val, ::zp::siz num); + template<typename buftyp,typename valtyp> zp_nothw buftyp * srh(buftyp * buf, valtyp & val, ::zp::siz num); } #include <zp/det/mem.ii> diff --git a/zp/include/zp/zp b/zp/include/zp/zp index 5aa2c66..1e9890f 100644 --- a/zp/include/zp/zp +++ b/zp/include/zp/zp @@ -309,31 +309,55 @@ namespace zp { template<typename typ> concept inttyp = ::zp::isinttyp<typ>::val; #endif + namespace det { + struct nulopt {}; + } + + zp_prv_trtval (::zp::det::nulopt) nulopt; + + template<typename typ> class opt { + public: + zp_nothw opt(::zp::det::nulopt); + opt(typ const& val); + + zp_nothw bool chk() const; + + zp_nothw typ const& val() const; + + template<typename funtyp,typename msgtyp> zp_nothw typ const& exp(funtyp const & fun,msgtyp const & msg) const; + + ::zp::opt<typ> operator =(typ const& val); + + private: + bool _hasval; + typ _val; + }; + template<typename typ> struct errtyp { public: zp_nothw typ val() const; - template<typename valtyp> zp_nothw ::zp::errtyp<typ> operator =(valtyp const & val); + template<typename valtyp> zp_nothw ::zp::errtyp<typ> operator =(valtyp const& val); private: typ errval; }; - template<typename typ,typename valtyp> zp_nothw ::zp::errtyp<typ> err(valtyp const & val); + template<typename typ,typename valtyp> zp_nothw ::zp::errtyp<typ> err(valtyp const& val); template<typename okytyp,typename errtyp> class res { public: - zp_nothw res(okytyp const & oky); - zp_nothw res(::zp::errtyp<errtyp> const & err); + zp_nothw res(okytyp const& oky); + zp_nothw res(::zp::errtyp<errtyp> const& err); zp_nothw bool chk() const; // true if okay. - zp_nothw okytyp const & oky() const; - zp_nothw errtyp const & err() const; + zp_nothw okytyp const& oky() const; + zp_nothw errtyp const& err() const; - template<typename funtyp,typename msgtyp> zp_nothw okytyp const & exp(funtyp const & fun,msgtyp const & msg) const; + template<typename funtyp,typename msgtyp> zp_nothw okytyp const& exp(funtyp const& fun,msgtyp const& msg) const; - ::zp::res<okytyp,errtyp> zp_nothw operator =(okytyp const & oky); - ::zp::res<okytyp,errtyp> zp_nothw operator =(::zp::errtyp<errtyp> const & err); + ::zp::res<okytyp,errtyp> zp_nothw operator =(okytyp const& oky); + ::zp::res<okytyp,errtyp> zp_nothw operator =(::zp::errtyp<errtyp> const& err); private: bool hasoky; @@ -364,7 +388,7 @@ namespace zp { zp_iln zp_noret zp_nothw inline void unrch() {zp_unrch();} #if zp_std_cxx11 // We cannot use template parameter packs before C++11, so this function becomes quite non-trivial to implement. - template<typename... typs> zp_iln inline auto syscal(::zp::syscalidt idt,typs const &... args) -> ::zp::syscalres {return ::zp_syscal(idt,args...);} + template<typename... typs> zp_iln inline auto syscal(::zp::syscalidt idt,typs const&... args) -> ::zp::syscalres {return ::zp_syscal(idt,args...);} #endif } |