<commit_before>/**
 * @file
 */
#pragma once
#if !USE_LAZY_DEEP_CLONE

#include "libbirch/config.hpp"
#include "libbirch/clone.hpp"
#include "libbirch/EagerMemo.hpp"
#include "libbirch/Nil.hpp"
#include "libbirch/SwapClone.hpp"
#include "libbirch/SwapContext.hpp"

#include <tuple>

namespace bi {
/**
 * Wraps another pointer type to apply lazy deep clone semantics.
 *
 * @ingroup libbirch
 *
 * @tparam P Pointer type.
 */
template<class P>
class EagerPtr {
  template<class U> friend class EagerPtr;
public:
  using T = typename P::value_type;
  template<class U> using cast_type = EagerPtr<typename P::template cast_type<U>>;

  /**
   * Constructor.
   */
  EagerPtr(const Nil& = nil) {
    //
  }

  /**
   * Constructor.
   */
  EagerPtr(T* object) :
      object(object) {
    //
  }

  /**
   * Constructor.
   */
  EagerPtr(const P& object) :
      object(object) {
    //
  }

  /**
   * Copy constructor.
   */
  EagerPtr(const EagerPtr<P>& o) :
      object(cloneUnderway ? static_cast<T*>(currentContext->get(o.get())) : o.object) {
    //
  }

  /**
   * Generic copy constructor.
   */
  template<class Q>
  EagerPtr(const EagerPtr<Q>& o) :
      object(o.object) {
    //
  }

  EagerPtr(EagerPtr<P> && o) = default;
  EagerPtr<P>& operator=(const EagerPtr<P>& o) = default;
  EagerPtr<P>& operator=(EagerPtr<P> && o) = default;

  /**
   * Generic copy assignment.
   */
  template<class Q>
  EagerPtr<P>& operator=(const EagerPtr<Q>& o) {
    object = o.object;
    return *this;
  }

  /**
   * Generic move assignment.
   */
  template<class Q>
  EagerPtr<P>& operator=(EagerPtr<Q> && o) {
    object = o.object;
    return *this;
  }

  /**
   * Value assignment.
   */
  template<class U,
      typename = std::enable_if_t<bi::has_assignment<T,U>::value>>
  EagerPtr<P>& operator=(const U& o) {
    *get() = o;
    return *this;
  }

  /**
   * Value conversion.
   */
  template<class U,
      typename = std::enable_if_t<bi::has_conversion<T,U>::value>>
  operator U() const {
    return static_cast<U>(*get());
  }

  /**
   * Is the pointer not null?
   */
  bool query() const {
    return static_cast<bool>(object);
  }

  /**
   * Get the raw pointer.
   */
  T* get() {
    return object.get();
  }

  /**
   * Get the raw pointer.
   */
  T* get() const {
    return object.get();
  }

  /**
   * Get the raw pointer as const.
   */
  const T* pull() {
    return object.get();
  }

  /**
   * Get the raw pointer as const.
   */
  const T* pull() const {
    return object.get();
  }

  /**
   * Deep clone.
   */
  EagerPtr<P> clone() const {
    SwapClone swapClone(true);
    SwapContext swapContext(EagerMemo::create());
    return EagerPtr<P>(static_cast<T*>(currentContext->copy(object.get())));
  }
<commit_msg>Fixed eager clone for null pointers.<commit_after>/**
 * @file
 */
#pragma once
#if !USE_LAZY_DEEP_CLONE

#include "libbirch/config.hpp"
#include "libbirch/clone.hpp"
#include "libbirch/EagerMemo.hpp"
#include "libbirch/Nil.hpp"
#include "libbirch/SwapClone.hpp"
#include "libbirch/SwapContext.hpp"

#include <tuple>

namespace bi {
/**
 * Wraps another pointer type to apply lazy deep clone semantics.
 *
 * @ingroup libbirch
 *
 * @tparam P Pointer type.
 */
template<class P>
class EagerPtr {
  template<class U> friend class EagerPtr;
  public:
  using T = typename P::value_type;
  template<class U> using cast_type = EagerPtr<typename P::template cast_type<U>>;

  /**
   * Constructor.
   */
  EagerPtr(const Nil& = nil) {
    //
  }

  /**
   * Constructor.
   */
  EagerPtr(T* object) :
      object(object) {
    //
  }

  /**
   * Constructor.
   */
  EagerPtr(const P& object) :
      object(object) {
    //
  }

  /**
   * Copy constructor.
   */
  EagerPtr(const EagerPtr<P>& o) {
    if (cloneUnderway && o.object) {
      object = static_cast<T*>(currentContext->get(o.get()));
    } else {
      object = o.object;
    }
  }

  /**
   * Generic copy constructor.
   */
  template<class Q>
  EagerPtr(const EagerPtr<Q>& o) :
      object(o.object) {
    //
  }

  EagerPtr(EagerPtr<P> && o) = default;
  EagerPtr<P>& operator=(const EagerPtr<P>& o) = default;
  EagerPtr<P>& operator=(EagerPtr<P> && o) = default;

  /**
   * Generic copy assignment.
   */
  template<class Q>
  EagerPtr<P>& operator=(const EagerPtr<Q>& o) {
    object = o.object;
    return *this;
  }

  /**
   * Generic move assignment.
   */
  template<class Q>
  EagerPtr<P>& operator=(EagerPtr<Q> && o) {
    object = o.object;
    return *this;
  }

  /**
   * Value assignment.
   */
  template<class U,
      typename = std::enable_if_t<bi::has_assignment<T,U>::value>>
  EagerPtr<P>& operator=(const U& o) {
    *get() = o;
    return *this;
  }

  /**
   * Value conversion.
   */
  template<class U,
      typename = std::enable_if_t<bi::has_conversion<T,U>::value>>
  operator U() const {
    return static_cast<U>(*get());
  }

  /**
   * Is the pointer not null?
   */
  bool query() const {
    return static_cast<bool>(object);
  }

  /**
   * Get the raw pointer.
   */
  T* get() {
    return object.get();
  }

  /**
   * Get the raw pointer.
   */
  T* get() const {
    return object.get();
  }

  /**
   * Get the raw pointer as const.
   */
  const T* pull() {
    return object.get();
  }

  /**
   * Get the raw pointer as const.
   */
  const T* pull() const {
    return object.get();
  }

  /**
   * Deep clone.
   */
  EagerPtr<P> clone() const {
    if (object) {
      SwapClone swapClone(true);
      SwapContext swapContext(EagerMemo::create());
      return EagerPtr<P>(static_cast<T*>(currentContext->copy(object.get())));
    } else {
      return EagerPtr<P>();
    }
  }

{'fraction_non_alphanumeric': 0.16646006729236762, 'fraction_numerical': 0.0, 'mean_word_length': 2.604339502233567, 'pattern_counts': {'":': 0, '<': 70, '<?xml version=': 0, '>': 74, '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': '4081128', 'n_tokens_mistral': 2138, 'n_tokens_neox': 2096, 'n_words': 439}