C++: Difference between revisions

No edit summary
Line 72: Line 72:
See [https://stackoverflow.com/questions/6462439/whats-the-difference-between-long-long-and-long SO] for the standard and guaranteed precision of these built-in types.
See [https://stackoverflow.com/questions/6462439/whats-the-difference-between-long-long-and-long SO] for the standard and guaranteed precision of these built-in types.


C++ also has fixed-width types in <code>#include <cstdint</code> (since C++11).<br>
C++ also has fixed-width types in <code>#include <cstdint></code> (since C++11).<br>
[https://en.cppreference.com/w/cpp/header/cstdint cppreference cstdint]<br>
[https://en.cppreference.com/w/cpp/header/cstdint cppreference cstdint]<br>
I recommend using these for anything with specific or high precision requirements.<br>
I recommend using these for anything with specific or high precision requirements.<br>
Line 237: Line 237:
// Calling methods
// Calling methods
// You can also pass in parameters as usual
// You can also pass in parameters as usual
std::thread my_thread(&Class::method, this));
std::thread my_thread(&Class::method, this);
// Lambda functions
// Lambda functions
std::thread my_thread([&]() {
std::thread my_thread([&]() {
Line 336: Line 336:
// Swap
// Swap
std::vector<float> my_vector(99);
std::vector<float> my_vector(99);
my_vector = std::vector<float>;
my_vector = std::vector<float>();
// Or alternatively
// Or alternatively
// std::vector<float>().swap(my_vector);
// std::vector<float>().swap(my_vector);
Line 563: Line 563:
// Peek
// Peek
// Always make sure stack is not empty
// Always make sure stack is not empty
char top = my_stack.top('a');
char top = my_stack.top();


// Pop
// Pop
Line 711: Line 711:
     dumb_array(const dumb_array& other)
     dumb_array(const dumb_array& other)
         : mSize(other.mSize),
         : mSize(other.mSize),
           mArray(mSize ? new int[mSize] : nullptr),
           mArray(mSize ? new int[mSize] : nullptr)
     {
     {
         // note that this is non-throwing, because of the data
         // note that this is non-throwing, because of the data