for_each - throws?

S

sks_cpp

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() );
 
D

Dhruv

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

Norbert Riedlin

sks_cpp said:
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
 

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
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top