mirror of
https://github.com/boostorg/utility.git
synced 2025-05-09 15:04:00 +00:00
Expanded base-from-member constructors to 10 arguments; did minor tweaks
[SVN r18791]
This commit is contained in:
parent
20a89040e1
commit
c1c8329403
@ -108,7 +108,13 @@ public:
|
|||||||
};
|
};
|
||||||
</pre></blockquote>
|
</pre></blockquote>
|
||||||
|
|
||||||
<p>Other projects can use similar custom base classes. The technique is basic enough to make a template, with a sample template class in this library. The main template parameter is the type of the enclosed member. The template class has several (explicit) constructor member templates, which implicitly type the constructor arguments and pass them to the member. The template class uses implicit copy construction and assignment, cancelling them if the enclosed member is non-copyable.</p>
|
<p>Other projects can use similar custom base classes. The technique
|
||||||
|
is basic enough to make a template, with a sample template class in
|
||||||
|
this library. The main template parameter is the type of the enclosed
|
||||||
|
member. The template class has several (explicit) constructor member
|
||||||
|
templates, which implicitly type the constructor arguments and pass them
|
||||||
|
to the member. The template class uses implicit copy construction and
|
||||||
|
assignment, cancelling them if the enclosed member is non-copyable.</p>
|
||||||
|
|
||||||
<p>Manually coding a base class may be better if the construction
|
<p>Manually coding a base class may be better if the construction
|
||||||
and/or copying needs are too complex for the supplied template class,
|
and/or copying needs are too complex for the supplied template class,
|
||||||
@ -129,15 +135,21 @@ class boost::base_from_member
|
|||||||
protected:
|
protected:
|
||||||
MemberType member;
|
MemberType member;
|
||||||
|
|
||||||
explicit base_from_member();
|
base_from_member();
|
||||||
|
|
||||||
template< typename T1 >
|
template< typename T1 >
|
||||||
explicit base_from_member( T1 x1 );
|
explicit base_from_member( T1 x1 );
|
||||||
|
|
||||||
|
template< typename T1, typename T2 >
|
||||||
|
base_from_member( T1 x1, T2 x2 );
|
||||||
|
|
||||||
//...
|
//...
|
||||||
|
|
||||||
template< typename T1, typename T2, typename T3 >
|
template< typename T1, typename T2, typename T3, typename T4,
|
||||||
explicit base_from_member( T1 x1, T2 x2, T3 x3 );
|
typename T5, typename T6, typename T7, typename T8, typename T9,
|
||||||
|
typename T10 >
|
||||||
|
base_from_member( T1 x1, T2 x2, T3 x3, T4 x4, T5 x5, T6 x6, T7 x7,
|
||||||
|
T8 x8, T9 x9, T10 x10 );
|
||||||
};
|
};
|
||||||
</pre></blockquote>
|
</pre></blockquote>
|
||||||
|
|
||||||
@ -152,7 +164,7 @@ for later base classes (or itself).</p>
|
|||||||
|
|
||||||
<p>There is a default constructor and several constructor member
|
<p>There is a default constructor and several constructor member
|
||||||
templates. These constructor templates can take as many arguments
|
templates. These constructor templates can take as many arguments
|
||||||
(currently up to three) as possible and pass them to a constructor of
|
(currently up to ten) as possible and pass them to a constructor of
|
||||||
the data member. Since C++ does not allow any way to explicitly state
|
the data member. Since C++ does not allow any way to explicitly state
|
||||||
the template parameters of a templated constructor, make sure that
|
the template parameters of a templated constructor, make sure that
|
||||||
the arguments are already close as possible to the actual type used in
|
the arguments are already close as possible to the actual type used in
|
||||||
@ -329,10 +341,10 @@ with the exact pointer type used in <code>switcher</code>'s constructor.</p>
|
|||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<p>Revised: 22 August 2001</p>
|
<p>Revised: 14 June 2003</p>
|
||||||
|
|
||||||
<p>Copyright © boost.org 2001. Permission to copy, use, modify,
|
<p>Copyright © Daryle Walker 2001, 2003. Permission to copy, use,
|
||||||
sell and distribute this document is granted provided this copyright
|
modify, sell and distribute this document is granted provided this copyright
|
||||||
notice appears in all copies. This document is provided "as
|
notice appears in all copies. This document is provided "as
|
||||||
is" without express or implied warranty, and with no claim as to
|
is" without express or implied warranty, and with no claim as to
|
||||||
its suitability for any purpose.</p>
|
its suitability for any purpose.</p>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Boost test program for base-from-member class templates -----------------//
|
// Boost test program for base-from-member class templates -----------------//
|
||||||
|
|
||||||
// (C) Copyright Daryle Walker 2001. Permission to copy, use, modify, sell
|
// (C) Copyright Daryle Walker 2001, 2003. Permission to copy, use, modify,
|
||||||
// and distribute this software is granted provided this copyright
|
// sell and distribute this software is granted provided this copyright
|
||||||
// notice appears in all copies. This software is provided "as is" without
|
// notice appears in all copies. This software is provided "as is" without
|
||||||
// express or implied warranty, and with no claim as to its suitability for
|
// express or implied warranty, and with no claim as to its suitability for
|
||||||
// any purpose.
|
// any purpose.
|
||||||
@ -9,13 +9,13 @@
|
|||||||
// See http://www.boost.org for most recent version including documentation.
|
// See http://www.boost.org for most recent version including documentation.
|
||||||
|
|
||||||
// Revision History
|
// Revision History
|
||||||
|
// 14 Jun 2003 Adjusted code for Boost.Test changes (Daryle Walker)
|
||||||
// 29 Aug 2001 Initial Version (Daryle Walker)
|
// 29 Aug 2001 Initial Version (Daryle Walker)
|
||||||
|
|
||||||
#define BOOST_INCLUDE_MAIN
|
#include <boost/test/minimal.hpp> // for BOOST_CHECK, main
|
||||||
#include <boost/test/test_tools.hpp> // for BOOST_TEST, main
|
|
||||||
|
|
||||||
#include <boost/config.hpp> // for BOOST_NO_MEMBER_TEMPLATES
|
#include <boost/config.hpp> // for BOOST_NO_MEMBER_TEMPLATES
|
||||||
#include <boost/cstdlib.hpp> // for boost::exit_success
|
#include <boost/cstdlib.hpp> // for boost::exit_success
|
||||||
#include <boost/noncopyable.hpp> // for boost::noncopyable
|
#include <boost/noncopyable.hpp> // for boost::noncopyable
|
||||||
|
|
||||||
#include <boost/utility/base_from_member.hpp> // for boost::base_from_member
|
#include <boost/utility/base_from_member.hpp> // for boost::base_from_member
|
||||||
@ -177,11 +177,11 @@ object_registrar obj_reg;
|
|||||||
int
|
int
|
||||||
test_main( int , char * [] )
|
test_main( int , char * [] )
|
||||||
{
|
{
|
||||||
BOOST_TEST( obj_reg.db_.empty() );
|
BOOST_CHECK( obj_reg.db_.empty() );
|
||||||
BOOST_TEST( obj_reg.defrauders_in_.empty() );
|
BOOST_CHECK( obj_reg.defrauders_in_.empty() );
|
||||||
BOOST_TEST( obj_reg.defrauders_out_.empty() );
|
BOOST_CHECK( obj_reg.defrauders_out_.empty() );
|
||||||
BOOST_TEST( obj_reg.overeager_.empty() );
|
BOOST_CHECK( obj_reg.overeager_.empty() );
|
||||||
BOOST_TEST( obj_reg.overkilled_.empty() );
|
BOOST_CHECK( obj_reg.overkilled_.empty() );
|
||||||
|
|
||||||
// Make a separate block to examine pre- and post-effects
|
// Make a separate block to examine pre- and post-effects
|
||||||
{
|
{
|
||||||
@ -189,20 +189,20 @@ test_main( int , char * [] )
|
|||||||
using std::endl;
|
using std::endl;
|
||||||
|
|
||||||
bad_class bc;
|
bad_class bc;
|
||||||
BOOST_TEST( obj_reg.db_.size() == 3 );
|
BOOST_CHECK( obj_reg.db_.size() == 3 );
|
||||||
BOOST_TEST( obj_reg.defrauders_in_.size() == 1 );
|
BOOST_CHECK( obj_reg.defrauders_in_.size() == 1 );
|
||||||
|
|
||||||
good_class_1 gc1;
|
good_class_1 gc1;
|
||||||
BOOST_TEST( obj_reg.db_.size() == 6 );
|
BOOST_CHECK( obj_reg.db_.size() == 6 );
|
||||||
BOOST_TEST( obj_reg.defrauders_in_.size() == 1 );
|
BOOST_CHECK( obj_reg.defrauders_in_.size() == 1 );
|
||||||
|
|
||||||
good_class_2 gc2;
|
good_class_2 gc2;
|
||||||
BOOST_TEST( obj_reg.db_.size() == 11 );
|
BOOST_CHECK( obj_reg.db_.size() == 11 );
|
||||||
BOOST_TEST( obj_reg.defrauders_in_.size() == 1 );
|
BOOST_CHECK( obj_reg.defrauders_in_.size() == 1 );
|
||||||
|
|
||||||
BOOST_TEST( obj_reg.defrauders_out_.empty() );
|
BOOST_CHECK( obj_reg.defrauders_out_.empty() );
|
||||||
BOOST_TEST( obj_reg.overeager_.empty() );
|
BOOST_CHECK( obj_reg.overeager_.empty() );
|
||||||
BOOST_TEST( obj_reg.overkilled_.empty() );
|
BOOST_CHECK( obj_reg.overkilled_.empty() );
|
||||||
|
|
||||||
// Getting the addresses of the objects ensure
|
// Getting the addresses of the objects ensure
|
||||||
// that they're used, and not optimized away.
|
// that they're used, and not optimized away.
|
||||||
@ -211,11 +211,11 @@ test_main( int , char * [] )
|
|||||||
cout << "Object 'gc2' is at " << &gc2 << '.' << endl;
|
cout << "Object 'gc2' is at " << &gc2 << '.' << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_TEST( obj_reg.db_.empty() );
|
BOOST_CHECK( obj_reg.db_.empty() );
|
||||||
BOOST_TEST( obj_reg.defrauders_in_.size() == 1 );
|
BOOST_CHECK( obj_reg.defrauders_in_.size() == 1 );
|
||||||
BOOST_TEST( obj_reg.defrauders_out_.size() == 1 );
|
BOOST_CHECK( obj_reg.defrauders_out_.size() == 1 );
|
||||||
BOOST_TEST( obj_reg.overeager_.empty() );
|
BOOST_CHECK( obj_reg.overeager_.empty() );
|
||||||
BOOST_TEST( obj_reg.overkilled_.empty() );
|
BOOST_CHECK( obj_reg.overkilled_.empty() );
|
||||||
|
|
||||||
return boost::exit_success;
|
return boost::exit_success;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// boost utility/base_from_member.hpp header file --------------------------//
|
// boost utility/base_from_member.hpp header file --------------------------//
|
||||||
|
|
||||||
// (C) Copyright Daryle Walker 2001. Permission to copy, use, modify, sell
|
// (C) Copyright Daryle Walker 2001, 2003. Permission to copy, use, modify,
|
||||||
// and distribute this software is granted provided this copyright
|
// sell and distribute this software is granted provided this copyright
|
||||||
// notice appears in all copies. This software is provided "as is" without
|
// notice appears in all copies. This software is provided "as is" without
|
||||||
// express or implied warranty, and with no claim as to its suitability for
|
// express or implied warranty, and with no claim as to its suitability for
|
||||||
// any purpose.
|
// any purpose.
|
||||||
@ -32,7 +32,7 @@ class base_from_member
|
|||||||
protected:
|
protected:
|
||||||
MemberType member;
|
MemberType member;
|
||||||
|
|
||||||
explicit base_from_member()
|
base_from_member()
|
||||||
: member()
|
: member()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@ -51,6 +51,48 @@ protected:
|
|||||||
: member( x1, x2, x3 )
|
: member( x1, x2, x3 )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
template< typename T1, typename T2, typename T3, typename T4 >
|
||||||
|
base_from_member( T1 x1, T2 x2, T3 x3, T4 x4 )
|
||||||
|
: member( x1, x2, x3, x4 )
|
||||||
|
{}
|
||||||
|
|
||||||
|
template< typename T1, typename T2, typename T3, typename T4, typename T5 >
|
||||||
|
base_from_member( T1 x1, T2 x2, T3 x3, T4 x4, T5 x5 )
|
||||||
|
: member( x1, x2, x3, x4, x5 )
|
||||||
|
{}
|
||||||
|
|
||||||
|
template< typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||||
|
typename T6 >
|
||||||
|
base_from_member( T1 x1, T2 x2, T3 x3, T4 x4, T5 x5, T6 x6 )
|
||||||
|
: member( x1, x2, x3, x4, x5, x6 )
|
||||||
|
{}
|
||||||
|
|
||||||
|
template< typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||||
|
typename T6, typename T7 >
|
||||||
|
base_from_member( T1 x1, T2 x2, T3 x3, T4 x4, T5 x5, T6 x6, T7 x7 )
|
||||||
|
: member( x1, x2, x3, x4, x5, x6, x7 )
|
||||||
|
{}
|
||||||
|
|
||||||
|
template< typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||||
|
typename T6, typename T7, typename T8 >
|
||||||
|
base_from_member( T1 x1, T2 x2, T3 x3, T4 x4, T5 x5, T6 x6, T7 x7, T8 x8 )
|
||||||
|
: member( x1, x2, x3, x4, x5, x6, x7, x8 )
|
||||||
|
{}
|
||||||
|
|
||||||
|
template< typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||||
|
typename T6, typename T7, typename T8, typename T9 >
|
||||||
|
base_from_member( T1 x1, T2 x2, T3 x3, T4 x4, T5 x5, T6 x6, T7 x7, T8 x8,
|
||||||
|
T9 x9 )
|
||||||
|
: member( x1, x2, x3, x4, x5, x6, x7, x8, x9 )
|
||||||
|
{}
|
||||||
|
|
||||||
|
template< typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||||
|
typename T6, typename T7, typename T8, typename T9, typename T10 >
|
||||||
|
base_from_member( T1 x1, T2 x2, T3 x3, T4 x4, T5 x5, T6 x6, T7 x7, T8 x8,
|
||||||
|
T9 x9, T10 x10 )
|
||||||
|
: member( x1, x2, x3, x4, x5, x6, x7, x8, x9, x10 )
|
||||||
|
{}
|
||||||
|
|
||||||
}; // boost::base_from_member
|
}; // boost::base_from_member
|
||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// Boost utility_fwd.hpp header file ---------------------------------------//
|
// Boost utility_fwd.hpp header file ---------------------------------------//
|
||||||
|
|
||||||
// (C) Copyright boost.org 2001. Permission to copy, use, modify, sell
|
// (C) Copyright boost.org 2001, 2003. Permission to copy, use, modify, sell
|
||||||
// and distribute this software is granted provided this copyright
|
// and distribute this software is granted provided this copyright
|
||||||
// notice appears in all copies. This software is provided "as is" without
|
// notice appears in all copies. This software is provided "as is" without
|
||||||
// express or implied warranty, and with no claim as to its suitability for
|
// express or implied warranty, and with no claim as to its suitability for
|
||||||
@ -22,12 +22,13 @@ template < typename MemberType, int UniqueID = 0 >
|
|||||||
class base_from_member;
|
class base_from_member;
|
||||||
|
|
||||||
|
|
||||||
// From <boost/utility.hpp> ------------------------------------------------//
|
// From <boost/noncopyable.hpp> --------------------------------------------//
|
||||||
|
|
||||||
class noncopyable;
|
class noncopyable;
|
||||||
|
|
||||||
// Also has a few function templates
|
// Also has a few function templates
|
||||||
|
|
||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user