I'm trying to make a function which insert an object into a list and returns
an iterator to the new element in the list. But as far as I know there is no
function which returns an iterator to the last element of a list. (.end()
returns an iterator one item past the end of the list) How could I solve
this? 20 2244
"xerix" schrieb I'm trying to make a function which insert an object into a list and
returns an iterator to the new element in the list. But as far as I know there is
no function which returns an iterator to the last element of a list. (.end() returns an iterator one item past the end of the list) How could I solve this?
try std::list<T>::back() and make sure that your list is not empty
Arne
"xerix" schrieb I'm trying to make a function which insert an object into a list and
returns an iterator to the new element in the list. But as far as I know there is
no function which returns an iterator to the last element of a list. (.end() returns an iterator one item past the end of the list) How could I solve this?
try std::list<T>::back() and make sure that your list is not empty
Arne
"Arne Adams" <in***@arneadams.com> wrote in message
news:c5*************@news.t-online.com... "xerix" schrieb I'm trying to make a function which insert an object into a list and returns an iterator to the new element in the list. But as far as I know there
is no function which returns an iterator to the last element of a list.
(.end() returns an iterator one item past the end of the list) How could I solve this?
try std::list<T>::back() and make sure that your list is not empty
Arne
back returns a reference to the last element from the list, but I need an
iterator to the last element of the list.
"Arne Adams" <in***@arneadams.com> wrote in message
news:c5*************@news.t-online.com... "xerix" schrieb I'm trying to make a function which insert an object into a list and returns an iterator to the new element in the list. But as far as I know there
is no function which returns an iterator to the last element of a list.
(.end() returns an iterator one item past the end of the list) How could I solve this?
try std::list<T>::back() and make sure that your list is not empty
Arne
back returns a reference to the last element from the list, but I need an
iterator to the last element of the list.
"xerix" <xe***@bla.nl> wrote in message
news:7f***************************@news.multikabel .nl... I'm trying to make a function which insert an object into a list and
returns an iterator to the new element in the list. But as far as I know there is
no function which returns an iterator to the last element of a list. (.end() returns an iterator one item past the end of the list) How could I solve this?
I don't know much about C++, but doesn't give end() an iterator to the
position where the next object will come? If so, you could first call end()
and then add the new object.
Sander
"xerix" <xe***@bla.nl> wrote in message
news:7f***************************@news.multikabel .nl... I'm trying to make a function which insert an object into a list and
returns an iterator to the new element in the list. But as far as I know there is
no function which returns an iterator to the last element of a list. (.end() returns an iterator one item past the end of the list) How could I solve this?
I don't know much about C++, but doesn't give end() an iterator to the
position where the next object will come? If so, you could first call end()
and then add the new object.
Sander
"Sander" <sa*******@nospam.hotmail.com> wrote in message
news:40**********************@dreader2.news.tiscal i.nl... "xerix" <xe***@bla.nl> wrote in message news:7f***************************@news.multikabel .nl... I'm trying to make a function which insert an object into a list and returns an iterator to the new element in the list. But as far as I know there
is no function which returns an iterator to the last element of a list.
(.end() returns an iterator one item past the end of the list) How could I solve this? I don't know much about C++, but doesn't give end() an iterator to the position where the next object will come? If so, you could first call
end() and then add the new object.
Sander
That ain't working either :(
"Sander" <sa*******@nospam.hotmail.com> wrote in message
news:40**********************@dreader2.news.tiscal i.nl... "xerix" <xe***@bla.nl> wrote in message news:7f***************************@news.multikabel .nl... I'm trying to make a function which insert an object into a list and returns an iterator to the new element in the list. But as far as I know there
is no function which returns an iterator to the last element of a list.
(.end() returns an iterator one item past the end of the list) How could I solve this? I don't know much about C++, but doesn't give end() an iterator to the position where the next object will come? If so, you could first call
end() and then add the new object.
Sander
That ain't working either :(
"xerix" <xe***@bla.nl> wrote in message
news:7f***************************@news.multikabel .nl... I'm trying to make a function which insert an object into a list and
returns an iterator to the new element in the list. But as far as I know there is
no function which returns an iterator to the last element of a list. (.end() returns an iterator one item past the end of the list) How could I solve this?
list has bidirectional iterators so you can do end()-1
"xerix" <xe***@bla.nl> wrote in message
news:7f***************************@news.multikabel .nl... I'm trying to make a function which insert an object into a list and
returns an iterator to the new element in the list. But as far as I know there is
no function which returns an iterator to the last element of a list. (.end() returns an iterator one item past the end of the list) How could I solve this?
list has bidirectional iterators so you can do end()-1
"xerix" <xe***@bla.nl> wrote in message
news:7f***************************@news.multikabel .nl... I'm trying to make a function which insert an object into a list and
returns an iterator to the new element in the list.
The list<T>::insert function already returns an iterator to the newly
inserted element.
But as far as I know there is no function which returns an iterator to the last element of a list. (.end() returns an iterator one item past the end of the list) How could I solve this?
Well I don't really see the connection between your two sentences, but if
you really want a function that returns an iterator to the last element of a
list then all you have to do is write one. Just use end() to get the one
past the end and then operator-- to move back to the end of the last.
template <class T>
list<T>::iterator last_element(list<T>& lst)
{
list<T>::iterator i = lst.end();
return --i;
}
Of course bad things will happen if you use this function on an empty list.
john
"xerix" <xe***@bla.nl> wrote in message
news:7f***************************@news.multikabel .nl... I'm trying to make a function which insert an object into a list and
returns an iterator to the new element in the list.
The list<T>::insert function already returns an iterator to the newly
inserted element.
But as far as I know there is no function which returns an iterator to the last element of a list. (.end() returns an iterator one item past the end of the list) How could I solve this?
Well I don't really see the connection between your two sentences, but if
you really want a function that returns an iterator to the last element of a
list then all you have to do is write one. Just use end() to get the one
past the end and then operator-- to move back to the end of the last.
template <class T>
list<T>::iterator last_element(list<T>& lst)
{
list<T>::iterator i = lst.end();
return --i;
}
Of course bad things will happen if you use this function on an empty list.
john
"Nick Hounsome" <nh***@blueyonder.co.uk> wrote in message
news:Ej****************@news-binary.blueyonder.co.uk... "xerix" <xe***@bla.nl> wrote in message news:7f***************************@news.multikabel .nl... I'm trying to make a function which insert an object into a list and returns an iterator to the new element in the list. But as far as I know there
is no function which returns an iterator to the last element of a list.
(.end() returns an iterator one item past the end of the list) How could I solve this?
list has bidirectional iterators so you can do end()-1
error C2784: 'ptrdiff_t std::operator -(const std::reverse_iterator<_RanIt>
&,const std::reverse_iterator<_RanIt> &)' : could not deduce template
argument for 'const std::reverse_iterator<_RanIt> &' from
'std::list<_Ty,_Ax>::iterator'
with
[
_Ty=int,
_Ax=std::allocator<int>
]
iter = listNum.end()--;
This isn't working either.
I'm using reverse iterators as a workaround, but that isn't actually what I
want.
"Nick Hounsome" <nh***@blueyonder.co.uk> wrote in message
news:Ej****************@news-binary.blueyonder.co.uk... "xerix" <xe***@bla.nl> wrote in message news:7f***************************@news.multikabel .nl... I'm trying to make a function which insert an object into a list and returns an iterator to the new element in the list. But as far as I know there
is no function which returns an iterator to the last element of a list.
(.end() returns an iterator one item past the end of the list) How could I solve this?
list has bidirectional iterators so you can do end()-1
error C2784: 'ptrdiff_t std::operator -(const std::reverse_iterator<_RanIt>
&,const std::reverse_iterator<_RanIt> &)' : could not deduce template
argument for 'const std::reverse_iterator<_RanIt> &' from
'std::list<_Ty,_Ax>::iterator'
with
[
_Ty=int,
_Ax=std::allocator<int>
]
iter = listNum.end()--;
This isn't working either.
I'm using reverse iterators as a workaround, but that isn't actually what I
want.
"John Harrison" <jo*************@hotmail.com> wrote in message
news:c5*************@ID-196037.news.uni-berlin.de... "xerix" <xe***@bla.nl> wrote in message news:7f***************************@news.multikabel .nl... I'm trying to make a function which insert an object into a list and returns an iterator to the new element in the list.
The list<T>::insert function already returns an iterator to the newly inserted element.
Aarg! This is what I was looking for. I just completely missed the insert
function because I always use push_back. I feel so stūpid.
Thank you!
"John Harrison" <jo*************@hotmail.com> wrote in message
news:c5*************@ID-196037.news.uni-berlin.de... "xerix" <xe***@bla.nl> wrote in message news:7f***************************@news.multikabel .nl... I'm trying to make a function which insert an object into a list and returns an iterator to the new element in the list.
The list<T>::insert function already returns an iterator to the newly inserted element.
Aarg! This is what I was looking for. I just completely missed the insert
function because I always use push_back. I feel so stūpid.
Thank you!
Nick Hounsome wrote: "xerix" <xe***@bla.nl> wrote in message news:7f***************************@news.multikabel .nl...
I'm trying to make a function which insert an object into a list and
returns
an iterator to the new element in the list. But as far as I know there is
no
function which returns an iterator to the last element of a list. (.end() returns an iterator one item past the end of the list) How could I solve this?
list has bidirectional iterators so you can do end()-1
You can't do that with bidirectional iterators. You might be able to do
--my_list.end(), though. It doesn't necessarily work for vectors and
strings, but should work for lists.
-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Nick Hounsome wrote: "xerix" <xe***@bla.nl> wrote in message news:7f***************************@news.multikabel .nl...
I'm trying to make a function which insert an object into a list and
returns
an iterator to the new element in the list. But as far as I know there is
no
function which returns an iterator to the last element of a list. (.end() returns an iterator one item past the end of the list) How could I solve this?
list has bidirectional iterators so you can do end()-1
You can't do that with bidirectional iterators. You might be able to do
--my_list.end(), though. It doesn't necessarily work for vectors and
strings, but should work for lists.
-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
"xerix" <xe***@bla.nl> wrote in message
news:b1***************************@news.multikabel .nl... "Nick Hounsome" <nh***@blueyonder.co.uk> wrote in message news:Ej****************@news-binary.blueyonder.co.uk... "xerix" <xe***@bla.nl> wrote in message news:7f***************************@news.multikabel .nl... I'm trying to make a function which insert an object into a list and returns an iterator to the new element in the list. But as far as I know there is no function which returns an iterator to the last element of a list. (.end() returns an iterator one item past the end of the list) How could I
solve this?
list has bidirectional iterators so you can do end()-1
error C2784: 'ptrdiff_t std::operator -(const
std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'std::list<_Ty,_Ax>::iterator' with [ _Ty=int, _Ax=std::allocator<int> ]
iter = listNum.end()--;
This isn't working either. I'm using reverse iterators as a workaround, but that isn't actually what
I want.
Why are you using reverse iterators?
If you want them then the last element is just list.rbegin()
You can then use base() to get a forward iterator.
"xerix" <xe***@bla.nl> wrote in message
news:b1***************************@news.multikabel .nl... "Nick Hounsome" <nh***@blueyonder.co.uk> wrote in message news:Ej****************@news-binary.blueyonder.co.uk... "xerix" <xe***@bla.nl> wrote in message news:7f***************************@news.multikabel .nl... I'm trying to make a function which insert an object into a list and returns an iterator to the new element in the list. But as far as I know there is no function which returns an iterator to the last element of a list. (.end() returns an iterator one item past the end of the list) How could I
solve this?
list has bidirectional iterators so you can do end()-1
error C2784: 'ptrdiff_t std::operator -(const
std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'std::list<_Ty,_Ax>::iterator' with [ _Ty=int, _Ax=std::allocator<int> ]
iter = listNum.end()--;
This isn't working either. I'm using reverse iterators as a workaround, but that isn't actually what
I want.
Why are you using reverse iterators?
If you want them then the last element is just list.rbegin()
You can then use base() to get a forward iterator. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: xerix |
last post by:
I'm trying to make a function which insert an object into a list and returns
an iterator to the new element in the list. But as far as I know there is no
function which returns an iterator to the...
|
by: sudeep |
last post by:
Data Storage
Problem Statement
In an organization there are 3 kinds of people: Staff, Students and
Research Associates. Research Associates are actually students who are
considered as staff,...
|
by: pinkfloydhomer |
last post by:
Isn't there an easier way than
lst = ...
?
|
by: Howard |
last post by:
Is there an easy way to get an iterator (*not* a reverse-iterator) to the
last element in a list? The last() function returns the element itself, not
an iterator.
Thanks,
-Howard
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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,...
|
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...
|
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...
|
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 projectplanning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
| |