From 2e5cbc218c9b03ca27ff54d1d63201de6484666e Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 7 Aug 2003 21:45:47 +0000 Subject: [PATCH] * Fix <>'s in code to be <>'s * Add section describing how we prefer #includes to be ordered git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7697 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/CodingStandards.html | 80 ++++++++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 26 deletions(-) diff --git a/docs/CodingStandards.html b/docs/CodingStandards.html index ace2d70c20a..1f6efd65793 100644 --- a/docs/CodingStandards.html +++ b/docs/CodingStandards.html @@ -14,6 +14,7 @@
  1. Commenting
  2. Comment Formatting +
  3. #include Style
  4. Source Code Width
  5. Use Spaces Instead of Tabs
  6. Indent Code Consistently @@ -123,6 +124,39 @@ In general, prefer C++ style (//) comments. They take less space, requ To comment out a large block of code, use #if 0 and #endif. These nest properly and are better behaved in general than C style comments.

    + +


    #include Style


    Source Code Width

      @@ -253,12 +287,6 @@ of these that defines an interface. This interface may be several functions, classes or data structures, but the important issue is how they work together.

      - - In general, a module should be implemented with one or more .cpp files. Each of these .cpp files should include the header that defines their interface first. This ensure that all of the dependences of the module header @@ -450,13 +478,13 @@ rather than a set of member functions, which leaves some leeway in how you actually implement it. Typically it looks something like this (I'll start with the const-iterator-only situation): - #include + #include <iterator> class container { public: typedef something_or_other value_type; class const_iterator: - public std::iterator { + public std::iterator<std::forward_iterator_tag, value_type> { friend class container; public: const value_type& operator*() const; @@ -568,7 +596,7 @@ the simple addition of a second class. typedef something_or_other value_type; class const_iterator; class iterator: - public std::iterator { + public std::iterator<std::forward_iterator_tag, value_type> { friend class container; friend class container::const_iterator; public: @@ -582,7 +610,7 @@ the simple addition of a second class. //... }; class const_iterator: - public std::iterator { + public std::iterator<std::forward_iterator_tag, value_type> { friend class container; public: const_iterator(); @@ -615,7 +643,7 @@ Bidirectional iterators add just two member functions to forward iterators: class iterator: - public std::iterator { + public std::iterator<std::bidirectional_iterator_tag, value_type> { public: //... iterator& operator--(); @@ -629,7 +657,7 @@ operator++(). Random access iterators add several more member and friend functions: class iterator: - public std::iterator { + public std::iterator<std::random_access_iterator_tag, value_type> { public: //... iterator& operator+=(difference_type rhs); @@ -638,10 +666,10 @@ Random access iterators add several more member and friend functions: friend iterator operator+(difference_type lhs, iterator rhs); friend iterator operator-(iterator lhs, difference_type rhs); friend difference_type operator-(iterator lhs, iterator rhs); - friend bool operator<(iterator lhs, iterator rhs); - friend bool operator>(iterator lhs, iterator rhs); - friend bool operator<=(iterator lhs, iterator rhs); - friend bool operator>=(iterator lhs, iterator rhs); + friend bool operator<(iterator lhs, iterator rhs); + friend bool operator>(iterator lhs, iterator rhs); + friend bool operator<=(iterator lhs, iterator rhs); + friend bool operator>=(iterator lhs, iterator rhs); //... }; @@ -677,24 +705,24 @@ Random access iterators add several more member and friend functions: // calculate distance between iterators } - bool operator<(container::iterator lhs, container::iterator rhs) { + bool operator<(container::iterator lhs, container::iterator rhs) { // perform less-than comparison } - bool operator>(container::iterator lhs, container::iterator rhs) { - return rhs < lhs; + bool operator>(container::iterator lhs, container::iterator rhs) { + return rhs < lhs; } - bool operator<=(container::iterator lhs, container::iterator rhs) { - return !(rhs < lhs); + bool operator<=(container::iterator lhs, container::iterator rhs) { + return !(rhs < lhs); } - bool operator>=(container::iterator lhs, container::iterator rhs) { - return !(lhs < rhs); + bool operator>=(container::iterator lhs, container::iterator rhs) { + return !(lhs < rhs); } Four of the functions (operator+=(), operator-=(), the second -operator-(), and operator<()) are nontrivial; the rest are +operator-(), and operator<()) are nontrivial; the rest are boilerplate. One feature of the above code that some experts may disapprove of is @@ -712,7 +740,7 @@ I hope all this is some help to anyone who needs to write their own STL-like containers and iterators. -- -Ross Smith The Internet Group, Auckland, New Zealand +Ross Smith <ross.s@ihug.co.nz> The Internet Group, Auckland, New Zealand @@ -741,7 +769,7 @@ If you get some free time, and you haven't read them: do so, you might learn som

      Chris Lattner
      -Last modified: Fri Jul 25 12:29:52 CDT 2003 +Last modified: Thu Aug 7 16:44:33 CDT 2003