C++ style guide: Difference between revisions

Jump to navigation Jump to search
97 bytes added ,  21 December 2023
m
Line 155: Line 155:
=== Namespace ===
=== Namespace ===


All code should be in the octave namespace.  This is an ongoing project.  We
All code should be in the {{codeline|octave}} namespace or in a namespace below it.
are still moving existing classes into namespaces but all new classes
should go somewhere into the "octave" namespace.  There is 1 extra level for namespaces
inside octave to be used with care, we don't want too many namespaces.
Ask before creating a new namespace.


* Indent namespaces as any other block.  Emacs and other editors can do this automatically.
Namespaces should start and stop using the special macros {{codeline|OCTAVE_BEGIN_NAMESPACE(XXX)}} and {{codeline|OCTAVE_END_NAMESPACE(XXX)}}. There is no indentation of code that is placed into namespaces using these macros.
* Define namespace on the .cc files;
* Do not use "using X" directives;
* Do not declare anything on the std namespace;


{{Code|namespace style on a .h file|<syntaxhighlight lang="cpp">
Example
// Note indentation
 
namespace octave
{{Code|Use of namespace macros|<syntaxhighlight lang="cpp">
{
OCTAVE_BEGIN_NAMESPACE(octave)
  namespace math
 
  {
OCTAVE_BEGIN_NAMESPACE(math)
    class foo
 
    {
template <typename T>
    public:
void
      foo (...);
umfpack_report_control (const double *Control);
    };
 
  }
OCTAVE_END_NAMESPACE(math)
}
OCTAVE_END_NAMESPACE(octave)
</syntaxhighlight>}}
</syntaxhighlight>}}


{{Code|namespace style on a .cc file|<syntaxhighlight lang="cpp">
If bare namespace directives must be used, as occasionally is required in Qt code, then the code within the namespace should be indented.
// Note indentation and that functions are not defined
 
// as "octave::math::foo:foo"
{{Code|bare namespace usage|<syntaxhighlight lang="cpp">
// Note indentation and that functions are not defined as "octave::math::foo:foo"
namespace octave
namespace octave
{
{
Line 195: Line 189:
}
}
</syntaxhighlight>}}
</syntaxhighlight>}}
==== Other Guidelines ====
* Do not use {{codeline|using XXX;}} directives
* Do not declare anything on the {{codeline|std::}} namespace


== Naming ==
== Naming ==
1,072

edits

Navigation menu