<commit_before>#ifndef PYTHONIC_INTRINSICS_H
#define PYTHONIC_INTRINSICS_H

#include <tuple>
#include <sstream>
#include <complex>

namespace pythonic {
    /* abs */
    using std::abs;
    PROXY(pythonic, abs);

    /* all */
    template <class T>
        bool all( sequence<T> const& s) {
            return s.end() == std::find_if(s.begin(), s.end(), [](T const&t) { return not bool(t); });
        }
    PROXY(pythonic, all);

    /* any */
    template <class T>
        bool any( sequence<T> const& s) {
            return s.end() != std::find_if(s.begin(), s.end(), [](T const&t) { return bool(t); });
        }
    PROXY(pythonic, any);

    /* bin */
    template<class T>
        std::string bin(T const &v) {
            std::ostringstream oss("0b");
            for(size_t i=1 << (8*sizeof(T)-1); i ; i>>=1)
                if(v & i) oss << "1";
                else oss << "0";
            return oss.str();
        }
    PROXY(pythonic, bin);

    /* chr */
    template<class T>
        std::string chr(T const &v) { return std::string(1,(char)v); }
    PROXY(pythonic, chr);

    /* cmp */
    template<class T0, class T1>
        bool cmp(T0 const& v0, T1 const& v1) {
            return v0 == v1 ? 0 : ( v0 < v1 ? -1 : 1 );
        }
    PROXY(pythonic, cmp);

    /* complex */
    template<class T0, class T1=double> // do not handle string as first argument
    std::complex<double> complex(T0 const& v0, T1 const& v1 = 0.) {
        return std::complex<double>(v0,v1);
    }
    PROXY(pythonic, complex);

    /* divmod */
    template<class T0, class T1>
        auto divmod(T0 const& t0, T1 const& t1) // other types are left over
            -> decltype(std::make_tuple(t0/t1, t0%t1)) {
                return std::make_tuple(t0/t1, t0%t1);
            }
    PROXY(pythonic, divmod);

    /* enumerate */
    template<class T>
    struct enumerate_iterator : std::iterator< std::forward_iterator_tag, long >{
        long value;
        typename sequence<T>::const_iterator iter;
        enumerate_iterator(long value, typename sequence<T>::const_iterator iter) : value(value), iter(iter) {}
        std::tuple<long,T>  operator*() { return std::make_tuple(value, *iter); }
        enumerate_iterator& operator++() { ++value,++iter; return *this; }
        enumerate_iterator operator++(int) { enumerate_iterator self(*this); ++value, ++iter; return self; }
        bool operator!=(enumerate_iterator const& other) { return value != other.value; }
    };

    template <class T>
    struct _enumerate {
        sequence<T> const& seq;
        typedef std::tuple<long, T> value_type;
        _enumerate( sequence<T> const& seq ) : seq(seq) {}
        enumerate_iterator<T> begin() const { return enumerate_iterator<T>(0L,seq.begin()); }
        enumerate_iterator<T> end() const { return enumerate_iterator<T>(seq.end()-seq.begin(), seq.end()); }
    };
    template <class T>
    _enumerate<T> enumerate(sequence<T> const& seq) { return _enumerate<T>(seq); }
    PROXY(pythonic,enumerate);

    /* filter */
    template<class F, class T>
        sequence<T> filter(F const& f, sequence<T> const& seq) { /* does not implement the full standard */
            sequence<T> out;
            std::copy_if(seq.begin(), seq.end(), std::back_inserter(out), f);
            return out;
        }
    PROXY(pythonic, filter);

    /* hex */
    template <class T>
        std::string hex(T const & v) {
            std::ostringstream oss("0x");
            oss << std::hex << v;
            return oss.str();
        }
    PROXY(pythonic, hex);

    /* id */
    template <class T>
        struct _id {
            intptr_t operator()(T const &t) {
                return reinterpret_cast<intptr_t>(&t);
            }
        };
    template <class T>
        struct _id< sequence<T> > {
            intptr_t operator()(sequence<T> const &t) {
                return reinterpret_cast<intptr_t>(&(*t.data));
            }
        };

    template <class T>
        intptr_t id(T const & t) {
            return _id<T>()(t);
        }
    PROXY(pythonic,id);

    /* in */
    template <class T, class V>
        bool in(T const &t, V const &v) {
            return std::find(t.begin(), t.end(), v) == t.end();
        }
    template <>
        bool in<std::string, std::string>(std::string const &t, std::string const &v) {
            return t.find(v) != std::string::npos;
        }
    PROXY(pythonic,in);
<commit_msg>Fix bug in the implementation of the in keyword.<commit_after>#ifndef PYTHONIC_INTRINSICS_H
#define PYTHONIC_INTRINSICS_H

#include <tuple>
#include <sstream>
#include <complex>

namespace pythonic {
    /* abs */
    using std::abs;
    PROXY(pythonic, abs);

