## page was renamed from ProgammingLanguages/C++ <> See also [[CodingStyle/C++]]. == STL == Wrap an existing C-style pointer to an array with std::vector: http://stackoverflow.com/a/15203325/14878; modifies std::vector internals to work. == C++11 == == Move semantics/perfect forwarding == * [[http://thbecker.net/articles/rvalue_references/section_01.html|C++ Rvalue References Explained]] * [[http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2027.html#Move_Semantics|Rvalue Reference Quick Look]] * [[http://en.cppreference.com/w/cpp/utility/move|std::move - cppreference.com]] * [[https://www.ibm.com/developerworks/community/blogs/5894415f-be62-4bc0-81c5-3956e82276f3/entry/RVO_V_S_std_move?lang=en|RVO V.S. std::move (C/C++ Cafe)]] * [[http://www.cprogramming.com/c++11/rvalue-references-and-move-semantics-in-c++11.html|Rvalue References and Move Semantics in C++11 - Cprogramming.com]] === Smart pointers === * [[https://arne-mertz.de/2015/12/shared_ptr-versus-unique_ptr-in-factory-functions/|shared_ptr Versus unique_ptr in Factory Functions]] * [[https://softwareengineering.stackexchange.com/questions/274801/raw-weak-ptr-unique-ptr-shared-ptr-etc-how-to-choose-them-wisely|c++ - raw, weak_ptr, unique_ptr, shared_ptr etc... How to choose them wisely? - Software Engineering Stack Exchange]] == Data structures == === B-tree-based maps & sets === * In 2013, Google open-sourced a mostly-STL-compatible b-tree implementation: [[https://isocpp.org/blog/2013/02/b-tree-containers-from-google|B-tree containers from Google]]. The old project is on Google code, but [[https://github.com/JGRennison/cpp-btree|JGRennison/cpp-btree]] is a fork with minor fixes and some C++11 support (e.g. move constructors, etc). * [[https://github.com/bingmann/stx-btree|bingmann/stx-btree]] * [[http://panthema.net/2018/0528-tlx-library/|tlx]] library contains a fast loser tree implementation, a newer version of the bingmann/stx-btree implemtnation, a smart pointer replacement for shared_ptr called counting_ptr, and std::string helper functions missing from STL. == Parsing == === JSON === * [[https://github.com/nlohmann/json|nlohmann/json]]: JSON for Modern C++ * [[https://github.com/lemire/simdjson|lemire/simdjson]]: Parsing gigabytes of JSON/sec == C++ and Python == * [[https://github.com/pybind/pybind11|pybind/pybind11]]: Seamless operability between C++11 and Python * [[https://github.com/wjakob/nanobind|wjakob/nanobind]]: Successor to pybind11, faster, requires C++17 and Python 3.8 * [[https://github.com/tbenthompson/cppimport|tbenthompson/cppimport]]: Import C++ files directly from Python == Helpers == * [[https://github.com/aantron/better-enums|aantron/better-enums]]: Compile-time enum to string, iteration, etc in a single header file. C++98-compatible. * [[https://github.com/Neargye/magic_enum|Neargye/magic_enum]]: Static (i.e. compile-time) reflection for enum, incl. enum to string, iteration, etc. Needs gcc-9 or later. == Interesting libraries == * [[https://github.com/fffaraz/awesome-cpp|awesome-cpp]]: A curated list of awesome C/C++ frameworks, libraries, resources, and shiny things. Inspired by awesome-... stuff. * [[https://github.com/nothings/single_file_libs|nothings/single_file_libs]]: List of single-file C/C++ libraries * [[https://github.com/hughperkins/Jinja2CppLight|hughperkins/Jinja2CppLight: (very) lightweight version of Jinja2 for C++]] == Other stuff == * [[https://www.conan.io/|Conan C/C++ Package Manager]] == Videos == === Curiously recurring C++ bugs at Facebook === [[https://www.youtube.com/watch?v=3MB2iiCkGxg|Curiously recurring C++ bugs at Facebook]] * Use `-fsanitize-address` and `-fsanitize-address-use-after-scope` * Use `-Wshadow`, and deal with noisy warnings === Patterns and Techniques Used in the Houdini 3D Graphics Application (Mark Elendt) === [[https://www.youtube.com/watch?v=2YXwg0n9e7E|CppCon 2018: Mark Elendt “Patterns and Techniques Used in the Houdini 3D Graphics Application”]] * Vector that uses realloc() instead of new/malloc(). Significantly faster than std::vector, but has problems with objects that are not `std::trivially_relocatable`. * Copy-on-write used in several places; paged arrays to used copy-on-write in arrays * Reference-counted strings to avoid copying strings. Bunch of `constexpr` stuff used to make static initialization (i.e. program startup) faster. == Language servers == === clangd === [[https://github.com/llvm-mirror/clang-tools-extra/commits/master/clangd/tool/ClangdMain.cpp|Source code for clangd's main file]]. See what options are supported, renamed, etc. === ccls === [[https://github.com/MaskRay/ccls|ccls]] is a language server for C/C++. The instructions below can also be used for compiling [[https://github.com/cquery-project/cquery|cquery]]. For Ubuntu 18.10, first install dependency packages (adjust clang package versions if needed): {{{#!highlight sh numbers=off sudo apt install -y clang libclang-dev libncurses-dev libtinfo5 llvm-dev zlib1g-dev }}} Download clang from [[https://releases.llvm.org|releases.llvm.org]: {{{#!highlight sh numbers=off wget --continue https://releases.llvm.org/7.0.1/clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-18.04.tar.xz # Extract into clang-llvm mkdir clang-llvm tar xvf clang*tar.xz -C clang-llvm --strip-components=1 }}} And configure with: {{{#!highlight sh numbers=off export CFLAGS=-O3 -march=native export CXXFLAGS=$CFLAGS cmake -H. -Bbuild -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=$PWD/clang-llvm/ }}} To build using the LLVM native on Ubuntu, use: {{{#!highlight sh numbers=off export CFLAGS=-O3 -march=native export CXXFLAGS=$CFLAGS cmake -H. -Bbuild-native \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_PREFIX_PATH=/usr/lib/llvm-7 \ -DLLVM_INCLUDE_DIR=/usr/lib/llvm-7/include \ -DLLVM_BUILD_INCLUDE_DIR=/usr/include/llvm-7/ \ -DLLVM_ENABLE_RTTI=on }}} Build with either: {{{#!highlight sh numbers=off make -C build -j$(nproc) cmake --build Release --parallel $(nproc) }}} adjust as appropriate for the version of LLVM you are using. If you're using the downloaded version of LLVM, you need to distribute that tarball with your ccls binary, and configure it's location as it's "resource directory". To run ccls independent of a language server-capable IDE: {{{#!highlight sh numbers=off ccls --index=$(pwd) -v=2 --init='{"cacheDirectory":"/home/samatj/splcore.main/Python3/.vscode/ccls","clang":{"resourceDir":"/home/samatj/Downloads/clang-resource-dir.tar/","extraArgs":["--gcc-toolchain=/usr"]}}' --log-file=ccls.log }}}