With reference to this question StackoVerflow 529831, this was one of the suggested approaches
template<typename Map> typename Map::const_iterator greatest_less(Map const& m, typename Map::key_type const& k) { //How to print K and Map m typename Map::const_iterator it = m.lower_bound(k); if(it != m.begin()) { return --it; } return m.end(); }
I would be interested in printing key K and Map m, How would go about this.
Use the
<<operator, making sure that<<is defined for both yourMap::key_typeandMap::data_typetypes (you will know if that is not the case as the code will not compile.)e.g. if your
Map::data_typeis astruct fractionwith membersfloat numeratorandfloat denominator,