[spirit][phoenix] operator[] hack for std::map

Howdy, I've been working on a parser in Spirit that uses Phoenix and came across an item that I needed to support: operator[] on std::map. Perhaps I overlooked this feature somewhere, but based on the code in operators.hpp, I crafted the following code for myself: namespace phoenix { // Workaround: std::map::operator[] uses a different return type than all // other standard containers. Phoenix doesn't account for that. template <typename TK, typename T0, typename T1> struct binary_operator<index_op, std::map<TK,T0>, T1> { typedef typename std::map<TK,T0>::mapped_type& result_type; static result_type eval(std::map<TK,T0>& container, T1 const& index) { return container[index]; } }; } // namespace phoenix I suspect that it would need generalizing to be added to Phoenix as it comes with Spirit, but I thought that it would be useful to alert others of the desire for this feature, if not supply a full implementation (I really don't have the time :( ). Cheers, ron

Ronald Garcia wrote:
Howdy,
I've been working on a parser in Spirit that uses Phoenix and came across an item that I needed to support: operator[] on std::map. Perhaps I overlooked this feature somewhere, but based on the code in operators.hpp, I crafted the following code for myself:
[...]
I suspect that it would need generalizing to be added to Phoenix as it comes with Spirit, but I thought that it would be useful to alert others of the desire for this feature, if not supply a full implementation (I really don't have the time :( ).
There's a full implementation available which includes a lot more (e.g. lazy container functions) by Angus Leeming. It's been lurking around for a long time already. I'll make it a point to make it available in the next release. Angus? -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net

Joel de Guzman wrote:
There's a full implementation available which includes a lot more (e.g. lazy container functions) by Angus Leeming. It's been lurking around for a long time already. I'll make it a point to make it available in the next release. Angus?
I'm lurking around. (But v busy ATM and then I'm skiing next week.) I haven't forgotten you ;-) Last time I looked, the stuff was fully functional. Maybe shove it on the spirit.sf.net repository for the time being? Angus
participants (3)
-
Angus Leeming
-
Joel de Guzman
-
Ronald Garcia