<commit_before>// Copyright (c) 2017 <NAME> <<EMAIL>>. All rights reserved.
// Use of this source code is governed by the BSD license that can be found in
// the LICENSE file.

// Please use std::any of c++17 if available.

#ifndef KL_ANY_H_
#define KL_ANY_H_
#include <memory>
#include <utility>

#include "option.h"

namespace kl {

class Store {
public:
  virtual ~Store() {}
};

template <typename T>
class StoreImpl : public Store {
public:
  StoreImpl() = default;
  template <typename V>  // just a trick of utilizing forwarding reference
  StoreImpl(V &&value) : store_(std::make_unique<T>(std::forward<V>(value))) {}
  const T &Get() { return *store_; }

private:
  std::unique_ptr<T> store_;
};

// it seems safe.
class Any {
public:
  Any() : store_(nullptr) {}

  template <typename T, typename V = typename std::decay<T>::type>
  Any(T &&value) : store_(new StoreImpl<V>(std::forward<T>(value))) {}

  template <typename T>
  Option<T> Of() {
    if (StoreImpl<T> *store = dynamic_cast<StoreImpl<T> *>(store_)) {<commit_msg>minor fix<commit_after>// Copyright (c) 2017 <NAME> <<EMAIL>>. All rights reserved.
// Use of this source code is governed by the BSD license that can be found in
// the LICENSE file.

// Please use std::any of c++17 if available.

#ifndef KL_ANY_H_
#define KL_ANY_H_
#include <memory>
#include <utility>

#include "option.h"

namespace kl {

class Store {
public:
  virtual ~Store() {}
};

template <typename T>
class StoreImpl : public Store {
public:
  StoreImpl() = default;
  template <typename V>  // just a trick of utilizing forwarding reference
  StoreImpl(V &&value) : store_(std::make_unique<T>(std::forward<V>(value))) {}
  const T &Get() { return *store_; }

private:
  std::unique_ptr<T> store_;
};

// it seems safe.
class Any {
public:
  Any() : store_(nullptr) {}

  template <typename T, typename V = typename std::decay<T>::type>
  Any(T &&value) : store_(new StoreImpl<V>(std::forward<T>(value))) {}

  template <typename T>
  Option<T> Of() {
    if (store_ == nullptr) {
      return None();
    }
    if (StoreImpl<T> *store = dynamic_cast<StoreImpl<T> *>(store_)) {
{'fraction_non_alphanumeric': 0.15475070555032927, 'fraction_numerical': 0.005644402634054563, 'mean_word_length': 4.213235294117647, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, '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': '24551', 'n_tokens_mistral': 731, 'n_tokens_neox': 707, 'n_words': 230}