<commit_before>//
// Created by Qiyu on 17-6-5.
//

#ifndef SERIALIZE_JSON_HPP
#define SERIALIZE_JSON_HPP
#include <string.h>
#include <math.h>
#include "reflection.hpp"

namespace iguana { namespace json
    {
        template<typename InputIt, typename T, typename F>
        T join(InputIt first, InputIt last, const T &delim, const F &f) {
            if (first == last)
                return T();

            T t = f(*first++);
            while (first != last) {
                t += delim;
                t += f(*first++);
            }
            return t;
        }

        template<typename Stream, typename InputIt, typename T, typename F>
        void join(Stream& ss, InputIt first, InputIt last, const T &delim, const F &f) {
            if (first == last)
                return;

            f(*first++);
            while (first != last) {
                ss.put(delim);
                f(*first++);
            }
        }

        template<typename Stream>
        void render_json_value(Stream& ss, std::nullptr_t) { ss.write("null"); }

        template<typename Stream>
        void render_json_value(Stream& ss, bool b) { ss.write(b ? "true" : "false"); };

        template<typename Stream, typename T>
        std::enable_if_t<!std::is_floating_point<T>::value&&(std::is_integral<T>::value || std::is_unsigned<T>::value || std::is_signed<T>::value)>
        render_json_value(Stream& ss, T value)
        {
            char temp[20];
            auto p = itoa_fwd(value, temp);
            ss.write(temp, p-temp);
        }

        template<typename Stream>
        void render_json_value(Stream& ss, int64_t value)
        {
            char temp[65];
            auto p = xtoa(value, temp, 10, 1);
            ss.write(temp, p - temp);
        }

        template<typename Stream>
        void render_json_value(Stream& ss, uint64_t value)
        {
            char temp[65];
            auto p = xtoa(value, temp, 10, 0);
            ss.write(temp, p - temp);
        }

        template<typename Stream, typename T>
        std::enable_if_t<std::is_floating_point<T>::value> render_json_value(Stream& ss, T value)
        {
            char temp[20];
            sprintf(temp, "%f", value);
            ss.write(temp);
        }

        template<typename Stream>
        void render_json_value(Stream& ss, const std::string &s)
        {
            ss.write_str(s.c_str(), s.size());
        }

        template<typename Stream>
        void render_json_value(Stream& ss, const char* s, size_t size)
        {
            ss.write_str(s, size);
        }

        template<typename Stream, typename T>
        std::enable_if_t<std::is_arithmetic<T>::value> render_key(Stream& ss, T t) {
            ss.put('"');
            render_json_value(ss, t);
            ss.put('"');
        }

        template<typename Stream>
        void render_key(Stream& ss, const std::string &s) {
            render_json_value(ss, s);
        }

        template<typename Stream, typename T>
        constexpr auto to_json(Stream& ss, T &&t) -> std::enable_if_t<is_reflection<T>::value>;

        template<typename Stream, typename T>
        auto render_json_value(Stream& ss, T &&t) -> std::enable_if_t<is_reflection<T>::value>
        {
            to_json(ss, std::forward<T>(t));
        }

        template<typename Stream, typename T>
        std::enable_if_t <std::is_enum<T>::value> render_json_value(Stream& ss, T val)
        {
            render_json_value(ss, (std::underlying_type_t<T>&)val);
        }

        template <typename Stream, typename T, size_t N>
        void render_json_value(Stream& ss, const T(&v)[N])
        {
            render_array(ss, v);
        }

        template<typename Stream, typename T>
        void render_array(Stream& ss, const T& v)
        {
            ss.put('[');
            join(ss, std::begin(v), std::end(v), ',',
                 [&ss](const auto &jsv) {
                     render_json_value(ss, jsv);
                 });
            ss.put(']');
        }

