758 questions
1
vote
1
answer
110
views
Is it possible to expand/deduce a parameter pack to/from array dimensions?
I am using the following code for automatic vector/matrix template parameter deduction (I am particullarily interested in automatic deduction from passing initializer lists)
template<class T, ...
6
votes
1
answer
169
views
Template argument deduction for templated conversion operator
Consider the following example:
struct S {
template< typename T >
operator T () {
std::cout << __PRETTY_FUNCTION__;
return T{};
}
};
int main() {
S s{};
...
0
votes
0
answers
59
views
variadic template parameters in non-deduced context of a function template [duplicate]
Question for C++ (starting from C++11) language lawyers.
Given the following trivial function template with a template parameter pack of integer values
template <int ... Is, typename T>
void foo ...
2
votes
1
answer
199
views
"function with deduced return type cannot be used before it is defined" when using template <> specialization
I'm running into an issue with function template specialization and return type deduction in C++. The following minimal example is meant to demonstrate the problem (https://godbolt.org/z/WT1Prnfh6):
#...
3
votes
1
answer
114
views
Is it possible to deduce a class template size_t parameter from the size of a braced initializer list?
Is there a way to get this class to deduce the size of the internal array from a brace enclosed initialization list?
#include <array>
template <typename Key, typename Value, size_t N>
...
4
votes
1
answer
168
views
Why does template deduction for a nested std::array with one element result in a one dimensional std::array?
The following code compiles successfully with clang and gcc. Naively, I would have expected a2 to have type std::array<std::array<int, 1>, 1>.
#include <array>
auto a1 = std::array{...
3
votes
2
answers
106
views
Disambiguating ambiguous function overloads because of converting constructor
Given a wrapper type
template <typename T>
struct Ptr
{
Ptr(T*);
};
a class hierarchy
struct Base {};
struct Derived : Base {};
and a set of function overloads
void f(Ptr<Base>);
...
0
votes
1
answer
54
views
template argument deduction with variadic template template
Example code could be found below or on compiler explorer. All 3 cases are allowed by gcc while SVariadicTemplate<S>::foo is rejected by clang and MSVC. Which compiler is correct on this case?
#...
6
votes
1
answer
85
views
How to make one function argument have priority when deducing template argument
I'm trying to write a set of util functions simplifying work with bit flags. One of them is
template< typename Flags >
void toggleFlag( Flags & targetFlags, Flags flagToSet, bool enabled )
{
...
2
votes
1
answer
125
views
C++ Templated Overload Resolution Fails Where Standard Resolution Wouldn't
There appears to be a discrepancy in how templated function overloads are resolved and how non-templated function overloads are resolved, but there seem to be some cases where it should not make a ...
2
votes
1
answer
122
views
How to pass an element of type T and an array of that T type as reference to a function in C++?
I have the following two functions, but I always get this compiler error:
deduced conflicting types for parameter 'T'
I figure that the problem is that T refers to an array and int at the same time, ...
2
votes
0
answers
37
views
Why does template-argument deduction work differently for function-templates compared to class-templates (via their constructors)? [duplicate]
I have a class structured like this, where FixedStr is implicitly constructible from a string-literal:
template<FixedStr K, class... T>
struct ParserCtx {
Parser<T...> parser;
...
0
votes
2
answers
101
views
how missing template argument is valid in one but not valid in other function?
why template argument missing in print_all(arr&) is valid but not in f(std::vector&) ?
source code link.
What am I missing ? please explain what happens when we compile ?
template<typename ...
0
votes
1
answer
106
views
How do I test if a class is derived from an arbitrary template class without specifying arguments? [duplicate]
I'm trying to make a complete concept is_derived_from_template where we take some typename DerivedSubject and some template<typename...> typename BasePredicate and see if DerivedSubject derives ...
0
votes
1
answer
48
views
Template type deducion for lambda inside packaged_task
Trying to create a JobProcessor that can execute any Job using packaged_task:
class JobProcessor
{
public:
JobProcessor(uint8_t numThreads = 8);
template<class Fn, class... ...