C++ Logo

std-proposals

Advanced search

Re: [std-proposals] operator*&

From: Jeremy Rifkin <rifkin.jer_at_[hidden]>
Date: Sat, 19 Oct 2024 10:19:25 -0500
Hello,

Why does this need to be an operator when &*it already works as you want?

Jeremy

On Sat, Oct 19, 2024 at 08:08 Frederick Virchanza Gotham via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> I've had the following in my codebase for a few years:
>
> string_view first = SomeFunction1();
> uint16_t a;
> std::from_chars( first.begin(), first.end(), a );
>
> This worked fine until I compiled with the Microsoft compiler, because
> on the Microsoft compiler, the string_view::iterator is not a simple
> typedef for a char pointer. I could have just changed it to:
>
> std::from_chars( &*first.begin(), &*first.end(), a);
>
> but this is undefined behaviour and it sets off the debugger in the
> GNU compiler. So instead I changed it to:
>
> uint16_t a = 0u;
> if ( first.size() ) std::from_chars( &first.front(),
> &first.back() + 1, a );
>
> Which got me thinking . . . maybe it would be handy if we could write
> an iterator as follows:
>
> class string_view {
> public:
> class iterator {
> public:
> char const *operator&*(void) { . . . }
> };
> };
>
> My first idea was that "&*" would be globbed as one token, but then
> that begs the question, how would the following two be treated?
>
> std::from_chars( & * first.begin(), & * first.end(), a);
> std::from_chars( &(*first.begin()), &(*first.end()), a);
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2024-10-19 15:19:37