Questions tagged [deduction-guide]

30 questions
2
votes
2 answers

Can a class template have more than one user defined deduction guide for the same constructor?

Is it valid to have more than one user defined deduction guide for the same constructor in a class template? For example: template class A { T t; public: A(T t): t(std::move(t)) { /* ... */ } }; template requires (…
Amir Kirsh
  • 12,564
  • 41
  • 74
2
votes
2 answers

Is it possible to get a template function to deduce the type of a template argument using either conversion or deduction guide?

Is it possible to get the compiler to deduce the type for the template function call, using either the type conversion or the deduction guide? And, if not, why not? #include template class Wrapper { public: Wrapper(T&&…
2
votes
1 answer

Can both a 'constexpr'-marked variable and a variable of static-storage duration allowed to be stored through a class type with a deduction guide?

Consider the following piece of code: template struct wrap { T thing; constexpr wrap(T thing) : thing(thing) {} }; template wrap(const T&) -> wrap; template void fun(); struct X { int a; }; int…
lekner
  • 21
  • 1
2
votes
1 answer

Variadic template error: 'In instantiation of' (gcc 9.2)

I'm learning about variadic template on c++17 on the Jason Turner's youtube channel then I copy his example code (shown below). In his video he uses the site godbolt.org with the gcc 7. #include template struct Merged : B…
TheArchitect
  • 1,160
  • 4
  • 15
  • 26
1
vote
1 answer

Constrain an input type in deduction guide

I want my class object's ctor to accept a functor that is able to be converted to a std::packaged_task whereas R is auto deduced from the functor's return value. Here's what I've got so far: Demo #include #include #include…
glades
  • 3,778
  • 1
  • 12
  • 34
1
vote
1 answer

Deduction guide based on number of parameters passed to constructor

Here's something I'm trying that doesn't seem to work: I want to toggle a compile time switch based on how a class object is instantiated. If there's just one constructor argument, the LengthOpt should equal to false, otherwise to true (my…
glades
  • 3,778
  • 1
  • 12
  • 34
1
vote
0 answers

Type is deducted successfully when is wrapped in method, but not when used in direct alias

Code where type deduction is wrapped method struct InterfaceOverriderFactory { template decltype(auto) operator()(Type) const noexcept { return typename…
Nufun
  • 58
  • 4
1
vote
0 answers

Template deduction with some user-supplied arguments

Suppose there is a class with two template parameters template class C { C(B::X x) {} }; is it possible to have a deduction guide where only one of the parameters is inferred and the other is…
1
vote
1 answer

Deduction Guide for a template template parameter

I have a set of structure's class as such: template struct Foo { T x_; T y_; constexpr Foo(T x, T y) : x_{x}, y_{y} {} }; template class Func> class Bar { private: Foo foo_; …
Francis Cugler
  • 7,788
  • 2
  • 28
  • 59
0
votes
1 answer

Is it possible to use fold expression in class template deduction guide?

I did a simple test as follow: #include template struct MyArray { template MyArray(First, Rest...); int dimension[N]; T m_array[D]; }; template…
Nima Ghorab
  • 309
  • 1
  • 3
  • 13
0
votes
1 answer

Deduction guide for brace initializer list

There is a implementation quite similar to std::initializer_list used in an environment where standart C++ library is not available: template class initializer_list { public: using value_type = T; using reference = const T &; …
0
votes
1 answer

Template candidate ignored despite a user provided deduction guide

I have a struct sequence similar to std::integer_sequence, but it can hold values of multiple types as non-type template parameters (sort of like a compile-time tuple). It is implicitly constructible from std::integer_sequence by using a constexpr…
0
votes
1 answer

Deduced conflicting types without template

I'm trying to create a type that can store either an int, a double, or an uint, like so: struct Value { /*...*/ Value& operator=(const int value) { /*...*/ } Value& operator=(const double value) { /*...*/ } Value& operator=(const…
0
votes
1 answer

Why does the class deduction guide fail when using a typedef?

In a piece of the code I currently write I make use of a class deduction guide. You can find the excerpt of the code stripped down to a simple (but meaningless example) below: I've got a class User, which derives its first template parameter from…
mutableVoid
  • 1,284
  • 2
  • 11
  • 29
0
votes
1 answer

How to automaticly deduce template parameter for a function parameter of type `basic_string_view` or the like?

The following is not working: template > void f(std::basic_string_view sv) { } int main(){ std::basic_string_view sv = "no";//ok std::basic_string_view svw = L"shit";//ok …
darune
  • 10,480
  • 2
  • 24
  • 62
1
2