Boost logo

Boost Users :

Subject: [Boost-users] [parameter] Weird behavior with bools
From: Ryan McConnehey (mccorywork_at_[hidden])
Date: 2010-08-26 01:48:57


I'm new to the parameter library and started with a simple example to
get my feet wet. The first problem I'm having is with type
restriction. The "name" variable is being restricted to a boolean
type. This doesn't seem to be enforced since I can pass this variable a
value of 15 and get this same value out. Currently my output has "name
= 15" and I expected the output to be "name = 1". Did I not correctly
enforce the type?

The second problem is with the default value of my variable. I thought
if the variable wasn't used then the third parameter, in the
declaration, is used for instantiation of that variable. I thought that
meant I could do this "m_name(args[_name])". The compiler gives an
error saying the operator[] can't deduce the arguments. What did I not
do that would allow this behavior.

Thank you for your time in helping me out.

Ryan

BOOST_PARAMETER_NAME(name)

struct myclass_impl
{
    template <class ArgumentPack>
    myclass_impl(ArgumentPack const& args)
    : m_name(args[_name | false])
    //: m_name(args[_name]) //gives a compile error
    {
      std::cout << "name = " << m_name << std::endl;
    }

private:
  int m_name;
};

struct myclass : public myclass_impl
{
    BOOST_PARAMETER_CONSTRUCTOR(
        myclass, (myclass_impl), tag
      , (optional
          (name, (bool), bool(false)))) // no semicolon
};

int main(int argc, char* argv[])
{
  myclass x(_name = 15);

return 0;
}


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