Hi,
I've got a question concerning iterators. I'm writing some container class
and iterators upon it. I have to have
typedef typex pointer;
typedef typey reference;
to be standard conforming. But what semantic requirements does the standard
expose on type typey (and typex). If I define
reference operator*(),
does the object I return have to be (non-const) referencable or can I return
a temporary object of typey? If I'm not allowed to, how can I write some
iterator and especially operator*(), if I have to create its result on the
fly? I hope, I made my question understandable.
regards,
alex 2 1374
"Alexander Stippler" <st**@mathemati k.uni-ulm.de> wrote in message
news:3f******@n ews.uni-ulm.de... Hi,
I've got a question concerning iterators. I'm writing some container class and iterators upon it. I have to have typedef typex pointer; typedef typey reference; to be standard conforming. But what semantic requirements does the
standard expose on type typey (and typex). If I define reference operator*(),
I forget all the details as to why but apparently to be a standard container
it turns out that pointer and reference have to be the obvious types (T*,
T&) (perhaps const or volatile but not proxy classes).
However you don't have to create standard containers and even the standard
contains "non-standard" containers in particular vector<bool> precisely
because reference isn't bool& and therefore you cannot take the address of
one to get bool*.
I think I MAY have come across all this in "Effective C++" or "More
Effective C++"
The main reason to give the typedef is so that standard algorithms can work
with your iterators.
If an algorith is supplied an iterator it cannot know directly what the
fundamental type is so it generally needs to use the typedefs
does the object I return have to be (non-const) referencable or can I
return a temporary object of typey? If I'm not allowed to, how can I write some
vector<bool> uses something that is not bool& and I don't know of any
practical drawback.
iterator and especially operator*(), if I have to create its result on the fly? I hope, I made my question understandable.
regards, alex
Nick Hounsome wrote: "Alexander Stippler" <st**@mathemati k.uni-ulm.de> wrote in message news:3f******@n ews.uni-ulm.de... Hi,
I've got a question concerning iterators. I'm writing some container class and iterators upon it. I have to have typedef typex pointer; typedef typey reference; to be standard conforming. But what semantic requirements does the standard expose on type typey (and typex). If I define reference operator*(),
I forget all the details as to why but apparently to be a standard container it turns out that pointer and reference have to be the obvious types (T*, T&) (perhaps const or volatile but not proxy classes).
However you don't have to create standard containers and even the standard contains "non-standard" containers in particular vector<bool> precisely because reference isn't bool& and therefore you cannot take the address of one to get bool*.
I think I MAY have come across all this in "Effective C++" or "More Effective C++"
The main reason to give the typedef is so that standard algorithms can work with your iterators. If an algorith is supplied an iterator it cannot know directly what the fundamental type is so it generally needs to use the typedefs
does the object I return have to be (non-const) referencable or can I return a temporary object of typey? If I'm not allowed to, how can I write some
vector<bool> uses something that is not bool& and I don't know of any practical drawback.
iterator and especially operator*(), if I have to create its result on the fly? I hope, I made my question understandable.
regards, alex
Indeed both the icc-STL and gcc-STL do not return references for operator*()
in some more general places, as I shortly noticed. Look at this, taken from
reverse_iterato r implementation:
reference operator*() const
{ // return designated value
_RanIt _Tmp = current;
return (*--_Tmp);
}
Thanks for your answer. I want to use STL algorithms and that is exactly the
extent to which I want to be standard conforming.
regards,
alex This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Alvin |
last post by:
Will it be possible to have more than one Iterator in a type?
|
by: ma740988 |
last post by:
typedef std::vector < std::complex < double > > complex_vec_type;
// option1
int main()
{
complex_vec_type cc ( 24000 );
complex_vec_type dd ( &cc, &cc );
}
versus
|
by: desktop |
last post by:
In accelerated C++ on page 146 there is this example:
template <class In, class Out>
Out copy(In begin, In end, Out dest)
{
While (begin != end)
*dest++ = *begin++;
return dest;
}
|
by: desktop |
last post by:
I am not sure I quite understand the use of iterators. I have this int
array:
int a = {1,2,3,4,5}
I would now like to make an iterator to the first and last element:
std::iterator<intiter;
iter = a;
|
by: desktop |
last post by:
1)
I have this code:
std::list<intmylist;
mylist.push_back(1);
mylist.push_back(2);
mylist.push_back(3);
mylist.push_back(4);
| |
by: kjackson.ken |
last post by:
I have code such as the following:
map<int, stringstringMap;
stringMap.insert(map<int,string>::value_type(1, "hello"));
map<int, string>::iterator iter;
iter = stringMap.find(1);
|
by: Jess |
last post by:
Hello,
Iterators are typically put into five different categories, namely
input iterator, output iterator, forward iterator, bidirectional
iterator and random iterator. The differences come from the
requirements each kind of iterator has to meet. Therefore, I think
the five categories are kind of conceptual thing, i.e. they are not
really C++ structs/classes etc, is this correct?
There are some functions that return iterators. For...
|
by: schickb |
last post by:
I think it would be useful if iterators on sequences had the __index__
method so that they could be used to slice sequences. I was writing a
class and wanted to return a list iterator to callers. I then wanted
to let callers slice from an iterator's position, but that isn't
supported without creating a custom iterator class.
Are there reasons for not supporting this generally? I realize not all
iterators would have the __index__ method,...
|
by: zr |
last post by:
Hi,
Does usage of checked iterators and checked containers make code more
secure?
If so, can that code considered to be reasonably secure?
|
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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();...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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...
| |