summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.txt5
-rw-r--r--test.cc17
-rw-r--r--zp/GNUmakefile6
-rw-r--r--zp/include/zp/det/zp.ii48
-rw-r--r--zp/include/zp/mth.h6
-rw-r--r--zp/include/zp/zp42
-rw-r--r--zp/include/zp/zp.h2
7 files changed, 74 insertions, 52 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 08d1707..e49b752 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,3 +1,8 @@
+# 1.1.0
+
+* Bump extension version;
+* Add type for storing either errors or return values: res;
+
# 1.0.0
* Update API-BREAK file;
diff --git a/test.cc b/test.cc
index 299a93b..6ce453f 100644
--- a/test.cc
+++ b/test.cc
@@ -198,13 +198,15 @@ int main() {
::std::cout <<"zp " <<::zp::ver.api <<"." <<::zp::ver.ext <<", run-time test\n";
try {
-#if false
[&] {
- tst("optionals");
+ tst("results");
- ::zp::opt<::zp::i8s> opt = ::zp::nulopt;
+ ::zp::res<::zp::i8s,::zp::i8s> res = ::zp::err<::zp::i8s>(0x45);
- cmp(opt.chk(),false);
+ cmp(res.chk(),false);
+ cmp(res.err(),0x45);
+
+ res = -0x45;
auto const fun = [](char const* msg) -> void {
::std::cout << msg << ::std::endl;
@@ -212,12 +214,9 @@ int main() {
::std::abort();
};
- opt = -0x45;
-
- cmp(opt.chk(),true);
- cmp(opt.exp(fun,"expectation failed"),-0x45);
+ cmp(res.chk(),true);
+ cmp(res.exp(fun,"expectation failed"),-0x45);
}();
-#endif
[&] {
tst("special numbers");
diff --git a/zp/GNUmakefile b/zp/GNUmakefile
index af90203..cc89537 100644
--- a/zp/GNUmakefile
+++ b/zp/GNUmakefile
@@ -91,8 +91,6 @@ OBJ_ZP_SYSCAL := source/ia32/zp/syscal.o
endif
OBJS := \
- $(OBJ_ZP_TRP) \
- \
$(OBJ_MEM_MEMCPY) \
$(OBJ_MEM_MEMEQU) \
$(OBJ_MEM_MEMFIL) \
@@ -131,7 +129,9 @@ OBJS := \
$(OBJ_STR_WSTREQU) \
$(OBJ_STR_WSTRFIL) \
$(OBJ_STR_WSTRLEN) \
- $(OBJ_STR_WSTRSRH)
+ $(OBJ_STR_WSTRSRH) \
+ \
+ $(OBJ_ZP_TRP)
ifneq "$(nosyscal)" "true"
OBJS := \
diff --git a/zp/include/zp/det/zp.ii b/zp/include/zp/det/zp.ii
index ddc34e8..f93e2c1 100644
--- a/zp/include/zp/det/zp.ii
+++ b/zp/include/zp/det/zp.ii
@@ -17,33 +17,45 @@ constexpr auto ::zp::iscstevl() noexcept -> bool {
}
#endif
-#if false
-#if zp_std_cxx11
-template<typename typ> constexpr ::zp::opt<typ>::opt(::zp::det::nulopt) noexcept : hasval(false),valval(typ {}) {
-}
+template<typename typ> zp_nothw typ zp::errtyp<typ>::val() const {return this->errval;}
-template<typename typ> constexpr ::zp::opt<typ>::opt(typ const & val) noexcept : hasval(true),valval(val) {
+template<typename typ> template<typename valtyp> zp_nothw ::zp::errtyp<typ> zp::errtyp<typ>::operator =(valtyp const & val) {
+ this->errval = static_cast<typ>(val);
+ return *this;
}
-template<typename typ> constexpr auto ::zp::opt<typ>::chk() const noexcept -> bool {
- return this->hasval;
+template<typename typ,typename valtyp> zp_nothw ::zp::errtyp<typ> zp::err(valtyp const & val) {
+ ::zp::errtyp<typ> err;
+ return err = val;
}
-template<typename typ> constexpr auto ::zp::opt<typ>::val() const noexcept -> typ {
- return this->valval;
+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> 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();
+ }
+
+ return this->okyval;
}
-template<typename typ> template<typename funtyp,typename msgtyp> auto ::zp::opt<typ>::exp(funtyp const & fun,msgtyp const & msg) const -> typ {
- zp_lik (this->hasval) {return this->valval;}
- fun(msg);
- ::zp::unrch();
+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 typ> constexpr auto ::zp::opt<typ>::operator = (typ const & val) noexcept -> ::zp::opt<typ> {
- this->hasval = true;
- this->valval = val;
+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();
return *this;
}
-#endif
-#endif // false
diff --git a/zp/include/zp/mth.h b/zp/include/zp/mth.h
index ff4c0e5..a4ccb31 100644
--- a/zp/include/zp/mth.h
+++ b/zp/include/zp/mth.h
@@ -128,15 +128,15 @@ zp_nothw zp_unseq zp_useres zp_divmodresi02s zp_divmodi02s(zp_i02s num,zp_i02s d
zp_nothw zp_unseq zp_useres zp_divmodresi04s zp_divmodi04s(zp_i04s num,zp_i04s den);
/* two-space dot product */
-zp_nothw zp_unseq zp_useres zp_f02 zp_dot2f02(zp_vec2f02 lvec,zp_vec2f02 rvec);
+zp_nothw zp_unseq zp_useres zp_f02 zp_dot2f02(zp_vec2f02 lvec,zp_vec2f02 rvec);
zp_nothw zp_unseq zp_useres zp_f04 zp_dot2f04(zp_vec2f04 lvec,zp_vec2f04 rvec);
/* three-space dot product */
-zp_nothw zp_unseq zp_useres zp_f02 zp_dot3f02(zp_vec3f02 lvec,zp_vec3f02 rvec);
+zp_nothw zp_unseq zp_useres zp_f02 zp_dot3f02(zp_vec3f02 lvec,zp_vec3f02 rvec);
zp_nothw zp_unseq zp_useres zp_f04 zp_dot3f04(zp_vec3f04 lvec,zp_vec3f04 rvec);
/* four-space dot product */
-zp_nothw zp_unseq zp_useres zp_f02 zp_dot4f02(zp_vec4f02 lvec,zp_vec4f02 rvec);
+zp_nothw zp_unseq zp_useres zp_f02 zp_dot4f02(zp_vec4f02 lvec,zp_vec4f02 rvec);
zp_nothw zp_unseq zp_useres zp_f04 zp_dot4f04(zp_vec4f04 lvec,zp_vec4f04 rvec);
/* exponentation */
diff --git a/zp/include/zp/zp b/zp/include/zp/zp
index 37a1ec2..5aa2c66 100644
--- a/zp/include/zp/zp
+++ b/zp/include/zp/zp
@@ -309,33 +309,39 @@ namespace zp {
template<typename typ> concept inttyp = ::zp::isinttyp<typ>::val;
#endif
-#if false
-#if zp_std_cxx11
- namespace det {
- struct nulopt {};
- }
+ template<typename typ> struct errtyp {
+ public:
+ zp_nothw typ val() const;
+ template<typename valtyp> zp_nothw ::zp::errtyp<typ> operator =(valtyp const & val);
- constexpr ::zp::det::nulopt nulopt = {};
+ private:
+ typ errval;
+ };
- template<typename typ> class opt {
- public:
- constexpr opt(::zp::det::nulopt) noexcept;
- constexpr opt(typ const & val) noexcept;
+ template<typename typ,typename valtyp> zp_nothw ::zp::errtyp<typ> err(valtyp const & val);
- constexpr auto chk() const noexcept -> bool;
+ template<typename okytyp,typename errtyp> class res {
+ public:
+ zp_nothw res(okytyp const & oky);
+ zp_nothw res(::zp::errtyp<errtyp> const & err);
- constexpr auto val() const noexcept -> typ;
+ zp_nothw bool chk() const; // true if okay.
+
+ zp_nothw okytyp const & oky() const;
+ zp_nothw errtyp const & err() const;
- template<typename funtyp,typename msgtyp> auto exp(funtyp const & fun,msgtyp const & msg) const -> typ;
+ template<typename funtyp,typename msgtyp> zp_nothw okytyp const & exp(funtyp const & fun,msgtyp const & msg) const;
- constexpr auto operator = (typ const & val) noexcept -> ::zp::opt<typ>;
+ ::zp::res<okytyp,errtyp> zp_nothw operator =(okytyp const & oky);
+ ::zp::res<okytyp,errtyp> zp_nothw operator =(::zp::errtyp<errtyp> const & err);
private:
- bool hasval;
- typ valval;
+ bool hasoky;
+ union {
+ okytyp okyval;
+ errtyp errval;
+ };
};
-#endif
-#endif // false
namespace det {
template<typename typ> struct ver {
diff --git a/zp/include/zp/zp.h b/zp/include/zp/zp.h
index 9aebe26..b584ed9 100644
--- a/zp/include/zp/zp.h
+++ b/zp/include/zp/zp.h
@@ -286,7 +286,7 @@ typedef decltype (nullptr) zp_nulptrtyp;
#endif
#define zp_apiver ((zp_i04)+0x1u) /* Programs expecting this version will still compile with the current extension version. */
-#define zp_extver ((zp_i04)+0x0u) /* The extension versions adds functionality without breaking the existing ones. */
+#define zp_extver ((zp_i04)+0x1u) /* The extension versions adds functionality without breaking the existing ones. */
/* The patch version is not public as it only changes implementation details. */
#define zp_bytelen ((zp_siz)+0x8u)