mlund / cpptricks

Collection of C++ snippets and header files that could be useful

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cpptricks

Collection of C++ snippets and header files that could be useful. Build and test with:

cmake .
make test
./test

Description

  • invsqrt.h. Quake fast inverse square root for floats/doubles.
  • stl_eigen_facade.h. Access vector of structures as Eigen objects
  • pairwise_iterator.h. Generates an iterable object pointing to all unique pairs in one container or between two containers. Dereferencing returns a std::tuple holding (const) references to the underlying data.
    std::vector<std::string> v = {"one","two", "three"};
    for (auto [i,j] : internal_pairs(v)):
    std::cout << i << "-" << j << " "; // --> "one-two" "one-three" "two-three"
    (similar to Python's itertools.combinations)
    std::vector<std::string> v1 = {"one","two"}, v2 = {"three"};
    for (auto [i,j] : cartesian_product(v1,v2)):
       std::cout << i << "-" << j << " "; // --> "one-three" "two-three"
    (similar to range-v3's cartesian_product)

About

Collection of C++ snippets and header files that could be useful

License:GNU General Public License v3.0


Languages

Language:C++ 90.8%Language:CMake 9.2%