Tag: templates
-
std::enable_if_t works with gcc and clang but does not compile with msvc
8 I have a friend function template operator<< that works with both gcc and clang but not with msvc. #include <iostream> #include <type_traits> template< typename T, std::enable_if_t< T{1}, int> =0 > class Foo { template< typename Ar, typename R> friend Ar& operator<<(Ar& os, const Foo<R>& foo) { return os; } }; int main() { Foo<int>…
-
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…
-
How do you create a template with replaceable variables for JS/React?
0 Context: I want to create a GraphQL query template with different variables that I can replace with key/values from another dictionary I want to give JS/React this template and dictionary and be able to replace the variables in the template with the corresponding values in the dictionary How would you recommend I do this?…
-
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…