std::set
, named NDos::set_multiplex
, which can view the elements in perspective of various comparison objects. For example, a set of playing cards could be sorted with rank first and suit second, or suit first and rank second; NDos::set_multiplex
enables to do this conveniently. NDos::set_multiplex
does this by inheriting a std::set
storing the elements, and multiple std::multiset
s storing the iterator to the elements.std::multiset
to be able to store references, and I replaced the std::multiset
s by them.std::list
, std::map
, std::unordered_set
, etc. From: NDos Dannyu Sent: Tuesday, January 3, 2017 7:57 PM To: ISO C++ Standard - Future Proposals Reply To: std-pr...@isocpp.org Subject: [std-proposals] Containers of references? |
I tried to make multiplex ofstd::set
, namedNDos::set_multiplex
, which can view the elements in perspective of various comparison objects. For example, a set of playing cards could be sorted with rank first and suit second, or suit first and rank second;NDos::set_multiplex
enables to do this conveniently.NDos::set_multiplex
does this by inheriting astd::set
storing the elements, and multiplestd::multiset
s storing the iterator to the elements.But I got a problem: I couldn't implement erasure method properly. It should be able to erase an element in perspective of any comparison object, but it can't. The ones storing the iterator to the elements expects the iterator to an element to be erased, and it is impossible to acquire such an iterator.
Did you try juststd::set<std::reference_wrapper<S>, std::less<S>> myset;myset.insert(std::ref(myobject));?That works for me, and AFAICT it doesn't create any excess temporaries anywhere.–ArthurP.S.: Feel free to take this to StackOverflow and post a link in this thread. :)
You can do that with a container of pointers, only that you have to
dereference the pointer before accessing the data. I think this conveys more
information, including the fact that the ownership of the data is unclear and
that the container doesn't own anything at all.
Arrays and containers of references are forbidden altogether, as a fundamental rule - not because there's no allocator written for references yet.If you had an array or container of references, there'd be no way to tell whether an indexing or arithmetic operation should act upon the element (or its storage) - or the thing to which it referred. (Using a struct that itself has a reference as its only member works around this because then you must disambiguate the names.) There are other reasons, but this is perhaps the most convincing one to me - and the one I see the least.
Then, we can just use different identifier for container of references.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/0e8a84fb-5d72-458e-b5b7-e28be7da1d4d%40isocpp.org.
But by all means, if you figure out a way to implement this in an existing compiler, please post the results.