summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.txt3
-rw-r--r--test.cc5
-rw-r--r--zp/include/zp/det/zp.ii12
-rw-r--r--zp/include/zp/zp21
4 files changed, 28 insertions, 13 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index ec351fb..42d1872 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -31,6 +31,9 @@
* Don't make res and opt constexpr;
* Define destructors for opt and res;
+* Define conversion function for opt;
+* Make assignment operators return references;
+
# 1.0.0
* Update API-BREAK file;
diff --git a/test.cc b/test.cc
index d22bc24..a96cb7a 100644
--- a/test.cc
+++ b/test.cc
@@ -259,6 +259,11 @@ int main() {
chkeq(opt.chk(),true);
chkeq(opt.exp(fun,"expectation failed"),-0x45);
+
+ ::zp::opt<::zp::i8s> const optasg = opt;
+
+ chkeq(optasg.chk(),true);
+ chkeq(optasg.exp(fun,"expectation failed"),-0x45);
}();
[&] {
diff --git a/zp/include/zp/det/zp.ii b/zp/include/zp/det/zp.ii
index 3d764bc..26a8a1d 100644
--- a/zp/include/zp/det/zp.ii
+++ b/zp/include/zp/det/zp.ii
@@ -45,25 +45,27 @@ template<typename typ> template<typename funtyp,typename msgtyp> auto ::zp::opt<
return this->_val;
}
-template<typename typ> auto ::zp::opt<typ>::operator =(::zp::det::nulopttyp) noexcept -> ::zp::opt<typ> {
+template<typename typ> auto ::zp::opt<typ>::operator =(::zp::det::nulopttyp) noexcept -> ::zp::opt<typ> & {
this->_hasval = false;
return *this;
}
-template<typename typ> auto ::zp::opt<typ>::operator =(typ const& val) -> ::zp::opt<typ> {
+template<typename typ> auto ::zp::opt<typ>::operator =(typ const& val) -> ::zp::opt<typ> & {
this->_hasval = true;
this->_val = val;
return *this;
}
-template<typename typ> auto ::zp::opt<typ>::operator =(typ && val) -> ::zp::opt<typ> {
+template<typename typ> auto ::zp::opt<typ>::operator =(typ && val) -> ::zp::opt<typ> & {
this->_hasval = true;
this->_val = val;
return *this;
}
+
+template<typename typ> ::zp::opt<typ>::operator typ() const noexcept {return this->_val;}
#endif
#if zp_std_cxx11
@@ -133,7 +135,7 @@ template<typename okytyp,typename errtyp> template<typename funtyp,typename msgt
return this->_okyval;
}
-template<typename okytyp,typename errtyp> auto ::zp::res<okytyp,errtyp>::operator =(::zp::res<okytyp,errtyp> const& oth) -> ::zp::res<okytyp,errtyp> {
+template<typename okytyp,typename errtyp> auto ::zp::res<okytyp,errtyp>::operator =(::zp::res<okytyp,errtyp> const& oth) -> ::zp::res<okytyp,errtyp> & {
this->~res();
this->_hasoky = oth._hasoky;
@@ -143,7 +145,7 @@ template<typename okytyp,typename errtyp> auto ::zp::res<okytyp,errtyp>::operato
return *this;
}
-template<typename okytyp,typename errtyp> auto ::zp::res<okytyp,errtyp>::operator =(::zp::res<okytyp,errtyp> && oth) -> ::zp::res<okytyp,errtyp> {
+template<typename okytyp,typename errtyp> auto ::zp::res<okytyp,errtyp>::operator =(::zp::res<okytyp,errtyp> && oth) -> ::zp::res<okytyp,errtyp> & {
this->~res();
this->_hasoky = oth._hasoky;
diff --git a/zp/include/zp/zp b/zp/include/zp/zp
index ef3dc93..2c970be 100644
--- a/zp/include/zp/zp
+++ b/zp/include/zp/zp
@@ -318,9 +318,11 @@ namespace zp {
template<typename typ> class opt {
public:
- opt(::zp::det::nulopttyp) noexcept;
- opt(typ const& val);
- opt(typ && val);
+ opt(::zp::opt<typ> const& oth) = default;
+ opt(::zp::opt<typ> && oth) = default;
+ opt(::zp::det::nulopttyp) noexcept;
+ opt(typ const& val);
+ opt(typ && val);
~opt() noexcept(false);
@@ -330,9 +332,12 @@ namespace zp {
template<typename funtyp,typename msgtyp> auto exp(funtyp const & fun,msgtyp const & msg) const noexcept -> typ const&;
- auto operator =(::zp::det::nulopttyp) noexcept -> ::zp::opt<typ>;
- auto operator =(typ const& val) -> ::zp::opt<typ>;
- auto operator =(typ && val) -> ::zp::opt<typ>;
+ auto operator =(::zp::opt<typ> const& oth) -> ::zp::opt<typ> & = default;
+ auto operator =(::zp::det::nulopttyp) noexcept -> ::zp::opt<typ> &;
+ auto operator =(typ const& val) -> ::zp::opt<typ> &;
+ auto operator =(typ && val) -> ::zp::opt<typ> &;
+
+ operator typ() const noexcept;
private:
bool _hasval;
@@ -360,8 +365,8 @@ namespace zp {
template<typename funtyp,typename msgtyp> auto exp(funtyp const& fun,msgtyp const& msg) const noexcept -> okytyp const&; // UB if fun returns or throws an uncaught exception.
- auto operator =(::zp::res<okytyp,errtyp> const& oth) -> ::zp::res<okytyp,errtyp>;
- auto operator =(::zp::res<okytyp,errtyp> && oth) -> ::zp::res<okytyp,errtyp>;
+ auto operator =(::zp::res<okytyp,errtyp> const& oth) -> ::zp::res<okytyp,errtyp> &;
+ auto operator =(::zp::res<okytyp,errtyp> && oth) -> ::zp::res<okytyp,errtyp> &;
private:
constexpr res() noexcept {};