#pragma once #ifndef FUNCTION_VIEW_INL_H_ #error "Direct inclusion of this file is not allowed, include function_view.h" // For the sake of sane code completion. #include "function_view.h" #endif #include namespace NYT { //////////////////////////////////////////////////////////////////////////////// template template TConcrete> TFunctionView::TFunctionView(TConcrete& concreteRef) noexcept : TFunctionView(&concreteRef) { } template template TConcrete> TFunctionView::TFunctionView(TConcrete* concretePtr) noexcept { Ptr_ = reinterpret_cast(concretePtr); Invoke_ = &TFunctionView::ConcreteInvoke; } template TFunctionView TFunctionView::Release() noexcept { auto copy = *this; Reset(); return copy; } template TResult TFunctionView::operator()(TArgs... args) noexcept(NoExcept) { YT_VERIFY(Ptr_); return Invoke_(std::forward(args)..., Ptr_); } template template TResult TFunctionView::ConcreteInvoke(TArgs... args, TErasedPtr ptr) noexcept(NoExcept) { return (*reinterpret_cast(ptr))(std::forward(args)...); } template TFunctionView::operator bool() const noexcept { return IsValid(); } template bool TFunctionView::IsValid() const noexcept { return Ptr_ != nullptr; } template void TFunctionView::Reset() noexcept { Ptr_ = nullptr; } //////////////////////////////////////////////////////////////////////////////// } // namespace NYT