Exemple #1
0
int main() {
    BaseA ba;
    BaseB bb;
    DerivA da;
    DerivB db;

    Any any;
    assert(!any.isSet());

    any.set(ba);
    assert(any.isSet());
    assert(any.get<BaseA>() == &ba);
    assert(any.get<BaseB>() == NULL);
    assert(any.get<DerivA>() == NULL);
    assert(any.get<DerivB>() == NULL);

    any.clear();
    assert(!any.isSet());
    assert(any.get<BaseA>() == NULL);
    assert(any.get<BaseB>() == NULL);
    assert(any.get<DerivA>() == NULL);
    assert(any.get<DerivB>() == NULL);

    any = bb;
    assert(any.isSet());
    assert(any.get<BaseA>() == NULL);
    assert(any.get<BaseB>() == &bb);
    assert(any.get<DerivA>() == NULL);
    assert(any.get<DerivB>() == NULL);

    any = da;
    assert(any.isSet());
    assert(any.get<BaseA>() == NULL);
    assert(any.get<BaseB>() == NULL);
    assert(any.get<DerivA>() == &da);
    assert(any.get<DerivB>() == NULL);

    any = db;
    assert(any.isSet());
    assert(any.get<BaseA>() == NULL);
    assert(any.get<BaseB>() == NULL);
    assert(any.get<DerivA>() == NULL);
    assert(any.get<DerivB>() == &db);

    Any any2 = any;
    assert(any.isSet());
    assert(any.get<BaseA>() == NULL);
    assert(any.get<BaseB>() == NULL);
    assert(any.get<DerivA>() == NULL);
    assert(any.get<DerivB>() == &db);

    Any any3(any2);
    assert(any.isSet());
    assert(any.get<BaseA>() == NULL);
    assert(any.get<BaseB>() == NULL);
    assert(any.get<DerivA>() == NULL);
    assert(any.get<DerivB>() == &db);

    return 0;
}