resource.hpp functional type_traits utility serif/utils/dependencies/snapshot.hpp src/include/serif/backend/mfem/solver/normalization/metric_computations.hpp src/include/serif/geometry/surface/samples.hpp src/include/serif/utils/dependencies/dependency_context.hpp serif::utils::dependencies::detail::OwnedValue serif::utils::dependencies::detail::BorrowedValue serif::utils::dependencies::Resource serif serif::utils serif::utils::dependencies serif::utils::dependencies::detail #pragmaonce #include<functional> #include<type_traits> #include<utility> #include"serif/utils/dependencies/snapshot.hpp" namespaceserif::utils::dependencies{ namespacedetail{ template<typenameT> structOwnedValue{ usingTarget=T; Tvalue; [[nodiscard]]constT&get()const{returnvalue;} }; template<typenameT> structBorrowedValue{ usingTarget=T; std::reference_wrapper<constT>value; [[nodiscard]]constT&get()const{returnvalue.get();} }; } template<typenameKeyT,typenameStorageT,typenamePolicyT> classResource{ public: usingKey=KeyT; usingTarget=typenameStorageT::Target; usingPolicy=PolicyT; Resource(StorageTstorage,PolicyTpolicy):m_storage(std::move(storage)),m_policy(std::move(policy)){} [[nodiscard]]constTarget&get()const{returnm_storage.get();} [[nodiscard]]constPolicyT&policy()const{returnm_policy;} private: StorageTm_storage; PolicyTm_policy; }; template<typenameT> inlineconstexprboolis_resource_v=false; template<typenameKeyT,typenameStorageT,typenamePolicyT> inlineconstexprboolis_resource_v<Resource<KeyT, StorageT, PolicyT>>=true; template<typenameT> conceptIsResource=is_resource_v<std::remove_cvref_t<T>>; template<typenameKeyT,typenameValueT,typenamePolicyT=ValueSnapshot> [[nodiscard]]autoown(ValueT&&value,PolicyTpolicy={}){ usingStorage=detail::OwnedValue<std::decay_t<ValueT>>; returnResource<KeyT, Storage, PolicyT>(Storage{.value=std::forward<ValueT>(value)},std::move(policy)); } template<typenameKeyT,typenameValueT,typenamePolicyT=ValueSnapshot> [[nodiscard]]autoborrow(ValueT&value,PolicyTpolicy={}){ usingStorage=detail::BorrowedValue<ValueT>; returnResource<KeyT,Storage,PolicyT>(Storage{.value=std::cref(value)},std::move(policy)); } template<typenameKeyT,typenameValueT,typenamePolicyT=ValueSnapshot> autoborrow(constValueT&&,PolicyT={})=delete; }