
On 4/9/2011 3:39 PM, TONGARI wrote:
2011/4/9 Joel de Guzman
mailto:joel@boost-consulting.com> Adapted classes are different beasts. Adapted classes may not expose their attributes by reference due to abstraction and information hiding. It's not uncommon for a class not to actually have an actual member variable. The best we can assume is that a class has a getter and setter member functions. When you access its member (e.g. using at_c or dereferencing an iterator), here's what happens:
1) If the adapted class is immutable, it returns the class' adapted get member function for the member.
E.g. T get_mem() const;
Really? Right after seeing your words I almost came up with a workaround... However, it turns out that it's either me misunderstanding you or it misbehaving.
For example, const foo f("foo"); // immutable, right? boost::fusion::front(f); // we still get a proxy, why?
You'll have to forgive me. Christophe just pointed out off-list that this is no longer the behavior for the sake of consistency. Here's the relevant discussion: Stefan Strasser proposed changes to the adapt class/adt interface: ,---- [(http://lists.boost.org/Archives/boost/2010/08/169996.php)] |Also very good points. I think the proxy should behave similar to Boost |ref, as it should expose an implicit conversion to T. This alone will |satisfy many code that expects T. As for exposing the proxy as the |value type of the sequence, you are right. However, what we can |probably do is to be consistent with handling const and non-const and |always return a proxy so there is no surprise when code works one way |and not the other way. `---- Pardon the noise. I think the changes all make sense.
Do you have any suggestion for using adapted class with Spirit that the OP wants to do?
Well, given the current API, you can write: std::cout << boost::fusion::front(f).get() << std::endl; See: [http://tinyurl.com/6aq97lj] http://www.boost.org/doc/libs/1_46_1/libs/fusion/doc/html/fusion/notes.html#... Regards, -- Joel de Guzman http://www.boostpro.com http://boost-spirit.com