Changes between Initial Version and Version 1 of Guidelines/Header


Ignore:
Timestamp:
Feb 14, 2010, 12:01:15 PM (13 years ago)
Author:
Daniel James
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Guidelines/Header

    v1 v1  
     1[[PageOutline]]
     2
     3= Boost Header policy = #intro
     4
     5Header files are the place where a library comes into
     6contact with user code and other libraries. To co-exist
     7peacefully and productively, headers must be "good
     8neighbors".
     9
     10Here are the standards for boost headers. Many of these are
     11also reasonable guidelines for general use.
     12
     13
     14 * Header filenames should have a .hpp (lowercase) extension.
     15 * Unless multiple inclusion is intended, wrap the header in
     16   #ifndef guards. Use a naming convention that minimizes the
     17   chance of clashes with macro names from other's code. The
     18   [#SampleHeader sample header] uses the Boost
     19   convention of all uppercase letters, with the header name
     20   prefixed by the namespace name, and suffixed with HPP,
     21   separated by underscores.
     22 * Wrap the header contents in a namespace to prevent global
     23   namespace pollution. The namespace approach to pollution
     24   control is strongly preferred to older approaches such as
     25   adding funny prefixes to global names. Libraries which are
     26   designed to work well with other Boost libraries should be
     27   placed in namespace `boost`.
     28 * Make sure that a translation unit consisting of just the
     29   contents of the header file will compile successfully.
     30 * Place the header file in a sub-directory to prevent
     31   conflict with identically named header files in other
     32   libraries. The parent directory is added to the compiler's
     33   include search path. Then both your code and user code
     34   specifies the sub-directory in `#include` directives.
     35   Thus the header [#SampleHeader sample header]
     36   would be included by `#include <boost/furball.hpp>`
     37 * The preferred ordering for class definitions is public
     38   members, protected members, and finally private members.
     39 * Include the boost/config.hpp
     40   [http://www.boost.org/doc/libs/release/libs/config/config.htm configuration header]
     41   if there is a need to deal with compiler or
     42   platform configuration issues.
     43
     44== Sample Header == #SampleHeader
     45
     46{{{
     47#!html
     48<pre>
     49//  Boost general library furball.hpp header file ---------------------------//
     50
     51  &lt;<i> Copyright and license notice</i>, as indicated in the <a href=
     52"http://www.boost.org/users/license.html">license page</a> &gt;
     53
     54//  See http://www.boost.org/ for latest version.
     55
     56#ifndef BOOST_FURBALL_HPP
     57#define BOOST_FURBALL_HPP
     58
     59namespace boost {
     60
     61//  Furball class declaration  -----------------------------------------------//
     62
     63  class furball
     64  {
     65    public:
     66      void throw_up();
     67    private:
     68      int whatever;
     69  };  // furball
     70
     71} // namespace
     72
     73#endif  // include guard
     74</pre>
     75}}}
     76
     77== Coding Style == #style
     78
     79The alert reader will have noticed that the
     80[#SampleHeader sample header] employs a certain coding
     81style for indentation, positioning braces, commenting ending
     82braces, and similar formatting issues. These stylistic issues
     83are viewed as personal preferences and are not part of the
     84Boost Header Policy.