fix doc example typo
[boost.git] / boost / utility / base_from_member.hpp
blob04aabb59e26ee92a21bfdfe53adb2a28198a4520
1 // boost utility/base_from_member.hpp header file --------------------------//
3 // Copyright 2001, 2003, 2004 Daryle Walker. Use, modification, and
4 // distribution are subject to the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or a copy at
6 // <http://www.boost.org/LICENSE_1_0.txt>.)
8 // See <http://www.boost.org/libs/utility/> for the library's home page.
10 #ifndef BOOST_UTILITY_BASE_FROM_MEMBER_HPP
11 #define BOOST_UTILITY_BASE_FROM_MEMBER_HPP
13 #include <boost/preprocessor/arithmetic/inc.hpp>
14 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
15 #include <boost/preprocessor/repetition/enum_params.hpp>
16 #include <boost/preprocessor/repetition/repeat_from_to.hpp>
19 // Base-from-member arity configuration macro ------------------------------//
21 // The following macro determines how many arguments will be in the largest
22 // constructor template of base_from_member. Constructor templates will be
23 // generated from one argument to this maximum. Code from other files can read
24 // this number if they need to always match the exact maximum base_from_member
25 // uses. The maximum constructor length can be changed by overriding the
26 // #defined constant. Make sure to apply the override, if any, for all source
27 // files during project compiling for consistency.
29 // Contributed by Jonathan Turkanis
31 #ifndef BOOST_BASE_FROM_MEMBER_MAX_ARITY
32 #define BOOST_BASE_FROM_MEMBER_MAX_ARITY 10
33 #endif
36 // An iteration of a constructor template for base_from_member -------------//
38 // A macro that should expand to:
39 // template < typename T1, ..., typename Tn >
40 // base_from_member( T1 x1, ..., Tn xn )
41 // : member( x1, ..., xn )
42 // {}
43 // This macro should only persist within this file.
45 #define BOOST_PRIVATE_CTR_DEF( z, n, data ) \
46 template < BOOST_PP_ENUM_PARAMS(n, typename T) > \
47 explicit base_from_member( BOOST_PP_ENUM_BINARY_PARAMS(n, T, x) ) \
48 : member( BOOST_PP_ENUM_PARAMS(n, x) ) \
49 {} \
50 /**/
53 namespace boost
56 // Base-from-member class template -----------------------------------------//
58 // Helper to initialize a base object so a derived class can use this
59 // object in the initialization of another base class. Used by
60 // Dietmar Kuehl from ideas by Ron Klatcho to solve the problem of a
61 // base class needing to be initialized by a member.
63 // Contributed by Daryle Walker
65 template < typename MemberType, int UniqueID = 0 >
66 class base_from_member
68 protected:
69 MemberType member;
71 base_from_member()
72 : member()
75 BOOST_PP_REPEAT_FROM_TO( 1, BOOST_PP_INC(BOOST_BASE_FROM_MEMBER_MAX_ARITY),
76 BOOST_PRIVATE_CTR_DEF, _ )
78 }; // boost::base_from_member
80 } // namespace boost
83 // Undo any private macros
84 #undef BOOST_PRIVATE_CTR_DEF
87 #endif // BOOST_UTILITY_BASE_FROM_MEMBER_HPP