0

I'm trying to create a set that doesn't require < or a hash function. I've created the following, but I'm not sure what the proper return types are for size(), cbegin(), and cend(). I've tried different combinations of std:: and deque<t>:: without much luck. I know the performance would theoretically be bad for this kind of object, but I never expect it to have more than 64 elements or so. I think this is likely mostly a syntax question.

#include <deque>
template <typename t> 
struct unordered_eq_set
{
public:
    //This is a set for items where < does not exist - inserts are O(N). 
    void insert(const t& item)
    {
        for (t& testItem : items)
        {
            if (testItem == item)
            {
                return;
            }
        }
        items.insert(item);
        return;
    }
    std::deque<t>::size_type size()
    {
        return items.size();
    }
    std::deque<t>::const_iterator cbegin()
    {
        return items.cbegin();
    }
    std::deque<t>::const_iterator cend()
    {
        return items.cend();
    }

private:
    std::deque<t> items;
};
int main()
{
    unordered_eq_set<int> dumbSet;
    dumbSet.insert(3);
    return 0;
}
Carbon
  • 3,010
  • 1
  • 17
  • 39

0 Answers0