Re: Why do Glib::ustring::operator[] and at() return values, not references?



I wonder, would anyone be interested in adding a proxy class, to be returned by operator[] and .at() on a non-const ustring, which would provide operator gunichar() and operator=()? It would then hold a reference to the string and the index with which it was instantiated, and delegate to .replace() to do 'assignment'.

The benefits of this are:

But the main drawback I could think of is this: It would change semantics for anyone currently using auto some_character = non_const_ustring[N], as the auto would now capture the proxy type, not a gunichar. To get the latter, the type would have to be explicitly specified to invoke the conversion operator. Or is there a clever way around this that I don't know?




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]