473,786 Members | 2,574 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

iterator_traits

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

Jul 22 '05 #1
3 1523
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::val ue_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::val ue_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::val ue_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_stri ng<int>.

Jul 22 '05 #4

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

Similar topics

14
3916
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
2742
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
2073
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 now Defect Report 484 on the standard library. I'm beginning to wonder if I've just misunderstood the purpose of iterator_traits::value_type. I constructed an input iterator where *i returns an int, but I set iterator_traits::value_type to bool....
4
1610
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 as though they were one huge range. I'm envisioning something along the lines of a library facility that provides an iterator type that encapsulates a set of ranges and abstracts out code to handle traversal through all of them as though all the...
6
1745
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 have one and make the data representation (a std::valarray) mutable instead. My question is, how bad is that? Am I running the risk of undefined behaviour, or is the worst case scenario simply const violation? -- Christopher Diggins...
21
5724
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 classes by inheriting from it, ie. class my_bidirectional_iterator : public bidirectional_iterator<double> { ... };
6
1600
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. The routing policy needs to take the node's neighbours and return a subset of them based on several criteria. Each message may have different routing policy. Thus, the policy should be specified while the new message is
1
2095
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. ) 2. Copy data from array into iterator ( array should be created dynamically within the function based on data_type of the data held by the iterator /container. ) Implementation ----------------------- //copies data from begin to end of...
6
3935
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);
0
9650
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
9497
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
10363
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
10164
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...
0
9962
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
5398
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...
1
4067
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
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.