项目作者: kzawisto

项目描述 :
Low overhead functional interface for stl containers inspired by Scala.
高级语言: C++
项目地址: git://github.com/kzawisto/glues.git
创建时间: 2018-09-13T18:31:51Z
项目社区:https://github.com/kzawisto/glues

开源协议:MIT License

下载


Glues

Low overhead Scala/FP like interface for C++ containers.

No indirect calls, no unneeded objects, compile time code generation.

  1. std::vector<int> v{0, 1, 2, 3, 4, 5};
  2. auto cumulated_product = mon(v.begin(), v.end())
  3. .map([](int i) { return i + 1; }) // lazy evaluation
  4. .scan_left([](double a, int b) { return a * b; }, 1.0); // sort of cumsum function as in scala
  5. // result is std::vector<int>{1, 2, 6, 24, 120, 720};
  6. auto result = glues::mon(v.begin(), v.end())
  7. .map([](int i){return i * i;}) // lazy
  8. .filter([](int i) {return i < 10;}) // lazy
  9. .accumulate([](std::string s, // computation here, one loop
  10. int a) { return s + std::to_string(a); },
  11. std::string("foo")); //
  12. // result is foo149
  13. std::vector<double> numbers{10, -1, 1000, 100};
  14. auto logarithms = glues::mon(numbers.begin(), numbers.end()).flat_map([](double i) {
  15. return i > 0 ?
  16. glues::some(log10(i)) : glues::none<double>(); // any iterable can be used here as return type
  17. }).run<std::deque<double>>(); // trigger execution and create a deque<double> for result
  18. // result is std::deque<double> {1.0, 3.0, 2.0};
  19. // see unit tests for more examples

Requirements:

C++11 or greater needed, Boost::container::small_vector, Boost::optional (tested with G++ 6.2, Boost 1.62).
Header only library.

Installation

Header-only library, download from git and copy includes to desired directory.

  1. git clone http://github.com/kzawisto/glues
  2. cd glues
  3. sudo rm -r /usr/include/glues
  4. sudo cp include/glues /usr/include

Tests

Clone repo, checkout desired version.
Then:

  1. cd glues/test
  2. make
  3. ./test

GoogleTest (GTest) v. 1.8 is needed for test