        template <typename Stream, typename T, size_t N><commit_msg>fix \include\iguana\json.hpp(119,13): error C3861: 'render_array': identifier not found<commit_after>//
// Created by Qiyu on 17-6-5.
//

#ifndef SERIALIZE_JSON_HPP
#define SERIALIZE_JSON_HPP
#include <string.h>
#include <math.h>
#include "reflection.hpp"

namespace iguana { namespace json
    {
        template<typename InputIt, typename T, typename F>
        T join(InputIt first, InputIt last, const T &delim, const F &f) {
            if (first == last)
                return T();

            T t = f(*first++);
            while (first != last) {
                t += delim;
                t += f(*first++);
            }
            return t;
        }

        template<typename Stream, typename InputIt, typename T, typename F>
        void join(Stream& ss, InputIt first, InputIt last, const T &delim, const F &f) {
            if (first == last)
                return;

            f(*first++);
            while (first != last) {
                ss.put(delim);
                f(*first++);
            }
        }

        template<typename Stream>
        void render_json_value(Stream& ss, std::nullptr_t) { ss.write("null"); }

        template<typename Stream>
        void render_json_value(Stream& ss, bool b) { ss.write(b ? "true" : "false"); };

        template<typename Stream, typename T>
        std::enable_if_t<!std::is_floating_point<T>::value&&(std::is_integral<T>::value || std::is_unsigned<T>::value || std::is_signed<T>::value)>
        render_json_value(Stream& ss, T value)
        {
            char temp[20];
            auto p = itoa_fwd(value, temp);
            ss.write(temp, p-temp);
        }

        template<typename Stream>
        void render_json_value(Stream& ss, int64_t value)
        {
            char temp[65];
            auto p = xtoa(value, temp, 10, 1);
            ss.write(temp, p - temp);
        }

        template<typename Stream>
        void render_json_value(Stream& ss, uint64_t value)
        {
            char temp[65];
            auto p = xtoa(value, temp, 10, 0);
            ss.write(temp, p - temp);
        }

        template<typename Stream, typename T>
        std::enable_if_t<std::is_floating_point<T>::value> render_json_value(Stream& ss, T value)
        {
            char temp[20];
            sprintf(temp, "%f", value);
            ss.write(temp);
        }

        template<typename Stream>
        void render_json_value(Stream& ss, const std::string &s)
        {
            ss.write_str(s.c_str(), s.size());
        }

        template<typename Stream>
        void render_json_value(Stream& ss, const char* s, size_t size)
        {
            ss.write_str(s, size);
        }

        template<typename Stream, typename T>
        std::enable_if_t<std::is_arithmetic<T>::value> render_key(Stream& ss, T t) {
            ss.put('"');
            render_json_value(ss, t);
            ss.put('"');
        }

        template<typename Stream>
        void render_key(Stream& ss, const std::string &s) {
            render_json_value(ss, s);
        }

        template<typename Stream, typename T>
        constexpr auto to_json(Stream& ss, T &&t) -> std::enable_if_t<is_reflection<T>::value>;

        template<typename Stream, typename T>
        auto render_json_value(Stream& ss, T &&t) -> std::enable_if_t<is_reflection<T>::value>
        {
            to_json(ss, std::forward<T>(t));
        }

        template<typename Stream, typename T>
        std::enable_if_t <std::is_enum<T>::value> render_json_value(Stream& ss, T val)
        {
            render_json_value(ss, (std::underlying_type_t<T>&)val);
        }

        template<typename Stream, typename T>
        void render_array(Stream& ss, const T& v)
        {
            ss.put('[');
            join(ss, std::begin(v), std::end(v), ',',
                 [&ss](const auto &jsv) {
                     render_json_value(ss, jsv);
                 });
            ss.put(']');
        }

        template <typename Stream, typename T, size_t N>
        void render_json_value(Stream& ss, const T(&v)[N])
        {
            render_array(ss, v);
        }

        

        template <typename Stream, typename T, size_t N>
{'fraction_non_alphanumeric': 0.1315028901734104, 'fraction_numerical': 0.006382466281310212, 'mean_word_length': 1.8677486187845305, 'pattern_counts': {'":': 0, '<': 77, '<?xml version=': 0, '>': 81, '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': '6489454', 'n_tokens_mistral': 2649, 'n_tokens_neox': 2514, 'n_words': 592}