List2 inherits storage2 to contain the a1 _ and a2 _ members _
[Cpp]
Struct logical_and;
Struct logical_or;
Template <class A1, class A2> class list2: private storage2 <A1, A2>
{
Private:
Typedef storage2 <A1, A2> base_type;
Public:
List2 (A1 a1, A2 a2): base_type (a1, a2 ){}
A1 operator [] (boost: arg <1>) const {return base_type: a1 _;}
A2 operator [] (boost: arg <2>) const {return base_type: a2 _;}
A1 operator [] (boost: arg <1> (*) () const {return base_type: a1 _;}
A2 operator [] (boost: arg <2> (*) () const {return base_type: a2 _;}
Template <class T> T & operator [] (_ bi: value <T> & v) const {return v. get ();}
Template <class T> T const & operator [] (_ bi: value <T> const & v) const {return v. get ();}
Template <class T> T & operator [] (reference_wrapper <T> const & v) const {return v. get ();}
Template <class R, class F, class L> typename result_traits <R, F >:: type operator [] (bind_t <R, F, L> & B) const {return B. eval (* this );}
Template <class R, class F, class L> typename result_traits <R, F >:: type operator [] (bind_t <R, F, L> const & B) const {return B. eval (* this );}
Template <class R, class F, class A> R operator () (type <R>, F & f, A & a, long)
{
Return unwrapper <F >:: unwrap (f, 0) (a [base_type: a1 _], a [base_type: a2 _]);
}
Template <class R, class F, class A> R operator () (type <R>, F const & f, A & a, long) const
{
Return unwrapper <F const>: unwrap (f, 0) (a [base_type: a1 _], a [base_type: a2 _]);
}
Template <class F, class A> void operator () (type <void>, F & f, A & a, int)
{
Unwrapper <F >:: unwrap (f, 0) (a [base_type: a1 _], a [base_type: a2 _]);
}
Template <class F, class A> void operator () (type <void>, F const & f, A & a, int) const
{
Unwrapper <F const>: unwrap (f, 0) (a [base_type: a1 _], a [base_type: a2 _]);
}
Template <class A> bool operator () (type <bool>, logical_and &/* f */, A & a, int)
{
Return a [base_type: a1 _] & a [base_type: a2 _];
}
Template <class A> bool operator () (type <bool>, logical_and const &/* f */, A & a, int) const
{
Return a [base_type: a1 _] & a [base_type: a2 _];
}
Template <class A> bool operator () (type <bool>, logical_or &/* f */, A & a, int)
{
Return a [base_type: a1 _] | a [base_type: a2 _];
}
Template <class A> bool operator () (type <bool>, logical_or const &/* f */, A & a, int) const
{
Return a [base_type: a1 _] | a [base_type: a2 _];
}
Template <class V> void accept (V & v) const
{
Base_type: accept (v );
}
Bool operator = (list2 const & rhs) const
{
Return ref_compare (base_type: a1 _, rhs. a1 _, 0) & ref_compare (base_type: a2 _, rhs. a2 _, 0 );
}
};
Code 1 defines two empty classes, indicating logic and or.
The following four functions are more than list1:
[Cpp]
A1 operator [] (boost: arg <1>) const {return base_type: a1 _;}
A2 operator [] (boost: arg <2>) const {return base_type: a2 _;}
A1 operator [] (boost: arg <1> (*) () const {return base_type: a1 _;}
A2 operator [] (boost: arg <2> (*) () const {return base_type: a2 _;}
Other list3-list9 is similar.
Conclusion: The listN template inherits the storageN template to obtain the ability to save the corresponding number of placeholders. The array operator [] () is provided to obtain these placeholder objects. Because operator () is provided, it is also a function object and the operator ()() the function can be represented by the execution parameter f and pass its own parameter to f.