All Questions
540
questions
0
votes
1
answer
53
views
How does defining template in vector of map works in c++ [duplicate]
I dont know if this is actually possible, but im trying to represent a field visualization in the form of vector of map , where each position is assign a different key and for every key position, it ...
1
vote
1
answer
81
views
I am trying to write templatized code to compare two vector but i am getting these error
#include <iostream>
#include <string>
#define BLOCK_SIZE 5
template<typename T>
class vec {
T*ptr;
int size;
int capacity;
public:
vec():size(0),capacity(...
1
vote
2
answers
119
views
Better way of writing similar functions that differ only by struct/class member variable name?
I have defined a struct and enums like this:
enum class ETerrainType : uint16_t {/*Enum types here*/};
enum class EBuildingType : uint16_t {/*Enum types here*/};
enum class EDecorationType : uint16_t {...
0
votes
1
answer
98
views
A function with a template in its argument throws an error when called with an int
I am trying to implement my own versioin of std::vector for practice. This is my first time working with templates so it's possible the solution is trivial but I have not been able to find anything on ...
1
vote
2
answers
94
views
Object Factories with variadic templates and parameter packing
I am trying to create a factory that can store a string as key and a lambda function that finds the appropriate constructor and pass the input arguments to it.
The reason is that, I serialize objects ...
2
votes
1
answer
108
views
Why this constructor which imitates `vector`'s initialization from iterators can work?
I use C++17, and I try to implement a fixed-length array whose length is determined at runtime. After consulting some information, I choose to implement it by privately inheriting std::vector. This is ...
-2
votes
1
answer
56
views
Extract type from a template, but dont do it for every types
I have this code
template <typename T>
struct TestWrapper;
template <template <typename> typename Outer, typename T>
struct TestWrapper<Outer<T>> {
T extradata;
vector&...
2
votes
1
answer
162
views
How do I implement a Vector with const correctness that forbids a normal iterator of such Vector to change the value at the address of the iterator
Background:
I am writing my own vector.h for fun (please don't judge). I am trying to remain const correct so I have implemented both a const .begin() function and non const .begin() functions for my ...
-2
votes
1
answer
86
views
Cannot pass struct to template function
So I'm trying to create a sorting function that takes in an std::vector and struct and sorts the vector based on the struct. My code for the function is this:
template<typename T, typename C> ...
0
votes
0
answers
42
views
How can I make this operator overload work?
I am using C++, I am relatively new to the language. Before even compiling, VSCode highlights that my transform call is overloaded. I suspect that this is because of the unclear typename, but this is ...
0
votes
0
answers
38
views
assignment operator in complex type vs arrays in C++ [duplicate]
It seems that BoVector rhs1 and BoVector rhs2 can assign all elements by a = square(bv); successfully. But it might not be a case in a common assignment of one array to another, say
int b[2]{ 1,2,3 };
...
2
votes
2
answers
86
views
Trying to print n-dimensional arrays in cpp
I am trying to print n dimensional arrays using a single function, which calls itself recursively if the parameter we are trying to print is a vector. Otherwise, the character should simply be printed....
0
votes
1
answer
204
views
How to decide a std::vector Type in runtime depends on loop elements type?
I have a list of my own data types, I want to convert it to std::vector of primitive type (int8_t/int/...).
I want to create a vector of primitive type (int32/int8) that will be choosen in runtime ...
1
vote
1
answer
204
views
How to create a template which gets input variables in square brackets? [closed]
First of all, I know my question is too bizarre due to English is not my mother tongue.
I have used Google to learn this but I did not understand anything actually.
I want to create a function like ...
0
votes
0
answers
59
views
Declare different typename once based on string
Lets say I have a function that is defined as
Edit: Added more details and reframed the question, thanks for the input
template <typename A, typename B>
void doSomething(string str, vector<A&...