Locating build-in functions

D

desktop

I am trying to find the build-in function find() in the C++ STD but I
don't know where to look. Where are the standard library functions located?
 
V

Victor Bazarov

desktop said:
I am trying to find the build-in function find() in the C++ STD but I
don't know where to look. Where are the standard library functions
located?

That's up to the implementation. The declaration of 'std::find'
function _template_ is in <algorithm>. The definition is _probably_
very close by.

V
 
D

desktop

Victor said:
That's up to the implementation. The declaration of 'std::find'
function _template_ is in <algorithm>. The definition is _probably_
very close by.

V

I have installed g++4.1 on ubuntu. But where do I look? I found a file
called algorithm in:


/usr/include/c++/4.1.2/

but it did not contain any implementations.
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

But where is that located?

That's up to the implementation but the file you found is a good bet.
But it seems that they only show the declarations and not the whole
definition.

When I look at the definition that comes with VC8 I see that it's not
just one function but rather a couple of them (some seem to be
overloaded for specific types or something, I didn't bother to investigate.

I don't see why you want the definition though, you can probably
implement a quite good one yourself, something like this:

template<typename Iter, typename Val>
Iter find(Iter first, Iter last, Val v)
{
for (; first != last; ++first)
{
if (*first == v)
return first;
}
return first;
}

Note that I have not tested this but it really is no more to it since
find() runs in linear time.
 
M

Markus Schoder

desktop said:
I have installed g++4.1 on ubuntu. But where do I look? I found a file
called algorithm in:


/usr/include/c++/4.1.2/

but it did not contain any implementations.

It includes other files that contain the actual implementation.

Look here /usr/include/c++/4.1.2/bits/stl_algo.h
 
J

James Kanze

But where is that located?

In the standard library. If you invoke the compiler as a C++
compiler, and it is correctly installed, the compiler usually
takes care of the rest of the details. (The one exception I've
encountered is VC++, where you have to set environment variables
such as %INCLUDE% to tell the compiler where things are.)
But it seems that they only show the declarations and not the whole
definition.

So? That's not your problem. The definition may change from
one implementation to the next anyway. (I don't know about
std::find, but the definitions of things like std::vector
definitly change, even depending on compiler options.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,297
Messages
2,571,529
Members
48,242
Latest member
BarbMott55

Latest Threads

Top