Ignore:
File:
1 edited

Legend:

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

    r58daf53 r64fc0ba  
    88//
    99// Author           : Andrew Beach
    10 // Created On       : Wed May 24 15:40:00 2017
     10// Created On       : Wed May 25 15:40:00 2017
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thr May 25 15:24:00 2017
     12// Last Modified On : Wed May 25 17:00:00 2017
    1313// Update Count     : 1
    1414//
     
    2626void ?{}(maybe(T) * this, T value) {
    2727        this->has_value = true;
    28         (&this->value){value};
     28        this->value = value;
    2929}
    3030
     
    3333        this->has_value = other.has_value;
    3434        if (other.has_value) {
    35                 (&this->value){other.value};
    36         }
    37 }
    38 
    39 forall(otype T)
    40 maybe(T) ?=?(maybe(T) * this, maybe(T) that) {
    41         if (this->has_value & that.has_value) {
    42                 this->value = that.value;
    43         } else if (this->has_value) {
    44                 ^(&this->value){};
    45                 this->has_value = false;
    46         } else if (that.has_value) {
    47                 this->has_value = true;
    48                 (&this->value){that.value};
     35                this->value = other.value;
    4936        }
    5037}
     
    5946forall(otype T)
    6047bool ?!=?(maybe(T) this, zero_t) {
    61         return this.has_value;
     48        return !this.has_value;
    6249}
    6350
     
    8269        return this->value;
    8370}
    84 
    85 forall(otype T)
    86 void set(maybe(T) * this, T value) {
    87         if (this->has_value) {
    88                 this->value = value;
    89         } else {
    90                 this->has_value = true;
    91                 (&this->value){value};
    92         }
    93 }
    94 
    95 forall(otype T)
    96 void set_none(maybe(T) * this) {
    97         if (this->has_value) {
    98                 this->has_value = false;
    99                 ^(&this->value){};
    100         }
    101 }
Note: See TracChangeset for help on using the changeset viewer.