/* * indexable_set.h */ #ifndef INDEXABLE_SET #define INDEXABLE_SET #include #include template, typename Allocator = std::allocator> struct indexable_set : public std::set { // types: using set_type = std::set; using size_type = typename set_type::size_type; // construct/copy/destroy: using std::set::set; // inherit some constructors... // Special member functions are implicitly-declared, se below. // Good style would be to default them all here! // added set operations: const Key& operator[](size_type index) const { return at(index); } const Key& at(size_type index) const { if (index >= set_type::size()) { throw std::out_of_range{"indexable_set::operator[] out of range"}; } auto iter = set_type::begin(); std::advance(iter, index); return *iter; } }; #endif /* * Constructors are NOT inherited, so default constructor, copy constructor * and move constructor are not inherited. They are implicitly-declared * in indexable_set (since not explicitly declared). * * The destructor is NOT inherited, it's implicitly-declared in indexable_set. * * Operator functions ARE inherited, but the inherited copy and move assignment * operators are hidden by implicitly-declared copy and move assignment operator * in indexable_set (since not explicitly declared). * * A using-declaration that brings in copy/move constructors and copy/move * assignment operators from the base class is NOT concidered an explicit * declaration and does NOT supress the implicit declarations of these in a * derived class. The functions introduced by a using-declaration are instead * hidden by the implicit declarations. A using-declaration cannot refer to a * destructor for a base class. * * So, all constructors for indexable_set except the copy/move constructors * are inherited from std::set. */