Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
-1 votes
3 answers
91 views

C++ function as a parameter where its parameter can be passed by value or by reference

I have the following functions where processArray is a generic function that is used to process an array. A function is passed to it as a parameter so that each element can also be processed. template&...
mihails.kuzmins's user avatar
1 vote
2 answers
64 views

c++ template template syntax: simplicity vs useability why not 'auto'

first code below compiled fine after sweating with the word 'class' five times in one line, and definition in "main" of shelf<std::vector, int> top_shelf; looks too fragmented to me, ...
Ammar Tamimi's user avatar
1 vote
2 answers
162 views

C++ : rebind variable of generic type

Re-use heap memory for generic types by rebinding variables. What I want to do: template <typename T> //unconstrained type //... { //in some complex procedural logic T rebindable = .../*r-...
user avatar
4 votes
2 answers
1k views

Access only one element of a pair in an unordered_map in c++

I'm trying to get the same behavior as a rust tuple destructuring in C++. For example: I have an unordered_map I want to iterate over. However, The only data that I care about are the values, and not ...
ltabis's user avatar
  • 113
1 vote
2 answers
691 views

How can I create a value_type type trait?

I am writing a program that will deal heavily with strings of varying types (i.e. std::string, std::string_view, const char*, char[], and friends with varying CharT). So, I am interesting in writing a ...
Wil's user avatar
  • 115
0 votes
3 answers
50 views

I have template function. by using function std::for_each replace every positive number by biggest number from this container

template function gets 2 iterators, begin and end iterators. template data type iterType is iterator type. I have error when trying to equate current iterator value to maximal value in lambda function ...
user163564's user avatar
2 votes
3 answers
129 views

Can you use a member of deleter to keep alive a shared_ptr?

Given the following types // interface and implementation used in one part of the codebase struct Image { virtual std::vector<uint8_t>& GetData () = 0; }; struct VecImage : public ...
marczellm's user avatar
  • 1,326
0 votes
1 answer
703 views

STL Iterator Inheritance : 'value_type' does not name a type

I am stuck trying to understand where this error comes from: error: ‘value_type’ in ‘struct std::iterator_traits<sha::Vector<int>::h_iterator>’ does not name a type I am trying to ...
Hybesis's user avatar
  • 127
8 votes
3 answers
3k views

Polymorphism (inheritance) and value types

I have a bunch of types, PixelMeasure, PointMeasure, CentimeterMeasure and so on, that represent a value with a unit. I would like them to have value semantics: e.g. effectively immutable, don't have ...
jdm's user avatar
  • 9,890
-2 votes
1 answer
1k views

c++ template argument deduction/substitution failed, in void parameter function [closed]

I try to implement simple get() function in linked list, which can store various types of data (One list can store char, string, int, float, ... in each node) class List{ //... template<...
user4315272's user avatar
-1 votes
2 answers
200 views

Why Can't I Get the bool Value from a value_type Returned by decltype?

This appears to be a visual-studio problem. This code runs fine in gcc but fails to compile in Visual Studio: #include <iostream> #include <type_traits> #include <typeinfo> using ...
Jonathan Mee's user avatar
  • 38.6k
6 votes
2 answers
1k views

Traits class to extract container's value_type from a back_insert_iterator

The std::back_insert_iterator has value_type equal to void, but it also has a protected member container that holds a pointer to the underlying Container. I am trying to write a traits class to ...
TemplateRex's user avatar
  • 70.1k
1 vote
2 answers
2k views

C++ Array or Vector of template classes with different value-type template parameters

One application needs to handle a set of datasets on which some operations can be performed. Each data set contains an array of points of a specific data type (int32, int16, float, complex) and the ...
davide's user avatar
  • 11
1 vote
1 answer
2k views

Why "const" is ignored in "const typename iterator_traits<RandomIterator>::reference"?

I have the following function and vector: template <class RandomIterator> RandomIterator upperBound(RandomIterator start, RandomIterator end, const typename iterator_traits<RandomIterator&...
user3068202's user avatar
32 votes
4 answers
21k views

How can I get sizeof a vector::value_type?

I want to get sizeof of the type that is contained in a vector. Here is what I tried: #include <iostream> #include <vector> int main() { std::vector<uint> vecs; std::cout &...
Chris's user avatar
  • 7,074

15 30 50 per page