User Tools

Site Tools


c

This is an old revision of the document!


C++

Eventually you will have to code in C++. You must have a solid understanding and skill regarding the following topics:

Our Coding Style

To uphold the quality of our implementations, it is vital to apply a unified coding style. Please adhere to the following guidelines, as shown in the following example class implementation, at all times.

template<typename SomeT, int ArgV, typename SomeTagT>
class typical_class  
{
  typedef typename result_of::meta_func<SomeT>::type   InternalType;
 
public:
  typedef SomeT     SomeType;
  typedef SomeType  some_type;
 
  static const int ArgValue  = ValueV;
  static const int arg_value = ValueV;
 
  template <typename AnotherT>
  void member_func(AnotherT const & foo) const
  {
    typedef typename result_of::more_meta<AnotherT>::type  BarType;
 
    if (short_condition)
      do_something();
 
    if ( very_long_condition )
    {
      lot_of_work();
      something_else();
    }
    ...
  }
 
  ...
 
private:
  SomeType  member_;
  int       value_;
};

Mind the following details:

  • No space after template keyword
  • Use of 'typename' for template parameters rather than class
  • Template arguments with trailing 'T' or 'V'
  • Opening braces on next line (one-liners may drop braces)
  • 2 spaces for each level of indentation (no tabs)
  • Public mapped members in both CamelCase and lower_case
  • Mapped types with trailing Type
  • Functions lower_case (including meta functions)
  • Alignment of subsequent code lines:
    SomeType  member_;
    int       value_;

rather than

    SomeType member_;
    int value_;
  • “<TYPE> const &” is preferred over “const <TYPE> &”
  • static const instead of enum for publishing integral template arguments
  • No indentation of public/private in order to easily convert a struct into a class later.
  • Functions may also be formatted as foo( a, b, c ); if this is visually more appealing. Same with < A<B> > for templates.
  • Avoid a trailing _t for the class name when part of the public API
c.1399542994.txt.gz · Last modified: 2014/05/08 09:56 by viennastar