[parameter] Weird behavior with bools
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; }
At Wed, 25 Aug 2010 22:48:57 -0700, Ryan McConnehey wrote:
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?
Looks like a bug to me. Daniel?
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.
Ditto, looks like a bug. If we don't already have tests for these cases, we should.
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; }
-- Dave Abrahams BoostPro Computing http://www.boostpro.com
On Sat, Aug 28, 2010 at 10:56 PM, Ryan McConnehey
David Abrahams wrote:
Ditto, looks like a bug. If we don't already have tests for these cases, we should.
Thank you for your time in helping me out.
Would you mind posting minimal test cases for these issues to Trac? -- Dave Abrahams BoostPro Computing http://www.boostpro.com
Dave Abrahams wrote:
Would you mind posting minimal test cases for these issues to Trac
I haven't used boost test before, so this might not be correct. Also,
I'm not sure the usefulness of the test that doesn't specify an optional
value. The desired method of extracting the "_name" parameter doesn't
compile. Once it does the test will always work.
Is "Trac" something specific or did you mean "track"? Is the below not
what is needed?
Ryan
#include
AMDG Ryan McConnehey wrote:
Dave Abrahams wrote:
Would you mind posting minimal test cases for these issues to Trac
I haven't used boost test before, so this might not be correct. Also, I'm not sure the usefulness of the test that doesn't specify an optional value. The desired method of extracting the "_name" parameter doesn't compile. Once it does the test will always work. Is "Trac" something specific or did you mean "track"? Is the below not what is needed?
Trac = http://svn.boost.org/trac/boost/ In Christ, Steven Watanabe
Steven Watanabe wrote:
AMDG
Ryan McConnehey wrote:
Dave Abrahams wrote:
Would you mind posting minimal test cases for these issues to Trac
I haven't used boost test before, so this might not be correct. Also, I'm not sure the usefulness of the test that doesn't specify an optional value. The desired method of extracting the "_name" parameter doesn't compile. Once it does the test will always work. Is "Trac" something specific or did you mean "track"? Is the below not what is needed?
Trac = http://svn.boost.org/trac/boost/
In Christ, Steven Watanabe Thanks. I've entered a new ticket for each item.
Ryan
On Mon, Aug 30, 2010 at 1:34 AM, Ryan McConnehey
Steven Watanabe wrote:
AMDG
Ryan McConnehey wrote:
Dave Abrahams wrote:
Would you mind posting minimal test cases for these issues to Trac
I haven't used boost test before, so this might not be correct.
Oh, I'm sorry! There's also no need or expectation that you use Boost.Test; simple assertions will do! -- Dave Abrahams BoostPro Computing http://www.boostpro.com
participants (4)
-
Dave Abrahams
-
David Abrahams
-
Ryan McConnehey
-
Steven Watanabe