Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r50353 - trunk/boost/test/utils
From: gennadiy.rozental_at_[hidden]
Date: 2008-12-22 02:53:35


Author: rogeeff
Date: 2008-12-22 02:53:34 EST (Mon, 22 Dec 2008)
New Revision: 50353
URL: http://svn.boost.org/trac/boost/changeset/50353

Log:
added support for parameter erase
Text files modified:
   trunk/boost/test/utils/named_params.hpp | 52 +++++++++++++++++++++++++++++++--------
   1 files changed, 41 insertions(+), 11 deletions(-)

Modified: trunk/boost/test/utils/named_params.hpp
==============================================================================
--- trunk/boost/test/utils/named_params.hpp (original)
+++ trunk/boost/test/utils/named_params.hpp 2008-12-22 02:53:34 EST (Mon, 22 Dec 2008)
@@ -23,6 +23,8 @@
 #include <boost/test/utils/rtti.hpp>
 #include <boost/test/utils/assign_op.hpp>
 
+#include <boost/type_traits/remove_reference.hpp>
+
 #include <boost/test/detail/suppress_warnings.hpp>
 
 //____________________________________________________________________________//
@@ -67,6 +69,10 @@
     operator T() const
     { report_access_to_invalid_parameter(); static T* v = 0; return *v; }
 
+ template<typename T>
+ T any_cast() const
+ { report_access_to_invalid_parameter(); static typename remove_reference<T>::type* v = 0; return *v; }
+
     template<typename Arg1>
     nil operator()( Arg1 const& )
     { report_access_to_invalid_parameter(); return nil(); }
@@ -82,6 +88,10 @@
     // Visitation support
     template<typename Visitor>
     void apply_to( Visitor& V ) const {}
+
+ static nil& inst() { static nil s_inst; return s_inst; }
+private:
+ nil() {}
 };
     
 // ************************************************************************** //
@@ -102,22 +112,29 @@
 // ************************************************************************** //
 
 template<typename NP, typename Rest = nil>
-struct named_parameter_combine : Rest, named_parameter_base<named_parameter_combine<NP,Rest> > {
+struct named_parameter_combine
+: Rest
+, named_parameter_base<named_parameter_combine<NP,Rest> > {
     typedef typename NP::ref_type res_type;
     typedef named_parameter_combine<NP,Rest> self_type;
 
     // Constructor
     named_parameter_combine( NP const& np, Rest const& r )
- : Rest( r ), m_param( np ) {}
+ : Rest( r )
+ , m_param( np )
+ {}
 
     // Access methods
     res_type operator[]( keyword<typename NP::id,true> kw ) const { return m_param[kw]; }
     res_type operator[]( keyword<typename NP::id,false> kw ) const { return m_param[kw]; }
     using Rest::operator[];
 
- bool has( keyword<typename NP::id,false> ) const { return true; }
+ bool has( keyword<typename NP::id,false> kw ) const { return m_param.has( kw ); }
     using Rest::has;
 
+ void erase( keyword<typename NP::id,false> kw ) const { m_param.erase( kw ); }
+ using Rest::erase;
+
 #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206))
     template<typename NP>
     named_parameter_combine<NP,self_type> operator,( NP const& np ) const
@@ -142,30 +159,42 @@
 } // namespace nfp_detail
 
 // ************************************************************************** //
-// ************** named_parameter_combine ************** //
+// ************** named_parameter ************** //
 // ************************************************************************** //
 
 template<typename T, typename unique_id,typename ReferenceType=T&>
 struct named_parameter
 : nfp_detail::named_parameter_base<named_parameter<T, unique_id,ReferenceType> >
 {
+ typedef nfp_detail::nil nil_t;
     typedef T data_type;
     typedef ReferenceType ref_type;
     typedef unique_id id;
 
     // Constructor
- explicit named_parameter( ref_type v ) : m_value( v ) {}
+ explicit named_parameter( ref_type v )
+ : m_value( v )
+ , m_erased( false )
+ {}
+ named_parameter( named_parameter const& np )
+ : m_value( np.m_value )
+ , m_erased( np.m_erased )
+ {}
 
     // Access methods
- ref_type operator[]( keyword<unique_id,true> ) const { return m_value; }
- ref_type operator[]( keyword<unique_id,false> ) const { return m_value; }
+ ref_type operator[]( keyword<unique_id,true> ) const { return m_erased ? nil_t::inst().any_cast<ref_type>() : m_value; }
+ ref_type operator[]( keyword<unique_id,false> ) const { return m_erased ? nil_t::inst().any_cast<ref_type>() : m_value; }
     template<typename UnknownId>
- nfp_detail::nil operator[]( keyword<UnknownId,false> ) const { return nfp_detail::nil(); }
+ nil_t operator[]( keyword<UnknownId,false> ) const { return nil_t::inst(); }
 
- bool has( keyword<unique_id,false> ) const { return true; }
+ bool has( keyword<unique_id,false> ) const { return !m_erased; }
     template<typename UnknownId>
     bool has( keyword<UnknownId,false> ) const { return false; }
 
+ void erase( keyword<unique_id,false> ) const { m_erased = true; }
+ template<typename UnknownId>
+ void erase( keyword<UnknownId,false> ) const {}
+
     // Visitation support
     template<typename Visitor>
     void apply_to( Visitor& V ) const
@@ -176,6 +205,7 @@
 private:
     // Data members
     ref_type m_value;
+ mutable bool m_erased;
 };
 
 //____________________________________________________________________________//
@@ -186,7 +216,7 @@
 
 namespace nfp_detail {
 typedef named_parameter<char, struct no_params_type_t,char> no_params_type;
-}
+} // namespace nfp_detail
 
 namespace {
 nfp_detail::no_params_type no_params( '\0' );
@@ -269,7 +299,7 @@
 {
     using namespace unit_test;
 
- assign_op( target, src, 0 );
+ assign_op( target, src, (int)0 );
 }
 
 //____________________________________________________________________________//


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk