Ignore:
Timestamp:
May 25, 2017, 11:38:36 AM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
e883a4b
Parents:
58ed882
Message:

Added maybe and result to libcfa makefiles and made some minor fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/containers/result.c

    r58ed882 r64fc0ba  
    2121void ?{}(result(T, E) * this) {
    2222        this->has_value = false;
    23         (this->error){};
     23        (&this->error){};
    2424}
    2525
     
    4949void ^?{}(result(T, E) * this) {
    5050        if (this->has_value) {
    51                 ^(this->value){};
     51                ^(&this->value){};
    5252        } else {
    53                 ^(this->error){};
     53                ^(&this->error){};
    5454        }
    5555}
    5656
    5757forall(otype T, otype E)
    58 _Bool ?!=?(result(T, E) this, zero_t) {
    59         return !this->has_value;
     58bool ?!=?(result(T, E) this, zero_t) {
     59        return !this.has_value;
    6060}
    6161
    6262forall(otype T, otype E)
    6363result(T, E) result_value(T value) {
    64         return (Result(T, E)){1, value};
     64        return (result(T, E)){1, value};
    6565}
    6666
    6767forall(otype T, otype E)
    6868result(T, E) result_error(E error) {
    69         return (Result(T, E)){0, value};
     69        return (result(T, E)){0, error};
    7070}
    7171
    7272forall(otype T, otype E)
    73 _Bool has_value(result(T, E) * this) {
     73bool has_value(result(T, E) * this) {
    7474        return this->has_value;
    7575}
     
    7777forall(otype T, otype E)
    7878T get(result(T, E) * this) {
    79     assertf(this->has_value, "attempt to get from result without value");
     79        assertf(this->has_value, "attempt to get from result without value");
    8080        return this->value;
    8181}
     
    8383forall(otype T, otype E)
    8484E get_error(result(T, E) * this) {
    85     assertf(this->has_value, "attempt to get from result without error");
     85        assertf(this->has_value, "attempt to get from result without error");
    8686        return this->error;
    8787}
Note: See TracChangeset for help on using the changeset viewer.