.. ot-exercise:: cxx11.exercises.bag_unique :dependencies: cxx11.exercises.bag_copy, cxx11.smart_pointers.unique_ptr, cxx11.new_language_features.auto, cxx11.new_language_features.range_based_for Exercise: Bag Of Items, By Unique Reference =========================================== Continuing from :doc:`bag-copy`, create a similar class ``BagUnique`` that contains pointers of type ``std::unique_ptr`` such that the tests below pass. Special features: * Find out: what would the return type of ``find_by_int() const`` be? * Can it be the vector's member type, a ``std::unique_ptr``? Why not? * A ``const std::unique_ptr&`` maybe? Why not? * Try to create a ``std::unique_ptr`` and assign it to variable which you then insert, like (naively) .. code-block:: c++ auto v = std::make_unique("something", 42); bag.insert(v); Does it work? What do you notice? .. literalinclude:: code/bag-unique-suite.cpp :caption: :download:`code/bag-unique-suite.cpp` :language: c++