stl includes

Discussion in 'C++' started by Anthony Knittel, Aug 8, 2005.

  1. 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
    Anthony Knittel, Aug 8, 2005
    #1
    1. Advertising

  2. Anthony Knittel wrote:
    > 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
    Anthony Knittel, Aug 8, 2005
    #2
    1. Advertising

  3. 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


    Anthony Knittel wrote:
    > Anthony Knittel wrote:
    >
    >> 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
    Anthony Knittel, Aug 8, 2005
    #3
  4. 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


    Anthony Knittel wrote:
    > Anthony Knittel wrote:
    >
    >> 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
    Anthony Knittel, Aug 8, 2005
    #4
  5. Anthony Knittel

    Mark P Guest

    Anthony Knittel wrote:
    > 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.
    Mark P, Aug 8, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Allan Bruce

    To STL or not to STL

    Allan Bruce, Oct 16, 2003, in forum: C++
    Replies:
    41
    Views:
    1,026
    Christopher Benson-Manica
    Oct 17, 2003
  2. Generic Usenet Account

    Unexpected behavior in STL "includes" algorithm

    Generic Usenet Account, Nov 2, 2005, in forum: C++
    Replies:
    4
    Views:
    327
    =?iso-8859-1?Q?Ali_=C7ehreli?=
    Nov 2, 2005
  3. Replies:
    4
    Views:
    788
    Daniel T.
    Feb 16, 2006
  4. Replies:
    2
    Views:
    542
    klaus hoffmann
    Feb 22, 2006
  5. Replies:
    5
    Views:
    496
    Markus Schoder
    Apr 16, 2006
Loading...

Share This Page