Tag: language-design
-
Why does ranges::for_each return the function?
10 The legacy std::for_each returns function as the standard only requires Function to meet Cpp17MoveConstructible according to [alg.foreach]: template<class InputIterator, class Function> constexpr Function for_each(InputIterator first, InputIterator last, Function f); Preconditions: Function meets the Cpp17MoveConstructible requirements. [Note: Function need not meet the requirements of Cpp17CopyConstructible. end note] This is reasonable since the user may want to…
-
Why does C++ have no std::invocable_r concept?
11 C++20 added concepts, and the standard library includes quite a few of them. One concept in particular caught my eye: std::invocable which validates that a functor can be invoked with a set of arguments. std::invocable is just syntactic sugar for std::is_invocable. However, the standard library further defines std::is_invocable_r which tests whether a functor can…
-
What is the purpose of _t aliases and _v variable templates for type traits?
7 There are a lot of *_v and *_t suffixes, like std::is_same_v, std::invoke_result_t, result_of_t and milions of other such functions. Why do they exist at all? Is it beneficial in any context to expose implementation details like std::result_of::type or std::is_same::value? Ignoring standard compliance, should the _v _t versions always be preferred? Could the ::type ::value…