Project 5 Frequently Asked Questions

Updated 11/15/2019

The most recent items appear first.


I'm having trouble getting heterogenous lookup working with the std::set<> containers in Model. If possible, I want to use a single heterogenous comparator for the Sim_objects container, the Agents container, and the Structure container. But the compiler keeps giving me very confusing error messages or telling me that the find() with a name string has no matching call.

Apparently something changed recently in the newer C++17 libraries for some of the development platforms - this had been working since C++14.  At this point it isn't clear whether this is a bug or a feature (due to a change in the Standard) in the newer libraries.


It looks like the approach for std::set<> described in the  Heterogenous Lookup Handout works fine on gcc 9.1.0 on CAEN, and also with at least some installations of MSVS 2019. In fact, it looks like you can rely on how shared_ptr<Agent> and shared_ptr<Structure> can be implicitly converted to shared_ptr<Sim_object>. But we've had reports of this not working for at least some versions of MSVS. However, the same code does not seem to work with newer versions of Xcode, even when separate comparators for Agent, Structure, or Sim_object are used.


If you are having trouble making this work, first check out the following:


1. Make sure that all of the operator() member functions in your comparison function object class are declared as const member functions — which is generally required of all comparison functors. 

2. If your comparison function object works for the set<shared_ptr<Sim_object>, Comp> but not for the Agents or Structures set<>, try changing it to a template class/struct, where the template parameter is the shared_ptr<> type; e.g. set<shared_ptr<Agent>, Comp<Agent>> 

3. If neither of these work, email us with your platform, platform version number, copy-paste of your comparator code, and a copy-paste of the code and the error message for just one or two of the bad lines of code.



Work-around: If this is getting you frustrated (very understandable!), there is a straightforward solution involving a simple good choice of the three containers requiring only C++98 features: Consider that you can get along just fine if you have name lookup only for the Agents and Structures containers, while in contrast the only container you need to be able to iterate through in name order is the Sim_objects container.