C++: Difference between revisions
No edit summary |
|||
Line 239: | Line 239: | ||
// Equivalent to FLT_MAX | // Equivalent to FLT_MAX | ||
std::numeric_limits<float>::max(); | std::numeric_limits<float>::max(); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 267: | Line 255: | ||
*Don't use stream (<iostream>, <stringstream>, etc.), use printf style functions instead. | *Don't use stream (<iostream>, <stringstream>, etc.), use printf style functions instead. | ||
*Don't use anything from STL that allocates memory, unless you don't care about memory management. | *Don't use anything from STL that allocates memory, unless you don't care about memory management. | ||
==STL== | |||
STL is the Standard Template Library.<br> | |||
STL can either refer to the 1994 original STL implementation by Stepanov and Lee from HP or the general set of algorithms, containers, functions, and iterators.<br> | |||
Many STL containers are now built into the standard library (std) of C++.<br> | |||
This section focuses only on the portions of STL which have been incorporated into the C++ standard library. | |||
==Containers== | |||
===Simple Containers=== | |||
====std::pair==== | |||
===Sequences=== | |||
====std::vector==== | |||
====std::list==== | |||
===Container adaptors=== | |||
====std::queue==== | |||
====std::stack==== | |||
===Associative Containers=== | |||
Also known as maps or associative arrays. | |||
====std::unordered_set==== | |||
<code>#include <unordered_set></code><br> | |||
This is a hashset.<br> | |||
<syntaxhighlight lang="cpp> | |||
std::unordered_set<int> my_set; | |||
// add things to myset | |||
my_set.insert(5); | |||
// Check contains | |||
my_set.find(5) != my_set.end(); | |||
</syntaxhighlight> | |||
====std::unordered_map==== | |||
==Boost== | ==Boost== | ||
== | |||
==Useful Libraries== | |||
A list of useful libraries | |||
===cxxopts=== | |||
[https://github.com/jarro2783/cxxopts Link]<br> | |||
A header-only C++ argument parser.<br> | |||
Note that if you already use Boost, you can use <code>Boost::Program_options</code> instead. | |||
===Eigen=== | |||
{main | Eigen} |