for_each - throws?

Discussion in 'C++' started by sks_cpp, Jul 3, 2003.

  1. sks_cpp

    sks_cpp Guest

    The for_each library function - does it throw any exceptions if the functor
    you pass it DOESN'T throw anything.

    Example:
    class Functor
    {
    bool operator()(int a) { if (a>10) return true; }
    };

    std::list<int> intList; // contains some integers in the container
    for_each( intList.begin(), intList.end(), Functor() );
    sks_cpp, Jul 3, 2003
    #1
    1. Advertising

  2. sks_cpp

    Dhruv Guest

    On Thu, 03 Jul 2003 17:05:24 +0000, sks_cpp wrote:

    > The for_each library function - does it throw any exceptions if the functor
    > you pass it DOESN'T throw anything.
    >
    > Example:
    > class Functor
    > {
    > bool operator()(int a) { if (a>10) return true; }
    > };

    Return and do what with the return value??????

    > std::list<int> intList; // contains some integers in the container
    > for_each( intList.begin(), intList.end(), Functor() );


    Regards,
    -Dhruv.
    Dhruv, Jul 3, 2003
    #2
    1. Advertising

  3. "sks_cpp" <> schrieb im Newsbeitrag
    news:eek:nZMa.369670$...
    > The for_each library function - does it throw any exceptions if the

    functor
    > you pass it DOESN'T throw anything.
    >
    > Example:
    > class Functor
    > {
    > bool operator()(int a) { if (a>10) return true; }
    > };
    >
    > std::list<int> intList; // contains some integers in the container
    > for_each( intList.begin(), intList.end(), Functor() );
    >

    Actually your program is allowed to do anything it likes, when the list
    containes integers that are smaller or equal to 10, because
    Functor::eek:perator()(int)'s return value is not specified, which invoces
    undefined behaviour. So, it even might throw an exception, but I think the
    probability is not very high.:)

    Norbert
    Norbert Riedlin, Jul 3, 2003
    #3
    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. Sean
    Replies:
    2
    Views:
    468
  2. Alex Vinokur
    Replies:
    5
    Views:
    607
    Alex Vinokur
    Nov 4, 2003
  3. John Black
    Replies:
    18
    Views:
    705
    Daniel T.
    Jun 16, 2004
  4. JeromeG
    Replies:
    1
    Views:
    506
    John Harrison
    Jun 24, 2004
  5. Dylan

    std::for_each question

    Dylan, Jul 4, 2004, in forum: C++
    Replies:
    5
    Views:
    8,552
    =?iso-8859-1?q?Josep_Mon=E9s_i_Teixidor?=
    Jul 5, 2004
Loading...

Share This Page