Skip to main content
Filter by
Sorted by
Tagged with
2 votes
2 answers
123 views

I have some function templates with same signature, and I'm trying to create a proxy function to call them with different types. How to pass the function name to the proxy function correctly? https://...
Tiger Hwang's user avatar
5 votes
1 answer
111 views

I have a following class: template<typename Population, typename... Operators> class GA { public: template<typename Evaluator, typename std::enable_if_t< std::...
Peter's user avatar
  • 121
3 votes
1 answer
143 views

I have a template function: template <class IndexType, class DataType, class EntityType> void my_func(...) I need to instantiate it for many combinations of IndexType/DataType/EntityType. Is ...
user30060245's user avatar
1 vote
2 answers
104 views

Think of a type P that should be thought of as templated by some type T. However, P wraps some perl library, and the type T is only known at run time. On the C++ side, I can ask a P for its type. ...
Bubaya's user avatar
  • 893
1 vote
2 answers
146 views

I want to split a custom interval class into smaller sub-intervals. The number of sub-intervals depends on the number of supplied arguments. An example implementation (compiler-explorer link) with ...
jack's user avatar
  • 1,832
4 votes
1 answer
124 views

Regardless of whether this is a good idea or not, is it allowed in C++ to have two template functions, that differ only in the type of a non-type template parameter. I am asking this question, because ...
K-os's user avatar
  • 248
1 vote
1 answer
65 views

I am new to C++ templates and I'm trying to make a constexpr template function that takes a parameter pack of other functions of return type bool (and in this example input type int) and checks if a ...
Vilim Hrupelj's user avatar
0 votes
3 answers
166 views

C++ version for project is 20. Suppose we have some service class template: template<int someSegmentSize> class SomeAbstractFileService { public: void init() { std::cout << &...
AlecadM's user avatar
0 votes
1 answer
157 views

This question is an extension of another question from a decade ago: #include<functional> template <typename ReturnType, typename... ArgumentTypes> struct Caller { static void Call(std:...
埃博拉酱's user avatar
3 votes
1 answer
191 views

I have a simple cpp template function as follows. #include <iostream> #include <concepts> template <typename T> requires std::integral<T> T add(T a, T b) { std::cout <&...
VivekDev's user avatar
  • 26.1k
1 vote
3 answers
142 views

This is a simple question, yet the Internet offers no answer or examples to this one: what is the correct means of passing a parameter pack to a std::tuple ? I have tried the following, only to find I ...
Ashley Ben Story's user avatar
3 votes
1 answer
98 views

To be short, I want to achieve something like "templatize" the operation of "getting an attribute of a object" as a generalized template function, like the function foo below. ...
LibrarristShalinward's user avatar
8 votes
1 answer
207 views

The code below behaves incorrectly. When f<0> or f<5> is called, it prints as if k = true, but the if statement behaves as if k = false. When f<1> is called, it does the opposite. ...
daniel creatd's user avatar
0 votes
0 answers
127 views

I am trying to do something involving CTAD within function calls and it's best to first explain the desired behavior with an example, before asking my questions. NB: the below is a bit of a ...
georgi koyrushki's user avatar
0 votes
0 answers
52 views

suppose i have this class : template <typename T> class MyClass{ } template <typename T> class MyOtherClass{ } and some generic template function template <typename A> void ...
uray's user avatar
  • 11.6k
1 vote
1 answer
107 views

I need to create a factory function to create an instance that can accept any type with the different number of arguments. I have two classes Employee and Contact and to create an instance for both ...
Muthuraj's user avatar
1 vote
2 answers
127 views

Is it mandatory to have a function template to pass std::vector as an argument as in the below code? Also, in the parameter, why do we need to pass <T> along with std::vector? template <...
Ussu20's user avatar
  • 199
2 votes
2 answers
122 views

I just wrote following simple code but it doesnt compile: #include <iostream> #include <string> class Obj{ public: std::string name = "Name"; std::string l_name = "...
Qwe Qwe's user avatar
  • 557
0 votes
2 answers
82 views

I have a utility function for transforming an iterable according to a functor: template<typename Iterable, typename Functor> auto transform(Iterable const& input, Functor&& ...
H.v.M.'s user avatar
  • 1,746
0 votes
1 answer
107 views

I have a struct which wraps multiple std::sets of data. I want access to the sets to be computed at compile time. To do this, I created a template constexpr getter method to return the requested set. /...
Jeff L's user avatar
  • 683
3 votes
4 answers
179 views

I am trying to wrap a c-style variant in a library. It uses a type enum, which I mean to fill using templates. A simplified version looks roughly like this: enum Type { Type_Int, Type_Double, ...
David van rijn's user avatar
4 votes
1 answer
85 views

In C++, is it possible to create a templated function which takes both a class type and a variable number of arguments? The function I'm imagining would work something like this (although this is ...
Enderhippo's user avatar
2 votes
2 answers
87 views

In the following code, the variable number of arguments assume a string variable in itself but it does not happen for string literals #include <iostream> #include <string> #include <...
soham's user avatar
  • 1,682
0 votes
0 answers
56 views

I have the code like this (it's simplified version, really code more complex): class IFoo { public: template <typename T> T GetInc(T x) const { return x; } }; class Foo : public IFoo { public:...
edmond's user avatar
  • 113
30 votes
1 answer
2k views

In the following example, 0 behaves in a special way: it chooses a different overload than one would expect for one example function call. I would like to know why. My understanding is also below. #...
toxic's user avatar
  • 600
-1 votes
1 answer
126 views

I made function template to pass stack-allocated array as parameter, which is shown below: struct Pos { int row; int col; Pos(int r, int c) { row = r; col = c; } Pos() { ...
Hyun's user avatar
  • 15
0 votes
2 answers
145 views

I am working on a C++ function template and I am trying to find a way to access the function arguments within the template. Specifically, I have a template function called enumerate that takes a ...
킵고잉's user avatar
1 vote
1 answer
118 views

I'm trying to create a overload for a function with variadic template arguments for a type and all its possible derivates. Naively i tried with just one overload and the base class as the first ...
ridilculous's user avatar
1 vote
1 answer
152 views

Consider: template <typename InputIt, typename T = typename std::remove_const<typename InputIt::value_type>::type> std::vector<T> WorkOnIt( InputIt first, InputIt last) { std::...
Mustang's user avatar
  • 449
7 votes
1 answer
201 views

I've defined two versions of a function template called compare: #include <cstring> using namespace std; // fist version template <size_t N, size_t M> int compare(const char (&a)[N], ...
fansure grin's user avatar
5 votes
1 answer
223 views

I have the following small C++ code sample, but I can't figure out why the compiler works this way, although I have spent quite a lot of time studying cppreference. I would appreciate any explanations!...
Евгений Лисицын's user avatar
0 votes
0 answers
83 views

I'm attempting to modify values in an Opencv::Mat using the code below: void gaussian_high_pass_kernel(cv::Mat& gaussianBlur, float sigma) { float d0 = sigma; for (int i = 0; i < scr....
meng lu's user avatar
2 votes
1 answer
116 views

I want to declare member function of template class as friend. But I got warning message such as warning: dependent nested name specifier 'Schedule<T>::' for friend class declaration is not ...
myoldgrandpa's user avatar
  • 1,039
0 votes
2 answers
257 views

If you have a concept and a class member function template like so: template<typename T> concept Vector2 = requires (T t) { t.x; t.y; }; struct Shape { bool contains(const Vector2 auto&)...
JensB's user avatar
  • 959
1 vote
2 answers
137 views

I have a template function parametrized by a compile-time constant whose type should be the same as the type of the function argument. For instance, I'm seeking to have this kind of syntax: #include &...
Oersted's user avatar
  • 3,834
1 vote
1 answer
162 views

my function looks like this template<bool extra> void func(int& arg1, const int arg2){ //a lot of code... if (extra && arg2 > 0) ++arg1; arg1 *= 10; //a lot of ...
fetis's user avatar
  • 33
1 vote
1 answer
121 views

Function-templates can be overloaded by using different template-parameter-lists (if I interpret https://en.cppreference.com/w/cpp/language/function_template correctly). If the template-parameter-...
wimalopaan's user avatar
  • 5,552
0 votes
1 answer
84 views

I have looked at most of the related posts but couldn't find a response that related to my specific usage scenario. The code is as shown below: //classA.h file #include <type_traits> #include &...
Vinod's user avatar
  • 1,215
4 votes
0 answers
200 views

In a header file of a large project, I have to forward declare a function template before the calling site. The code boils down to this: //H1.h #pragma once template <typename> void f(); ...
zwhconst's user avatar
  • 1,647
2 votes
1 answer
377 views

Suppose the following function template<size_t N> constexpr std::array<float, N> make_ones() { std::array<float, N> ret{}; for (size_t k = 0; k != N; ++k) { ret[k]...
user877329's user avatar
  • 6,296
2 votes
2 answers
142 views

What is the difference between using "typename" before the return type of a function and without using it at the declaration of a function like the following below? And what is different if ...
Crackie's user avatar
  • 355
0 votes
3 answers
168 views

I want to calculate the sum of any number of arguments given to function sum. Assuming that integers given to the function will satisfy operator+. If I comment out the function sum() (the one having ...
Aditya Garg's user avatar
2 votes
2 answers
155 views

The best way for me to describe what I am asking is a simple example. template<typename T> void execute_example(T* begin, T* end) { T val = 10 * 0.8; while (begin != end) { ...
Sam Moldenha's user avatar
2 votes
3 answers
198 views

What is the proper C++ syntax to supply and use std::less as a template argument? #include <iostream> #include <functional> template<typename CMP> float order(float a, float b) { ...
wcochran's user avatar
  • 11k
9 votes
2 answers
628 views

Despite, the fact, we have std::max, I wanted to try if it is possible to make a Max version that takes variadic arguments and calls the Max recursively for finding the max element. I saw similar ...
MyClass's user avatar
  • 362
2 votes
2 answers
215 views

I am trying to generalize a function for a game engine I am writing to simplify the shader loading process. Anyway, the difficulty arises in my attempts to templating the function. I attempted to ...
ModernEraCaveman's user avatar
0 votes
1 answer
400 views

fn foo<T>() -> f32 { return 0.0; } So I want to define a function that accepts only certain types (e.g. i32, i64, f32) as template parameter. For this case I hope to define only foo<...
Rahn's user avatar
  • 5,565
0 votes
1 answer
200 views

To easily re-write a big switch-case, I'm trying constexpr function template like this (it's only a simplified version with just cout): #include <iostream> template<int T> constexpr void ...
huseyin tugrul buyukisik's user avatar
1 vote
2 answers
1k views

I looked up to this and this SO answers, but none solves my problem. Short description: the template function, where much more should happen than just that of this example, should be able to wrap any ...
deponovo's user avatar
  • 1,442
1 vote
1 answer
136 views

So, I have an assignment for college to create templates for these functions and ive done it by the instructions.. However, the fillDefault, which I had to make a specialization for int doesnt work. I ...
PrzgiBaklo's user avatar

1
2 3 4 5
12