Questions tagged [inserter]
20 questions
13
votes
2 answers
Inserters for STL stack and priority_queue
std::vector, std::list and std::deque have std::back_inserter, and std::set has std::inserter.
For std::stack and std::priority_queue I would assume the equivalent inserter would be a push() but I can't seem to find the correct function to call.
My…
Matthieu N.
6
votes
2 answers
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 extract the container's value_type, along these…

TemplateRex
- 69,038
- 19
- 164
- 304
6
votes
1 answer
Improving efficiency of std::copy() with back_inserter() or inserter()
back_inserter and insert_iterator are very handy, but they're also very inefficient!
When you're appending chars, for example, there is a great deal of overhead for every element when you're copying, when in many situations, there really doesn't…

user541686
- 205,094
- 128
- 528
- 886
4
votes
2 answers
std::inserter not working
I am writing a code, in which one of the files uses set_intersection function, and the last parameter to this function is supposed to be an inserter. But when I compile the code, I see the following errors:
error C2039: 'inserter' : is not a member…

user1232138
- 5,451
- 8
- 37
- 64
3
votes
1 answer
Why is appending std::deque object to itself through std::copy successful if the deque is not large enough?
The book is right, I just misread a line.
As the answer by @uneven_mark clearly points out, the following question hinges upon a misreading of mine.
While reading The C++ Standard Library (2nd edition) by Josuttis, I got somehow convinced that coll…

Enlico
- 23,259
- 6
- 48
- 102
3
votes
1 answer
Insert Iterators vs container's member function inserter
I've been studying stl for the past two weeks and been dealing with alot of vector, deque, and list. All those times I've been using push_back(), push_front(), insert(). Currently though, I've been introduced to "Insert Iterators" which are…

Joey Arnold Andres
- 368
- 4
- 15
2
votes
1 answer
Why is std::inserter so slow?
Let's consider the following code
#include
using container = std::vector;
const int size = 1000000;
const int count = 1000;
void foo(std::insert_iterator ist)
{
for(int i=0; i

Amxx
- 3,020
- 2
- 24
- 45
1
vote
1 answer
stl copy () iterator: binary '>>' : no operator found
Here I have a basic example from a pdf on STL.
Why doesn't it work?
#include "stdafx.h"
#include
#include
#include
#include
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
vector…

4pie0
- 29,204
- 9
- 82
- 118
1
vote
1 answer
Error: Overloading ambiguity between "std::copy
I have a code like below:
#include
#include
std::set s1;
std::set s2;
std::set myresult;
void some_func() {
std::set_difference(s1.begin(), s1.end(), s2.begin(),…

Vijay
- 65,327
- 90
- 227
- 319
1
vote
1 answer
BQ Insert to record type successful not data not inserted
I'm trying to insert data into Bigquery following the example at
text with pre-created table as against the given example.
My code is as follows
type tagInfo struct {
proj_name string `bigquery:"proj_name"`
Tags Tags …

Sreekanth
- 13
- 4
1
vote
1 answer
What's the idiomatic way to get a backwards inserter with a fallback to any inserter?
I want to insert elements into a STL container (whose type is a template parameter). If the container allows for back_insertion, I want to use that, otherwise just any inserter.
I would like to avoid having to implement my own trait just for this,…

einpoklum
- 118,144
- 57
- 340
- 684
1
vote
1 answer
how to write any custom data type to file using ifstream?
as question says, i want to write custom data type data of a class maybe to a file using ifstream in c++. Need help.

NativeCoder
- 1,033
- 1
- 10
- 16
0
votes
1 answer
How to assign the values returned by make_pair to the inserter
I have to pass an inserter as a function argument, so that I assign the values returned by make_pair to the inserter and store them into a container. Can somebody help me to understand the make_pair and inserter correlation?
#include…

Xavi
- 57
- 8
0
votes
2 answers
Copying string into set in lowercase?
I have the following small and easy code:
int main(int argc, char *argv[]) {
std::vector in;
std::set out;
in.push_back("Hi");
in.push_back("Dear");
in.push_back("Buddy");
for (const auto& item :…

Daniel
- 2,318
- 2
- 22
- 53
0
votes
2 answers
How to cin to a back_inserter or any inserter in c++?
So I was thinking of simplifying this snippet
#include
using namespace std;
int n;
vector A;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 0; i < n; i++) {
int…

Salman Elgamal
- 3
- 1