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 ? 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/
"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
"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>. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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>
|
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
|
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....
|
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...
|
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...
| |
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>
{
...
};
|
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
|
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...
|
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);
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |