Boost logo

Boost Users :

From: StephQ (pelux_at_[hidden])
Date: 2007-12-03 15:06:30


I have the following 3 problems:

1) I can not use BOOST_PARAMETER_MEMBER_FUNCTION (and the const version) inside
a template class.

The following code:

#include <boost/parameter.hpp>

BOOST_PARAMETER_NAME(mu)
BOOST_PARAMETER_NAME(sigma)

template<class T1>
class mah
{
private:
  
  int t1;
  int t2;

public:

  BOOST_PARAMETER_MEMBER_FUNCTION(
    (void), set, tag,
    (optional
      (mu, *, 1)
      (sigma, *, 2)
    )
  )
  {
    t1 = mu;
    t2 = sigma;
  }
};

int main()
{
  mah<int> chissa;

  chissa.set( 2, 1 );
}

Results in (with MSVC, similar error with gcc 3.4 cygwin):

1>c:\develop\essl_alpha\essl\test\parametertest1.cpp(27) :
warning C4346:
'boost::parameter::aux::argument_pack<mah<T1>::
boost_param_params_27set<int>>::type'
: dependent name is not a type
1> prefix with 'typename' to indicate a type
1> c:\develop\essl_alpha\essl\test\parametertest1.cpp(32) :
see reference
to class template instantiation 'mah<T1>' being compiled
1>c:\develop\essl_alpha\essl\test\parametertest1.cpp(27) :
error C2923:
'mah<T1>::boost_param_result_27set' :
'boost::parameter::aux::argument_pack<mah<T1>::
boost_param_params_27set<int>>::type'
is not a valid template type argument for parameter 'Args'
1>c:\develop\essl_alpha\essl\test\parametertest1.cpp(27) :
warning C4346:
'mah<T1>::boost_param_result_27set::type' : dependent name is not a type
1> prefix with 'typename' to indicate a type
1>c:\develop\essl_alpha\essl\test\parametertest1.cpp(27) :
error C2146: syntax
error : missing ';' before identifier 'set'
1>c:\develop\essl_alpha\essl\test\parametertest1.cpp(27) :
error C4430: missing
type specifier - int assumed. Note: C++ does not support default-int
1>c:\develop\essl_alpha\essl\test\parametertest1.cpp(27) :
warning C4183: 'set':
missing return type; assumed to be a member function returning 'int'

2) I would like to create a class template for a "named tuple", something like:

named_tuple<int,double,mu,sigma> n;
// mu, sigma previously declared, maybe BOOST_PARAMETER_NAME?
// should contain two variables of type int, double. Would be really nice if
they are named exactly _mu and _sigma, so I need boost PP or something?

n.set( _mu=1, _sigma=2.0 ); // set internal variables
n.set( _mu=1 );
double x = n.get( _sigma );
n.get( _mu, _sigma ); // This returns a tuple with the internal values.

I think a class like this could be really usefull, and it would be really nice
to see tuples get this extension. IMHO they are very clear from a user point of
view.

The problem (apart from problem 1) is that the macro
BOOST_PARAMETER_MEMBER_FUNCTION does not play nicely if I just put a template
parameter (say N1 of named_tuple<T1,T2,N1,N2>) instead of mu in

BOOST_PARAMETER_MEMBER_FUNCTION(
  (void), set, tag,
  (optional
    (mu, *, 1)
    (sigma, *, 2)
  )

Again I suspect I need boost PP or use directly ArgumentPack.

3) How should I consider the overloading of a BOOST_PARAMETER_MEMBER_FUNCTION?
Is it fine to just write the following?

class mah2 : public mah // mah as before but with no templates.
{
public:

  template<class A1, class A2>
  void set( A1 a1, A2 a2 ) // need to supply defaults here...
  {
    mah<int,int>::set( a1, a2 );
  }
};

As usual any help is extremely appreciated.

Thank you in advance.

Best Regards
StephQ


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net