Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

neilisaac / torch   python

Repository URL to install this package:

Version: 1.8.0 

/ include / ATen / core / dispatch / RegistrationHandleRAII.h

#pragma once

#include <functional>

namespace c10 {

class RegistrationHandleRAII final {
public:
  explicit RegistrationHandleRAII(std::function<void()> onDestruction)
      : onDestruction_(std::move(onDestruction)) {}

  ~RegistrationHandleRAII() {
    if (onDestruction_) {
      onDestruction_();
    }
  }

  RegistrationHandleRAII(const RegistrationHandleRAII&) = delete;
  RegistrationHandleRAII& operator=(const RegistrationHandleRAII&) = delete;

  RegistrationHandleRAII(RegistrationHandleRAII&& rhs) noexcept
      : onDestruction_(std::move(rhs.onDestruction_)) {
    rhs.onDestruction_ = nullptr;
  }

  RegistrationHandleRAII& operator=(RegistrationHandleRAII&& rhs) noexcept {
    onDestruction_ = std::move(rhs.onDestruction_);
    rhs.onDestruction_ = nullptr;
    return *this;
  }

private:
  std::function<void()> onDestruction_;
};

}