Can standard container templates be instantiated with incomplete types?

Here’s my attempt at an interpretation: The standard simply says you mustn’t do this, even though any given concrete implementation may have no problem supporting such a construction. But imagine for example if someone wanted to write a “small vector” optimization by which a vector always contains space for, say, five elements. Immediately you’d be … Read more

Same random numbers every loop iteration

When you call srand(x), then the value of x determines the sequence of pseudo-random numbers returned in following calls to rand(), depending entirely on the value of x. When you’re in a loop and call srand() at the top: while (…) { srand(time(0)); x = rand(); y = rand(); } then the same random number … Read more

Use OpenSSL RSA key with .Net

I am using openssl 0.9.6g and I have created public/private keypair using RSA_generate_key(). It gives me keys like: —–BEGIN RSA PUBLIC KEY—– … —–END RSA PUBLIC KEY—– I think what I am looking for is “how to convert rsa public key from pkcs#1 to x509 format. Yeah, .Net can consume some ASN.1/DER encoded keys, and … Read more

What does std::match_results::size return?

You get 1 because regex_search returns only 1 match, and size() will return the number of capture groups + the whole match value. Your matches is…: Object of a match_results type (such as cmatch or smatch) that is filled by this function with information about the match results and any submatches found. If [the regex … Read more

boost_1_60_0 .zip installation in windows

Since yours is now the third “How do I build boost on Windows?” question that I’ve seen since 1.60.0 was released here are my own personal Windows boost build notes: Windows does not directly support boost, so you can download it and put it wherever you want. The boost user guide recommends creating a BOOST_ROOT … Read more

Can’t Mod Zero?

The C++ Standard(2003) says in ยง5.6/4, […] If the second operand of / or % is zero the behavior is undefined; […] That is, following expressions invoke undefined-behavior(UB): X / 0; //UB X % 0; //UB Note also that -5 % 2 is NOT equal to -(5 % 2) (as Petar seems to suggest in … Read more

String Literal address across translation units [duplicate]

You can not rely on identical string literals having the same memory location, it is an implementation decision. The C99 draft standard tells us that it is unspecified whether the same string literal are distinct, from section 6.4.5 String literals: It is unspecified whether these arrays are distinct provided their elements have the appropriate values. … Read more