Boost logo

Boost :

From: Jaakko Jarvi (jajarvi_at_[hidden])
Date: 2003-07-02 17:06:41


Dear Boosters,

The enable_if library defines the enable_if and disable_if templates,
which are tools for controlling which function templates are included
in the overload resolution set based on the properties of the argument
types.

The following example demonstrates their use:

template <class T>
typename enable_if<boost::is_arithmetic<T>::value, void>::type foo(T t) {
  std::cout << "An arithmetic type\n";
}

template <class T>
typename disable_if<boost::is_arithmetic<T>::value, void>::type foo(T t) {
  std::cout << "Not an arithmetic type\n";
}

foo(1); // outputs "An arithmetic type"
foo("1"); // outputs "Not an arithmetic type"

The first function is only included in the overload resolution set if
the boost::is_arithmetic<T>::value is true, whereas the second
function is only included when boost::is_arithmetic<T>::value is
false.

The enable_if template can also be used to control which partial
specializations are considered when searching for the most specialized
template.

The submission is available in the files section under the enable_if
directory.

The files are also available in the boost-sandbox in:

  boost/utility/enable_if.hpp
  libs/utility/doc/enable_if.html
  libs/utility/test/enable_if*

We ask you to note the following during the review:

No commenting on the license is necessary. The current license is
potentially not Boost compatible, but is permissive enough for this
review, and will be replaced with a Boost compatible (the standard
Boost license?) one if the library is accepted to Boost.

The directory structure in the tar-ball (or zip-ball) does not fully
reflect boost directory structure. The library is intended to be part
of Boost.Utility, and be included as part of including
"boost/utility.hpp".

There's no Jamfile yet, but there is a Makefile that compiles and runs
all the tests. Note that GCC 3.2 fails on the test:

  enable_if_no_disambiguation.cpp

Best Regards,

  Jaakko Järvi, Jeremiah Willcock and Andrew Lumsdaine


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk