I like simple and functional.
jim-holmstroem / citertools Goto Github PK
View Code? Open in Web Editor NEWPython itertools and surrounding methods written i templated C++11
Python itertools and surrounding methods written i templated C++11
#ifndef _CITERTOOLS_COMPOSITION2_H_
#define _CITERTOOLS_COMPOSITION2_H_
#include <cit/definition.h>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#ifndef _CITERTOOLS_CPP11_
#error "Nothing in <cit/map2.h> can be used when not using C++11!"
#else
namespace cit2 {
template<typename F, typename... Fs>
class _composition : public std::unary_function<
typename _composition<Fs...>::argument_type,
typename F::result_type
>{
const F & _f;
const _composition<Fs...> & _fs;
public:
_composition(const F & f, const Fs &... fs) : _f(f), _fs(fs...) {};
inline typename F::result_type operator() (
const typename _composition<Fs...>::argument_type arg
) const {
return _f(_fs(arg));
};
};
template<>
template<typename F>
class _composition<F> : public std::unary_function<
typename F::argument_type,
typename F::result_type
>{
const F & _f;
public:
_composition(const F & f) : _f(f) {};
inline const typename F::result_type operator() (
const typename F::argument_type arg
) const {
return _f(arg);
};
};
template<typename F, typename... Fs>
_composition<F, Fs...> composition(const F & f, const Fs &... fs) {
return _composition<F, Fs...>(f, fs...);
};
}
#endif /* _CITERTOOLS_CPP11_ */
#endif /* _CITERTOOLS_COMPOSITION2_H_ */
1 and 2 arguments work but 3 fails with this:
g++ -o test/composition2 -std=c++0x -Wall test/composition2.cpp -Iinclude/
In file included from test/composition2.cpp:1:0:
include/cit/composition2.h: In instantiation of ‘cit2::_composition<F, Fs>::_composition(const F&, const Fs& ...) [with F = std::negate<int>; Fs = {std::negate<int>, std::negate<int>}]’:
include/cit/composition2.h:54:47: required from ‘cit2::_composition<F, Fs ...> cit2::composition(const F&, const Fs& ...) [with F = std::negate<int>; Fs = {std::negate<int>, std::negate<int>}]’
test/composition2.cpp:31:91: required from here
include/cit/composition2.h:25:71: error: expression list treated as compound expression in mem-initializer [-fpermissive]
_composition(const F & f, const Fs &... fs) : _f(f), _fs(fs...) {};
^
include/cit/composition2.h:25:71: warning: left operand of comma operator has no effect [-Wunused-value]
include/cit/composition2.h:25:71: error: invalid initialization of reference of type ‘const cit2::_composition<std::negate<int>, std::negate<int> >&’ from expression of type ‘const std::negate<int>’
make: *** [test/composition2] Error 1
compose(negate, sum)
the rightmost container will be evaluated \prod n_i/n_N times which is more then the needed 1.
any(t, ts...) = t || any(ts...)
all(t, ts...) = t && all(ts...)
what if T != bool
?
can one use any(ts...) = reduce(op::or, ts)
(will it still be O(n/2) ?)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.