<commit_before>/**
 * A wrapper to hold any type
 * @since  2016.01.12
 * @author <NAME> <<EMAIL>>
 * @link   http://chensoft.com
 */
#pragma once

#include <type_traits>
#include <utility>

namespace chen
{
    class any final
    {
    public:
        any() = default;
        any(const any &o);
        any(any &&o);

        template <typename T>
        any(T &val)
        : _ptr(new data<typename std::decay<T>::type>(val))
        {
        }

        template <typename T>
        any(const T &val)
        : _ptr(new data<typename std::remove_cv<typename std::decay<const T>::type>::type>(val))
        {
        }

        template <typename T>
        any(T &&val)
        : _ptr(new data<typename std::decay<T>::type>(std::move(val)))
        {
        }

        ~any();

    public:
        /**
         * Copy & Move
         */
        any& operator=(const any &o);
        any& operator=(any &&o);

        /**
         * Assignment
         * e.g: Any a; a = 15;
         */
        template <typename T>
        any& operator=(T &val)
        {
            this->clear();
            this->_ptr = new data<typename std::decay<T>::type>(val);
            return *this;
        }

        template <typename T>
        any& operator=(const T &val)
        {
            this->clear();
            this->_ptr = new data<typename std::remove_cv<typename std::decay<const T>::type>::type>(val);
            return *this;
        }

        template <typename T>
        any& operator=(T &&val)
        {
            this->clear();
            this->_ptr = new data<typename std::decay<T>::type>(std::move(val));
            return *this;
        }

        /**
         * Conversion
         * e.g: Any a(15); int i = a;
         */
        template <typename T>
        operator T() const
        {
            auto d = dynamic_cast<data<T>*>(this->_ptr);
            return d ? d->val : T();
        }

    public:
        /**
         * Test empty
         */
        bool empty() const;

        /**
         * Check type<commit_msg>any: add reference to avoid copy<commit_after>/**
 * A wrapper to hold any type
 * @since  2016.01.12
 * @author <NAME> <<EMAIL>>
 * @link   http://chensoft.com
 */
#pragma once

#include <type_traits>
#include <stdexcept>
#include <utility>

namespace chen
{
    class any final
    {
    public:
        any() = default;
        any(const any &o);
        any(any &&o);

        template <typename T>
        any(T &val)
        : _ptr(new data<typename std::decay<T>::type>(val))
        {
        }

        template <typename T>
        any(const T &val)
        : _ptr(new data<typename std::remove_cv<typename std::decay<const T>::type>::type>(val))
        {
        }

        template <typename T>
        any(T &&val)
        : _ptr(new data<typename std::decay<T>::type>(std::move(val)))
        {
        }

        ~any();

    public:
        /**
         * Copy & Move
         */
        any& operator=(const any &o);
        any& operator=(any &&o);

        /**
         * Assignment
         * e.g: Any a; a = 15;
         */
        template <typename T>
        any& operator=(T &val)
        {
            this->clear();
            this->_ptr = new data<typename std::decay<T>::type>(val);
            return *this;
        }

        template <typename T>
        any& operator=(const T &val)
        {
            this->clear();
            this->_ptr = new data<typename std::remove_cv<typename std::decay<const T>::type>::type>(val);
            return *this;
        }

        template <typename T>
        any& operator=(T &&val)
        {
            this->clear();
            this->_ptr = new data<typename std::decay<T>::type>(std::move(val));
            return *this;
        }

        /**
         * Conversion
         * e.g: Any a(15); int i = a;
         */
        template <typename T>
        operator T() const
        {
            auto d = dynamic_cast<data<T>*>(this->_ptr);

            if (d)
                return d->val;
            else
                throw std::runtime_error("any bad cast");
        }

        /**
         * Reference, avoid copy
         */
        template <typename T>
        T& ref()
        {
            auto d = dynamic_cast<data<T>*>(this->_ptr);

            if (d)
                return d->val;
            else
                throw std::runtime_error("any bad cast");
        }

        template <typename T>
        const T& cref() const
        {
            auto d = dynamic_cast<data<T>*>(this->_ptr);

            if (d)
                return d->val;
            else
                throw std::runtime_error("any bad cast");
        }

    public:
        /**
         * Test empty
         */
        bool empty() const;

        /**
         * Check type
{'fraction_non_alphanumeric': 0.1452653485952133, 'fraction_numerical': 0.004994797086368366, 'mean_word_length': 1.3839285714285714, 'pattern_counts': {'":': 0, '<': 66, '<?xml version=': 0, '>': 86, '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': '5240500', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1401, 'n_words': 344}