What are the most widely used C++ vector/matrix math/linear algebra libraries, and their cost and benefit tradeoffs?

There are quite a few projects that have settled on the Generic Graphics Toolkit for this. The GMTL in there is nice – it’s quite small, very functional, and been used widely enough to be very reliable. OpenSG, VRJuggler, and other projects have all switched to using this instead of their own hand-rolled vertor/matrix math. I’ve found … Read more

What are the differences between struct and class in C++?

You forget the tricky 2nd difference between classes and structs. Quoth the standard (§11.2.2 in C++98 through C++11): In absence of an access-specifier for a base class, public is assumed when the derived class is declared struct and private is assumed when the class is declared class. And just for completeness’ sake, the more widely known difference between class and … Read more

Fastest way to check if a file exist using standard C++/C++11,14,17/C?

Well I threw together a test program that ran each of these methods 100,000 times, half on files that existed and half on files that didn’t. Results for total time to run the 100,000 calls averaged over 5 runs, Method Time exists_test0 (ifstream) 0.485s exists_test1 (FILE fopen) 0.302s exists_test2 (posix access()) 0.202s exists_test3 (posix stat()) 0.134s The stat() function provided the … Read more

How to iterate over a vector?

If you have access to C++11 you can use range-based for loops Otherwise you should use begin() and end() You can also use std::begin and std::end (these require C++11 as well) begin will return an iterator to the first element in your vector. end will return an iterator to one element past the end of your vector. So the order in which you get the elements iterating … Read more

Difference in make_shared and normal shared_ptr in C++

The difference is that std::make_shared performs one heap-allocation, whereas calling the std::shared_ptr constructor performs two. Where do the heap-allocations happen? std::shared_ptr manages two entities: the control block (stores meta data such as ref-counts, type-erased deleter, etc) the object being managed std::make_shared performs a single heap-allocation accounting for the space necessary for both the control block and the data. In the other … Read more

expected expression in C++?

You problem is this: Here only the cout is part of the if statement. The loop is not. You need to add braces around the whole block.

What does the assignment of ~0u to a variable mean in C++?

It indicates bitwise not; all bits in the integer will be flipped, which in this case produces a number where all bits are 1. Note that since it is unsigned, if the integer is widened during assignment the extended bits would be 0. For example assuming that unsigned short is 2 bytes and unsigned int is 4: If you … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)