Boost logo

Boost :

From: Ronald Garcia (garcia_at_[hidden])
Date: 2005-02-01 19:50:31


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
// 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 :( ).



Boost list run by bdawes at, gregod at, cpdaniel at, john at