cppfront icon indicating copy to clipboard operation
cppfront copied to clipboard

[SUGGESTION] add special cases for [unique.]new and shared.new when using custom deleters

Open farmerpiki opened this issue 1 year ago • 0 comments
trafficstars

Will your feature suggestion automate or eliminate X% of current C++ guidance literature? not for cpp1 but it would definitely help improve initialization and remove some of the duplication and guidance for cpp2

and [unique.]new_with_deleter and shared.new_with_deleter ... or make an overload for new with 2 template parameters there's 2 major ways to declare these in current c++

  • std::unique_ptr<EC_KEY, decltype(&EC_KEY_free)> ec_pubkey{..., &EC_KEY_free}; or
  • std::unique_ptr<PGresult,decltype([](PGresult* ptr) -> void { PQclear(ptr); })> ... for the second declaration you luckily don't have to repeat the destructor these would look significantly nicer in cpp2 if for version 1 we only need to specify the function once, and also be simpler to think about if we had a unified syntax.

I'm also curious if maybe there was a real good technical reason the equivalent make_unique, make_shared with destructors are missing from cpp? I tried searching for this but it would seem I can't formulate the question in a way that I find answers

farmerpiki avatar Aug 09 '24 11:08 farmerpiki