operator==

This is a discussion on operator== within the C++ Programming forums, part of the General Programming Boards category; It doesn't feel like reinventing the wheel that much (perhaps even a more specific function all_equal , since the call ...

  1. #16
    The larch
    Join Date
    May 2006
    Posts
    3,573
    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
    Location
    Sweden
    Posts
    135
    std::adjacent_find does its job :P

  3. #18
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,717
    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
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Page 2 of 2 FirstFirst 12
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


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