C++ Logo

std-proposals

Advanced search

Re: [std-proposals] operator*&

From: Giuseppe D'Angelo <giuseppe.dangelo_at_[hidden]>
Date: Sat, 19 Oct 2024 15:19:16 +0200
Il 19/10/24 15:07, Frederick Virchanza Gotham via Std-Proposals ha scritto:
> 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:

Is this now turning into StackOverflow?

std::string_view::iterator models std::contiguous_iterator and therefore
you already have a way, it's called std::to_address.

My 2 c,
--
Giuseppe D'Angelo

Received on 2024-10-19 13:19:19