Tag: c++-concepts
-
How to reuse the return type of a function call inside a requires expression?
7 I’m writing a concept that checks if a type can be used in an expression that composes 2 functions: template<typename T> concept C = requires(T t) { f(g(t)); }; i.e., I want to check if for a given object t of type T, I can call g(t) and then use the resulting value as…
-
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…
-
C++20 use concept to restrict an ‘auto’ non-type template argument?
9 I have a template class taking several non-type arguments (GPIO descriptors). Auto is used to allow several different GPIO implementations to be used. These implementations can’t derive from a common base class. Can I use a concept to restrict these arguments to ones with the right interface? I got a concept but it’s not…
-
Inconsistent behavior of std::common_reference_with on tuples. Which is correct?
11 Background: I’m trying to port a library to compile on MSVC. That library stores data in a tuple of vectors (std::tuple<std::vector<Ts>…>), and uses a custom iterator to iterate over all vectors simultaneously (similar to what a zip_iterator does). The iterator defines types that look like this (assuming Ts… -> <int, int>) : `value_type` is…
-
declval()() – what does this mean in the below context?
18 This is from: https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/include/std/type_traits template<typename _Xp, typename _Yp> using __cond_res = decltype(false ? declval<_Xp(&)()>()() : declval<_Yp(&)()>()()); … template<typename _Tp1, typename _Tp2> struct __common_reference_impl<_Tp1, _Tp2, 3, void_t<__cond_res<_Tp1, _Tp2>>> { using type = __cond_res<_Tp1, _Tp2>; }; I’m trying to figure out what _Xp(&)() is – is it a function call signature? i.e. a constructor? Doesn’t really…