Ask coding questions

← Back to all posts
C++ unknown type?
xxpertHacker (865)

I'm trying to figure out what type u'0' and u"0" are, but std::char8_t doesn't exist, so is it an un-named type?

Ahh, these don't even compare!
https://repl.it/@xxpertHacker/missingno-1#main.cpp

Comments
hotnewtop
xxpertHacker (865)

@DynamicSquid @CSharpIsGud
I need help, do either of you have any time to check out this nonsense?

CSharpIsGud (931)

@xxpertHacker You mean like this?

char8_t c = 0;

std::cout << (typeid(u'0') == typeid(c)) << "\n"; // 1

char8_t isn't in std

xxpertHacker (865)

@CSharpIsGud Ha, do you have a C++ 20 compiler or what?

Repl uses a C++17 compiler.

xxpertHacker (865)

@DynamicSquid Yeah, same, afaict, it's a C++20 keyword. I sure can't get it to run on Repl.

@CSharpIsGud, can you link the Repl?

And regardless of char8_t or whatever, why does my second Repl's assertions fail? That makes no sense, whatsoever; I only used relative type deduction.

xxpertHacker (865)

@DynamicSquid @CSharpIsGud
Oh shoot, I do think it is char8_t, even if it's not exposed as the keyword, since I got a compiler errors mentioning it by name:

././base64.hpp:40:15: error: initializing 'char8_t' array with plain string
      literal
        constexpr u8 b64[] =
                     ^
././base64.hpp:41:3: note: add 'u8' prefix to form a 'char8_t' string literal
                "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                ^
                u8

with u8 as a type alias of decltype(u8'\0').

Now I'm just lost as to what *u8"" is, if it's not char8_t const&.

DynamicSquid (4630)

@xxpertHacker I'm so lost. This hurts my head.

xxpertHacker (865)

@CSharpIsGud That just confirms what I said, that char8_t is a C++20 thing?

Baconman321 (1060)

wait wut u can declare operators? kewl!

Oh, wait... I read it wrong :/