C++ Logo

std-proposals

Advanced search

[std-proposals] Macro scope

From: BAMBYK <uravasinski_at_[hidden]>
Date: Fri, 1 Sep 2023 08:34:29 +0300
This is similar to a regular namespace but with macros. Libraries does
often use macros and it is usually done by a large of capital letters with
the identificator of library at the beginning (boost for example):
BOOST_<macro meaning>

But a something similar to namespace can be used for grouping such kind of
macros.
# scope BOOST
 # define macro1
 # define macro2
 # define one 1
# endscope
 // apply macro 'one' from the scope BOOST
 BOOST.one;
 // do some preprocessor conditions
 # ifdef BOOST.one
  std::cout << "A scope BOOST has macro 'one'." << '\n';
 # endif

Or if a macro is used in settings purpose

# scope BOOST
  /*
here we define a scope with specific macro that is used in boost library as
setting (for example)
 */
 # define setting1
# endscope

// inside boost library

# scope BOOST
 // other macros of BOOST library
 # define setting2
# endscope

/*
   first scope BOOST and second are concatenated and in result the BOOST
consists of:
   setting1
   setting2

   So this way we've defined a custom setting for that scope
*/

# ifdef BOOST.setting1
  // do something
# endif


These scopes can be used for other purposes too and not for library only as
they let user group their macros better. The benefit is also it is not
wholly consists of the capslock so is easer to read.

Received on 2023-09-01 05:34:42