473,748 Members | 2,658 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

hybrid of back_inserter and forward_iterato r

I want sort of a hybrid between these two. I want an iterator where *
operator can both read from and write to elements in the collection,
intelligently calling push_back if necessary in order to write without
going out of bounds.

Is something like this possible? I have something I whipped together
that seems to work with the test cases I've given it, but I'm not 100%
confident that it's bulletproof since it's been quite some time since
I was heavily involved with STL. Can post it if necessary, but
chances are this has been tried before and I'll either get a "yes,
look here for code" or "no don't even bother".

Thanks

Jun 14 '07 #1
1 1381
On 2007-06-14 22:01, Zachary Turner wrote:
I want sort of a hybrid between these two. I want an iterator where *
operator can both read from and write to elements in the collection,
intelligently calling push_back if necessary in order to write without
going out of bounds.

Is something like this possible? I have something I whipped together
that seems to work with the test cases I've given it, but I'm not 100%
confident that it's bulletproof since it's been quite some time since
I was heavily involved with STL. Can post it if necessary, but
chances are this has been tried before and I'll either get a "yes,
look here for code" or "no don't even bother".
Depends a bit of what behaviour you expect from it, but if you want it
to always insert at the end (even if the iterator is not at the end)
then it should be fairly trivial (I think, I have not really looked into
it) if you keep a reference to the container in the iterator.

--
Erik Wikström
Jun 15 '07 #2

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

Similar topics

5
3226
by: Markus Seibold | last post by:
Dear NG, I am working on a student project about a mobile tourism information system and among others I have to answer the question whether to use: - a relational database - a XML-native database - a hybrid (XML atop relational database) Can anyone please provide me with links and preferably article on this topic (so that I can cite them in my paper)?
8
2738
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));
2
4600
by: Joe Laughlin | last post by:
Joe Laughlin wrote: > Mike Wahler wrote: >> "Joe Laughlin" <Joseph.V.Laughlin@boeing.com> wrote in >> message news:I60Dvs.FqL@news.boeing.com... <snip> >>> Joe Laughlin wrote: >>> std::back_insert_iterator<std::string>::operator=(const >>> std::back_insert_iterator<std::string>&) >> >> 'back_insert_iterator' requires that the container type
3
3133
by: silverburgh.meryl | last post by:
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...
1
2421
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
3044
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.
17
4495
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>
0
944
by: johnsmith3853 | last post by:
Hey Guys, I am still in a thinking stage and will like to learn from your experience, and was wondering if any of you folks have a hybrid environment i.e. Linux and Proprietary systems and what kind of issues do you run into. And also, what pieces of technology you have - which are open source and which ones you have are proprietary and any changes you anticipate 1 year out. Greatly appreciate your help. - John Smith
0
9561
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9381
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
9332
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,...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6078
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
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3316
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
2791
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.