I want to overload the std::find so i don't have to write array.begin(),
array.end() everytime. so the following is my solution:
template <template <typename EleT> class ContainerT, typename ElementT>
typename ContainerT<ElementT>::iterator // return type
find(
const ContainerT<ElementT>& container,
const ElementT& element)
{
return std::find(container.begin(), container.end(),
element);
}
But I got const type conversion error from the overloaded find above. But
once I took away the const before the container parameter, i.e.
template <template <typename EleT> class ContainerT, typename ElementT>
typename ContainerT<ElementT>::iterator // return type
find(
ContainerT<ElementT>& container, // container no longer
cost
const ElementT& element)
{
return std::find(container.begin(), container.end(),
element);
}
I have no compiler errors. But the find shouldn't modify the container so it
ought to be a const reference.
What's wrong??
ben 1 1266
Ahh, never mind. I figured that out. std::find returns an iterator with
which one can change the content of the container...
ben
"ben" <be******@hotmail.com> wrote in message
news:42***********************@news.optusnet.com.a u... I want to overload the std::find so i don't have to write array.begin(), array.end() everytime. so the following is my solution:
template <template <typename EleT> class ContainerT, typename
ElementT> typename ContainerT<ElementT>::iterator // return type find( const ContainerT<ElementT>& container, const ElementT& element) { return std::find(container.begin(), container.end(), element); }
But I got const type conversion error from the overloaded find above. But once I took away the const before the container parameter, i.e.
template <template <typename EleT> class ContainerT, typename
ElementT> typename ContainerT<ElementT>::iterator // return type find( ContainerT<ElementT>& container, // container no longer cost const ElementT& element) { return std::find(container.begin(), container.end(), element); }
I have no compiler errors. But the find shouldn't modify the container so
it ought to be a const reference.
What's wrong??
ben
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Praveen |
last post by:
In the ISPF editor I am using, for a particullar PO Dataset I am
getting the result of FIND statement narrowed down to the colums
48-56. i.e. if I give "FIND 'TO' ALL", the result I am getting as...
|
by: Jim Holder |
last post by:
I tried building libpcap and tcpdump from my Red Hat 7 RPMs. The
tcpdump make couldn't find ioccom.h and sockio.h.
When a header file is missing, how do you find it?
Thanks.
|
by: Busin |
last post by:
bool arr;
arr = true;
For the element arr, is there any fastest algorithm to fast find the two
elements on both side of "n" and both elements are cloest to "23"?
Thanks!
|
by: Tony Girgenti |
last post by:
Hello.
I'm developing and testing a web application using VS.NET 2003, VB, .NET
Framework 1.1.4322, ASP.NET 1.1.4322 and IIS5.1 on a WIN XP Pro, SP2
computer. I'm using a web form.
For a...
|
by: =?Utf-8?B?Q2hyaXM=?= |
last post by:
Hi,
How can I implement regex to find complete or partial words or a group of
words. Similar to the "Find" in MS Word. I need to scan text files eg
look for "test"
or "this is a test"
or...
|
by: ak |
last post by:
Recently at an interview i was asked the following question :
Assuming the function lookupName is defined, what's wrong with this
code (hint: 2 bugs)?
const char *getName(const char *c) {...
|
by: emily224 |
last post by:
Hello,
I have been trying to understand this source code, which I retreived from my online course test. I would like to know how to find the answer for the question on the test. Im sure the answer...
|
by: emily224 |
last post by:
Hello,
I have been trying to understand this source code, which I retreived from my online course test. I would like to know how to find the answer for the question on the test. Im sure the answer...
|
by: raylopez99 |
last post by:
I suspect the answer to this question is that it's impossible, but how
do I make the below code work, at the point where it breaks (marked
below). See error CS0411
This is the complete code. ...
|
by: Christian Meier |
last post by:
Hello Newsgroup
I have a question about the find function of std::set.
When I have a "std::set<int*>", why can't I call the find() function with an
"const int*"? I know that my key type is...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
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...
| |