    /* all */
    template <class T>
        bool all( sequence<T> const& s) {
            return s.end() == std::find_if(s.begin(), s.end(), [](T const&t) { return not bool(t); });
        }
    PROXY(pythonic, all);

    /* any */
    template <class T>
        bool any( sequence<T> const& s) {
            return s.end() != std::find_if(s.begin(), s.end(), [](T const&t) { return bool(t); });
        }
    PROXY(pythonic, any);

    /* bin */
    template<class T>
        std::string bin(T const &v) {
            std::ostringstream oss("0b");
            for(size_t i=1 << (8*sizeof(T)-1); i ; i>>=1)
                if(v & i) oss << "1";
                else oss << "0";
            return oss.str();
        }
    PROXY(pythonic, bin);

    /* chr */
    template<class T>
        std::string chr(T const &v) { return std::string(1,(char)v); }
    PROXY(pythonic, chr);

    /* cmp */
    template<class T0, class T1>
        bool cmp(T0 const& v0, T1 const& v1) {
            return v0 == v1 ? 0 : ( v0 < v1 ? -1 : 1 );
        }
    PROXY(pythonic, cmp);

    /* complex */
    template<class T0, class T1=double> // do not handle string as first argument
    std::complex<double> complex(T0 const& v0, T1 const& v1 = 0.) {
        return std::complex<double>(v0,v1);
    }
    PROXY(pythonic, complex);

    /* divmod */
    template<class T0, class T1>
        auto divmod(T0 const& t0, T1 const& t1) // other types are left over
            -> decltype(std::make_tuple(t0/t1, t0%t1)) {
                return std::make_tuple(t0/t1, t0%t1);
            }
    PROXY(pythonic, divmod);

    /* enumerate */
    template<class T>
    struct enumerate_iterator : std::iterator< std::forward_iterator_tag, long >{
        long value;
        typename sequence<T>::const_iterator iter;
        enumerate_iterator(long value, typename sequence<T>::const_iterator iter) : value(value), iter(iter) {}
        std::tuple<long,T>  operator*() { return std::make_tuple(value, *iter); }
        enumerate_iterator& operator++() { ++value,++iter; return *this; }
        enumerate_iterator operator++(int) { enumerate_iterator self(*this); ++value, ++iter; return self; }
        bool operator!=(enumerate_iterator const& other) { return value != other.value; }
    };

    template <class T>
    struct _enumerate {
        sequence<T> const& seq;
        typedef std::tuple<long, T> value_type;
        _enumerate( sequence<T> const& seq ) : seq(seq) {}
        enumerate_iterator<T> begin() const { return enumerate_iterator<T>(0L,seq.begin()); }
        enumerate_iterator<T> end() const { return enumerate_iterator<T>(seq.end()-seq.begin(), seq.end()); }
    };
    template <class T>
    _enumerate<T> enumerate(sequence<T> const& seq) { return _enumerate<T>(seq); }
    PROXY(pythonic,enumerate);

    /* filter */
    template<class F, class T>
        sequence<T> filter(F const& f, sequence<T> const& seq) { /* does not implement the full standard */
            sequence<T> out;
            std::copy_if(seq.begin(), seq.end(), std::back_inserter(out), f);
            return out;
        }
    PROXY(pythonic, filter);

    /* hex */
    template <class T>
        std::string hex(T const & v) {
            std::ostringstream oss("0x");
            oss << std::hex << v;
            return oss.str();
        }
    PROXY(pythonic, hex);

    /* id */
    template <class T>
        struct _id {
            intptr_t operator()(T const &t) {
                return reinterpret_cast<intptr_t>(&t);
            }
        };
    template <class T>
        struct _id< sequence<T> > {
            intptr_t operator()(sequence<T> const &t) {
                return reinterpret_cast<intptr_t>(&(*t.data));
            }
        };

    template <class T>
        intptr_t id(T const & t) {
            return _id<T>()(t);
        }
    PROXY(pythonic,id);

    /* in */
    template <class T, class V>
        bool in(T const &t, V const &v) {
            return std::find(t.begin(), t.end(), v) != t.end();
        }
    template <>
        bool in<std::string, std::string>(std::string const &t, std::string const &v) {
            return t.find(v) != std::string::npos;
        }
    PROXY(pythonic,in);

{'fraction_non_alphanumeric': 0.15677252833576477, 'fraction_numerical': 0.010324318258332398, 'mean_word_length': 2.2173285198555956, 'pattern_counts': {'":': 0, '<': 121, '<?xml version=': 0, '>': 105, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5814420', 'n_tokens_mistral': 2981, 'n_tokens_neox': 2966, 'n_words': 718}