Code Monkey home page Code Monkey logo

citertools's Introduction

Me

I like simple and functional.

citertools's People

Contributors

gardell avatar jim-holmstroem avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

citertools's Issues

compile error with 3 arguments for composition2

#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

any/all

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) ?)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.