473,322 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

iterator_traits

Is there a way in C++, given an iterator, I can get the container it's
pointing to, in analogy of anIterator::value_type which gives the type of
the elements of the container ?

Jul 22 '05 #1
3 1506
Lieven wrote in news:41***********************@news.skynet.be in
comp.lang.c++:
Is there a way in C++, given an iterator, I can get the container it's
pointing to, in analogy of anIterator::value_type which gives the type of
the elements of the container ?


No, sorry. There simply isn't enough information associated with
an iterator type to work back to the container.

As an example a T * type could be an iterator into an inbuilt array
T array[ 100 ] or a std::vector< T >.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #2

"Lieven" <li*************@hotmail.com> wrote in message
news:41***********************@news.skynet.be...
Is there a way in C++, given an iterator, I can get the container it's
pointing to, in analogy of anIterator::value_type which gives the type of
the elements of the container ?


You can't even get the type of container its pointing into, unless its one of
the standard inerter iterators.

Jonathan
Jul 22 '05 #3
"Rob Williscroft" <rt*@freenet.co.uk> wrote in message
Lieven wrote in news:41***********************@news.skynet.be in

Is there a way in C++, given an iterator, I can get the container it's
pointing to, in analogy of anIterator::value_type which gives the type of the elements of the container ?


No, sorry. There simply isn't enough information associated with
an iterator type to work back to the container.

As an example a T * type could be an iterator into an inbuilt array
T array[ 100 ] or a std::vector< T >.


As far as standard containers go, it could also be a std::basic_string<int>.

Jul 22 '05 #4

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

Similar topics

14
by: Gianni Mariani | last post by:
Does anyone know if this is supposed to work ? template <unsigned N> int strn( const char str ) { return N; } #include <iostream>
16
by: Kitty | last post by:
Hi, everyone. Given a vector<int>, what is the fastest way to find out whether there is a repeated element in it? The result is just "true" or "false". Thanks. Kitty
8
by: chris | last post by:
I tried to post this to comp.std.c++ some time ago, but for some reason I aren't getting any automatic confirmation. I thought I would therefore post it here. Some time ago I submitted what is...
4
by: Arturo Cuebas | last post by:
I've got a bunch of file_iterator<> (http://tinyurl.com/3uuxa) begin/end pairs that point to various chunks in a file. It would be super-cool, in my program, to be able to treat all of these ranges...
6
by: christopher diggins | last post by:
I wrote a dynamic matrix class similar to the one described in TCPL 3rd Edition. Rather than define two separate iterators for const and non-const scenarios I decided to be a lazy bastard and only...
21
by: T.A. | last post by:
I understand why it is not safe to inherit from STL containers, but I have found (in SGI STL documentation) that for example bidirectional_iterator class can be used to create your own iterator...
6
by: gexarchakos | last post by:
Hi there, Please give me at least a hint... I have a problem implementing a function object with parameters two iterators. That is: A class 'node' produces messages using a routing policy....
1
by: antoanish | last post by:
Hello, My Requirement is 1. Copy data from iterator to an array ( array should be created dynamically within the function based on data_type of the data held by the iterator /container. )...
6
by: Peng Yu | last post by:
Hi, I'm wondering if the following assignment is lazy copy or not? Thanks, Peng std::vector<intv. v.push_back(1); v.push_back(2);
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.