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



On 28 June 2017 at 10:47, Jonathan Wakely <gtkmm kayari org> wrote:
On 28 June 2017 at 09:39, Daniel Boles wrote:
> 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?

There's no way around it. There have been proposals for an "operator
auto" that would make it possible to control the deduced type, mostly
for use by _expression_ templates, but nothing that is part of C++ yet.

Interesting to hear about the proposals; thanks.
 
Another downside of a proxy is it can outlive the string, so this
would be undefined (without some internal complexity to track
lifetimes):

Yeah, I thought about that briefly but forgot by the time I was writing the email. I wonder whether sigc::trackable can help here, although maybe that's getting too complex to be worthwhile.





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