Sometimes what you want to do is just change a set of policies within the
current scope: the one thing you should not do in
this situation is use the configuration macros, as this can
lead to "One Definition Rule" violations. Instead this library
provides a pair of macros especially for this purpose.

Let's consider the special functions first: we can declare a set of forwarding
functions that all use a specific policy using the macro BOOST_MATH_DECLARE_SPECIAL_FUNCTIONS(Policy).
This macro should be used either inside a unique namespace set aside for
the purpose (for example, a C namespace for a C-style policy), or an unnamed
namespace if you just want the functions visible in global scope for the
current file only.

Suppose we want C::foo()
to behave in a C-compatible way and set ::errno on error rather than throwing
any exceptions.

We'll begin by including the needed header for our function:

#include<boost/math/special_functions.hpp>//using boost::math::tgamma; // Not needed because using C::tgamma.

Open up the "C" namespace that we'll use for our functions,
and define the policy type we want: in this case a C-style one that sets
::errno and returns a standard value, rather than throwing exceptions.

This mechanism is particularly useful when we want to define a project-wide
policy, and don't want to modify the Boost source, or to set project
wide build macros (possibly fragile and easy to forget).

The same mechanism works well at file scope as well, by using an unnamed
namespace, we can ensure that these declarations don't conflict with any
alternate policies present in other translation units:

Handling policies for the statistical distributions is very similar except
that now the macro BOOST_MATH_DECLARE_DISTRIBUTIONS accepts two parameters:
the floating point type to use, and the policy type to apply. For example:

BOOST_MATH_DECLARE_DISTRIBUTIONS(double,mypolicy)

Results a set of typedefs being defined like this:

typedefboost::math::normal_distribution<double,mypolicy>normal;

The name of each typedef is the same as the name of the distribution class
template, but without the "_distribution" suffix.

Suppose we want a set of distributions to behave as follows:

Return infinity on overflow, rather than throwing an exception.

Don't perform any promotion from double to long double internally.

Return the closest integer result from the quantiles of discrete
distributions.

We'll begin by including the needed header for all the distributions:

#include<boost/math/distributions.hpp>

Open up an appropriate namespace, calling it my_distributions,
for our distributions, and define the policy type we want. Any policies
we don't specify here will inherit the defaults:

This mechanism is particularly useful when we want to define a project-wide
policy, and don't want to modify the Boost source or set project wide
build macros (possibly fragile and easy to forget).

Note

There is an important limitation to note: you can *not use the macros
BOOST_MATH_DECLARE_DISTRIBUTIONS and BOOST_MATH_DECLARE_SPECIAL_FUNCTIONS
in the same namespace*, as doing so creates ambiguities
between functions and distributions of the same name.

As before, the same mechanism works well at file scope as well: by using
an unnamed namespace, we can ensure that these declarations don't conflict
with any alternate policies present in other translation units: