C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Another typing laziness features

From: organicoman <organicoman_at_[hidden]>
Date: Sun, 13 Mar 2022 02:59:47 +0400
>Hello All,>The '=default ' keyword next to a structure's >special functions could be extended to the >following:>struct needsAhash{ int m_i; SomeComplicatedType m_t; /*define here the necessary Ctors & al*/ ... auto hash(int val) const = std::hash<int>(needsAhash::m_i);};>In the above snippet, i mixed a member >function declaration with a plain function call.>The intention is to tell the compiler to stamp >the following:auto hash(int val){ return std::hash<int>(m_i);}auto hash(int val) : is the member function std::hash<int>(needsAhash::m_i) : is the implementation function. >The compiler is supposed to copy all the >declaration specifiers of the "implementation >function" into the member function,.i.e inline, >noexcept, constexpr...etc then add on top of >them the specifiers declared with the >member function. >What do you think about this feature?Or maybe the syntax could be like this also:auto hash(int val) const = [m_i] std::hash<int>;Where we capture the member variable by value or by reference or whatever specifiers we like.In this alternative syntax, i avoided the function call and used a "function capture", i.e capturing the function declaration and implementation for the data member "m_i" then stamp it into the member function, while preserving any other member function declaration specifiers provided by the programmer. Nadir. Sent from my Galaxy
-------- Original message --------From: organicoman via Std-Proposals <std-proposals_at_[hidden]> Date: 3/13/22 2:42 AM (GMT+04:00) To: std-proposals_at_[hidden] Cc: organicoman <organicoman_at_[hidden]> Subject: [std-proposals] Another typing laziness features Hello All,The '=default ' keyword next to a structure's special functions could be extended to the following:struct needsAhash{ int m_i; SomeComplicatedType m_t; /*define here the necessary Ctors & al*/ ... auto hash(int val) const = std::hash<int>(needsAhash::m_i);};In the above snippet, i mixed a member function declaration with a plain function call.The intention is to tell the compiler to stamp the following:auto hash(int val){ return std::hash<int>(m_i);}auto hash(int val) : is the member function std::hash<int>(needsAhash::m_i) : is the implementation function. The compiler is supposed to copy all the declaration specifiers of the "implementation function" into the member function,.i.e inline, noexcept, constexpr...etc then add on top of them the specifiers declared with the member function. What do you think about this feature?Nadir.

Received on 2022-03-12 22:59:52