/** ** \file misc/unique.hxx ** \brief Inline implementation of misc::unique. */ #pragma once #include #include namespace misc { template unique::unique(const data_type& s) // FIXME DONE: Some code was deleted here (Initializations). /** \brief Following the Flyweight design pattern, set the attribute to a unique reference of value s. You might want to check out std::set methods on cppreference.com. */ { if (object_set_instance().insert(s).second) { obj_ = &(*(object_set_instance().find(s))); } else { obj_ = &(*(object_set_instance().find(s))); } } template typename unique::object_set_type& unique::object_set_instance() { // FIXME DONE: Some code was deleted here (Classical Singleton pattern, a la Scott Meyers'). /** \brief Create a persistent instance of a set which would hold each value. */ static object_set_type res{}; return res; } template typename unique::object_size_type unique::object_map_size() { // FIXME DONE: Some code was deleted here. return object_set_instance().size(); } template inline const typename unique::data_type& unique::get() const { // FIXME DONE: Some code was deleted here. return *obj_; } template inline unique::operator const data_type&() const { // FIXME DONE: Some code was deleted here. return *obj_; } template inline typename unique::value_type& unique::operator=(const value_type& rhs) { if (this != &rhs) obj_ = rhs.obj_; return *this; } template inline bool unique::operator==(const value_type& rhs) const { return obj_ == rhs.obj_; } template inline bool unique::operator!=(const value_type& rhs) const { return !operator==(rhs); } template inline bool unique::operator<(const value_type& rhs) const { C cmp; assertion(obj_); assertion(rhs.obj_); return cmp(*obj_, *rhs.obj_); } template inline std::ostream& operator<<(std::ostream& ostr, const unique& the) { return ostr << the.get(); } } // namespace misc