473,765 Members | 1,957 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pass a back_inserter as the output iterator in remove_copy_if algorithm

i have the following code, but it does not compile because I pass in
back_inserter(b ) as the output iterator in the remove_copy_if
algorithm.
My questions are:
1. why it does not compile? Passing a back_inserter() works for copy()
algorithm, why not remove_copy_if( )?
2. is there a work-around for my problem? I think one solution is to
allocate 'b' as big as 'a', but that seems to be a waste of memory for
the case of b is a lot smaller than a.

Thank you.

class EvenValue {
public:
bool operator() (float value) {
return (int)value %2 ? false : true;
}
};

float func1(vector<fl oat>& a, float max ) {

vector<float> b;
vector<float>:: iterator itr = remove_copy_if (a.begin(), a.end(),
back_inserter(b ), EvenValue() );

// do something with 'b'
return 0.0;
}

Feb 15 '06 #1
3 3135
Here is the compilation error:

../A.cpp: In member function 'float func1(vector<fl oat>&()':
.../A.cpp:361: error: conversion from
'std::back_inse rt_iterator<std ::vector<float, std::allocator< float> >
' to non-scalar type '__gnu_cxx::__n ormal_iterator< float*, std::vector<flo at, std::allocator< float> > >' requested


Feb 15 '06 #2
<si************ ***@gmail.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
i have the following code, but it does not compile because I pass in
back_inserter(b ) as the output iterator in the remove_copy_if
algorithm.


That's not the reason. The reason is that if you pass a back_inserter, you
get back a back_inserter as the result; you're trying to use that
back_inserter to initialize an ordinary iterator.
Feb 15 '06 #3
Thanks. Sorry for my oversight.

Feb 15 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

38
3685
by: Grant Edwards | last post by:
In an interview at http://acmqueue.com/modules.php?name=Content&pa=showpage&pid=273 Alan Kay said something I really liked, and I think it applies equally well to Python as well as the languages mentioned: I characterized one way of looking at languages in this way: a lot of them are either the agglutination of features or they're a crystallization of style. Languages such as APL, Lisp, and Smalltalk are what you might call style...
8
2741
by: Mark A. Gibbs | last post by:
I have a string conversion function that looks something like this (apologies, but I cannot post the actual code): whar_t char_to_wchar(char); wstring to_wstring(const string& s) { wstring result(s.length(), '\0'); transform(s.begin(), s.end(), result.begin(), ptr_fun(char_to_wchar));
41
8340
by: Berk Birand | last post by:
Hi, I am just learning about the array/pointer duality in C/C++. I couldn't help wondering, is there a way to pass an array by value? It seems like the only way to do is to pass it by reference?? Thanks, BB
6
1747
by: Anirudh Ramachandran | last post by:
Hi all, I have a homework problem here, where I have to perform a set intersection on two sets and use the result elsewhere. I have this code: #include <iostream> #include <iterator> #include <set> #include <algorithm>
1
2424
by: Allerdyce.John | last post by:
Can I use back_inserter as the output iterator? The following code wont't compile, is there a reason for that? How can I achieve what I want? (grow aList if needed) class build { public: A* operator()(string& str) { return new Astr); }
6
3045
by: Daniel T. | last post by:
The line marked (1) below compiles fine and does exactly what I would expect, but the line marked (2) does not compile at all on my system. error: variable or field 'bar' declared void My question is, does the standard dictate that the value_type of a back_inserter is 'void'? If so, why? I would expect the value_type of a back_inserter to be the same as the value_type of the container it wraps.
23
6544
by: Sanjay Kumar | last post by:
Folks, I am getting back into C++ after a long time and I have this simple question: How do pyou ass a STL container like say a vector or a map (to and from a function) ? function: vector<string> tokenize(string s){
17
4497
by: Jess | last post by:
Hello, The iterator adaptor "back_inserter" takes a container and returns a iterator so that we can insert elements to the end of the container. Out of curiosity, I tried to look at what element the returned iterator refers to. Here is my code: #include<iostream> #include<vector> #include<iterator>
3
4515
by: vasili | last post by:
hello All, I have a simple issue. I defined a custom container, that encloses a std::list, which in turn holds objects that are a simple abstraction of a six position array. Now, i would like to serialize the whole newly-defined container, in order to copy the contents to another array. So i thought to define an iterator which represented a "pointer" to the container's data. But, when i feed these iterators to std::copy the compiler...
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9399
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9955
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7378
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5421
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.