Should I use std::default_random_engine or should I use std::mt19937?

For lightweight randomnes (e.g. games), you could certainly consider default_random_engine. But if your code depends heavily on quality of randomness (e.g. simulation software), you shouldn’t use it, as it gives only minimalistic garantees: It is the library implemention’s selection of a generator that provides at least acceptable engine behavior for relatively casual, inexpert, and/or lightweight … Read more

Copy Constructor in C++ is called when object is returned from a function?

It’s called exactly to avoid problems. A new object serving as result is initialized from the locally-defined object, then the locally defined object is destroyed. In case of deep-copy user-defined constructor it’s all the same. First storage is allocated for the object that will serve as result, then the copy constructor is called. It uses … Read more

Why can’t we add a Web API as a “service reference” in Visual Studio the same way we can with WCF or ASMX?

Do you mean a Rest Web Service? With Rest, there is no service definition page, like with WCF or ASMX. Usually people want to use a Rest API with JSON.. however.. if you are just looking for a JSON output, and you want your clients to quickly be able to connect to your service, you … Read more

CMake not generating compile_commands.json

This ended up being an issue with using an old version of CMake. I ended up installing the newest version and it worked as expected. According to Clang docs “Currently CMake (since 2.8.5) supports generation of compilation databases for Unix Makefile builds (Ninja builds in the works) with the option CMAKE_EXPORT_COMPILE_COMMANDS.”

How should I set up my integration tests to use a test database with Entity Framework?

Thanks so much to @Justin and @Petro for your answers, which have helped me immensely. The solution I have come up with is a combination of the techniques you suggested. The solution described below provides a new database for each run of the tests, and a separate transaction for each test. I added a connection … Read more

.NET Core Cookie Authentication SignInAsync not working

as of .net 2.x, if you’re using cookie auth, ensure you include the authenticationScheme and specify name and role claim types, the identity and auth properties. //You should specify the ‘types’ of the claims which acts as ‘name’ and ‘role’, furthermore, you should have claims with those types in your claimsIdentity like that var identity … Read more

what is the meaning of restrict in the function signature?

It’s something introduced in C99 which lets the compiler know that the pointer passed in there isn’t pointing to the same place as any other pointers in the arguments. If you give this hint to the compiler, it can do some more aggressive optimizations without breaking code. As an example, consider this function: int add(int … Read more