Boost logo

Boost Users :

Subject: Re: [Boost-users] [parameter] Weird behavior with bools
From: Ryan McConnehey (mccorywork_at_[hidden])
Date: 2010-08-29 20:54:24


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 <boost/test/unit_test.hpp>

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
    {}

    int getValue(void) const { return m_name; }
 
private:
  int m_name;
};
 
struct myclass : public myclass_impl
{
    BOOST_PARAMETER_CONSTRUCTOR(
        myclass, (myclass_impl), tag
      , (optional
          (name, (bool), bool(false)))) // no semicolon
};
 
BOOST_AUTO_TEST_CASE( parameter_bool_test )
{
  myclass a0(_name = 15);
  BOOST_CHECK_EQUAL( a0.getValue(), 1 );

  myclass a1;
  BOOST_CHECK_EQUAL( a1.getValue(), 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