Is the u8 string literal necessary in C++11

The encoding of “Test String” is the implementation-defined system encoding (the narrow, possibly multibyte one). The encoding of u8″Test String” is always UTF-8. The examples aren’t terribly telling. If you included some Unicode literals (such as \U0010FFFF) into the string, then you would always get those (encoded as UTF-8), but whether they could be expressed … Read more

nested struct initialization literals

While initialization the anonymous struct is only known under its type name (in your case A). The members and functions associated with the struct are only exported to the outside after the instance exists. You have to supply a valid instance of A to initialize MemberA: b := B { A: A{MemberA: “test1”}, MemberB: “test2”, … Read more

Java hexadecimal base double literal

It turns out it is possible, although that surprised me. Section 3.10.2 of the JLS gives the structure of floating point literals, including HexadecimalFloatingPointLiteral. public class Test { public static void main(String[] args) { double d1 = 0xAAAAAAAAAAAAAAAAAAp0d; double d2 = 0x1.8p1d; System.out.println(d1); // A very big number System.out.println(d2); // 24 = 1.5 * 2^1 … Read more

Why is it allowed to pass R-Values by const reference but not by normal reference?

For your final question: how can a const reference keep pointing to an R-Value (anonymous variable) Here is the answer. The C++ language says that a local const reference prolongs the lifetime of temporary values until the end of the containing scope, but saving you the cost of a copy-construction (i.e. if you were to use an … Read more

How can I use a dynamic format string with the format! macro?

Short answer: it cannot be done. Long answer: the format! macro (and its derivatives) requires a string literal, that is a string known at compilation-time. In exchange for this requirement, if the arguments provided do not match the format, a compilation error is raised. What you are looking for is known as a template engine. … Read more

How to use digit separators for Python integer literals?

Update a few years later: Python 3.6 now supports PEP515, and so you can use _ for float and integer literal readability improvement. Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (AMD64)] on win32 Type “help”, “copyright”, “credits” or “license” for more information. >>> 1_1000 11000 >>> For historical reference, you can … Read more