Vector with references to unique_ptr

The caller only needs to read the content

If the caller won't participate in the ownership of the pointer, then just use raw pointer. In fact, raw pointer can be considered as a pointer without ownership.

std::vector<std::unique_ptr<entry>> master;

std::vector<const entry*>
get_entries()
{
    std::vector<const entry*> entries;

    for ( auto const &ptr : master ) {
        /* if something satisfied */ 
        entries.push_back(ptr.get());
    }
    return entries;
}

Unique pointer is a "value type" containing a pointer.

So you could treat it as if it is a value type.

But it is uncopyable. So, the solution maybe use const references.

This also can't be applied to "vector" types. So, the solution is to use the reference_wrapper

//type alias for readability
using uEntry = std::unique_ptr<Entry>;

std::vector<uEntry> entries;

std::vector<std::reference_wrapper<const uEntry>> getEntries() {

    std::vector<std::reference_wrapper<const uEntry>> priventries;

    std::for_each(entries.begin(), entries.end(), [&](const uEntry &e) {
        if (e->a > 5) {
            priventries.push_back(std::cref<uEntry>(e));
        }
    });

    return priventries;
}

int main(int argc, const char * argv[]) {
    entries.push_back(uEntry(new Entry(5)));
    entries.push_back(uEntry(new Entry(7)));
    std::cout << getEntries().size();
    return 0;
}