I often come across situations where a library component needs to buffer a large amount of data for later processing. The problem is that at the design stage a choice needs to be made as to whether to store copies of, or references to, the data. Both methods have advantages/disadvantages:Storing copies requires either duplicating the data, or temporarily giving up ownership.Storing references creates a dependency on the lifetime of the callers data.It would be nice if the component could offer a choice of either method.I've had a go at implementing a policy-based solution to this problem. This solution only works for std::string types, but could easily be extended to other types.The 'policies' look like this:class StoreStringCopy{protected:    using InputType     = const std::string&;    using ValueType     = std::string;    using ReferenceType = boost::string_ref;    StoreStringCopy() = default;    ReferenceType store(InputType value)    {        auto copy_it = copies_.emplace(value);        return *copy_it.first;    }private:    std::unordered_set<ValueType> copies_;};class StoreStringReference{protected:    using InputType     = boost::string_ref;    using ValueType     = boost::string_ref;    using ReferenceType = boost::string_ref;    StoreStringReference() = default;    ReferenceType store(InputType value)    {        return value;    }};And here is a simple use-case which stores sub-strings of the data:template <typename StoragePolicy>class Foo : StoragePolicy{public:    using typename StoragePolicy::InputType;    Foo() = default;    void add(InputType s)    {        ReferenceType c = store(s);        substrings_.emplace_back(c.substr(0, c.length() - 1));        substrings_.emplace_back(c.substr(1, c.length() - 1));    }    void print() const    {        for (const auto& ss : substrings_) {            std::cout << ss << std::endl;        }    }private:    using typename StoragePolicy::ReferenceType;    using StoragePolicy::store;    std::vector<ReferenceType> substrings_;};The advantage of this design is that the user can easily switch strategy at compile-time depending on the context.I am looking for critiques of this design, and any improvements.
Storage policies
c++;strings;template meta programming