C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 07-08-2009, 04:08 PM   #16
The larch
 
Join Date: May 2006
Posts: 3,082
It doesn't feel like reinventing the wheel that much (perhaps even a more specific function all_equal, since the call to all turned out to be quite complicated in this case). You can base the implementation of that on C++ algorithms.

While I very much appreciate the power of C++ algorithms, they are very generic which means that if you read the code, it may not be quite obvious what it is supposed to achieve. For this reason I tend to wrap even single calls to some algorithm in a separate function (where I unleash all the powers of boost function objects )
__________________
I might be wrong.

Quote:
Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
Quoted more than 1000 times (I hope).
anon is offline   Reply With Quote
Old 07-08-2009, 11:56 PM   #17
C++0x User
 
Tux0r's Avatar
 
Join Date: Nov 2008
Location: Sweden
Posts: 133
std::adjacent_find does its job :P
Tux0r is offline   Reply With Quote
Old 07-09-2009, 02:29 AM   #18
C++ Witch
 
laserlight's Avatar
 
Join Date: Oct 2003
Location: Singapore
Posts: 10,352
Quote:
Originally Posted by Tux0r
std::adjacent_find does its job :P
Yes, but I do not think anon was disputing that; it was perhaps not very prudent to say that "probably the cleanest way would be to define your own function" since that does not quite answer your question, so you need to read it in the context of "you can implement it using STL algorithms".

If you can come up with a name that is more descriptive than all (like all_equal, I suppose), then by implementing a function template you enhance the readability of your code and actually reduce the "reinvention of the wheel" since you now can apply your generic algorithm instead of implementing what you want to do using a more generic algorithm every time you want to do it.

In the case of an array, you might even save on an unnecessary computation of a one past the end pointer (though compiler optimisation may well do that for you anyway), since the use of adjacent_find in this case uses a one past the end iterator twice.
__________________
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar

Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
laserlight is offline   Reply With Quote
Reply

Tags
class, operator==

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
stl error eklavya8 C++ Programming 8 06-30-2008 12:01 PM
"error: incomplete type is not allowed" Fahrenheit C++ Programming 9 05-10-2005 09:52 PM
Problem with Template Function and overloaded equality operator silk.odyssey C++ Programming 7 06-08-2004 04:30 AM
operator== Unregistered C++ Programming 4 03-26-2002 05:24 PM


All times are GMT -6. The time now is 11:05 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22