stl includes

  • Thread starter Anthony Knittel
  • Start date
A

Anthony Knittel

does anyone know a good source for finding the appropriate includes for
various STL types, for example InputIterators and similar? I've dug
through countless STL references and they always seem to leave out where
types like InputIterator and binary_predicate<T,T,T> etc are defined.


A
 
A

Anthony Knittel

Anthony said:
does anyone know a good source for finding the appropriate includes for
various STL types, for example InputIterators and similar? I've dug
through countless STL references and they always seem to leave out where
types like InputIterator and binary_predicate<T,T,T> etc are defined.

specifically what i'm trying to do is write a function that can operate
using any InputIterator, as follows:

InputIterator selectRandom(InputIterator first, InputIterator last)
{
InputIterator iter, chosen;

float pSelect;

if (first == last) return last; // no elements to choose from
Size thisElement = 1;

for (iter = first; iter != last; iter++)
{
pSelect = 1 / (float) thisElement;
if (_pRand(pSelect)) chosen = iter;

thisElement++;
}

return chosen;
}


but every time i try and compile it complains that "`InputIterator' was
not declared in this scope", which seems either a namespace or include
problem, i'm having trouble getting around it.


A
 
A

Anthony Knittel

ok figured out the problem (don't mind me..)

i was mistaking InputIterator for a defined type, but its just a
reference to a type used in a template. ie the following works:

template <class InputIterator>
InputIterator selectRandom(InputIterator first, InputIterator last);

i didn't realise you could create template methods without having to
specify a type within <> symbols.


A
 
A

Anthony Knittel

ok figured out the problem (don't mind me..)

i was mistaking InputIterator for a defined type, but its just a
reference to a type used in a template. ie the following works:

template <class InputIterator>
InputIterator selectRandom(InputIterator first, InputIterator last);

i didn't realise you could create template methods without having to
specify a type within <> symbols.


A
 
M

Mark P

Anthony said:
does anyone know a good source for finding the appropriate includes for
various STL types, for example InputIterators and similar? I've dug
through countless STL references and they always seem to leave out where
types like InputIterator and binary_predicate<T,T,T> etc are defined.


A

Look for the SGI STL reference.
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top