Boost logo

Boost Users :

Subject: [Boost-users] [program-options] Line width ignored on add()-ed options_description?
From: Rhys Ulerich (rhys.ulerich_at_[hidden])
Date: 2014-01-13 16:37:42


I've got a "primary" options_description instance to which I add()
other "secondary" options_description instances. I want operator<< to
print the primary and all secondary instances with the primary
instance's line width.

I expect that this should happen automagically because, after
construction, I cannot adjust the private m_line_length member of the
secondary instances through any public means. However, it does not.
A small re-create follows my signature.

In my applications, I do not control the construction of the secondary
instances and so I cannot adjust the secondary instance's
construction-time width setting.

Is this behavior a deliberate design decision? Some minor rework to
options_description::print(...) within src/options_description.cpp
would make it possible.

Thanks,
Rhys

#include <iostream>
#include <boost/program_options.hpp>

  int main()
  {
      static const char lengthy[] = "123456789 123456789 123456789 123456789 "
                                    "123456789 123456789 123456789 123456789 "
                                    "123456789 123456789 123456789 123456789 "
                                    "123456789 123456789 123456789 123456789 "
                                    "123456789 123456789 123456789 123456789 "
                                    "123456789 123456789 123456789 123456789 "
                                    "123456789 123456789 123456789 123456789 ";

      boost::program_options::options_description foo(255); // Linewidth 255
      foo.add_options() ( "foo", lengthy );

      boost::program_options::options_description bar; //
Default line width
      bar.add_options() ( "bar", lengthy );

      // foo should either dictate bar's line width, or...
      // I should be able to change it via a public interface...
      // ... but I seemingly cannot.
      foo.add(bar);

      // Option --foo has a nice long width,
      // but option --bar is truncated.
      std::cout << foo;

  }


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