diff --git a/doc/typeof.qbk b/doc/typeof.qbk index 4b3169f..d396054 100644 --- a/doc/typeof.qbk +++ b/doc/typeof.qbk @@ -1,18 +1,16 @@ -[library Typeof +[library Boost.Typeof [authors [Vertleyb, Arkadiy], [Holt, Peder]] [copyright 2004 2005 Arkadiy Vertleyb, Peder Holt] [license 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 ) ] [last-revision $Date$] ] -[xinclude catalog.xml] - [section:moti Motivation] [c++] @@ -20,7 +18,7 @@ Today many template libraries supply object generators to simplify object creation by utilizing the C++ template argument deduction facility. Consider `std::pair`. In order to instantiate this class template and create a temporary object of this instantiation, -one has to supply both type parameters and value parameters: +one has to supply template parameters, as well as parameters to the constructor: std::pair(5, 3.14159); @@ -42,7 +40,7 @@ It would be nice to deduce the type of the object (on the left) from the express it is initialized with (on the right), but the current C++ syntax does not allow for this. The above example demonstrates the essence of the problem but does not demonstrate its scale. -Many libraries, especially expression template libraries, create objects of really complicated types, +Many libraries, especially expression template libraries, create objects of really complex types, and go a long way to hide this complexity behind object generators. Consider a nit Boost.Lambda functor: _1 > 15 && _2 < 20 @@ -78,7 +76,8 @@ she would have to specify something like this: f = _1 > 15 && _2 < 20; -Not exactly elegant. To solve this problem, the C++ standard committee is considering +Not exactly elegant. To solve this problem (as well as some other problems), +the C++ standard committee is considering a few additions to the standard language, such as `typeof/decltype` and `auto` (see [@http://www.osl.iu.edu/~jajarvi/publications/papers/decltype_n1478.pdf http://www.osl.iu.edu/~jajarvi/publications/papers/decltype_n1478.pdf]). @@ -93,6 +92,10 @@ Much better, but some duplication still exists. The `auto` type solves the rest auto f = _1 > 15 && _2 < 20; +The purpose of the Boost.Typeof library is to provide a library-based solution, +which could be used until the language-based facility is added to the Standard +and becomes widely available. + [endsect] [section:tuto Tutorial] @@ -156,7 +159,7 @@ in a dependent context: } Both `BOOST_TYPEOF` and `BOOST_AUTO` strip top-level qualifiers. -Therefore, to allocate a reference, this has to be defined explicitly: +Therefore, to allocate for example a reference, it has to be specified explicitly: namespace ex5 { @@ -177,7 +180,7 @@ If your define your own type, the Typeof Library cannot handle it unless you let it know about this type. You tell the Typeof Library about a type (or template) by the means of "registering" this type/template. -Any source or header file where types/templates are registered should +Any source or header file where types/templates are registered has to contain the following line before any registration is done: #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP() @@ -265,14 +268,14 @@ The `BOOST_AUTO` macro emulates the proposed `auto` keyword in C++. BOOST_AUTO_TPL(var,expr) [variablelist Arguments -[[var][initialized with expr]] +[[var][a variable to be initialized with the expression]] [[expr][a valid c++ expression]] ] [h4 Remarks] If you want to use `auto` in a template-context, use `BOOST_AUTO_TPL(expr)`, -which takes care of `typename` inside the `auto` expression. +which takes care of the `typename` keyword inside the `auto` expression. [h4 Sample Code] @@ -386,51 +389,6 @@ decreasing this number may help to boost compile-time performance. [endsect] -[section:lval LVALUE_TYPEOF] - -The `BOOST_LVALUE_TYPEOF` macro preserves the L-valueness of an expression. - -[h4 Usage] - - BOOST_LVALUE_TYPEOF(expr) - -[variablelist Arguments -[[expr][a valid c++ expression that has a type]] -] - -[h4 Remarks] - -This macro attempts to emulate the `decltype`. Its rules, however, -are directly built on the rules of binding a reference, and therefore -differ from the ones of real `decltype`: - -[table rules of LVALUE_TYPEOF -[[expr][decltype][LVALUE_TYPEOF]] -[[int i;][int][int&]] -[[const int ci = 0;][const int][const int&]] -[[int& ri = i;][int&][int&]] -[[const int& cri = ci;][const int&][const int&]] -[[int foo();][int][int]] -[[const int foo();][const int][const int&]] -[[int& foo();][int&][int&]] -[[const int& foo();][const int&][const int&]] -[[21][int][compiler-dependent]] -[[int(21)][int][int]] -] - -[h4 Sample Code] - - int& get_value(int& a); - int get_value(const double& a); - - int main() - { - int a=5; - typedef BOOST_LVALUE_TYPEOF(get_value(a)) type; - } - -[endsect] - [section:regtype REGISTER_TYPE] The `BOOST_TYPEOF_REGISTER_TYPE` macro informs the Typeof Library @@ -488,12 +446,12 @@ and template template parameters: * A type template parameter is described by the `(class)` or `(typename)` sequence element * A template parameter of a well-known integral type can be described by -simply supplying its type, like `(unsigned int)`. +simply supplying its type, like (`unsigned int`). The following well-known integral types are supported: - * `[signed/unsigned] char` - * `[unsigned] short` - * `[unsigned] int` - * `[unsigned] long` + * [`signed`/`unsigned`] `char` + * [`unsigned`] `short` + * [`unsigned`] `int` + * [`unsigned`] `long` * `unsigned` * `bool` * `size_t` @@ -578,7 +536,7 @@ but removes the top-level qualifiers, `const&` BOOST_TYPEOF_TPL(expr) [variablelist Arguments -[[expr][a valid c++ expression that can be converted to const T&]] +[[expr][a valid c++ expression that can be bound to const T&]] ] [h4 Remarks] @@ -602,7 +560,7 @@ which takes care of `typename` inside the `typeof` expression. [endsect] -[section:typo TYPEOF_NESTED_TYPEDEF, TYPEOF_NESTED_TYPEDEF_TPL] +[section:typn TYPEOF_NESTED_TYPEDEF, TYPEOF_NESTED_TYPEDEF_TPL] The `TYPEOF_NESTED_TYPEDEF` macro works in much the same way as the 'TYPEOF' macro does, but workarounds several compiler deficiencies. @@ -614,7 +572,7 @@ workarounds several compiler deficiencies. [variablelist Arguments [[name][a valid identifier to nest the typeof operation inside] -[expr][a valid c++ expression that can be converted to const T&]] +[expr][a valid c++ expression that can be bound to const T&]] ] [h4 Remarks] @@ -652,7 +610,7 @@ which takes care of `typename` inside the `typeof` expression. Many compilers support typeof already, most noticeable GCC and Metrowerks. -Igor Chesnokov recently discovered a method that allows to implement `typeof` +Igor Chesnokov discovered a method that allows to implement `typeof` on the VC series of compilers. It uses a bug in the Microsoft compiler that allows a nested class of base to be defined in a class derived from base: @@ -854,15 +812,6 @@ for a given project in order to support `typeof`. [endsect] -[section:comp Compilers] - -The system has been tested with the following compilers: - -* MSVC 6.5/7.0/7.1/8.0; -* GCC 3.4.2 - -[endsect] - [section:limi Limitations] Nested template template parameters are not supported, like: @@ -909,8 +858,10 @@ or in any other way contributed to the library development * Joel de Guzman * Daniel James * Vesa Karvonen +* Andy Little * Paul Mensonides * Alexander Nasonov +* Tobias Schwinger * Martin Wille [endsect]