diff --git a/addressof_fn_test.cpp b/addressof_fn_test.cpp deleted file mode 100644 index 0d043bf..0000000 --- a/addressof_fn_test.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include - -#if defined(BOOST_MSVC) -#pragma warning(disable: 4786) // identifier truncated in debug info -#pragma warning(disable: 4710) // function not inlined -#pragma warning(disable: 4711) // function selected for automatic inline expansion -#pragma warning(disable: 4514) // unreferenced inline removed -#endif - -// addressof_fn_test.cpp: addressof( f ) -// -// Copyright (c) 2008, 2009 Peter Dimov -// -// Distributed under the Boost Software License, Version 1.0. -// See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt - -#include -#include - - -void f0() -{ -} - -void f1(int) -{ -} - -void f2(int, int) -{ -} - -void f3(int, int, int) -{ -} - -void f4(int, int, int, int) -{ -} - -void f5(int, int, int, int, int) -{ -} - -void f6(int, int, int, int, int, int) -{ -} - -void f7(int, int, int, int, int, int, int) -{ -} - -void f8(int, int, int, int, int, int, int, int) -{ -} - -void f9(int, int, int, int, int, int, int, int, int) -{ -} - -int main() -{ - BOOST_TEST( boost::addressof( f0 ) == &f0 ); - BOOST_TEST( boost::addressof( f1 ) == &f1 ); - BOOST_TEST( boost::addressof( f2 ) == &f2 ); - BOOST_TEST( boost::addressof( f3 ) == &f3 ); - BOOST_TEST( boost::addressof( f4 ) == &f4 ); - BOOST_TEST( boost::addressof( f5 ) == &f5 ); - BOOST_TEST( boost::addressof( f6 ) == &f6 ); - BOOST_TEST( boost::addressof( f7 ) == &f7 ); - BOOST_TEST( boost::addressof( f8 ) == &f8 ); - BOOST_TEST( boost::addressof( f9 ) == &f9 ); - - return boost::report_errors(); -} diff --git a/addressof_np_test.cpp b/addressof_np_test.cpp deleted file mode 100644 index 9e155d4..0000000 --- a/addressof_np_test.cpp +++ /dev/null @@ -1,50 +0,0 @@ -// -// Copyright 2013 Peter Dimov -// -// Distributed under the Boost Software License, Version 1.0. -// See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt -// - -#include -#include -#include - -#if defined( BOOST_NO_CXX11_NULLPTR ) - -void nullptr_test() -{ -} - -#else - -void nullptr_test() -{ - { - auto x = nullptr; - BOOST_TEST( boost::addressof(x) == &x ); - } - - { - auto const x = nullptr; - BOOST_TEST( boost::addressof(x) == &x ); - } - - { - auto volatile x = nullptr; - BOOST_TEST( boost::addressof(x) == &x ); - } - - { - auto const volatile x = nullptr; - BOOST_TEST( boost::addressof(x) == &x ); - } -} - -#endif - -int main() -{ - nullptr_test(); - return boost::report_errors(); -} diff --git a/addressof_test.cpp b/addressof_test.cpp deleted file mode 100644 index 9619cc3..0000000 --- a/addressof_test.cpp +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright (C) 2002 Brad King (brad.king@kitware.com) -// Douglas Gregor (gregod@cs.rpi.edu) -// -// Distributed under the Boost Software License, Version 1.0. (See -// accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -// For more information, see http://www.boost.org - - -#include - -#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) -#pragma warning(push, 3) -#endif - -#include - -#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) -#pragma warning(pop) -#endif - -#include - -template void scalar_test( T * = 0 ) -{ - T* px = new T(); - - T& x = *px; - BOOST_TEST( boost::addressof(x) == px ); - - const T& cx = *px; - const T* pcx = boost::addressof(cx); - BOOST_TEST( pcx == px ); - - volatile T& vx = *px; - volatile T* pvx = boost::addressof(vx); - BOOST_TEST( pvx == px ); - - const volatile T& cvx = *px; - const volatile T* pcvx = boost::addressof(cvx); - BOOST_TEST( pcvx == px ); - - delete px; -} - -template void array_test( T * = 0 ) -{ - T nrg[3] = {1,2,3}; - T (*pnrg)[3] = &nrg; - BOOST_TEST( boost::addressof(nrg) == pnrg ); - - T const cnrg[3] = {1,2,3}; - T const (*pcnrg)[3] = &cnrg; - BOOST_TEST( boost::addressof(cnrg) == pcnrg ); -} - -struct addressable -{ - addressable( int = 0 ) - { - } -}; - -struct useless_type {}; - -class nonaddressable { -public: - - nonaddressable( int = 0 ) - { - } - - void dummy(); // Silence GCC warning: all member of class are private - -private: - - useless_type operator&() const; -}; - -int main() -{ - scalar_test(); - scalar_test(); - scalar_test(); - scalar_test(); - - array_test(); - array_test(); - array_test(); - array_test(); - - return boost::report_errors(); -} diff --git a/addressof_test2.cpp b/addressof_test2.cpp deleted file mode 100644 index b1c36f8..0000000 --- a/addressof_test2.cpp +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright (C) 2002 Brad King (brad.king@kitware.com) -// Douglas Gregor (gregod@cs.rpi.edu) -// -// Copyright 2009 Peter Dimov -// -// Distributed under the Boost Software License, Version 1.0. (See -// accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -// For more information, see http://www.boost.org - - -#include - -#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) -#pragma warning(push, 3) -#endif - -#include - -#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) -#pragma warning(pop) -#endif - -#include - -template void scalar_test( T * = 0 ) -{ - T* px = new T(); - - T& x = *px; - BOOST_TEST( boost::addressof(x) == px ); - - const T& cx = *px; - const T* pcx = boost::addressof(cx); - BOOST_TEST( pcx == px ); - - volatile T& vx = *px; - volatile T* pvx = boost::addressof(vx); - BOOST_TEST( pvx == px ); - - const volatile T& cvx = *px; - const volatile T* pcvx = boost::addressof(cvx); - BOOST_TEST( pcvx == px ); - - delete px; -} - -template void array_test( T * = 0 ) -{ - T nrg[3] = {1,2,3}; - T (*pnrg)[3] = &nrg; - BOOST_TEST( boost::addressof(nrg) == pnrg ); - - T const cnrg[3] = {1,2,3}; - T const (*pcnrg)[3] = &cnrg; - BOOST_TEST( boost::addressof(cnrg) == pcnrg ); -} - -class convertible { -public: - - convertible( int = 0 ) - { - } - - template operator U () const - { - return U(); - } -}; - -class convertible2 { -public: - - convertible2( int = 0 ) - { - } - - operator convertible2* () const - { - return 0; - } -}; - -int main() -{ - scalar_test(); - scalar_test(); - - array_test(); - array_test(); - - return boost::report_errors(); -} diff --git a/checked_delete.html b/checked_delete.html index 33b5bcb..1b93256 100644 --- a/checked_delete.html +++ b/checked_delete.html @@ -1,122 +1,15 @@ - + - - Boost: checked_delete.hpp documentation - - - - - - - - - - - -
boost.png (6897 bytes) - -

checked_delete.hpp

-
 
-

- The header <boost/checked_delete.hpp> defines two - function templates, checked_delete and checked_array_delete, - and two class templates, checked_deleter and checked_array_deleter. -

-

The C++ Standard allows, in 5.3.5/5, pointers to incomplete class types to be - deleted with a delete-expression. When the class has a non-trivial - destructor, or a class-specific operator delete, the behavior is undefined. - Some compilers issue a warning when an incomplete type is deleted, but - unfortunately, not all do, and programmers sometimes ignore or disable - warnings.

-

A particularly troublesome case is when a smart pointer's destructor, such as - boost::scoped_ptr<T>::~scoped_ptr, is instantiated with an - incomplete type. This can often lead to silent, hard to track failures.

-

The supplied function and class templates can be used to prevent these problems, - as they require a complete type, and cause a compilation error otherwise.

-

Synopsis

-
-namespace boost
-{
-
-template<class T> void checked_delete(T * p);
-template<class T> void checked_array_delete(T * p);
-template<class T> struct checked_deleter;
-template<class T> struct checked_array_deleter;
-
-}
-
-

checked_delete

-

template<class T> void checked_delete(T * p);

-
-

- Requires: T must be a complete type. The expression delete p - must be well-formed. -

-

- Effects: delete p; -

-
-

checked_array_delete

-

template<class T> void checked_array_delete(T - * p);

-
-

- Requires: T must be a complete type. The expression delete [] p - must be well-formed. -

-

- Effects: delete [] p; -

-
-

checked_deleter

-
-template<class T> struct checked_deleter
-{
-    typedef void result_type;
-    typedef T * argument_type;
-    void operator()(T * p) const;
-};
-
-

void checked_deleter<T>::operator()(T * p) const;

-
-

- Requires: T must be a complete type. The expression delete p - must be well-formed. -

-

- Effects: delete p; -

-
-

checked_array_deleter

-
-template<class T> struct checked_array_deleter
-{
-    typedef void result_type;
-    typedef T * argument_type;
-    void operator()(T * p) const;
-};
-
-

void checked_array_deleter<T>::operator()(T * p) const;

-
-

- Requires: T must be a complete type. The expression delete [] p - must be well-formed. -

-

- Effects: delete [] p; -

-
-

Acknowledgements

-

- The function templates checked_delete and checked_array_delete - were originally part of <boost/utility.hpp>, and the - documentation acknowledged Beman Dawes, Dave Abrahams, Vladimir Prus, Rainer - Deyke, John Maddock, and others as contributors. -

-

-
- Copyright © 2002 by Peter Dimov. Distributed under the Boost Software License, Version - 1.0. See accompanying file LICENSE_1_0.txt or - copy at http://www.boost.org/LICENSE_1_0.txt.

- + + +Automatic redirection + + +Automatic redirection failed, please go to +checked_delete.html
+

© Copyright Beman Dawes, 2001

+

Distributed under the Boost Software License, Version 1.0. (See accompanying +file LICENSE_1_0.txt or copy +at www.boost.org/LICENSE_1_0.txt)

+ diff --git a/checked_delete_test.cpp b/checked_delete_test.cpp deleted file mode 100644 index 41fdc9a..0000000 --- a/checked_delete_test.cpp +++ /dev/null @@ -1,28 +0,0 @@ -// Boost checked_delete test program ---------------------------------------// - -// Copyright Beman Dawes 2001. Distributed under the Boost -// Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/utility for documentation. - -// Revision History -// 21 May 01 Initial version (Beman Dawes) - -#include // for checked_delete - -// This program demonstrates compiler errors when trying to delete an -// incomplete type. - -namespace -{ - class Incomplete; -} - -int main() -{ - Incomplete * p = 0; - boost::checked_delete(p); // should cause compile time error - boost::checked_array_delete(p); // should cause compile time error - return 0; -} // main diff --git a/enable_if.html b/enable_if.html index 9988f3a..0cd1a98 100644 --- a/enable_if.html +++ b/enable_if.html @@ -1,464 +1,15 @@ - - -enable_if - - - - - - - - - - -
-
- - -

-enable_if

-
-
-Copyright 2003 Jaakko Järvi, Jeremiah Willcock, Andrew Lumsdaine.
-Copyright 2011 Matt Calabrese.
-
- - -

1  Introduction

- - -The enable_if family of templates is a set of tools to allow a function template or a class template specialization -to include or exclude itself from a set of matching functions or specializations -based on properties of its template arguments. -For example, one can define function templates that -are only enabled for, and thus only match, an arbitrary set of types -defined by a traits class. The enable_if templates can also be -applied to enable class template specializations. Applications of -enable_if are discussed in length -in [1] and [2].
-
- - -

1.1  Synopsis

- - -
namespace boost {
-  template <class Cond, class T = void> struct enable_if;
-  template <class Cond, class T = void> struct disable_if;
-  template <class Cond, class T> struct lazy_enable_if;
-  template <class Cond, class T> struct lazy_disable_if;
-
-  template <bool B, class T = void> struct enable_if_c;
-  template <bool B, class T = void> struct disable_if_c;
-  template <bool B, class T> struct lazy_enable_if_c;
-  template <bool B, class T> struct lazy_disable_if_c;
-}
-
- - -

1.2  Background

- - -Sensible operation of template function overloading in C++ relies -on the SFINAE (substitution-failure-is-not-an-error) -principle [3]: if an invalid argument -or return type is formed during the instantiation of a function -template, the instantiation is removed from the overload resolution -set instead of causing a compilation error. The following example, -taken from [1], -demonstrates why this is important: -
int negate(int i) { return -i; }
-
-template <class F>
-typename F::result_type negate(const F& f) { return -f(); }
-
-
-Suppose the compiler encounters the call negate(1). The first -definition is obviously a better match, but the compiler must -nevertheless consider (and instantiate the prototypes) of both -definitions to find this out. Instantiating the latter definition with -F as int would result in: -
int::result_type negate(const int&);
-
-
-where the return type is invalid. If this were an error, adding an unrelated function template -(that was never called) could break otherwise valid code. -Due to the SFINAE principle the above example is not, however, erroneous. -The latter definition of negate is simply removed from the overload resolution set.
-
-The enable_if templates are tools for controlled creation of the SFINAE -conditions.
-
- - -

2  The enable_if templates

- - -The names of the enable_if templates have three parts: an optional lazy_ tag, -either enable_if or disable_if, and an optional _c tag. -All eight combinations of these parts are supported. -The meaning of the lazy_ tag is described in Section 3.3. -The second part of the name indicates whether a true condition argument should -enable or disable the current overload. -The third part of the name indicates whether the condition argument is a bool value -(_c suffix), or a type containing a static bool constant named value (no suffix). -The latter version interoperates with Boost.MPL.
-
-The definitions of enable_if_c and enable_if are as follows (we use enable_if templates -unqualified but they are in the boost namespace). -
template <bool B, class T = void>
-struct enable_if_c {
-  typedef T type;
-};
-
-template <class T>
-struct enable_if_c<false, T> {};
-
-template <class Cond, class T = void>
-struct enable_if : public enable_if_c<Cond::value, T> {};
-
-
-An instantiation of the enable_if_c template with the parameter -B as true contains a member type type, defined -to be T. If B is -false, no such member is defined. Thus -enable_if_c<B, T>::type is either a valid or an invalid type -expression, depending on the value of B. -When valid, enable_if_c<B, T>::type equals T. -The enable_if_c template can thus be used for controlling when functions are considered for -overload resolution and when they are not. -For example, the following function is defined for all arithmetic types (according to the -classification of the Boost type_traits library): -
template <class T>
-typename enable_if_c<boost::is_arithmetic<T>::value, T>::type 
-foo(T t) { return t; }
-
-
-The disable_if_c template is provided as well, and has the -same functionality as enable_if_c except for the negated condition. The following -function is enabled for all non-arithmetic types. -
template <class T>
-typename disable_if_c<boost::is_arithmetic<T>::value, T>::type 
-bar(T t) { return t; }
-
-
-For easier syntax in some cases and interoperation with Boost.MPL we provide versions of -the enable_if templates taking any type with a bool member constant named -value as the condition argument. -The MPL bool_, and_, or_, and not_ templates are likely to be -useful for creating such types. Also, the traits classes in the Boost.Type_traits library -follow this convention. -For example, the above example function foo can be alternatively written as: -
template <class T>
-typename enable_if<boost::is_arithmetic<T>, T>::type 
-foo(T t) { return t; }
-
-
- - - -

3  Using enable_if

- - -The enable_if templates are defined in -boost/utility/enable_if.hpp, which is included by boost/utility.hpp.
-
-With respect to function templates, enable_if can be used in multiple different ways: - -
    -
  • As the return type of an instantiatied function -
  • As an extra parameter of an instantiated function -
  • As an extra template parameter (useful only in a compiler that supports C++0x default -arguments for function template parameters, see Enabling function -templates in C++0x for details) -
- -In the previous section, the return type form of enable_if was shown. As an example -of using the form of enable_if that works via an extra function parameter, the -foo function in the previous section could also be written -as: -
template <class T>
-T foo(T t, typename enable_if<boost::is_arithmetic<T> >::type* dummy = 0); 
-
-
Hence, an extra parameter of type void* is added, but it is given -a default value to keep the parameter hidden from client code. -Note that the second template argument was not given to enable_if, as the default -void gives the desired behavior.
-
-Which way to write the enabler is largely a matter of taste, but for certain functions, only a -subset of the options is possible: -
  • -Many operators have a fixed number of arguments, thus enable_if must be used either in the -return type or in an extra template parameter. -
  • Functions that have a variadic parameter list must use either the return type form or an extra -template parameter. -
  • Constructors do not have a return type so you must use either an extra function parameter or an -extra template parameter. -
  • Constructors that have a variadic parameter list must an extra template parameter. -
  • Conversion operators can only be written with an extra template parameter. -
- - - -

3.1  Enabling function templates in C++0x

- -In a compiler which supports C++0x default arguments for function template parameters, you can -enable and disable function templates by adding an additional template parameter. This approach -works in all situations where you would use either the return type form of enable_if or -the function parameter form, including operators, constructors, variadic function templates, and -even overloaded conversion operations. - -As an example: - -
#include <boost/type_traits/is_arithmetic.hpp>
-#include <boost/type_traits/is_pointer.hpp>
-#include <boost/utility/enable_if.hpp>
-
-class test
-{
-public:
-  // A constructor that works for any argument list of size 10
-  template< class... T
-          , typename boost::enable_if_c< sizeof...( T ) == 10, int >::type = 0
-          >
-  test( T&&... );
-
-  // A conversion operation that can convert to any arithmetic type
-  template< class T
-          , typename boost::enable_if< boost::is_arithmetic< T >, int >::type = 0
-          >
-  operator T() const;
-
-  // A conversion operation that can convert to any pointer type
-  template< class T
-          , typename boost::enable_if< boost::is_pointer< T >, int >::type = 0
-          >
-  operator T() const;
-};
-
-int main()
-{
-  // Works
-  test test_( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 );
-
-  // Fails as expected
-  test fail_construction( 1, 2, 3, 4, 5 );
-
-  // Works by calling the conversion operator enabled for arithmetic types
-  int arithmetic_object = test_;
-
-  // Works by calling the conversion operator enabled for pointer types
-  int* pointer_object = test_;
-
-  // Fails as expected
-  struct {} fail_conversion = test_;
-}
-
-
- - - -

3.2  Enabling template class specializations

- - -Class template specializations can be enabled or disabled with enable_if. -One extra template parameter needs to be added for the enabler expressions. -This parameter has the default value void. -For example: -
template <class T, class Enable = void> 
-class A { ... };
-
-template <class T>
-class A<T, typename enable_if<is_integral<T> >::type> { ... };
-
-template <class T>
-class A<T, typename enable_if<is_float<T> >::type> { ... };
-
-
Instantiating A with any integral type matches the first specialization, -whereas any floating point type matches the second one. All other types -match the primary template. -The condition can be any compile-time boolean expression that depends on the -template arguments of the class. -Note that again, the second argument to enable_if is not needed; the default (void) -is the correct value.
-
- - -

3.3  Overlapping enabler conditions

- - -Once the compiler has examined the enabling conditions and included the -function into the overload resolution set, normal C++ overload resolution -rules are used to select the best matching function. -In particular, there is no ordering between enabling conditions. -Function templates with enabling conditions that are not mutually exclusive can -lead to ambiguities. For example: -
template <class T>
-typename enable_if<boost::is_integral<T>, void>::type 
-foo(T t) {}
-
-template <class T>
-typename enable_if<boost::is_arithmetic<T>, void>::type 
-foo(T t) {}
-
-
-All integral types are also arithmetic. Therefore, say, for the call foo(1), -both conditions are true and both functions are thus in the overload resolution set. -They are both equally good matches and thus ambiguous. -Of course, more than one enabling condition can be simultaneously true as long as -other arguments disambiguate the functions.
-
-The above discussion applies to using enable_if in class template -partial specializations as well.
-
- - -

3.4  Lazy enable_if

- - -In some cases it is necessary to avoid instantiating part of a -function signature unless an enabling condition is true. For example: -
template <class T, class U> class mult_traits;
-
-template <class T, class U>
-typename enable_if<is_multipliable<T, U>, typename mult_traits<T, U>::type>::type
-operator*(const T& t, const U& u) { ... }
-
-
Assume the class template mult_traits is a traits class defining -the resulting type of a multiplication operator. The is_multipliable traits -class specifies for which types to enable the operator. Whenever -is_multipliable<A, B>::value is true for some types A and B, -then mult_traits<A, B>::type is defined.
-
-Now, trying to invoke (some other overload) of operator* with, say, operand types C and D -for which is_multipliable<C, D>::value is false -and mult_traits<C, D>::type is not defined is an error on some compilers. -The SFINAE principle is not applied because -the invalid type occurs as an argument to another template. The lazy_enable_if -and lazy_disable_if templates (and their _c versions) can be used in such -situations: -
template<class T, class U>
-typename lazy_enable_if<is_multipliable<T, U>, mult_traits<T, U> >::type
-operator*(const T& t, const U& u) { ... }
-
-
The second argument of lazy_enable_if must be a class type -that defines a nested type named type whenever the first -parameter (the condition) is true.
-
- - -
Note
- -Referring to one member type or static constant in a traits class -causes all of the members (type and static constant) of that -specialization to be instantiated. Therefore, if your traits classes -can sometimes contain invalid types, you should use two distinct -templates for describing the conditions and the type mappings. In the -above example, is_multipliable<T, U>::value defines when -mult_traits<T, U>::type is valid.
-
- - -

3.5  Compiler workarounds

- - -Some compilers flag functions as ambiguous if the only distinguishing factor is a different -condition in an enabler (even though the functions could never be ambiguous). For example, -some compilers (e.g. GCC 3.2) diagnose the following two functions as ambiguous: -
template <class T>
-typename enable_if<boost::is_arithmetic<T>, T>::type 
-foo(T t);
-
-template <class T>
-typename disable_if<boost::is_arithmetic<T>, T>::type 
-foo(T t);
-
-
Two workarounds can be applied: -
  • -Use an extra dummy parameter which disambiguates the functions. Use a default value for -it to hide the parameter from the caller. For example: -
    template <int> struct dummy { dummy(int) {} };
    -
    -template <class T>
    -typename enable_if<boost::is_arithmetic<T>, T>::type 
    -foo(T t, dummy<0> = 0);
    -
    -template <class T>
    -typename disable_if<boost::is_arithmetic<T>, T>::type 
    -foo(T t, dummy<1> = 0);
    -

    -
    -
  • Define the functions in different namespaces and bring them into a common -namespace with using declarations: -
    namespace A {
    -  template <class T>
    -  typename enable_if<boost::is_arithmetic<T>, T>::type 
    -  foo(T t);
    -}
    -
    -namespace B {
    -  template <class T>
    -  typename disable_if<boost::is_arithmetic<T>, T>::type 
    -  foo(T t);
    -}
    -
    -using A::foo;
    -using B::foo;
    -
    -
    -Note that the second workaround above cannot be used for member -templates. On the other hand, operators do not accept extra arguments, -which makes the first workaround unusable. As the net effect, -neither of the workarounds are of assistance for templated operators that -need to be defined as member functions (assignment and -subscript operators). -
- - -

4  Acknowledgements

- -We are grateful to Howard Hinnant, Jason Shirk, Paul Mensonides, and Richard -Smith whose findings have influenced the library.
-
- - -

References

-
[1]
-Jaakko Järvi, Jeremiah Willcock, Howard Hinnant, and Andrew Lumsdaine. -Function overloading based on arbitrary properties of types. -C/C++ Users Journal, 21(6):25--32, June 2003.
-
-
[2]
-Jaakko Järvi, Jeremiah Willcock, and Andrew Lumsdaine. -Concept-controlled polymorphism. -In Frank Pfennig and Yannis Smaragdakis, editors, Generative - Programming and Component Engineering, volume 2830 of LNCS, pages - 228--244. Springer Verlag, September 2003.
-
-
[3]
-David Vandevoorde and Nicolai M. Josuttis. -C++ Templates: The Complete Guide. -Addison-Wesley, 2002.
- -
-

