Date: Sat, 19 Oct 2024 14:07:52 +0100
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);
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);
Received on 2024-10-19 13:07:59