473,385 Members | 2,162 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

find() question

ben
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
Jul 23 '05 #1
1 1266
ben
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

Jul 23 '05 #2

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

Similar topics

2
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...
5
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.
3
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!
9
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...
7
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...
26
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) {...
2
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...
4
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...
3
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. ...
7
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...
0
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,...
0
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...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
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...
0
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,...
0
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...

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.