Esempio n. 1
0
shared_ptr<const ctype::type_t> container_type(const ctype::type_t& t) {
    if (detail::isinstance<ctype::sequence_t>(t)) {
        const ctype::sequence_t& seq = detail::up_get<ctype::sequence_t>(t);
        return make_shared<const ctype::cuarray_t>(
            seq.sub().ptr());
    } else if (!detail::isinstance<ctype::tuple_t>(t)) {
        return t.ptr();
    }
    bool match = true;
    const ctype::tuple_t& t_tuple = boost::get<const ctype::tuple_t&>(t);
    vector<shared_ptr<const ctype::type_t> > sub_types;
    for(auto i = t_tuple.begin(); i != t_tuple.end(); i++) {
        shared_ptr<const ctype::type_t> sub_container = container_type(*i);
        match = match && (sub_container == i->ptr());
        sub_types.push_back(container_type(*i));
    }
    if (match) {
        return t.ptr();
    }
    return make_shared<const ctype::tuple_t>(std::move(sub_types));
}
shared_ptr<const ctype::type_t> allocate::container_type(const ctype::type_t& t) {
    if (detail::isinstance<ctype::sequence_t>(t)) {
        const ctype::sequence_t& st = detail::up_get<const ctype::sequence_t&>(t);
        return make_shared<const ctype::cuarray_t>(st.sub().ptr());
    } else if (detail::isinstance<ctype::tuple_t>(t)) {
        const ctype::tuple_t& tt = boost::get<const ctype::tuple_t&>(t);
        vector<shared_ptr<const ctype::type_t> > subs;
        bool containerize = false;
        for(auto i = tt.begin(); i != tt.end(); i++) {
            shared_ptr<const ctype::type_t> container_type_i =
                container_type(*i);

            subs.push_back(container_type_i);
            containerize = containerize || (i->ptr() != container_type_i);
        }
        if (!containerize) {
            return t.ptr();
        }
        return make_shared<const ctype::tuple_t>(
            move(subs));
    } else {
        return t.ptr();
    }
}