samedi 29 septembre 2018

Why first code work and the second doesn't?

Why this line work: auto it = objects.insert(objects.end(), {move(object), 0, 0});

In function:

    Id Add(T object) {
    auto it = objects.insert(objects.end(), {move(object), 0, 0});

    int id = objects.size();
    arr.insert({&(*it).pri, id - 1});

    return id - 1;
}

But this line doesn't (can't compile): auto iter = objects.insert(objects.end(), {*it, 0, 0}); At this function:

    template <typename ObjInputIt, typename IdOutputIt>
void Add(ObjInputIt range_begin, ObjInputIt range_end,
       IdOutputIt ids_begin) {
    auto begin = objects.size();

    for (auto it = range_begin; it != range_end; it++) {
        auto iter = objects.insert(objects.end(), {*it, 0, 0});
        int id = objects.size();
        arr.insert({&(*iter).pri, id - 1});
    }

    auto end = objects.size();

    ids_begin = {begin, end - 1};
}

Aucun commentaire:

Enregistrer un commentaire