Does boost have a datatype for set operations that is simpler than the STL?

Nope. But I here is how to clean it up. First, rewrite iterator based functions as ranged based functions. This halves your boilerplate. Second, have them return container builders rather than take insert iterators: this gives you efficient assignment syntax. Third, and probably too far, write them as named operators. The final result is you … Read more

Immutable version of EnumSet

Are you looking for Sets.immutableEnumSet (Guava) perhaps? Returns an immutable set instance containing the given enum elements. Internally, the returned set will be backed by an EnumSet. The iteration order of the returned set follows the enum’s iteration order, not the order in which the elements appear in the given collection.

Mapping Set using @ElementCollection

for future googlers! finally i managed to solve the problem, i just had to put the annotations somewhere else in my code , @ElementCollection(targetClass = Days.class) @CollectionTable(name = “days”, joinColumns = @JoinColumn(name = “rule_id”)) @Column(name = “daysOfWeek”, nullable = false) @Enumerated(EnumType.STRING) public Set<Days> getDays() { return days; } as you can see i wrote the … Read more

Call to implicitly-deleted default constructor of ‘unordered_set< vector >‘

It’s because unordered_set is using std::hash template to compute hash for its entries and there is no std::hash for pairs. You have to define custom hash to use unordered_set. struct vector_hash { template <class T1, class T2> std::size_t operator () (std::pair<T1, T2> const &v) const { return std::hash<T1>()(v.size()); } }; and then declare your unordered_set … Read more

JSTL Sets and Lists – checking if item exists in a Set

You could do this using JSTL tags, but the result is not optimal: <%@ taglib prefix=”c” uri=”http://java.sun.com/jsp/jstl/core”%> <html> <body> <jsp:useBean id=”numbers” class=”java.util.HashSet” scope=”request”> <% numbers.add(“one”); numbers.add(“two”); numbers.add(“three”); %> </jsp:useBean> <c:forEach items=”${numbers}” var=”value”> <c:if test=”${value == ‘two’}”> <c:set var=”found” value=”true” scope=”request” /> </c:if> </c:forEach> ${found} </body> </html> A better way would be to use a custom … Read more

How to use Python sets and add strings to it in as a dictionary value

You can write a single element tuple as @larsmans explained, but it is easy to forget the trailing comma. It may be less error prone if you just use lists as the parameters to the set constructor and methods: Dictionary[key_1] = set([‘name’]) Dictionary[key_2] = set([‘name_2’, ‘name_3’]) Dictionary[key_2].add([‘name_3’]) should all work the way you expect.

tech