Skip to main content
2 votes
2 answers
153 views

Is there a way to prevent implicit conversions happening in concepts? For example, this example compiles with GCC and clang when I actually want it to give an error that the char constructor is ...
Hello Worlder's user avatar
5 votes
1 answer
205 views

Only for academic reasons I try out SFINAE vs. concepts and wrote my own traits. I know there is std::is_integral and a lot of other stuff. I use decltype( ptr+ T{}){}; to check if it is an integer ...
Klaus's user avatar
  • 26.1k
Advice
1 vote
1 replies
102 views

Why can't we put a constraint on the first type parameter of the concept? Why can't we use the short form of the concept for non-type parameter? Why is it possible to specialize concepts only in ...
ValeriyKarasikov's user avatar
7 votes
2 answers
406 views

I am trying to come up with a way to determine, whether a given format string is valid for a given Type at compile time. I was expecting for a simple concept to work: template<typename T> ...
Jens's user avatar
  • 213
3 votes
0 answers
131 views

Having issues finding a syntax for hoisting constrained member function outside of its class that GCC is happy with. At this point I'm starting to think it's a GCC bug. struct S { template<...
Thibaut's user avatar
  • 2,460
3 votes
2 answers
199 views

I've a C++ concept where I need to check that the class has a particular public attribute. My problem is that the concept works if I use it directly, but fails if I use it in std::visit. This is the ...
Jepessen's user avatar
  • 12.7k
2 votes
1 answer
156 views

Here is some basic example: template <typename T, typename Callable> constexpr auto foo(T arg, Callable&& make) -> decltype(make(std::declval<T>())) { return make(arg); }...
Oersted's user avatar
  • 3,914
7 votes
2 answers
224 views

I have a function that should only accept 3-component vector types. I have: template <typename T> concept Vec3Like = requires(T t) { t.x; t.y; t.z; }; template <Vec3Like vec3_t, ...
Zebrafish's user avatar
  • 16.6k
6 votes
0 answers
246 views

Given the concept, template <typename T> concept CanFoo = requires(Eigen::Array2d const& x) { { T::Foo(x) } -> std::same_as<double>; }; I expect, as someone new to actually ...
Jack's user avatar
  • 61
2 votes
2 answers
112 views

I want to write a function that moves the data of a container into another container using an iterator pair. I have the following concept: template <typename Iter, typename T> concept ...
Raildex's user avatar
  • 5,468
22 votes
3 answers
2k views

This is similar to Understanding concepts. Check if a member is static, but that Q&A only asks why it doesn't work, and here I'm asking how to fix it. Consider the following code: struct A { ...
HolyBlackCat's user avatar
4 votes
2 answers
185 views

I have several structs in the form struct MyStruct1 { std::string myName; // ... } but not all of them have a member of type std::string and variable named myName. I'm writing a function template,...
RocketSearcher's user avatar
15 votes
1 answer
406 views

When using a type constraint on a forwarding reference argument, the constraint is given as an lvalue reference to the type. For example, the call to h in the following code does not compile because ...
Sven Sandberg's user avatar
2 votes
0 answers
97 views

Usually I define my template classes as following (template<template<class> class T> is essential here): // Foo.h template<template<class> class T> class Foo { void foo(); ...
master_clown's user avatar
5 votes
1 answer
170 views

The libstdc++ implementation of std::ranges::ref_view, following the C++ standard, includes the following code: template<range _Range> requires is_object_v<_Range> class ref_view : ...
Fei Du's user avatar
  • 80

15 30 50 per page
1
2 3 4 5
91