[Insight-developers] namespace itk

Brad King brad.king at kitware.com
Wed Aug 9 13:39:08 EDT 2000


I have changed the way in which we delimit the "itk" namespace in all
currently checked in sources in Insight/Code/Common.  Please use this
method in all new files:

To begin the namespace, use:

ITK_NAMESPACE_BEGIN

instead of

namespace itk {

To end the namespace, use:

ITK_NAMESPACE_END

instead of

} // namespace itk

These macros are defined in itkMacro.h, so they should be available in all
sources.  They are simply defined as:

#define ITK_NAMESPACE_BEGIN namespace itk {
#define ITK_NAMESPACE_END   }

Reasons for using macros instead of the namespace keyword include:

1.) Improved readability.  Although "namespace itk {" was clear,
a comment was required to mark the end of the namespace
("}" v. "} // namespace itk"), and it is easy to forget to write the
comment.

2.) It is easy to change the name of the namespace, or remove it
completely.

3.) Nothing fancy is needed to prevent emacs from indenting any extra
spaces due to the { and } delimiters.

This approach to namespaces used on a large scale seems to be somewhat
common.  An example is in SGI's implementation of STL
(http://www.sgi.com/Technology/STL).  Here the macros are used for the
"std" namespace, in case a compiler wants to ignore it (like gcc without
-fhonor-std).

If anyone has any arguments against this approach, feel free to post them
here.  It would be really easy to remove all the macros, and replace them
with the old "namespace itk {...} //namespace itk" approach.

-Brad






More information about the Insight-developers mailing list