<commit_before>/** printContainer.h --- 
 *
 * Copyright (C) 2010 <NAME>
 *
 * Author: <NAME> <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License v3 as
 * published by the Free Software Foundation and including the exceptions
 * at http://opencog.org/wiki/Licenses
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program; if not, write to:
 * Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */


#ifndef _OPENCOG_PRINTCONTAINER_H
#define _OPENCOG_PRINTCONTAINER_H

#include <iterator>
#include <algorithm>

namespace opencog {
    
    /**
     * stream out all elements in [from, to( with delimiter
     * 'delimiter', opening with 'left' and closing with 'right'.
     *
     * For instance if N = {1, 2, 3, 4} then
     * ostreamContainer(std::cout, N.begin(), N.end(), "{", ";", "}")
     * displays "{1;2;3;4}"
     */
    template<class Out, class It>
    Out& ostreamContainer(Out& out,
                          It from,
                          It to,
                          const std::string& delimiter = "", 
                          const std::string& left = "", 
                          const std::string& right = "")
    {
        out << left;
        if(from != to) {
            It last = --to;
            std::copy(from, last, std::ostream_iterator<typename It::value_type>(out, delimiter.c_str()));
            out << *last;
        }
        out << right;
        return out;
    }

    /**
     * like above but consider the entire container
     */
    template<class Out, class Con>
    Out& ostreamContainer(Out& out,
                          const Con& container,
                          const std::string& delimiter = "", 
                          const std::string& left = "", 
                          const std::string& right = "") {
        return ostreamContainer(out, container.begin(), container.end(),
                                delimiter, left, right);
    }

    /**
     * like ostreamContainer but uses std::cout
     */
    template<class It>
    void printContainer(It from,
                        It to,
                        const std::string& delimiter = "",
                        const std::string& left = "", 
                        const std::string& right = "")
    {
        ostreamContainer(std::cout, from, to,
                         left, delimiter, right);
    }

    template<class Con>
    void printContainer(const Con& container,
                        const std::string& delimiter = "",
                        const std::string& left = "", 
                        const std::string& right = "")
    {
        ostreamContainer(std::cout, container,
                         left, delimiter, right);
    }
    
} // ~namespace opencog
#endif // _OPENCOG_PRINTCONTAINER_H<commit_msg>changed default delimiter of printContainer to one space instead of the empty string<commit_after>/** printContainer.h --- 
 *
 * Copyright (C) 2010 <NAME>
 *
 * Author: <NAME> <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License v3 as
 * published by the Free Software Foundation and including the exceptions
 * at http://opencog.org/wiki/Licenses
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program; if not, write to:
 * Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */


#ifndef _OPENCOG_PRINTCONTAINER_H
#define _OPENCOG_PRINTCONTAINER_H

#include <iterator>
#include <algorithm>

namespace opencog {
    
    /**
     * stream out all elements in [from, to( with delimiter
     * 'delimiter', opening with 'left' and closing with 'right'.
     *
     * For instance if N = {1, 2, 3, 4} then
     * ostreamContainer(std::cout, N.begin(), N.end(), "{", ";", "}")
     * displays "{1;2;3;4}"
     */
    template<class Out, class It>
    Out& ostreamContainer(Out& out,
                          It from,
                          It to,
                          const std::string& delimiter = " ",
                          const std::string& left = "",
                          const std::string& right = "")
    {
        out << left;
        if(from != to) {
            It last = --to;
            std::copy(from, last, std::ostream_iterator<typename It::value_type>(out, delimiter.c_str()));
            out << *last;
        }
        out << right;
        return out;
    }

    /**
     * like above but consider the entire container
     */
    template<class Out, class Con>
    Out& ostreamContainer(Out& out,
                          const Con& container,
                          const std::string& delimiter = " ",
                          const std::string& left = "", 
                          const std::string& right = "") {
        return ostreamContainer(out, container.begin(), container.end(),
                                delimiter, left, right);
    }

    /**
     * like ostreamContainer but uses std::cout
     */
    template<class It>
    void printContainer(It from,
                        It to,
                        const std::string& delimiter = " ",
                        const std::string& left = "",
                        const std::string& right = "")
    {
        ostreamContainer(std::cout, from, to,
                         left, delimiter, right);
    }

    template<class Con>
    void printContainer(const Con& container,
                        const std::string& delimiter = " ",
                        const std::string& left = "", 
                        const std::string& right = "")
    {
        ostreamContainer(std::cout, container,
                         left, delimiter, right);
    }
    
} // ~namespace opencog
#endif // _OPENCOG_PRINTCONTAINER_H
{'fraction_non_alphanumeric': 0.10691727006624557, 'fraction_numerical': 0.0073948544138037284, 'mean_word_length': 1.7970702283498492, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 25, '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': '6485805', 'n_tokens_mistral': 1749, 'n_tokens_neox': 1664, 'n_words': 571}