Copyright Jaakko Järvi*, Jeremiah Willcock*, Andrew Lumsdaine*, Matt Calabrese
-{jajarvi|jewillco|lums}@osl.iu.edu, rivorus@gmail.com
-*Indiana University
-Open Systems Lab
-Use, modification and distribution are subject to the -Boost Software License, Version 1.0. -(See accompanying file LICENSE_1_0.txt -or copy at - http://www.boost.org/LICENSE_1_0.txt -). -

- - - -
-
This document was translated from LATEX by -HEVEA. -
- - + + + + +Automatic redirection + + +Automatic redirection failed, please go to +enable_if.html
+

© Copyright Beman Dawes, 2001

+

Distributed under the Boost Software License, Version 1.0. (See accompanying +file LICENSE_1_0.txt or copy +at www.boost.org/LICENSE_1_0.txt)

+ + diff --git a/enable_if/test/Jamfile.v2 b/enable_if/test/Jamfile.v2 deleted file mode 100644 index 77a8798..0000000 --- a/enable_if/test/Jamfile.v2 +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright David Abrahams 2003. -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at -# http://www.boost.org/LICENSE_1_0.txt) - -# For more information, see http://www.boost.org/ - -project - : requirements /boost/test//boost_test_exec_monitor - ; - -test-suite utility/enable_if - : - [ run constructors.cpp ] - [ run dummy_arg_disambiguation.cpp ] - [ run lazy.cpp ] - [ run lazy_test.cpp ] - [ run member_templates.cpp ] - [ run namespace_disambiguation.cpp ] - [ run no_disambiguation.cpp ] - [ run partial_specializations.cpp ] - ; - diff --git a/enable_if/test/constructors.cpp b/enable_if/test/constructors.cpp deleted file mode 100644 index 0d465de..0000000 --- a/enable_if/test/constructors.cpp +++ /dev/null @@ -1,62 +0,0 @@ -// Boost enable_if library - -// Copyright 2003 (c) The Trustees of Indiana University. - -// Use, modification, and distribution is subject to the Boost Software -// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) -// Jeremiah Willcock (jewillco at osl.iu.edu) -// Andrew Lumsdaine (lums at osl.iu.edu) - -#include - -#include -#include - -using boost::enable_if; -using boost::disable_if; -using boost::is_arithmetic; - -struct container { - bool my_value; - - template - container(const T&, const typename enable_if, T>::type * = 0): - my_value(true) {} - - template - container(const T&, const typename disable_if, T>::type * = 0): - my_value(false) {} -}; - -// example from Howard Hinnant (tests enable_if template members of a templated class) -template -struct xstring -{ - template - xstring(It begin, It end, typename - disable_if >::type* = 0) - : data(end-begin) {} - - int data; -}; - - -int test_main(int, char*[]) -{ - - BOOST_CHECK(container(1).my_value); - BOOST_CHECK(container(1.0).my_value); - - BOOST_CHECK(!container("1").my_value); - BOOST_CHECK(!container(static_cast(0)).my_value); - - char sa[] = "123456"; - BOOST_CHECK(xstring(sa, sa+6).data == 6); - - - return 0; -} - diff --git a/enable_if/test/dummy_arg_disambiguation.cpp b/enable_if/test/dummy_arg_disambiguation.cpp deleted file mode 100644 index 60dfdfd..0000000 --- a/enable_if/test/dummy_arg_disambiguation.cpp +++ /dev/null @@ -1,46 +0,0 @@ -// Boost enable_if library - -// Copyright 2003 (c) The Trustees of Indiana University. - -// Use, modification, and distribution is subject to the Boost Software -// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) -// Jeremiah Willcock (jewillco at osl.iu.edu) -// Andrew Lumsdaine (lums at osl.iu.edu) - -#include - -#include -#include - -using boost::enable_if; -using boost::disable_if; -using boost::is_arithmetic; - -template struct dummy { - dummy(int) {}; -}; - -template -typename enable_if, bool>::type -arithmetic_object(T t, dummy<0> = 0) { return true; } - -template -typename disable_if, bool>::type -arithmetic_object(T t, dummy<1> = 0) { return false; } - - -int test_main(int, char*[]) -{ - - BOOST_CHECK(arithmetic_object(1)); - BOOST_CHECK(arithmetic_object(1.0)); - - BOOST_CHECK(!arithmetic_object("1")); - BOOST_CHECK(!arithmetic_object(static_cast(0))); - - return 0; -} - diff --git a/enable_if/test/lazy.cpp b/enable_if/test/lazy.cpp deleted file mode 100644 index f04111e..0000000 --- a/enable_if/test/lazy.cpp +++ /dev/null @@ -1,82 +0,0 @@ -// Boost enable_if library - -// Copyright 2003 (c) The Trustees of Indiana University. - -// Use, modification, and distribution is subject to the Boost Software -// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) -// Jeremiah Willcock (jewillco at osl.iu.edu) -// Andrew Lumsdaine (lums at osl.iu.edu) - -#include - -#include -#include - -using boost::enable_if_c; -using boost::lazy_enable_if_c; - -// This class provides a reduced example of a traits class for -// computing the result of multiplying two types. The member typedef -// 'type' in this traits class defines the return type of this -// operator. The return type member is invalid unless both arguments -// for mult_traits are values that mult_traits expects (ints in this -// case). This kind of situation may arise if a traits class only -// makes sense for some set of types, not all C++ types. - -template struct is_int { - BOOST_STATIC_CONSTANT(bool, value = (boost::is_same::value)); -}; - -template -struct mult_traits { - typedef typename T::does_not_exist type; -}; - -template <> -struct mult_traits { - typedef int type; -}; - - -// Next, a forwarding function mult() is defined. It is enabled only -// when both arguments are of type int. The first version, using -// non-lazy enable_if_c does not work. - -#if 0 -template -typename enable_if_c< - is_int::value && is_int::value, - typename mult_traits::type ->::type -mult(const T& x, const U& y) {return x * y;} -#endif - -// A correct version uses lazy_enable_if_c. -// This template removes compiler errors from invalid code used as an -// argument to enable_if_c. - -#if 1 -template -typename lazy_enable_if_c< - is_int::value & is_int::value, - mult_traits ->::type -mult(const T& x, const U& y) {return x * y;} -#endif - -double mult(int i, double d) { return (double)i * d; } - -int test_main(int, char*[]) -{ - - - BOOST_CHECK(mult(1, 2) == 2); - - BOOST_CHECK(mult(1, 3.0) == 3.0); - - return 0; -} - diff --git a/enable_if/test/lazy_test.cpp b/enable_if/test/lazy_test.cpp deleted file mode 100644 index 9ec5324..0000000 --- a/enable_if/test/lazy_test.cpp +++ /dev/null @@ -1,100 +0,0 @@ -// Boost enable_if library - -// Copyright 2003 (c) The Trustees of Indiana University. - -// Use, modification, and distribution is subject to the Boost Software -// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) -// Jeremiah Willcock (jewillco at osl.iu.edu) -// Andrew Lumsdaine (lums at osl.iu.edu) - -// Testing all variations of lazy_enable_if. - -#include -#include - -#include -#include - -using boost::lazy_enable_if; -using boost::lazy_disable_if; - -using boost::lazy_enable_if_c; -using boost::lazy_disable_if_c; - - -template -struct is_int_or_double { - BOOST_STATIC_CONSTANT(bool, - value = (boost::is_same::value || - boost::is_same::value)); -}; - -template -struct some_traits { - typedef typename T::does_not_exist type; -}; - -template <> -struct some_traits { - typedef bool type; -}; - -template <> -struct some_traits { - typedef bool type; -}; - -template -struct make_bool { - typedef bool type; -}; - -template <> -struct make_bool {}; - -template <> -struct make_bool {}; - -namespace A { - - template - typename lazy_enable_if, some_traits >::type - foo(T t) { return true; } - - template - typename lazy_enable_if_c::value, some_traits >::type - foo2(T t) { return true; } -} - -namespace B { - template - typename lazy_disable_if, make_bool >::type - foo(T t) { return false; } - - template - typename lazy_disable_if_c::value, make_bool >::type - foo2(T t) { return false; } -} - -int test_main(int, char*[]) -{ - using namespace A; - using namespace B; - BOOST_CHECK(foo(1)); - BOOST_CHECK(foo(1.0)); - - BOOST_CHECK(!foo("1")); - BOOST_CHECK(!foo(static_cast(0))); - - BOOST_CHECK(foo2(1)); - BOOST_CHECK(foo2(1.0)); - - BOOST_CHECK(!foo2("1")); - BOOST_CHECK(!foo2(static_cast(0))); - - return 0; -} - diff --git a/enable_if/test/member_templates.cpp b/enable_if/test/member_templates.cpp deleted file mode 100644 index 55e2d80..0000000 --- a/enable_if/test/member_templates.cpp +++ /dev/null @@ -1,43 +0,0 @@ -// Boost enable_if library - -// Copyright 2003 (c) The Trustees of Indiana University. - -// Use, modification, and distribution is subject to the Boost Software -// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) -// Jeremiah Willcock (jewillco at osl.iu.edu) -// Andrew Lumsdaine (lums at osl.iu.edu) - -#include - -#include -#include - -using boost::enable_if; -using boost::disable_if; -using boost::is_arithmetic; - -struct container { - template - typename enable_if, bool>::type - arithmetic_object(const T&, const int* /* disambiguate */ = 0) {return true;} - - template - typename disable_if, bool>::type - arithmetic_object(const T&) {return false;} -}; - -int test_main(int, char*[]) -{ - - BOOST_CHECK(container().arithmetic_object(1)); - BOOST_CHECK(container().arithmetic_object(1.0)); - - BOOST_CHECK(!container().arithmetic_object("1")); - BOOST_CHECK(!container().arithmetic_object(static_cast(0))); - - return 0; -} - diff --git a/enable_if/test/namespace_disambiguation.cpp b/enable_if/test/namespace_disambiguation.cpp deleted file mode 100644 index 45d4f0a..0000000 --- a/enable_if/test/namespace_disambiguation.cpp +++ /dev/null @@ -1,47 +0,0 @@ -// Boost enable_if library - -// Copyright 2003 (c) The Trustees of Indiana University. - -// Use, modification, and distribution is subject to the Boost Software -// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) -// Jeremiah Willcock (jewillco at osl.iu.edu) -// Andrew Lumsdaine (lums at osl.iu.edu) - -#include -#include - -#include -#include - -using boost::enable_if; -using boost::mpl::not_; -using boost::is_arithmetic; - -namespace A { - template - typename enable_if, bool>::type - arithmetic_object(T t) { return true; } -} - -namespace B { - template - typename enable_if >, bool>::type - arithmetic_object(T t) { return false; } -} - -int test_main(int, char*[]) -{ - using namespace A; - using namespace B; - BOOST_CHECK(arithmetic_object(1)); - BOOST_CHECK(arithmetic_object(1.0)); - - BOOST_CHECK(!arithmetic_object("1")); - BOOST_CHECK(!arithmetic_object(static_cast(0))); - - return 0; -} - diff --git a/enable_if/test/no_disambiguation.cpp b/enable_if/test/no_disambiguation.cpp deleted file mode 100644 index e2416ed..0000000 --- a/enable_if/test/no_disambiguation.cpp +++ /dev/null @@ -1,43 +0,0 @@ -// Boost enable_if library - -// Copyright 2003 (c) The Trustees of Indiana University. - -// Use, modification, and distribution is subject to the Boost Software -// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) -// Jeremiah Willcock (jewillco at osl.iu.edu) -// Andrew Lumsdaine (lums at osl.iu.edu) - -#include -#include - -#include -#include - -using boost::mpl::not_; -using boost::enable_if; -using boost::is_arithmetic; - -template -typename enable_if, bool>::type -arithmetic_object(T t) { return true; } - -template -typename enable_if >, bool>::type -arithmetic_object(T t) { return false; } - - -int test_main(int, char*[]) -{ - - BOOST_CHECK(arithmetic_object(1)); - BOOST_CHECK(arithmetic_object(1.0)); - - BOOST_CHECK(!arithmetic_object("1")); - BOOST_CHECK(!arithmetic_object(static_cast(0))); - - return 0; -} - diff --git a/enable_if/test/partial_specializations.cpp b/enable_if/test/partial_specializations.cpp deleted file mode 100644 index 1d4db99..0000000 --- a/enable_if/test/partial_specializations.cpp +++ /dev/null @@ -1,67 +0,0 @@ -// Boost enable_if library - -// Copyright 2003 (c) The Trustees of Indiana University. - -// Use, modification, and distribution is subject to the Boost Software -// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) -// Jeremiah Willcock (jewillco at osl.iu.edu) -// Andrew Lumsdaine (lums at osl.iu.edu) - -#include - -#include -#include - -using boost::enable_if_c; -using boost::disable_if_c; -using boost::enable_if; -using boost::disable_if; -using boost::is_arithmetic; - -template -struct tester; - -template -struct tester::value>::type> { - BOOST_STATIC_CONSTANT(bool, value = true); -}; - -template -struct tester::value>::type> { - BOOST_STATIC_CONSTANT(bool, value = false); -}; - -template -struct tester2; - -template -struct tester2 >::type> { - BOOST_STATIC_CONSTANT(bool, value = true); -}; - -template -struct tester2 >::type> { - BOOST_STATIC_CONSTANT(bool, value = false); -}; - -int test_main(int, char*[]) -{ - - BOOST_CHECK(tester::value); - BOOST_CHECK(tester::value); - - BOOST_CHECK(!tester::value); - BOOST_CHECK(!tester::value); - - BOOST_CHECK(tester2::value); - BOOST_CHECK(tester2::value); - - BOOST_CHECK(!tester2::value); - BOOST_CHECK(!tester2::value); - - return 0; -} - diff --git a/index.html b/index.html index 1275a81..493be93 100644 --- a/index.html +++ b/index.html @@ -14,19 +14,19 @@

But that doesn't mean there isn't useful stuff here. Take a look:

- addressof
+ addressof (moved to the Boost.Core library)
base_from_member
BOOST_BINARY
call_traits
- checked_delete
+ checked_delete (moved to the Boost.Core library)
compressed_pair
declval
- enable_if
+ enable_if (moved to the Boost.Core library)
in_place_factory
iterator_adaptors
generator iterator adaptors
next/prior
- noncopyable
+ noncopyable (moved to the Boost.Core library)
operators
result_of
throw_exception
diff --git a/noncopyable_test.cpp b/noncopyable_test.cpp deleted file mode 100644 index d5d2994..0000000 --- a/noncopyable_test.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// boost class noncopyable test program ------------------------------------// - -// (C) Copyright Beman Dawes 1999. Distributed under the Boost -// Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org for most recent version including documentation. - -// Revision History -// 9 Jun 99 Add unnamed namespace -// 2 Jun 99 Initial Version - -#include -#include - -// This program demonstrates compiler errors resulting from trying to copy -// construct or copy assign a class object derived from class noncopyable. - -namespace -{ - class DontTreadOnMe : private boost::noncopyable - { - public: - DontTreadOnMe() { std::cout << "defanged!" << std::endl; } - }; // DontTreadOnMe - -} // unnamed namespace - -int main() -{ - DontTreadOnMe object1; - DontTreadOnMe object2(object1); - object1 = object2; - return 0; -} // main - diff --git a/ref_ct_test.cpp b/ref_ct_test.cpp deleted file mode 100644 index a3b5eea..0000000 --- a/ref_ct_test.cpp +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright David Abrahams and Aleksey Gurtovoy -// 2002-2004. Distributed under the Boost Software License, Version -// 1.0. (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -// compile-time test for "boost/ref.hpp" header content -// see 'ref_test.cpp' for run-time part - -#include -#include -#include -#include -#include - -#include - -namespace { - -template< typename T, typename U > -void ref_test(boost::reference_wrapper) -{ - typedef typename boost::reference_wrapper::type type; - BOOST_STATIC_ASSERT((boost::is_same::value)); - BOOST_STATIC_ASSERT((boost::is_same::value)); -} - -template< typename T > -void assignable_test(T x) -{ - x = x; -} - -template< bool R, typename T > -void is_reference_wrapper_test(T) -{ - BOOST_STATIC_ASSERT(boost::is_reference_wrapper::value == R); -} - -template< typename R, typename Ref > -void cxx_reference_test(Ref) -{ -#if BOOST_WORKAROUND(__BORLANDC__, < 0x600) - typedef typename boost::remove_const::type ref; - BOOST_STATIC_ASSERT((boost::is_same::value)); -#else - BOOST_STATIC_ASSERT((boost::is_same::value)); -#endif -} - -template< typename R, typename Ref > -void unwrap_reference_test(Ref) -{ -#if BOOST_WORKAROUND(__BORLANDC__, < 0x600) - typedef typename boost::remove_const::type ref; - typedef typename boost::unwrap_reference::type type; -#else - typedef typename boost::unwrap_reference::type type; -#endif - BOOST_STATIC_ASSERT((boost::is_same::value)); -} - -} // namespace - -int main() -{ - int i = 0; - int& ri = i; - - int const ci = 0; - int const& rci = ci; - - // 'ref/cref' functions test - ref_test(boost::ref(i)); - ref_test(boost::ref(ri)); - ref_test(boost::ref(ci)); - ref_test(boost::ref(rci)); - - ref_test(boost::cref(i)); - ref_test(boost::cref(ri)); - ref_test(boost::cref(ci)); - ref_test(boost::cref(rci)); - - // test 'assignable' requirement - assignable_test(boost::ref(i)); - assignable_test(boost::ref(ri)); - assignable_test(boost::cref(i)); - assignable_test(boost::cref(ci)); - assignable_test(boost::cref(rci)); - - // 'is_reference_wrapper' test - is_reference_wrapper_test(boost::ref(i)); - is_reference_wrapper_test(boost::ref(ri)); - is_reference_wrapper_test(boost::cref(i)); - is_reference_wrapper_test(boost::cref(ci)); - is_reference_wrapper_test(boost::cref(rci)); - - is_reference_wrapper_test(i); - is_reference_wrapper_test(ri); - is_reference_wrapper_test(ci); - is_reference_wrapper_test(rci); - - // ordinary references/function template arguments deduction test - cxx_reference_test(i); - cxx_reference_test(ri); - cxx_reference_test(ci); - cxx_reference_test(rci); - - cxx_reference_test(i); - cxx_reference_test(ri); - cxx_reference_test(i); - cxx_reference_test(ri); - cxx_reference_test(ci); - cxx_reference_test(rci); - - // 'unwrap_reference' test - unwrap_reference_test(boost::ref(i)); - unwrap_reference_test(boost::ref(ri)); - unwrap_reference_test(boost::cref(i)); - unwrap_reference_test(boost::cref(ci)); - unwrap_reference_test(boost::cref(rci)); - - unwrap_reference_test(i); - unwrap_reference_test(ri); - unwrap_reference_test(ci); - unwrap_reference_test(rci); - unwrap_reference_test(i); - unwrap_reference_test(ri); - unwrap_reference_test(i); - unwrap_reference_test(ri); - unwrap_reference_test(ci); - unwrap_reference_test(rci); - - return 0; -} diff --git a/ref_test.cpp b/ref_test.cpp deleted file mode 100644 index 71481fa..0000000 --- a/ref_test.cpp +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright David Abrahams and Aleksey Gurtovoy -// 2002-2004. Distributed under the Boost Software License, Version -// 1.0. (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -// run-time test for "boost/ref.hpp" header content -// see 'ref_ct_test.cpp' for compile-time part - -#if defined(_MSC_VER) && !defined(__ICL) -# pragma warning(disable: 4786) // identifier truncated in debug info -# pragma warning(disable: 4710) // function not inlined -# pragma warning(disable: 4711) // function selected for automatic inline expansion -# pragma warning(disable: 4514) // unreferenced inline removed -#endif - -#include - -#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) -# pragma warning(push, 3) -#endif - -#include - -#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) -# pragma warning(pop) -#endif - - -#define BOOST_INCLUDE_MAIN -#include - -namespace { -using namespace boost; - -template -struct ref_wrapper -{ - // Used to verify implicit conversion - static T* get_pointer(T& x) - { - return &x; - } - - static T const* get_const_pointer(T const& x) - { - return &x; - } - - template - static T* passthru(Arg x) - { - return get_pointer(x); - } - - template - static T const* cref_passthru(Arg x) - { - return get_const_pointer(x); - } - - static void test(T x) - { - BOOST_CHECK(passthru(ref(x)) == &x); - BOOST_CHECK(&ref(x).get() == &x); - - BOOST_CHECK(cref_passthru(cref(x)) == &x); - BOOST_CHECK(&cref(x).get() == &x); - } -}; - -struct copy_counter { - static int count_; - copy_counter(copy_counter const& /*other*/) { - ++count_; - } - copy_counter() {} - static void reset() { count_ = 0; } - static int count() { return copy_counter::count_; } -}; - -int copy_counter::count_ = 0; - -} // namespace unnamed - -template -void do_unwrap(T t) { - - /* typename unwrap_reference::type& lt = */ - unwrap_ref(t); - -} - -void unwrap_test() { - - int i = 3; - const int ci = 2; - - do_unwrap(i); - do_unwrap(ci); - do_unwrap(ref(i)); - do_unwrap(cref(ci)); - do_unwrap(ref(ci)); - - copy_counter cc; - BOOST_CHECK(cc.count() == 0); - - do_unwrap(cc); - do_unwrap(ref(cc)); - do_unwrap(cref(cc)); - - BOOST_CHECK(cc.count() == 1); - BOOST_CHECK(unwrap_ref(ref(cc)).count() == 1); -} - -int test_main(int, char * []) -{ - ref_wrapper::test(1); - ref_wrapper::test(1); - unwrap_test(); - return 0; -} diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 2829574..276dc22 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -16,23 +16,15 @@ alias unit_test_framework # Please keep the tests ordered by filename test-suite utility : - [ run ../addressof_fn_test.cpp ] - [ run ../addressof_np_test.cpp ] - [ run ../addressof_test.cpp ] - [ run ../addressof_test2.cpp ] [ run ../base_from_member_test.cpp ] [ run ../base_from_member_ref_test.cpp ] [ run ../binary_test.cpp ] [ run ../call_traits_test.cpp : -u ] - [ compile-fail ../checked_delete_test.cpp ] [ run ../compressed_pair_test.cpp ../../test/build//boost_test_exec_monitor/static : -u ] [ run ../iterators_test.cpp ../../test/build//boost_test_exec_monitor/static ] [ run next_prior_test.cpp ../../test/build//boost_test_exec_monitor/static ] - [ compile-fail ../noncopyable_test.cpp ] [ run ../numeric_traits_test.cpp ] [ run ../operators_test.cpp ../../test/build//boost_test_exec_monitor/static ] - [ compile ../ref_ct_test.cpp ] - [ run ../ref_test.cpp ../../test/build//boost_test_exec_monitor/static ] [ compile result_of_test.cpp ] [ run ../shared_iterator_test.cpp ] [ run string_ref_test1.cpp unit_test_framework ] diff --git a/utility.htm b/utility.htm index 8096b40..5443bd4 100644 --- a/utility.htm +++ b/utility.htm @@ -14,23 +14,19 @@ Class templates supporting the base-from-member idiom

  • - Function templates checked_delete() and - checked_array_delete()
  • + Function templates checked_delete() and + checked_array_delete() (moved to the Boost.Core library)
  • Function templates next() and prior()
  • - Class noncopyable
  • + Class noncopyable (moved to the Boost.Core library)
  • - Function template addressof()
  • + Function template addressof() (moved to the Boost.Core library)
  • Class template result_of
  • Macro BOOST_BINARY
  • Other utilities not part of utility.hpp
  • -

    - Function templates checked_delete() and - checked_array_delete()

    -

    See separate documentation.

    Function templates next() and prior()

    Certain data types, such as the C++ Standard Library's forward and bidirectional @@ -71,79 +67,7 @@ const std::list<T>::iterator next = boost::next(prev, 2); example, the iterator four iterators prior to the given iterator p may be obtained by prior(p, 4).

    Contributed by Dave Abrahams. Two-argument versions by Daniel Walker.

    -

    Class noncopyable

    -

    Class noncopyable is a base class.  Derive your own class - from noncopyable when you want to prohibit copy construction - and copy assignment.

    -

    Some objects, particularly those which hold complex resources like files or - network connections, have no sensible copy semantics.  Sometimes there are - possible copy semantics, but these would be of very limited usefulness and be - very difficult to implement correctly.  Sometimes you're implementing a - class that doesn't need to be copied just yet and you don't want to take the - time to write the appropriate functions.  Deriving from noncopyable - will prevent the otherwise implicitly-generated functions (which don't have the - proper semantics) from becoming a trap for other programmers.

    -

    The traditional way to deal with these is to declare a private copy constructor - and copy assignment, and then document why this is done.  A new alternative - was introduced in C++2011, declaring a copy constructor and a copy assignment - operator, but marking both as deleted.  Deriving - from noncopyable is simpler and clearer, and doesn't require additional - documentation.

    -

    The program noncopyable_test.cpp can be used - to verify class noncopyable works as expected. It has have been run - successfully under GCC 2.95, Metrowerks CodeWarrior 5.0, and Microsoft Visual - C++ 6.0 sp 3.

    -

    Contributed by Dave Abrahams.

    -

    Example

    -
    -
    // inside one of your own headers ...
    -#include <boost/utility.hpp>
     
    -class ResourceLadenFileSystem : boost::noncopyable {
    -...
    -
    -

    Rationale

    -

    Class noncopyable has protected constructor and destructor members to emphasize - that it is to be used only as a base class.  Dave Abrahams notes concern - about the effect on compiler optimization of adding (even trivial inline) - destructor declarations. He says "Probably this concern is misplaced, - because noncopyable will be used mostly for classes which own resources and - thus have non-trivial destruction semantics."  With C++2011, using an - optimized and trivial constructor and similar destructor can be enforced by - declaring both and marking them default.

    -

    Function template addressof()

    -

    Function addressof() returns the address of an object.

    -
    -
    template <typename T> inline T*                addressof(T& v);
    -template <typename T> inline const T*          addressof(const T& v);
    -template <typename T> inline volatile T*       addressof(volatile T& v);
    -template <typename T> inline const volatile T* addressof(const volatile T& v);
    -
    -
    -

    C++ allows programmers to replace the unary operator&() class - member used to get the address of an object. Getting the real address of an - object requires ugly casting tricks to avoid invoking the overloaded operator&(). - Function addressof() provides a wrapper around the necessary - code to make it easy to get an object's real address. -

    -

    The program addressof_test.cpp can be used to - verify that addressof() works as expected.

    -

    Contributed by Brad King based on ideas from discussion with Doug Gregor.

    -

    Example

    -
    -
    #include <boost/utility.hpp>
    -
    -struct useless_type {};
    -class nonaddressable {
    -  useless_type operator&() const;
    -};
    -
    -void f() {
    -  nonaddressable x;
    -  nonaddressable* xp = boost::addressof(x);
    -  // nonaddressable* xpe = &x; /* error */
    -}
    -

    Class template result_of

    The class template result_of helps determine the type of a @@ -631,8 +555,6 @@ BOOST_STATIC_ASSERT((

    Created by Doug Gregor. Contributions from Daniel Walker, Eric Niebler, Michel Morin and others

    -

    Class templates for the Base-from-Member Idiom

    -

    See separate documentation.

    Macro BOOST_BINARY

    The macro BOOST_BINARY is used for the