Thread: operator==

  1. #16
    The larch
    Join Date
    May 2006
    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.

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

  2. #17
    C++11 User Tux0r's Avatar
    Join Date
    Nov 2008
    std::adjacent_find does its job :P

  3. #18
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

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

Tags for this Thread

Website Security Test