<commit_before>/*
 *  Copyright (c) 2014, Facebook, Inc.
 *  All rights reserved.
 *
 *  This source code is licensed under the BSD-style license found in the
 *  LICENSE file in the root directory of this source tree. An additional grant
 *  of patent rights can be found in the PATENTS file in the same directory.
 */

#ifndef FATAL_INCLUDE_fatal_container_uninitialized_h
#define FATAL_INCLUDE_fatal_container_uninitialized_h

#include <memory>
#include <utility>

namespace fatal {

///////////////////
// uninitialized //
///////////////////

// TODO: DOCUMENT AND TEST
template <typename T, bool Destroy = true>
struct uninitialized {
  using type = T;

  type const &reference() const noexcept { return container_.value; }

  type &reference() noexcept { return container_.value; }

  type const *pointer() const noexcept {
    return std::addressof(container_.value);
  }

  type *pointer() noexcept { return std::addressof(container_.value); }

  template <typename... Args>
  type &construct(Args &&...args)
    noexcept(noexcept(type(std::forward<Args>(args)...)))
  {
    return *new (pointer()) type(std::forward<Args>(args)...);
  }

  type *destroy() noexcept {
    reference().~type();
    return pointer();
  }

  type const &operator *() const noexcept { return container_.value; }

  type &operator *() noexcept { return container_.value; }

  type const *operator ->() const noexcept {
    return std::addressof(container_.value);
  }

  type *operator ->() noexcept { return std::addressof(container_.value); }


private:
  union union_type {
    union_type() noexcept {} \
    union_type(union_type const &) noexcept {} \
    union_type(union_type &&) noexcept {} \
    ~union_type() noexcept {
      if (Destroy) {
        value.~type();
      }
    }
    type value;
  };

  union_type container_;
};

} // namespace fatal {

#undef // FATAL_INCLUDE_fatal_container_uninitialized_h<commit_msg>- implementing uninitialized in terms of unitary_union<commit_after>/*
 *  Copyright (c) 2014, Facebook, Inc.
 *  All rights reserved.
 *
 *  This source code is licensed under the BSD-style license found in the
 *  LICENSE file in the root directory of this source tree. An additional grant
 *  of patent rights can be found in the PATENTS file in the same directory.
 */

#ifndef FATAL_INCLUDE_fatal_container_uninitialized_h
#define FATAL_INCLUDE_fatal_container_uninitialized_h

#include <fatal/container/unitary_union.h>

#include <memory>
#include <utility>

namespace fatal {

///////////////////
// uninitialized //
///////////////////

// TODO: DOCUMENT AND TEST
template <typename T, bool AutomaticallyDestroy = true>
struct uninitialized {
  using type = T;

  type const &reference() const noexcept { return container_.value; }

  type &reference() noexcept { return container_.value; }

  type const *pointer() const noexcept {
    return std::addressof(container_.value);
  }

  type *pointer() noexcept { return std::addressof(container_.value); }

  template <typename... Args>
  type &construct(Args &&...args)
    noexcept(noexcept(type(std::forward<Args>(args)...)))
  {
    return *new (pointer()) type(std::forward<Args>(args)...);
  }

  type *destroy() noexcept {
    reference().~type();
    return pointer();
  }

  type const &operator *() const noexcept { return container_.value; }

  type &operator *() noexcept { return container_.value; }

  type const *operator ->() const noexcept {
    return std::addressof(container_.value);
  }

  type *operator ->() noexcept { return std::addressof(container_.value); }


private:
  using union_type = unitary_union<type, AutomaticallyDestroy>;

  union_type container_;
};

} // namespace fatal {

#endif // FATAL_INCLUDE_fatal_container_uninitialized_h
{'fraction_non_alphanumeric': 0.13785733368955383, 'fraction_numerical': 0.0021373230029388193, 'mean_word_length': 3.549210206561361, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3198699', 'n_tokens_mistral': 1130, 'n_tokens_neox': 1073, 'n_words': 319}