Boost Configuration Guide for C++
Boost Configuration Guide for C++
Config
Vesa Karvonen, John Maddock Beman Dawes
Copyright © 2001-2007 Beman Dawes, Vesa Karvonen, John Maddock
Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
[Link]
Table of Contents
Configuring Boost for Your Platform ......................................................................................................................... 2
Using the default boost configuration ................................................................................................................. 2
The <boost/[Link]> header ......................................................................................................................... 2
Using the configure script ................................................................................................................................ 2
User settable options ....................................................................................................................................... 3
Advanced configuration usage .......................................................................................................................... 6
Testing the boost configuration ......................................................................................................................... 7
Boost Macro Reference ........................................................................................................................................... 9
Macros that describe C++03 defects .................................................................................................................. 9
Macros that describe optional features .............................................................................................................. 16
Macros that describe possible C++ future features .............................................................................................. 22
Macros that describe C++11 features not supported ............................................................................................. 22
Macros that allow use of C++11 features with C++03 compilers ............................................................................ 25
Boost Helper Macros .................................................................................................................................... 29
Boost Informational Macros ........................................................................................................................... 35
Boost Deprecated Macros .............................................................................................................................. 37
Macros for libraries with separate source code ................................................................................................... 40
Standard Integer Types .......................................................................................................................................... 45
Overview .................................................................................................................................................... 45
Rationale .................................................................................................................................................... 45
Caveat emptor ............................................................................................................................................. 45
Exact-width integer types ............................................................................................................................... 45
Minimum-width integer types ......................................................................................................................... 45
Fastest minimum-width integer types ............................................................................................................... 46
Greatest-width integer types ........................................................................................................................... 46
Integer Constant Macros ................................................................................................................................ 46
Guidelines for Boost Authors .................................................................................................................................. 48
Disabling Compiler Warnings ......................................................................................................................... 48
Adding New Defect Macros ........................................................................................................................... 49
Adding New Feature Test Macros .................................................................................................................... 50
Modifying the Boost Configuration Headers ...................................................................................................... 50
Rationale ............................................................................................................................................................ 51
The problem ................................................................................................................................................ 51
The solution ................................................................................................................................................ 51
Acknowledgements ............................................................................................................................................... 52
Using boost "as is" without trying to reconfigure is the recommended method for using boost. You can, however, run the configure
script if you want to, and there are regression tests provided that allow you to test the current boost configuration with your particular
compiler setup.
Boost library users can request support for additional compilers or platforms by visiting our Trac and submitting a support request.
#include <boost/[Link]>
While Boost library users are not required to include that file directly, or use those configuration macros, such use is acceptable. The
configuration macros are documented as to their purpose, usage, and limitations which makes them usable by both Boost library and
user code.
Boost informational or helper macros are designed for use by Boost users as well as for our own internal use. Note however, that
the feature test and defect test macros were designed for internal use by Boost libraries, not user code, so they can change at any
time (though no gratuitous changes are made to them). Boost library problems resulting from changes to the configuration macros
are caught by the Boost regression tests, so the Boost libraries are updated to account for those changes. By contrast, Boost library
user code can be adversely affected by changes to the macros without warning. The best way to keep abreast of changes to the
macros used in user code is to monitor the discussions on the Boost developers list.
If you know that boost is incorrectly configured for your particular setup, and you are on a UNIX like platform, then you may want
to try and improve things by running the boost configure script. From a shell command prompt you will need to cd into <boost-
root>/libs/config/ and type:
sh ./configure
you will see a list of the items being checked as the script works its way through the regression tests. Note that the configure script
only really auto-detects your compiler if it's called g++, c++ or CC. If you are using some other compiler you will need to set one
or more of the following environment variables:
Variable Description
For example to run the configure script with HP aCC, you might use something like:
export CXX="aCC"
export CXXFLAGS="-Aa -DAportable -D__HPACC_THREAD_SAFE_RB_TREE \
-DRWSTD_MULTI_THREAD -DRW_MULTI_THREAD -D_REENTRANT -D_THREAD_SAFE"
export LDFLAGS="-DAportable"
export LIBS="-lpthread"
sh ./configure
However you run the configure script, when it finishes you will find a new header -[Link]- located in the <boost-
root>/libs/config/ directory. Note that configure does not install this header into your boost include path by default. This
header contains all the options generated by the configure script, plus a header-section that contains the user settable options from
the default version of <boost/config/[Link]> (located under <boost-root>/boost/config/). There are two ways you can use
this header:
• Option 1: copy the header into <boost-root>/boost/config/ so that it replaces the default [Link] provided by boost. This
option allows only one configure-generated setup; boost developers should avoid this option, as it incurs the danger of accidentally
committing a configure-modified <boost/config/[Link]> to the svn repository (something you will not be thanked for!).
• Option 2: give the header a more memorable name, and place it somewhere convenient; then, define the macro
BOOST_USER_CONFIG to point to it. For example create a new sub-directory <boost-root>/boost/config/ user/, and copy
the header there; for example as [Link]. Then, when compiling add the command line option:
-DBOOST_USER_CONFIG="<boost/config/user/[Link]>", and boost will use the new configur-
ation header. This option allows you to generate more than one configuration header, and to keep them separate from the boost
source - so that updates to the source do not interfere with your configuration.
Macro Description
BOOST_USER_CONFIG When defined, it should point to the name of the user configur-
ation file to include prior to any boost configuration files. When
not defined, defaults to <boost/config/[Link]>.
BOOST_COMPILER_CONFIG When defined, it should point to the name of the compiler con-
figuration file to use. Defining this cuts out the compiler selec-
tion logic, and eliminates the dependency on the header contain-
ing that logic. For example if you are using gcc, then you could
define BOOST_COMPILER_CONFIG to <boost/config/com-
piler/[Link]>.
BOOST_STDLIB_CONFIG When defined, it should point to the name of the standard library
configuration file to use. Defining this cuts out the standard
library selection logic, and eliminates the dependency on the
header containing that logic. For example if you are using
STLport, then you could define BOOST_STDLIB_CONFIG to
<boost/config/stdlib/[Link]>.
BOOST_PLATFORM_CONFIG When defined, it should point to the name of the platform con-
figuration file to use. Defining this cuts out the platform selection
logic, and eliminates the dependency on the header containing
that logic. For example if you are compiling on linux, then you
could define BOOST_PLATFORM_CONFIG to <boost/con-
fig/platform/[Link]>.
BOOST_STRICT_CONFIG The normal behavior for compiler versions that are newer than
the last known version, is to assume that they have all the same
defects as the last known version. By setting this define, then
compiler versions that are newer than the last known version
are assumed to be fully conforming with the standard. This is
probably most useful for boost developers or testers, and for
those who want to use boost to test beta compiler versions.
Macro Description
BOOST_ASSERT_CONFIG When this flag is set, if the config finds anything unknown, then
it will stop with a #error rather than continue. Boost regression
testers should set this define, as should anyone who wants to
quickly check whether boost is supported on their platform.
BOOST_DISABLE_WIN32 When defined, disables the use of Win32 specific API's, even
when these are available. Also has the effect of setting
BOOST_DISABLE_THREADS unless BOOST_HAS_PTHREADS is
set. This option may be set automatically by the config system
when it detects that the compiler is in "strict mode".
BOOST_ALL_NO_LIB Tells the config system not to automatically select which librar-
ies to link against. Normally if a compiler supports #pragma lib,
then the correct library build variant will be automatically selec-
ted and linked against, simply by the act of including one of that
library's headers. This macro turns that feature off.
Macro Description
BOOST_WHATEVER_NO_LIB Tells the config system not to automatically select which library
to link against for library "whatever", replace WHATEVER in
the macro name with the name of the library; for example
BOOST_DATE_TIME_NO_LIB or BOOST_REGEX_NO_LIB. Nor-
mally if a compiler supports #pragma lib, then the correct
library build variant will be automatically selected and linked
against, simply by the act of including one of that library's
headers. This macro turns that feature off.
BOOST_LIB_TOOLSET Overrides the name of the toolset part of the name of library
being linked to; note if defined this must be defined to a quoted
string literal, for example "abc".
Boost's configuration is structured so that the user-configuration is included first (defaulting to <boost/config/[Link]> if
BOOST_USER_CONFIG is not defined). This sets up any user-defined policies, and gives the user-configuration a chance to influence
what happens next.
Next the compiler, standard library, and platform configuration files are included. These are included via macros (BOOST_COM-
PILER_CONFIG etc, see user settable macros), and if the corresponding macro is undefined then a separate header that detects which
compiler/standard library/platform is in use is included in order to set these. The config can be told to ignore these headers altogether
if the corresponding BOOST_NO_XXX macro is set (for example BOOST_NO_COMPILER_CONFIG to disable including any compiler
configuration file - see user settable macros).
Finally the boost configuration header, includes <boost/config/[Link]>; this header contains any boiler plate configuration code
- for example where one boost macro being set implies that another must be set also.
Now when you use boost, its configuration header will go straight to our "frozen" versions, and ignore the default versions, you will
now be insulated from any configuration changes when you update boost. This technique is also useful if you want to modify some
of the boost configuration files; for example if you are working with a beta compiler release not yet supported by boost.
File Description
no_*[Link] Individual compiler defect test files. Each of these should com-
pile, if one does not then the corresponding BOOST_NO_XXX
macro needs to be defined - see each test file for specific details.
no_*[Link] Individual compiler defect test files. Each of these should not
compile, if one does then the corresponding BOOST_NO_XXX
macro is defined when it need not be - see each test file for
specific details.
has_*[Link] Individual feature test files. If one of these does not compile
then the corresponding BOOST_HAS_XXX macro is defined when
it should not be - see each test file for specific details.
has_*[Link] Individual feature test files. If one of these does compile then
the corresponding BOOST_HAS_XXX macro can be safely defined
- see each test file for specific details.
Although you can run the configuration regression tests as individual test files, there are rather a lot of them, so there are a couple
of shortcuts to help you out:
If you have built the boost regression test driver, then you can use this to produce a nice html formatted report of the results using
the supplied test file.
./configure --enable-test
in which case the script will test the current configuration rather than creating a new one from scratch.
If you are reporting the results of these tests for a new platform/library/compiler then please include a log of the full compiler output,
the output from config_info.cpp, and the pass/fail test results.
10
template<typename T>
struct foo : {
template<typename U>
struct bar : public U {};
};
template<class T, type↵
name T::type value>
class X { ... };
// #1
template<class T> void f(T);
// #2
tem↵
plate<class T,class U> void f(T(*)(U));
void bar(int);
11
12
13
BOOST_NO_RTTI Compiler The compiler may (or may not) have the
typeid operator, but RTTI on the dynamic
type of an object is not supported.
BOOST_NO_STD_ALLOCATOR Standard library The C++ standard library does not provide
a standards conforming std::allocat-
or.
BOOST_NO_STD_MIN_MAX Standard library The C++ standard library does not provide
the min() and max() template functions
that should be in <algorithm>.
14
15
void f() {}
void g() { return f(); }
16
17
BOOST_HAS_SGI_TYPE_TRAITS Compiler, Standard library The compiler has native support for SGI
style type traits.
18
19
20
21
Macro Description
22
Macro Description
BOOST_NO_CXX11_ATOMIC_SMART_PTR The standard library <memory> does not support atomic smart
pointer operations.
BOOST_NO_CXX11_HDR_FUNCTIONAL The standard library does not provide a C++11 compatible ver-
sion of <functional>.
23
Macro Description
BOOST_NO_CXX11_AUTO_DECLARATIONS The compiler does not support type deduction for variables de-
clared with the auto keyword (auto var = ...;).
BOOST_NO_CXX11_AUTO_MULTIDECLARATIONS The compiler does not support type deduction for multiple
variables declared with the auto keyword (auto var = ...,
*ptr = ...;).
BOOST_NO_CXX11_DECLTYPE_N3276 The compiler does not support the extension to decltype de-
scribed in N3276, accepted in Madrid, March 2011.
BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS The compiler does not support default template arguments for
function templates.
BOOST_NO_CXX11_LOCAL_CLASS_TEMPLATE_PARAMETERS The compiler does not allow to pass local classes as template
parameters (this macro intentionally does not control passing
of unnamed types as template parameters, see also N2657).
24
Macro Description
BOOST_NO_CXX11_TRAILING_RESULT_TYPES The compiler does not support the new function result type
specification syntax (e.g. auto foo(T) -> T;).
BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX The compiler does not support the C++11 Unified Initialization
Syntax.
25
Macro Description
BOOST_ALIGNMENT(X), BOOST_NO_ALIGNMENT Some compilers don't support the alignas keyword but provide
other means to specify alignment (usually, through compiler-
specific attributes). The macro BOOST_ALIGNMENT(X) will
expand to the alignas(X) keyword if the compiler supports
it or to some compiler-specific attribute to achieve the specified
alignment. If no such compiler-specific attribute is known then
BOOST_ALIGNMENT(X) will expand to nothing and
BOOST_NO_ALIGNMENT will be defined. Unlike native alignas,
X must always be a compile-time integer constant. The macro
can be used to specify alignment of types and data:
BOOST_CONSTEXPR Some compilers don't support the use of constexpr. This macro
expands to nothing on those compilers, and constexpr else-
where. For example, when defining a constexpr function or
constructor replace:
constexpr tuple();
with:
BOOST_CONSTEXPR tuple();
BOOST_CONSTEXPR_OR_CONST Some compilers don't support the use of constexpr. This macro
expands to const on those compilers, and constexpr else-
where. For example, when defining const expr variables replace:
with:
static BOOST_CONSTEX↵
PR_OR_CONST UIntType xor_mask = a;
with:
26
Macro Description
struct my_struct
{
BOOST_DEFAULTED_FUNCTION(my_struct(), {})
};
is equivalent to:
struct my_struct
{
my_struct() = default;
};
or:
struct my_struct
{
my_struct() {}
};
27
Macro Description
struct noncopyable
{
BOOST_DELETED_FUNCTION(noncopyable(noncopy↵
able const&))
BOOST_DELETED_FUNCTION(noncopyable& oper↵
ator= (noncopyable const&))
};
is equivalent to:
struct noncopyable
{
noncopyable(noncopyable const&) = delete;
noncopyable& operator= (noncopy↵
able const&) = delete;
};
or:
struct noncopyable
{
private:
noncopyable(noncopyable const&);
noncopyable& operator= (noncopy↵
able const&);
};
28
Macro Description
BOOST_MSVC_ENABLE_2012_NOV_CTP For Microsoft Visual C++ 2012, enable the C++11 features
supplied by the November 2012 Community Technology Pre-
view. These features are not automatically enabled because the
CTP is non-supported alpha code that is not recommended for
production use. This macro must be defined before including
any Boost headers, and must be defined for all translation units
in the program, including Boost library builds. This macro will
no longer have any effect once an official Microsoft release
supports the CTP features.
29
Macro Description
#include <boost/detail/[Link]>
usage is then:
BOOST_PREVENT_MACRO_SUBSTITUTION Sometimes you have a function name with the same name as a
C macro, for example "min" and "max" member functions, in
which case one can prevent the function being expanded as a
macro using:
[Link] BOOST_PREVENT_MACRO_SUBSTITU↵
TION(arg1, arg2);
([Link])(arg1, arg2);
BOOST_DEDUCED_TYPENAME Some compilers don't support the use of typename for dependent
types in deduced contexts. This macro expands to nothing on
those compilers, and typename elsewhere. For example, replace:
template <class T> void f(T, typename T::type);
with: template <class T> void f(T, BOOST_DE-
DUCED_TYPENAME T::type);
30
Macro Description
BOOST_HASH_MAP_HEADER The header to include to get the SGI hash_map class. This
macro is only available if BOOST_HAS_HASH is defined.
BOOST_HASH_SET_HEADER The header to include to get the SGI hash_set class. This
macro is only available if BOOST_HAS_HASH is defined.
BOOST_SLIST_HEADER The header to include to get the SGI slist class. This macro
is only available if BOOST_HAS_SLIST is defined.
BOOST_STD_EXTENSION_NAMESPACE The namespace used for std library extensions (hashtable classes
etc).
struct foo{
static const int value = 2;
};
use:
struct foo{
BOOST_STATIC_CONSTANT(int, value = 2);
};
31
Macro Description
switch (x) {
case 40:
case 41:
if (truth_is_out_there) {
++x;
BOOST_FALLTHROUGH; // Use instead ↵
of/along with annotations in
// comments.
} else {
return x;
}
case 42:
...
32
Macro Description
BOOST_EXPLICIT_TEMPLATE_TYPE(t) BOOST_EXPLI- Some compilers silently "fold" different function template in-
CIT_TEMPLATE_NON_TYPE(t,v) BOOST_APPEND_EXPLI- stantiations if some of the template parameters don't appear in
CIT_TEMPLATE_TYPE(t) BOOST_APPEND_EXPLICIT_TEM- the function parameter list. For instance:
PLATE_NON_TYPE(t,v)
#include <iostream>
#include <ostream>
#include <typeinfo>
int main() {
f<1>();
f<2>();
g<int>();
g<double>();
}
BOOST_USE_FACET(Type, loc) When the standard library does not have a conforming
std::use_facet there are various workarounds available, but
they differ from library to library. This macro provides a consist-
ent way to access a locale's facets. For example, replace:
std::use_facet<Type>(loc); with: BOOST_USE_FA-
CET(Type, loc); Note do not add a std:: prefix to the front
of BOOST_USE_FACET.
33
Macro Description
BOOST_HAS_FACET(Type, loc) When the standard library does not have a comforming
std::has_facet there are various workarounds available, but
they differ from library to library. This macro provides a consist-
ent way to check a locale's facets. For example, replace:
std::has_facet<Type>(loc); with: BOOST_HAS_FA-
CET(Type, loc); Note do not add a std:: prefix to the front
of BOOST_HAS_FACET.
BOOST_JOIN(X,Y) This piece of macro magic joins the two arguments together,
even when one of the arguments is itself a macro (see 16.3.1 in
C++ standard). This is normally used to create a mangled name
in combination with a predefined macro such a __LINE__.
BOOST_FORCEINLINE This macro can be used in place of the inline keyword to in-
struct the compiler that the function should always be inlined.
Overuse of this macro can lead to significant bloat, while good
use can increase performance in certain cases, such as computa-
tion-intensive code built through generative programming
techniques.
Usage example:
template<class T>
BOOST_FORCEINLINE T& f(T& t)
{
return t;
}
Note that use of this macro can lead to cryptic error messages
with some compilers. Consider defining it to inline before
including the [Link] header in order to be able to debug
errors more easily.
BOOST_NOINLINE This macro can be used in place of the inline keyword to in-
struct the compiler that the function should never be inlined.
One should typically use this macro to mark functions that are
unlikely to be called, such as error handling routines.
Usage example:
34
Macro Description
Usage example:
BOOST_LIKELY(X) BOOST_UNLIKELY(X) These macros communicate to the compiler that the conditional
expression X is likely or unlikely to yield a positive result. The
expression should result in a boolean value. The result of the
macro is an integer or boolean value equivalent to the result of
X.
Usage example:
if (BOOST_UNLIKELY(ptr == NULL))
handle_error("ptr is NULL");
35
36
37
38
39
• Selecting which compiled library to link against based upon the compilers settings
40
The Microsoft VC++ compiler has long supplied __declspec(dllexport) and __declspec(dllimport) extensions for this
purpose, as do virtually all other compilers targeting the Windows platform.
Modern versions of the GNU GCC compiler provide the __attribute__((visibility("default"))) extension to indicate
that a symbol should be exported. All other symbols may be hidden by using the -fvisibility-hidden or -fvisibility-ms-com-
pat compiler switches.
Boost supplies several macros to make it easier to manage symbol visibility in a way that is portable between compilers and operating
systems.
Macro Description
Typical usage:
boost/foo/[Link]
41
...
#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_FOO_DYN_LINK)
# if defined(BOOST_FOO_SOURCE)
# define BOOST_FOO_DECL BOOST_SYMBOL_EXPORT
# else
# define BOOST_FOO_DECL BOOST_SYMBOL_IMPORT
# endif
#else
# define BOOST_FOO_DECL
#endif
...
boost/foo/[Link]
#include <boost/foo/[Link]>
...
class BOOST_FOO_DECL bar { ... };
...
void BOOST_FOO_DECL f();
...
boost/libs/foo/src/[Link]
#define BOOST_FOO_SOURCE
#include <boost/foo/[Link]>
...
void BOOST_FOO_DECL f()
{
...
}
...
ABI Fixing
When linking against a pre-compiled library it vital that the ABI used by the compiler when building the library matches exactly the
ABI used by the code using the library. In this case ABI means things like the struct packing arrangement used, the name mangling
scheme used, or the size of some types (enum types for example). This is separate from things like threading support, or runtime
library variations, which have to be dealt with by build variants. To put this in perspective there is one compiler (Borland's) that has
so many compiler options that make subtle changes to the ABI, that at least in theory there 3200 combinations, and that's without
considering runtime library variations. Fortunately these variations can be managed by #pragma's that tell the compiler what ABI
to use for the types declared in your library. In order to avoid sprinkling #pragma's all over the boost headers, there are some prefix
and suffix headers that do the job. Typical usage is:
my_library.hpp
42
#ifndef MY_INCLUDE_GUARD
#define MY_INCLUDE_GUARD
namespace boost {
my_library.cpp
...
// nothing special need be done in the implementation file
...
The user can disable this mechanism by defining BOOST_DISABLE_ABI_HEADERS, or they can define BOOST_ABI_PREFIX and/or
BOOST_ABI_SUFFIX to point to their own prefix/suffix headers if they so wish.
To solve this issue, some compilers allow source code to contain #pragma's that instruct the linker which library to link against, all
the user need do is include the headers they need, place the compiled libraries in their library search path, and the compiler and linker
do the rest. [Link] supports this via the header <boost/config/auto_link.hpp>, before including this header one or more
of the following macros need to be defined:
BOOST_LIB_NAME Required: An identifier containing the basename of the library, for example 'boost_regex'.
BOOST_DYN_LINK Optional: when set link to dll rather than static library.
BOOST_LIB_DIAGNOSTIC Optional: when set the header will print out the name of the library selected (useful for debugging).
If the compiler supports this mechanism, then it will be told to link against the appropriately named library, the actual algorithm
used to mangle the name of the library is documented inside <boost/config/auto_link.hpp> and has to match that used to
create the libraries via bjam 's install rules.
my_library.hpp
43
...
//
// Don't include auto-linking code if the user has disabled it by
// defining BOOST_ALL_NO_LIB, or BOOST_MY_LIBRARY_NO_LIB, or if this
// is one of our own source files (signified by BOOST_MY_LIBRARY_SOURCE):
//
#if !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_MY_LIBRARY_NO_LIB) && !defined(BOOST_MY_LIB↵
RARY_SOURCE)
# define BOOST_LIB_NAME boost_my_library
# ifdef BOOST_MY_LIBRARY_DYN_LINK
# define BOOST_DYN_LINK
# endif
# include <boost/config/auto_link.hpp>
#endif
...
my_library.cpp
#include <boost/my_library/my_library.hpp>
...
44
The specifications for these types are based on the ISO/IEC 9899:1999 C Language standard header <stdint.h>. The 64-bit types
required by the C standard are not required in the boost header, and may not be supplied for all platforms/compilers, because long
long is not [yet] included in the C++ standard.
Rationale
The organization of the [Link] headers and classes is designed to take advantage of <stdint.h> types from the 1999 C standard
without causing undefined behavior in terms of the 1998 C++ standard. The header <boost/[Link]> makes the standard integer
types safely available in namespace boost without placing any names in namespace std. The intension is to complement rather
than compete with the C++ Standard Library. Should some future C++ standard include <stdint.h> and <cstdint>, then
<boost/[Link]> will continue to function, but will become redundant and may be safely deprecated.
Because these are boost headers, their names conform to boost header naming conventions rather than C++ Standard Library header
naming conventions.
Caveat emptor
As an implementation artifact, certain C <limits.h> macro names may possibly be visible to users of <boost/[Link]>. Don't use
these macros; they are not part of any Boost-specified interface. Use boost::integer_traits<> or std::numeric_limits<>
instead.
As another implementation artifact, certain C <stdint.h> typedef names may possibly be visible in the global namespace to users of
<boost/[Link]>. Don't use these names, they are not part of any Boost-specified interface. Use the respective names in namespace
boost instead.
These types are optional. However, if a platform supports integer types with widths of 8, 16, 32, 64, or any combination thereof,
then <boost/[Link]> does provide the corresponding typedefs.
The following minimum-width integer types are provided for all platforms:
• int_least8_t
• int_least16_t
45
• int_least32_t
• uint_least8_t
• uint_least16_t
• uint_least32_t
The following types are available only if, after including <boost/[Link]>, the macro BOOST_NO_INT64_T is not defined:
• int_least64_t
• uint_least64_t
There is no guarantee that these types are fastest for all purposes. In any case, however, they satisfy the signedness and width require-
ments.
The following fastest minimum-width integer types are provided for all platforms:
• int_fast8_t
• int_fast16_t
• int_fast32_t
• uint_fast8_t
• uint_fast16_t
• uint_fast32_t
The following types are available only if, after including <boost/[Link]>, the macro BOOST_NO_INT64_T is not defined:
• int_fast64_t
• uint_fast64_t
The typedef uintmax_t designates an unsigned integer type capable of representing any value of any unsigned integer type.
The macros INT64_C and UINT64_C are also defined if the the macro BOOST_NO_INT64_T is not defined.
46
For example:
#include <boost/[Link]>
47
Centralizing configuration information in this header reduces the number of files that must be modified when porting libraries to
new platforms, or when compilers are updated. Ideally, no other files would have to be modified when porting to a new platform.
Configuration headers are controversial because some view them as condoning broken compilers and encouraging non-standard
subsets. Adding settings for additional platforms and maintaining existing settings can also be a problem. In other words, configuration
headers are a necessary evil rather than a desirable feature. The boost [Link] policy is designed to minimize the problems and
maximize the benefits of a configuration header.
Note that:
• Boost library implementers are not required to "#include <boost/[Link]>", and are not required in any way to support
compilers that do not comply with the C++ Standard (ISO/IEC 14882).
• If a library implementer wishes to support some non-conforming compiler, or to support some platform specific feature, "#include
<boost/[Link]>" is the preferred way to obtain configuration information not available from the standard headers such
as <climits>, etc.
• If configuration information can be deduced from standard headers such as <climits>, use those standard headers rather than
<boost/[Link]>.
• Boost files that use macros defined in <boost/[Link]> should have sensible, standard conforming, default behavior if the
macro is not defined. This means that the starting point for porting <boost/[Link]> to a new platform is simply to define
nothing at all specific to that platform. In the rare case where there is no sensible default behavior, an #error message should describe
the problem.
• If a Boost library implementer wants something added to [Link], post a request on the Boost mailing list. There is no
guarantee such a request will be honored; the intent is to limit the complexity of [Link].
• The intent is to support only compilers which appear on their way to becoming C++ Standard compliant, and only recent releases
of those compilers at that.
• The intent is not to disable mainstream features now well-supported by the majority of compilers, such as namespaces, exceptions,
RTTI, or templates.
Note that:
• This header should never be included by another Boost header, it should only ever be used by a library source file or a test
case.
• The header should be included before you include any other header.
• This header only disables warnings that are hard or impossible to otherwise deal with, and which are typically emitted by one
compiler only, or in one compilers own standard library headers.
48
Compiler Warning
Visual C++ 8 and later C4996: Error 'function': was declared deprecated
Intel C++ Warning 1786: relates to the use of "deprecated" standard library
functions rather like C4996 in Visual C++.
When you name the macro, follow the BOOST_NO_SOMETHING naming convention, so that it's obvious that this is a macro reporting
a defect.
Finally, add the test program to the regression tests. You will need to place the test case in a .ipp file with the following comments
near the top:
// MACRO: BOOST_NO_FOO
// TITLE: foo
// DESCRIPTION: If the compiler fails to support foo
These comments are processed by the autoconf script, so make sure the format follows the one given. The file should be named
"boost_no_foo.ipp", where foo is the defect description - try and keep the file name under the Mac 30 character filename limit
though. You will also need to provide a function prototype "int test()" that is declared in a namespace with the same name as
the macro, but in all lower case, and which returns zero on success:
namespace boost_no_foo {
int test()
{
// test code goes here:
//
return 0;
}
Once the test code is in place in libs/config/test, updating the configuration test system proceeds as:
• cd into libs/config/tools and run bjam. This generates the .cpp file test cases from the .ipp file, updates the libs/con-
fig/test/all/Jamfile.v2, config_test.cpp and config_info.cpp.
• cd into libs/config/test/all and run bjam MACRONAME compiler-list, where MACRONAME is the name of the
new macro, and compiler-list is a space separated list of compilers to test with.
The xxx_pass_test and the xxx_fail_test should both report **passed**.
If MACRONAME is not defined when it should be defined, xxx_pass_test will not report **passed**. If MACRONAME is
defined when it should not be defined, xxx_fail_test will not report **passed**.
• cd into libs/config/test and run bjam config_info config_test compiler-list. config_info should build and
run cleanly for all the compilers in compiler-list while config_test should fail for those that have the defect, and pass for
those that do not.
• Define the defect macro in those config headers that require it.
49
• Document the macro in this documentation (please do not forget this step!!)
• Commit everything.
• Keep an eye on the regression tests for new failures in [Link] caused by the addition.
<boost/config/[Link]> is included by default, don't add extra code to this file unless you have to. If you do, please remember to
update libs/config/tools/[Link] as well.
<boost/config/[Link]> is always included so be careful about modifying this file as it breaks dependencies for everyone. This
file should include only "boilerplate" configuration code, and generally should change only when new macros are added.
The compiler/platform/standard library selection code is set up so that unknown platforms are ignored and assumed to be fully
standards compliant - this gives unknown platforms a "sporting chance" of working "as is" even without running the configure script.
When adding or modifying the individual mini-configs, assume that future, as yet unreleased versions of compilers, have all the defects
of the current version. Although this is perhaps unnecessarily pessimistic, it cuts down on the maintenance of these files, and exper-
ience suggests that pessimism is better placed than optimism here!
50
Rationale
The problem with many traditional "textbook" implementations of configuration headers (where all the configuration options are in
a single "monolithic" header) is that they violate certain fundamental software engineering principles which would have the effect
of making boost more fragile, more difficult to maintain and more difficult to use safely. You can find a description of the principles
from the following article.
The problem
Consider a situation in which you are concurrently developing on multiple platforms. Then consider adding a new platform or
changing the platform definitions of an existing platform. What happens? Everything, and this does literally mean everything, recom-
piles. Isn't it quite absurd that adding a new platform, which has absolutely nothing to do with previously existing platforms, means
that all code on all existing platforms needs to be recompiled?
Effectively, there is an imposed physical dependency between platforms that have nothing to do with each other. Essentially, the
traditional solution employed by configuration headers does not conform to the Open-Closed Principle:
"A module should be open for extension but closed for modification."
Furthermore, consider the complexity and fragility of the platform detection code. What if a simple change breaks the detection on
some minor platform? What if someone accidentally or on purpose (as a workaround for some other problem) defines some platform
dependent macros that are used by the detection code? A traditional configuration header is one of the most volatile headers of the
entire library, and more stable elements of Boost would depend on it. This violates the Stable Dependencies Principle:
After even a minor change to a traditional configuration header on one minor platform, almost everything on every platform should
be tested if we follow sound software engineering practice.
Another important issue is that it is not always possible to submit changes to <boost/[Link]>. Some boost users are currently
working on platforms using tools and libraries that are under strict Non-Disclosure Agreements. In this situation it is impossible to
submit changes to a traditional monolithic configuration header, instead some method by which the user can insert their own config-
uration code must be provided.
The solution
The approach taken by boost's configuration headers is to separate configuration into three orthogonal parts: the compiler, the
standard library and the platform. Each compiler/standard library/platform gets its own mini-configuration header, so that changes
to one compiler's configuration (for example) does not affect other compilers. In addition there are measures that can be taken both
to omit the compiler/standard library/platform detection code (so that adding support to a new platform does not break dependencies),
or to freeze the configuration completely; providing almost complete protection against dependency changes.
51
Acknowledgements
Beman Dawes provided the original [Link] and part of this document.
Vesa Karvonen provided a description of the principles (see rationale) and put together an early version of the current configuration
setup.
John Maddock put together the configuration current code, the test programs, the configuration script and the reference section of
this document.
Numerous boost members, past and present, have contributed fixes to boost's configuration.
52