CppCoreGuidelines icon indicating copy to clipboard operation
CppCoreGuidelines copied to clipboard

T.46 contradicts the idea of type traits and is not resource-friendly

Open kitsnet opened this issue 7 months ago • 1 comments

T.46, which requires types used as template arguments to be at least semiregular, seems to make type traits use (or any kind of generic compile-time reasoning based on types) disallowed for non-default-constructible and/or non-copyable types.

Another problem with T.46 is that it disallows using generic implementations with resource-conscious or lifetime-conscious types. Even the example of std::vector<T>, provided as a motivation for the rule, can show the deficiency of this rule when T is (non-copyable) std::unique_ptr.

kitsnet avatar Aug 01 '25 09:08 kitsnet

I agreed this rule is out of place. A template should not unnecessary constrain parameters and semi-regualar could exclude valid uses. Stl vector and sort do not require semi-regular. It also contriducts rule T.40 which recommends passing function objects which don't have to be semi-regular.

bgloyer avatar Aug 02 '25 07:08 bgloyer